List of usage examples for java.beans PropertyDescriptor getName
public String getName()
From source file:ar.com.fdvs.dj.domain.builders.ReflectiveReportBuilder.java
/** * Adds columns for the specified properties. * @param _properties the array of <code>PropertyDescriptor</code>s to be added. * @throws ColumnBuilderException if an error occurs. * @throws ClassNotFoundException if an error occurs. *//*from ww w .j a v a 2s . com*/ private void addProperties(final PropertyDescriptor[] _properties) throws ColumnBuilderException, ClassNotFoundException { for (int i = 0; i < _properties.length; i++) { final PropertyDescriptor property = _properties[i]; if (isValidProperty(property)) { addColumn(getColumnTitle(property), property.getName(), property.getPropertyType().getName(), getColumnWidth(property)); } } setUseFullPageWidth(true); }
From source file:com.github.jasonruckman.sidney.generator.BeanBuilder.java
private Accessors.FieldAccessor accessor(Method method) { PropertyDescriptor descriptor = BeanUtils.findPropertyForMethod(method); Class<?> declaringClass = method.getDeclaringClass(); Field field = Fields.getFieldByName(declaringClass, descriptor.getName()); return Accessors.newAccessor(field); }
From source file:com.bstek.dorado.config.ExpressionMethodInterceptor.java
protected void discoverInterceptingMethods(Class<?> clazz) throws Exception { interceptingReadMethods = new HashMap<Method, ReadMethodDescriptor>(); interceptingWriteMethods = new HashMap<Method, Method>(); Map<Method, ReadMethodDescriptor> getterMethods = interceptingReadMethods; Map<Method, Method> setterMethods = interceptingWriteMethods; Map<String, Expression> expressionProperties = getExpressionProperties(); BeanInfo beanInfo = Introspector.getBeanInfo(clazz); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String property = propertyDescriptor.getName(); if (expressionProperties.containsKey(property)) { Method readMethod = propertyDescriptor.getReadMethod(); Method writeMethod = propertyDescriptor.getWriteMethod(); if (readMethod != null) { if (readMethod.getDeclaringClass() != clazz) { readMethod = clazz.getMethod(readMethod.getName(), readMethod.getParameterTypes()); }//from ww w .j av a 2 s . com getterMethods.put(readMethod, new ReadMethodDescriptor(property, null)); } if (writeMethod != null) { if (writeMethod.getDeclaringClass() != clazz) { writeMethod = clazz.getMethod(writeMethod.getName(), writeMethod.getParameterTypes()); } setterMethods.put(writeMethod, readMethod); } } } }
From source file:jp.co.opentone.bsol.framework.test.dataset.bean.BeanTable.java
private boolean isIgnoreProperty(PropertyDescriptor desc) { final Set<String> ignoreNames = new HashSet<String>(); ignoreNames.add("class"); return desc.getReadMethod() == null || ignoreNames.contains(desc.getName()); }
From source file:net.firejack.platform.core.store.registry.resource.ResourceVersionStore.java
private void copyResourceVersionProperties(RV dest, RV orig) { PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils(); PropertyDescriptor[] propertyDescriptors = propertyUtils.getPropertyDescriptors(orig); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String name = propertyDescriptor.getName(); if (ArrayUtils.contains(new String[] { "class", "id", "version", "status", "updated", "created" }, name)) {/*from w w w .java 2 s. com*/ continue; } if (propertyUtils.isReadable(orig, name) && propertyUtils.isWriteable(dest, name)) { try { Object value = propertyUtils.getSimpleProperty(orig, name); if (value instanceof Timestamp) { value = ConvertUtils.convert(value, Date.class); } BeanUtils.copyProperty(dest, name, value); } catch (Exception e) { // Should not happen } } } }
From source file:de.micromata.genome.jpa.PropertyEntityCopier.java
protected <T> EntityCopyStatus copyToImpl(IEmgr<?> emgr, Class<? extends T> iface, T dest, T orig, String... ignores) {//from w w w. j av a 2 s.c om EntityCopyStatus ret = EntityCopyStatus.NONE; for (PropertyDescriptor pd : EmgrPropertyUtils.getEntityPropertyDescriptors(iface)) { if (ArrayUtils.contains(ignores, pd.getName()) == true) { continue; } ret = ret.combine(copyProperty(emgr, pd, iface, dest, orig)); } return ret; }
From source file:name.martingeisse.common.javascript.serialize.BeanToJavascriptObjectSerializer.java
/** * /*from w w w . jav a2 s.co m*/ */ private void serializeAllFields(final T bean, final JavascriptAssembler assembler) throws Exception { for (final PropertyDescriptor property : PropertyUtils.getPropertyDescriptors(bean)) { final String beanPropertyName = property.getName(); if (beanPropertyName.equals("class")) { continue; } final String serializedFieldName = mapPropertyNameToSerializedName(beanPropertyName); final Object value = property.getReadMethod().invoke(bean); assembler.prepareObjectProperty(serializedFieldName); serializeFieldValue(bean, assembler, beanPropertyName, serializedFieldName, value); } }
From source file:com.blackbear.flatworm.ParseUtils.java
/** * Attempt to find the collection property on {@code target} indicated by the {@code propertyName} and then see if the "collection" * returned has an {@code add(Object)} method and if it does - invoke it with the {@code toAdd} instance. If any of the parameters are * {@code null} then no action is taken. * * @param target The object that has the collection property for which the {@code toAdd} instance will be added. * @param collectionPropertyName The name of the Java BeanBO property that will return a collection (may not be a {@link * java.util.Collection} so long as there is an {@code add(Object)} method). Note that if this returns a * null value a {@link FlatwormConfigurationException} will be thrown. * @param toAdd The instance to add to the collection indicated. * @throws FlatwormParserException Should the underlying collection referenced by {@code propertyName} be {@code null} or non-existent, * should no {@code add(Object)} method exist on the collection and should any error occur while * invoking the {@code add(Object)} method if it is found (reflection style errors). *///from w ww . j a v a 2 s. com public static void addValueToCollection(Object target, String collectionPropertyName, Object toAdd) throws FlatwormParserException { if (target == null || StringUtils.isBlank(collectionPropertyName) || toAdd == null) return; try { PropertyDescriptor propertyDescriptor = PropertyUtils.getPropertyDescriptor(target, collectionPropertyName); if (propertyDescriptor != null) { Object collectionInstance = PropertyUtils.getProperty(target, collectionPropertyName); if (collectionInstance != null) { // Once compiled, generics lose their converterName reference and it defaults to a simple java.lang.Object.class // so that's the method parameter we'll search by. Method addMethod = propertyDescriptor.getPropertyType().getMethod("add", Object.class); if (addMethod != null) { addMethod.invoke(collectionInstance, toAdd); } else { throw new FlatwormParserException(String.format( "The collection instance %s for property %s in class %s does not have an add method.", collectionInstance.getClass().getName(), propertyDescriptor.getName(), target.getClass().getName())); } } else { throw new FlatwormParserException(String.format( "Unable to invoke the add method on collection %s as it is currently null for instance %s.", propertyDescriptor.getName(), target.getClass().getName())); } } else { throw new FlatwormParserException(String.format( "%s does not have a getter for property %s - the %s instance could therefore not be added to the collection.", target.getClass().getName(), collectionPropertyName, toAdd.getClass().getName())); } } catch (Exception e) { throw new FlatwormParserException(String.format( "Unable to invoke the add method on the collection for property %s in bean %s with object of converterName %s", collectionPropertyName, target.getClass().getName(), toAdd.getClass().getName()), e); } }
From source file:org.springmodules.validation.bean.conf.loader.annotation.handler.hibernate.HibernatePropertyValidationAnnotationHandler.java
/** * Handles the given property level annotation and manipulates the given bean validation configuration accordingly. * * @param annotation The annotation to handle. * @param clazz The annotated class.// www . ja v a 2 s .c o m * @param descriptor The property descriptor of the annotated property. * @param configuration The bean validation configuration to manipulate. */ public void handleAnnotation(Annotation annotation, Class clazz, PropertyDescriptor descriptor, MutableBeanValidationConfiguration configuration) { if (annotation instanceof Valid) { configuration.addCascadeValidation(new CascadeValidation(descriptor.getName())); return; } Class annotationClass = annotation.annotationType(); ValidatorClass validatorClassAnnotation = (ValidatorClass) annotationClass .getAnnotation(ValidatorClass.class); Class<? extends Validator> validatorClass = validatorClassAnnotation.value(); Validator validator = (Validator) BeanUtils.instantiateClass(validatorClass); validator.initialize(annotation); Condition condition = Conditions.property(descriptor.getName(), new HibernateValidatorCondition(validator)); String message; try { message = (String) annotationClass.getMethod("message").invoke(annotation); } catch (NoSuchMethodException nsme) { message = annotationClass.getSimpleName() + ".error"; } catch (IllegalAccessException e) { message = annotationClass.getSimpleName() + ".error"; } catch (InvocationTargetException e) { message = annotationClass.getSimpleName() + ".error"; } configuration.addPropertyRule(descriptor.getName(), new DefaultValidationRule(condition, message, message, new Object[0])); }
From source file:com.bstek.dorado.data.type.EntityDataTypeSupport.java
protected void doCreatePropertyDefinitons() throws Exception { Class<?> type = getMatchType(); if (type == null) { type = getCreationType();//from ww w .ja v a2s . c o m } if (type == null || type.isPrimitive() || type.isArray() || Map.class.isAssignableFrom(type)) { return; } PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String name = propertyDescriptor.getName(); if (!BeanPropertyUtils.isValidProperty(type, name)) continue; PropertyDef propertyDef = getPropertyDef(name); DataType dataType = null; Class<?> propertyType = propertyDescriptor.getPropertyType(); if (Collection.class.isAssignableFrom(propertyType)) { ParameterizedType parameterizedType = (ParameterizedType) propertyDescriptor.getReadMethod() .getGenericReturnType(); if (parameterizedType != null) { dataType = DataUtils.getDataType(parameterizedType); } } if (dataType == null) { dataType = DataUtils.getDataType(propertyType); } if (propertyDef == null) { if (dataType != null) { propertyDef = new BasePropertyDef(name); propertyDef.setDataType(dataType); addPropertyDef(propertyDef); if (dataType instanceof EntityDataType || dataType instanceof AggregationDataType) { propertyDef.setIgnored(true); } } } else if (propertyDef.getDataType() == null) { if (dataType != null) propertyDef.setDataType(dataType); } } }