use of java.beans.PropertyDescriptor in project liquibase by liquibase.
the class HeaderColumnNameMappingStrategy method loadDescriptorMap.
/**
* builds a map of property descriptors for the Bean.
* @return - map of property descriptors
* @throws IntrospectionException - thrown on error getting information about the bean.
*/
protected Map<String, PropertyDescriptor> loadDescriptorMap() throws IntrospectionException {
Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>();
PropertyDescriptor[] descriptors;
descriptors = loadDescriptors(getType());
for (PropertyDescriptor descriptor : descriptors) {
map.put(descriptor.getName().toUpperCase().trim(), descriptor);
}
return map;
}
use of java.beans.PropertyDescriptor in project camel by apache.
the class SObjectTree method updateGeneralObjectId.
boolean updateGeneralObjectId(final String id, final Object object) {
final Class<? extends Object> clazz = object.getClass();
final BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(clazz);
} catch (final IntrospectionException e) {
throw new IllegalStateException(e);
}
final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
final Optional<PropertyDescriptor> maybeIdProperty = Arrays.stream(propertyDescriptors).filter(pd -> "id".equals(pd.getName())).findFirst();
if (maybeIdProperty.isPresent()) {
final Method readMethod = maybeIdProperty.get().getReadMethod();
try {
readMethod.invoke(object, id);
return true;
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
}
return false;
}
use of java.beans.PropertyDescriptor in project translationstudio8 by heartsome.
the class ReflectiveColumnPropertyAccessor method getPropertyDescriptor.
private PropertyDescriptor getPropertyDescriptor(R rowObj, int columnIndex) throws IntrospectionException {
if (propertyDescriptorMap == null) {
propertyDescriptorMap = new HashMap<String, PropertyDescriptor>();
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(rowObj.getClass()).getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
propertyDescriptorMap.put(propertyDescriptor.getName(), propertyDescriptor);
}
}
final String propertyName = propertyNames.get(columnIndex);
return propertyDescriptorMap.get(propertyName);
}
use of java.beans.PropertyDescriptor in project spring-framework by spring-projects.
the class ExtendedBeanInfo method findExistingPropertyDescriptor.
private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) {
for (PropertyDescriptor pd : this.propertyDescriptors) {
final Class<?> candidateType;
final String candidateName = pd.getName();
if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
candidateType = ipd.getIndexedPropertyType();
if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) {
return pd;
}
} else {
candidateType = pd.getPropertyType();
if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) {
return pd;
}
}
}
return null;
}
use of java.beans.PropertyDescriptor in project spring-framework by spring-projects.
the class BeanUtilsTests method testSPR6063.
@Test
public void testSPR6063() {
PropertyDescriptor[] descrs = BeanUtils.getPropertyDescriptors(Bean.class);
PropertyDescriptor keyDescr = BeanUtils.getPropertyDescriptor(Bean.class, "value");
assertEquals(String.class, keyDescr.getPropertyType());
for (PropertyDescriptor propertyDescriptor : descrs) {
if (propertyDescriptor.getName().equals(keyDescr.getName())) {
assertEquals(propertyDescriptor.getName() + " has unexpected type", keyDescr.getPropertyType(), propertyDescriptor.getPropertyType());
}
}
}
Aggregations