Search in sources :

Example 31 with PropertyDescriptor

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;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap)

Example 32 with PropertyDescriptor

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;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) XStreamImplicit(com.thoughtworks.xstream.annotations.XStreamImplicit) Arrays(java.util.Arrays) XStreamAlias(com.thoughtworks.xstream.annotations.XStreamAlias) XStreamOmitField(com.thoughtworks.xstream.annotations.XStreamOmitField) Introspector(java.beans.Introspector) AbstractDescribedSObjectBase(org.apache.camel.component.salesforce.api.dto.AbstractDescribedSObjectBase) BeanInfo(java.beans.BeanInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) StreamSupport(java.util.stream.StreamSupport) RestError(org.apache.camel.component.salesforce.api.dto.RestError) Method(java.lang.reflect.Method) AbstractSObjectBase(org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase) Set(java.util.Set) Collectors(java.util.stream.Collectors) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) PropertyDescriptor(java.beans.PropertyDescriptor) Optional(java.util.Optional) ObjectHelper(org.apache.camel.util.ObjectHelper) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 33 with PropertyDescriptor

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);
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor)

Example 34 with PropertyDescriptor

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;
}
Also used : IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 35 with PropertyDescriptor

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());
        }
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Test(org.junit.Test)

Aggregations

PropertyDescriptor (java.beans.PropertyDescriptor)841 Method (java.lang.reflect.Method)400 BeanInfo (java.beans.BeanInfo)342 IntrospectionException (java.beans.IntrospectionException)191 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)171 SimpleBeanInfo (java.beans.SimpleBeanInfo)142 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)141 InvocationTargetException (java.lang.reflect.InvocationTargetException)109 ArrayList (java.util.ArrayList)90 HashMap (java.util.HashMap)66 Field (java.lang.reflect.Field)60 Map (java.util.Map)52 Test (org.junit.Test)39 IOException (java.io.IOException)35 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)34 List (java.util.List)33 Type (java.lang.reflect.Type)21 HashSet (java.util.HashSet)21 Set (java.util.Set)20 LinkedHashMap (java.util.LinkedHashMap)19