List of usage examples for org.springframework.beans BeanUtils findPropertyType
public static Class<?> findPropertyType(String propertyName, @Nullable Class<?>... beanClasses)
From source file:com.trigonic.utils.spring.cmdline.OptionPropertyHandler.java
public OptionPropertyHandler(Option option, PropertyDescriptor property, Class<?> beanClass) { super(option, property.getName(), BeanUtils.findPropertyType(property.getName(), new Class[] { beanClass })); }
From source file:com.trigonic.utils.spring.cmdline.OperandPropertyHandler.java
public OperandPropertyHandler(Operand operand, PropertyDescriptor property, Class<?> beanClass) { super(operand, property.getName(), BeanUtils.findPropertyType(property.getName(), new Class[] { beanClass })); }
From source file:com.expressui.core.util.BeanPropertyType.java
private static BeanPropertyType getBeanPropertyTypeImpl(Class clazz, String propertyPath) { String[] properties = propertyPath.split("\\."); Class containingType;//from w w w. j a v a 2 s . co m Class currentPropertyType = clazz; BeanPropertyType beanPropertyType = null; for (String property : properties) { Class propertyType = BeanUtils.findPropertyType(property, new Class[] { currentPropertyType }); Assert.PROGRAMMING.isTrue(propertyType != null && !propertyType.equals(Object.class), "Invalid property path: " + clazz + "." + propertyPath); Class propertyPathType; Class collectionValueType = null; if (Collection.class.isAssignableFrom(propertyType)) { collectionValueType = ReflectionUtil.getCollectionValueType(currentPropertyType, property); propertyPathType = collectionValueType; } else { propertyPathType = propertyType; } containingType = currentPropertyType; currentPropertyType = propertyPathType; beanPropertyType = new BeanPropertyType(beanPropertyType, property, propertyType, containingType, collectionValueType); } return beanPropertyType; }
From source file:org.iff.infra.util.spring.script.ScriptFactoryPostProcessor.java
/** * Create a config interface for the given bean definition, defining setter * methods for the defined property values as well as an init method and * a destroy method (if defined)./*from www .ja v a 2s .c o m*/ * <p>This implementation creates the interface via CGLIB's InterfaceMaker, * determining the property types from the given interfaces (as far as possible). * @param bd the bean definition (property values etc) to create a * config interface for * @param interfaces the interfaces to check against (might define * getters corresponding to the setters we're supposed to generate) * @return the config interface * @see org.springframework.cglib.proxy.InterfaceMaker * @see org.springframework.beans.BeanUtils#findPropertyType */ protected Class<?> createConfigInterface(BeanDefinition bd, Class<?>[] interfaces) { InterfaceMaker maker = new InterfaceMaker(); PropertyValue[] pvs = bd.getPropertyValues().getPropertyValues(); for (PropertyValue pv : pvs) { String propertyName = pv.getName(); Class<?> propertyType = BeanUtils.findPropertyType(propertyName, interfaces); String setterName = "set" + StringUtils.capitalize(propertyName); Signature signature = new Signature(setterName, Type.VOID_TYPE, new Type[] { Type.getType(propertyType) }); maker.add(signature, new Type[0]); } if (bd instanceof AbstractBeanDefinition) { AbstractBeanDefinition abd = (AbstractBeanDefinition) bd; if (abd.getInitMethodName() != null) { Signature signature = new Signature(abd.getInitMethodName(), Type.VOID_TYPE, new Type[0]); maker.add(signature, new Type[0]); } if (abd.getDestroyMethodName() != null) { Signature signature = new Signature(abd.getDestroyMethodName(), Type.VOID_TYPE, new Type[0]); maker.add(signature, new Type[0]); } } return maker.create(); }
From source file:org.gvnix.web.datatables.util.DatatablesUtils.java
/** * prepares order part for a query of findByCriteria * //www . j a va 2 s.c om * @param entity * @param orderByAssociations * @param datatablesCriterias * @param associationMap * @return */ @SuppressWarnings("unchecked") private static <E extends Comparable<?>, T> List<OrderSpecifier<?>> prepareQueryOrder(PathBuilder<T> entity, Map<String, List<String>> orderByAssociations, DatatablesCriterias datatablesCriterias, Map<String, PathBuilder<?>> associationMap) { List<OrderSpecifier<?>> orderSpecifiersList = new ArrayList<OrderSpecifier<?>>(); if (datatablesCriterias.hasOneSortedColumn()) { LOGGER.debug("Preparing order for entity {}", entity.getType()); OrderSpecifier<?> queryOrder; for (ColumnDef column : datatablesCriterias.getSortingColumnDefs()) { // If column is not sortable, don't add it to order by clauses if (!column.isSortable()) { continue; } // If no sort direction provided, don't add this column to // order by clauses if (column.getSortDirection() == null) { LOGGER.debug("Column {} ignored: not sortDirection", column.getName()); continue; } // Convert Datatables sort direction to Querydsl order Order order = Order.DESC; if (column.getSortDirection() == SortDirection.ASC) { order = Order.ASC; } // Entity field name and type. Type must extend Comparable // interface String fieldName = unescapeDot(column.getName()); LOGGER.trace("Adding column {} {}...", fieldName, order); Class<E> fieldType = (Class<E>) QuerydslUtils.getFieldType(fieldName, entity); List<String> attributes = orderByAssociations.get(fieldName); try { // If column is an association and there are given // order by attributes, add those attributes to ORDER BY // clauses if (attributes != null && attributes.size() > 0) { PathBuilder<?> associationPath = associationMap.get(fieldName); List<String> associationFields = orderByAssociations.get(fieldName); for (String associationFieldName : associationFields) { // Get associated entity field type Class<E> associationFieldType = (Class<E>) BeanUtils.findPropertyType( associationFieldName, ArrayUtils.<Class<?>>toArray(fieldType)); queryOrder = QuerydslUtils.createOrderSpecifier(associationPath, associationFieldName, associationFieldType, order); orderSpecifiersList.add(queryOrder); LOGGER.trace("Added order: {}", queryOrder); } } // Otherwise column is an entity property else { queryOrder = QuerydslUtils.createOrderSpecifier(entity, fieldName, fieldType, order); orderSpecifiersList.add(queryOrder); LOGGER.trace("Added order: {}", queryOrder); } } catch (ClassCastException ex) { // Do nothing, on class cast exception order specifier will // be null LOGGER.debug("CastException preparing order for entity {}", entity.getType(), ex); continue; } catch (Exception ex) { LOGGER.warn("Exception preparing order for entity {}", entity.getType(), ex); continue; } } } return orderSpecifiersList; }
From source file:org.gvnix.web.datatables.util.QuerydslUtils.java
/** * Obtains the class type of the property named as {@code fieldName} of the * entity.// w w w.j a v a 2 s . c o m * * @param fieldName the field name. * @param entity the entity with a property named as {@code fieldName} * @return the class type */ public static <T> Class<?> getFieldType1(String fieldName, PathBuilder<T> entity) { Class<?> entityType = entity.getType(); String fieldNameToFindType = fieldName; // Makes the array of classes to find fieldName agains them Class<?>[] classArray = ArrayUtils.<Class<?>>toArray(entityType); if (fieldName.contains(SEPARATOR_FIELDS)) { String[] fieldNameSplitted = StringUtils.split(fieldName, SEPARATOR_FIELDS); for (int i = 0; i < fieldNameSplitted.length - 1; i++) { Class<?> fieldType = BeanUtils.findPropertyType(fieldNameSplitted[i], ArrayUtils.<Class<?>>toArray(entityType)); classArray = ArrayUtils.add(classArray, fieldType); entityType = fieldType; } fieldNameToFindType = fieldNameSplitted[fieldNameSplitted.length - 1]; } return BeanUtils.findPropertyType(fieldNameToFindType, classArray); }
From source file:org.gvnix.web.datatables.util.impl.DatatablesUtilsBeanImpl.java
/** * prepares order part for a query of findByCriteria * //from w w w.ja v a 2 s .co m * @param entity * @param orderByAssociations * @param datatablesCriterias * @param associationMap * @return */ @SuppressWarnings("unchecked") private <E extends Comparable<?>, T> List<OrderSpecifier<?>> prepareQueryOrder(PathBuilder<T> entity, Map<String, List<String>> orderByAssociations, DatatablesCriterias datatablesCriterias, Map<String, PathBuilder<?>> associationMap) { List<OrderSpecifier<?>> orderSpecifiersList = new ArrayList<OrderSpecifier<?>>(); if (datatablesCriterias.hasOneSortedColumn()) { LOGGER.debug("Preparing order for entity {}", entity.getType()); OrderSpecifier<?> queryOrder; for (ColumnDef column : datatablesCriterias.getSortingColumnDefs()) { // If column is not sortable, don't add it to order by clauses if (!column.isSortable()) { continue; } // If no sort direction provided, don't add this column to // order by clauses if (column.getSortDirection() == null) { LOGGER.debug("Column {} ignored: not sortDirection", column.getName()); continue; } // Convert Datatables sort direction to Querydsl order Order order = Order.DESC; if (column.getSortDirection() == SortDirection.ASC) { order = Order.ASC; } // Entity field name and type. Type must extend Comparable // interface String fieldName = unescapeDot(column.getName()); LOGGER.trace("Adding column {} {}...", fieldName, order); Class<E> fieldType = (Class<E>) querydslUtilsBean.getFieldType(fieldName, entity); List<String> attributes = orderByAssociations.get(fieldName); try { // If column is an association and there are given // order by attributes, add those attributes to ORDER BY // clauses if (attributes != null && attributes.size() > 0) { PathBuilder<?> associationPath = associationMap.get(fieldName); List<String> associationFields = orderByAssociations.get(fieldName); for (String associationFieldName : associationFields) { // Get associated entity field type Class<E> associationFieldType = (Class<E>) BeanUtils.findPropertyType( associationFieldName, ArrayUtils.<Class<?>>toArray(fieldType)); queryOrder = querydslUtilsBean.createOrderSpecifier(associationPath, associationFieldName, associationFieldType, order); orderSpecifiersList.add(queryOrder); LOGGER.trace("Added order: {}", queryOrder); } } // Otherwise column is an entity property else { queryOrder = querydslUtilsBean.createOrderSpecifier(entity, fieldName, fieldType, order); orderSpecifiersList.add(queryOrder); LOGGER.trace("Added order: {}", queryOrder); } } catch (ClassCastException ex) { // Do nothing, on class cast exception order specifier will // be null LOGGER.debug("CastException preparing order for entity {}", entity.getType(), ex); continue; } catch (Exception ex) { LOGGER.warn("Exception preparing order for entity {}", entity.getType(), ex); continue; } } } return orderSpecifiersList; }
From source file:org.springframework.scripting.support.ScriptFactoryPostProcessor.java
/** * Create a config interface for the given bean definition, defining setter * methods for the defined property values as well as an init method and * a destroy method (if defined).// w w w.j a v a 2s . c o m * <p>This implementation creates the interface via CGLIB's InterfaceMaker, * determining the property types from the given interfaces (as far as possible). * @param bd the bean definition (property values etc) to create a * config interface for * @param interfaces the interfaces to check against (might define * getters corresponding to the setters we're supposed to generate) * @return the config interface * @see org.springframework.cglib.proxy.InterfaceMaker * @see org.springframework.beans.BeanUtils#findPropertyType */ protected Class<?> createConfigInterface(BeanDefinition bd, @Nullable Class<?>[] interfaces) { InterfaceMaker maker = new InterfaceMaker(); PropertyValue[] pvs = bd.getPropertyValues().getPropertyValues(); for (PropertyValue pv : pvs) { String propertyName = pv.getName(); Class<?> propertyType = BeanUtils.findPropertyType(propertyName, interfaces); String setterName = "set" + StringUtils.capitalize(propertyName); Signature signature = new Signature(setterName, Type.VOID_TYPE, new Type[] { Type.getType(propertyType) }); maker.add(signature, new Type[0]); } if (bd instanceof AbstractBeanDefinition) { AbstractBeanDefinition abd = (AbstractBeanDefinition) bd; if (abd.getInitMethodName() != null) { Signature signature = new Signature(abd.getInitMethodName(), Type.VOID_TYPE, new Type[0]); maker.add(signature, new Type[0]); } if (StringUtils.hasText(abd.getDestroyMethodName())) { Signature signature = new Signature(abd.getDestroyMethodName(), Type.VOID_TYPE, new Type[0]); maker.add(signature, new Type[0]); } } return maker.create(); }