Example usage for java.beans PropertyDescriptor getPropertyType

List of usage examples for java.beans PropertyDescriptor getPropertyType

Introduction

In this page you can find the example usage for java.beans PropertyDescriptor getPropertyType.

Prototype

public synchronized Class<?> getPropertyType() 

Source Link

Document

Returns the Java type info for the property.

Usage

From source file:com.lingxiang2014.template.directive.BaseDirective.java

protected List<Filter> getFilters(Map<String, TemplateModel> params, Class<?> type, String... ignoreProperties)
        throws TemplateModelException {
    List<Filter> filters = new ArrayList<Filter>();
    PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type);
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        String propertyName = propertyDescriptor.getName();
        Class<?> propertyType = propertyDescriptor.getPropertyType();
        if (!ArrayUtils.contains(ignoreProperties, propertyName) && params.containsKey(propertyName)) {
            Object value = FreemarkerUtils.getParameter(propertyName, propertyType, params);
            filters.add(Filter.eq(propertyName, value));
        }/*w  ww . j  a v a  2 s .  c om*/
    }
    return filters;
}

From source file:org.mule.module.netsuite.api.model.expression.filter.FilterExpressionBuilder.java

private Object addAttribute(String attributeName, SearchRecord attributeGroup) throws Exception {
    PropertyDescriptor descriptor = newDescriptor(attributeName, attributeGroup);
    Object attributeObject = descriptor.getPropertyType().newInstance();
    descriptor.getWriteMethod().invoke(attributeGroup, attributeObject);
    return attributeObject;

}

From source file:gr.abiss.calipso.uischema.serializer.UiSchemaSerializer.java

private String getDataType(Class domainClass, PropertyDescriptor descriptor, String name) {
    return fieldTypes.get(descriptor.getPropertyType().getSimpleName());
}

From source file:org.archive.spring.ConfigPathConfigurer.java

/**
 * Find any ConfigPath properties in the passed bean; ensure that
 * if they have a null 'base', that is replaced with the job home
 * directory. Also, remember all ConfigPaths so fixed-up for later
 * reference. /*from   w  ww .  ja v  a  2  s. c om*/
 * 
 * @param bean
 * @param beanName
 * @return Same bean as passed in, fixed as necessary
 */
protected Object fixupPaths(Object bean, String beanName) {
    BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
    for (PropertyDescriptor d : wrapper.getPropertyDescriptors()) {
        if (d.getPropertyType().isAssignableFrom(ConfigPath.class)
                || d.getPropertyType().isAssignableFrom(ConfigFile.class)) {
            Object value = wrapper.getPropertyValue(d.getName());
            if (value != null && value instanceof ConfigPath) {
                String patchName = beanName + "." + d.getName();
                fixupConfigPath((ConfigPath) value, patchName);
            }
        } else if (Iterable.class.isAssignableFrom(d.getPropertyType())) {
            Iterable<?> iterable = (Iterable<?>) wrapper.getPropertyValue(d.getName());
            if (iterable != null) {
                int i = 0;
                for (Object candidate : iterable) {
                    if (candidate != null && candidate instanceof ConfigPath) {
                        String patchName = beanName + "." + d.getName() + "[" + i + "]";
                        fixupConfigPath((ConfigPath) candidate, patchName);
                    }
                    i++;
                }
            }
        }
    }
    return bean;
}

From source file:org.apache.tiles.evaluator.el.TilesContextELResolver.java

/**
 * Collects bean infos from a class and filling a list.
 *
 * @param clazz The class to be inspected.
 * @param list The list to fill.// www. j  a  v a2  s .com
 * @param properties The properties set to be filled.
 * @since 2.1.0
 */
protected void collectBeanInfo(Class<?> clazz, List<FeatureDescriptor> list, Set<String> properties) {
    BeanInfo info = null;
    try {
        info = Introspector.getBeanInfo(clazz);
    } catch (Exception ex) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot inspect class " + clazz, ex);
        }
    }
    if (info == null) {
        return;
    }
    for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
        pd.setValue("type", pd.getPropertyType());
        pd.setValue("resolvableAtDesignTime", Boolean.TRUE);
        list.add(pd);
        properties.add(pd.getName());
    }
}

From source file:grails.util.GrailsClassUtils.java

/**
 * Retrieves all the properties of the given class which are assignable to the given type
 *
 * @param clazz             The class to retrieve the properties from
 * @param propertySuperType The type of the properties you wish to retrieve
 * @return An array of PropertyDescriptor instances
 *///from   w  w  w. j  ava 2s  .  com
public static PropertyDescriptor[] getPropertiesAssignableToType(Class<?> clazz, Class<?> propertySuperType) {
    if (clazz == null || propertySuperType == null)
        return new PropertyDescriptor[0];

    Set<PropertyDescriptor> properties = new HashSet<PropertyDescriptor>();
    PropertyDescriptor descriptor = null;
    try {
        PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(clazz);
        for (int i = 0; i < descriptors.length; i++) {
            descriptor = descriptors[i];
            Class<?> currentPropertyType = descriptor.getPropertyType();
            if (propertySuperType.isAssignableFrom(descriptor.getPropertyType())) {
                properties.add(descriptor);
            }
        }
    } catch (Exception e) {
        if (descriptor == null) {
            LOG.error(String.format("Got exception while checking property descriptors for class %s",
                    clazz.getName()), e);
        } else {
            LOG.error(String.format(
                    "Got exception while checking PropertyDescriptor.propertyType for field %s.%s",
                    clazz.getName(), descriptor.getName()), e);
        }
        return new PropertyDescriptor[0];
    }
    return properties.toArray(new PropertyDescriptor[properties.size()]);
}

From source file:org.openehr.adl.rm.RmBeanReflector.java

private Class<?> extractGenericType(Class<?> beanClass, PropertyDescriptor pd)
        throws ReflectiveOperationException {
    checkArgument(List.class.isAssignableFrom(pd.getPropertyType()));

    Field field = getField(beanClass, pd);
    ParameterizedType stringListType = (ParameterizedType) field.getGenericType();
    return (Class<?>) stringListType.getActualTypeArguments()[0];
}

From source file:grails.util.GrailsClassUtils.java

/**
 * Retrieves all the properties of the given class for the given type
 *
 * @param clazz The class to retrieve the properties from
 * @param propertyType The type of the properties you wish to retrieve
 *
 * @return An array of PropertyDescriptor instances
 *///from ww  w .  j a va2  s  . c  om
public static PropertyDescriptor[] getPropertiesOfType(Class<?> clazz, Class<?> propertyType) {
    if (clazz == null || propertyType == null) {
        return new PropertyDescriptor[0];
    }

    Set<PropertyDescriptor> properties = new HashSet<PropertyDescriptor>();
    PropertyDescriptor descriptor = null;
    try {
        PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(clazz);
        for (int i = 0; i < descriptors.length; i++) {
            descriptor = descriptors[i];
            Class<?> currentPropertyType = descriptor.getPropertyType();
            if (isTypeInstanceOfPropertyType(propertyType, currentPropertyType)) {
                properties.add(descriptor);
            }
        }
    } catch (Exception e) {
        if (descriptor == null) {
            LOG.error(String.format("Got exception while checking property descriptors for class %s",
                    clazz.getName()), e);
        } else {
            LOG.error(String.format(
                    "Got exception while checking PropertyDescriptor.propertyType for field %s.%s",
                    clazz.getName(), descriptor.getName()), e);
        }
        // if there are any errors in instantiating just return null for the moment
        return new PropertyDescriptor[0];
    }
    return properties.toArray(new PropertyDescriptor[properties.size()]);
}

From source file:org.openehr.adl.rm.RmBeanReflector.java

private Field getField(Class<?> beanClass, PropertyDescriptor pd) throws ReflectiveOperationException {
    final Method readMethod;
    if (Boolean.class == pd.getPropertyType()) {
        readMethod = beanClass.getMethod("is" + StringUtils.capitalize(pd.getName()));
    } else {//from  ww w  .  j a v a 2s  .c  o m
        readMethod = pd.getReadMethod();
    }
    Class<?> declaringClass = readMethod.getDeclaringClass();
    return declaringClass.getDeclaredField(pd.getName());

}

From source file:egovframework.com.ext.ldapumt.service.impl.ObjectMapper.java

/**
 * ContextAdapter?  ? vo .//w w  w .  ja  va2s  . c om
 */
public Object mapFromContext(Object arg0) throws NamingException {
    DirContextAdapter adapter = (DirContextAdapter) arg0;
    Attributes attrs = adapter.getAttributes();

    LdapObject vo = null;

    try {
        vo = (LdapObject) type.newInstance();
    } catch (Exception e2) {
        throw new RuntimeException(e2);
    }

    vo.setDn(adapter.getDn().toString());

    BeanInfo beanInfo;
    try {
        beanInfo = Introspector.getBeanInfo(type);
    } catch (IntrospectionException e1) {
        throw new RuntimeException(e1);
    }

    PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();

    for (PropertyDescriptor descriptor : propertyDescriptors) {
        if (attrs.get(descriptor.getName()) != null)
            try {
                Class<?> o = descriptor.getPropertyType();
                if (o == int.class)
                    PropertyUtils.setProperty(vo, descriptor.getName(),
                            Integer.valueOf((String) attrs.get(descriptor.getName()).get()));
                if (o == String.class)
                    PropertyUtils.setProperty(vo, descriptor.getName(),
                            (String) attrs.get(descriptor.getName()).get());
                if (o == Boolean.class)
                    PropertyUtils.setProperty(vo, descriptor.getName(),
                            ((String) attrs.get(descriptor.getName()).get()).equals("Y"));

            } catch (Exception e) {
                throw new RuntimeException(e);
            }
    }

    return vo;
}