List of usage examples for java.beans PropertyDescriptor getPropertyType
public synchronized Class<?> getPropertyType()
From source file:org.kuali.rice.kns.web.struts.form.pojo.PojoPropertyUtilsBean.java
/** * helper method makes sure we don't return "" for collections *///from ww w . jav a2s . c om private Object getUnreachableNestedProperty(Object arg0, String arg1) { try { PropertyDescriptor propertyDescriptor = getPropertyDescriptor(arg0, arg1); if (propertyDescriptor == null || Collection.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { return null; } } catch (IllegalAccessException e) { // ignore } catch (InvocationTargetException e) { // ignore } catch (NoSuchMethodException e) { // ignore } return ""; }
From source file:org.kuali.rice.kns.service.impl.DictionaryValidationServiceImpl.java
/** * calls validate format and required check for the given propertyDescriptor * * @param entryName//from w w w . ja v a 2 s . c o m * @param object * @param propertyDescriptor * @param errorPrefix */ @Override @Deprecated public void validatePrimitiveFromDescriptor(String entryName, Object object, PropertyDescriptor propertyDescriptor, String errorPrefix, boolean validateRequired) { // validate the primitive attributes if defined in the dictionary if (null != propertyDescriptor && getDataDictionaryService().isAttributeDefined(entryName, propertyDescriptor.getName())) { Object value = ObjectUtils.getPropertyValue(object, propertyDescriptor.getName()); Class propertyType = propertyDescriptor.getPropertyType(); if (TypeUtils.isStringClass(propertyType) || TypeUtils.isIntegralClass(propertyType) || TypeUtils.isDecimalClass(propertyType) || TypeUtils.isTemporalClass(propertyType)) { // check value format against dictionary if (value != null && StringUtils.isNotBlank(value.toString())) { if (!TypeUtils.isTemporalClass(propertyType)) { validateAttributeFormat(entryName, propertyDescriptor.getName(), value.toString(), errorPrefix + propertyDescriptor.getName()); } } else if (validateRequired) { validateAttributeRequired(entryName, propertyDescriptor.getName(), value, Boolean.FALSE, errorPrefix + propertyDescriptor.getName()); } } } }
From source file:org.nextframework.persistence.GenericDAO.java
protected void checkFileProperties() { if (isDetectFileProperties()) { BeanWrapper beanWrapper;//from w w w .j av a 2s . c o m try { beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(beanClass.newInstance()); PropertyDescriptor[] propertyDescriptors = beanWrapper.getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (File.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { if (propertyDescriptor.getReadMethod().getAnnotation(Transient.class) == null) { fileProperties.add(propertyDescriptor); } } } } catch (Exception e) { throw new RuntimeException("Cannot check file type for dao", e); } } }
From source file:no.sesat.search.datamodel.BeanDataObjectInvocationHandler.java
private boolean checkPropertyClass(final Class cls, final Property property) { boolean correct = false; if (property.getValue() == null) { return true; }// www . jav a 2s .com try { PropertyDescriptor[] descriptors = Introspector.getBeanInfo(cls).getPropertyDescriptors(); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getName().equals(property.getName())) { final Class<?> propertyType = property.getValue().getClass().equals(MapDataObjectSupport.class) ? Map.class : property.getValue().getClass(); correct |= descriptor.getPropertyType() == null || descriptor.getPropertyType().isAssignableFrom(propertyType); break; } } } catch (IntrospectionException e) { /* Do nothing, return value already set */ } return correct; }
From source file:org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass.java
/** * Populates the domain class properties map * * @param propertyDescriptors The property descriptors *///from w w w . ja v a 2 s .c o m private void populateDomainClassProperties(PropertyDescriptor[] propertyDescriptors) { for (PropertyDescriptor descriptor : propertyDescriptors) { if (descriptor.getPropertyType() == null) { // indexed property continue; } // ignore certain properties if (GrailsDomainConfigurationUtil.isNotConfigurational(descriptor)) { GrailsDomainClassProperty property = new DefaultGrailsDomainClassProperty(this, descriptor, defaultConstraints); propertyMap.put(property.getName(), property); if (property.isIdentity()) { identifier = property; } else if (property.getName().equals(GrailsDomainClassProperty.VERSION)) { version = property; } } } }
From source file:ResultSetIterator.java
/** * Creates a new object and initializes its fields from the ResultSet. * * @param rs The result set./*from w w w. j av a 2 s. c o m*/ * @param type The bean type (the return type of the object). * @param props The property descriptors. * @param columnToProperty The column indices in the result set. * @return An initialized object. * @throws SQLException if a database error occurs. */ private Object createBean(ResultSet rs, Class type, PropertyDescriptor[] props, int[] columnToProperty) throws SQLException { Object bean = this.newInstance(type); for (int i = 1; i < columnToProperty.length; i++) { if (columnToProperty[i] == PROPERTY_NOT_FOUND) { continue; } PropertyDescriptor prop = props[columnToProperty[i]]; Class propType = prop.getPropertyType(); Object value = this.processColumn(rs, i, propType); if (propType != null && value == null && propType.isPrimitive()) { value = primitiveDefaults.get(propType); } this.callSetter(bean, prop, value); } return bean; }
From source file:org.grails.datastore.mapping.model.config.GormMappingConfigurationStrategy.java
public List<PersistentProperty> getPersistentProperties(PersistentEntity entity, MappingContext context, ClassMapping classMapping) {/*w w w . ja va 2s. c o m*/ final List<PersistentProperty> persistentProperties = new ArrayList<PersistentProperty>(); ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(entity.getJavaClass()); // owners are the classes that own this class Collection embedded = cpf.getStaticPropertyValue(EMBEDDED, Collection.class); if (embedded == null) embedded = Collections.emptyList(); Collection transients = cpf.getStaticPropertyValue(TRANSIENT, Collection.class); if (transients == null) transients = Collections.emptyList(); // hasMany associations for defining one-to-many and many-to-many Map hasManyMap = getAssociationMap(cpf); // mappedBy for defining by which property an association is mapped Map mappedByMap = cpf.getStaticPropertyValue(MAPPED_BY, Map.class); if (mappedByMap == null) mappedByMap = Collections.emptyMap(); // hasOne for declaring a one-to-one association with the foreign key in the child Map hasOneMap = cpf.getStaticPropertyValue(HAS_ONE, Map.class); if (hasOneMap == null) hasOneMap = Collections.emptyMap(); for (PropertyDescriptor descriptor : cpf.getPropertyDescriptors()) { if (descriptor.getPropertyType() == null || descriptor.getPropertyType() == Object.class) { // indexed property continue; } if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null) { // non-persistent getter or setter continue; } if (descriptor.getName().equals(VERSION) && !entity.isVersioned()) { continue; } Field field = cpf.getDeclaredField(descriptor.getName()); if (field != null && java.lang.reflect.Modifier.isTransient(field.getModifiers())) { continue; } final String propertyName = descriptor.getName(); if (isExcludedProperty(propertyName, classMapping, transients)) continue; Class<?> propertyType = descriptor.getPropertyType(); Class currentPropType = propertyType; // establish if the property is a one-to-many // if it is a Set and there are relationships defined // and it is defined as persistent if (embedded.contains(propertyName)) { if (isCollectionType(currentPropType)) { Class relatedClassType = (Class) hasManyMap.get(propertyName); if (relatedClassType == null) { Class javaClass = entity.getJavaClass(); Class genericClass = MappingUtils.getGenericTypeForProperty(javaClass, propertyName); if (genericClass != null) { relatedClassType = genericClass; } } if (relatedClassType != null) { if (propertyFactory.isSimpleType(relatedClassType)) { Basic basicCollection = propertyFactory.createBasicCollection(entity, context, descriptor); persistentProperties.add(basicCollection); } else { EmbeddedCollection association = propertyFactory.createEmbeddedCollection(entity, context, descriptor); persistentProperties.add(association); if (isPersistentEntity(relatedClassType)) { association.setAssociatedEntity( getOrCreateAssociatedEntity(entity, context, relatedClassType)); } else { PersistentEntity embeddedEntity = context.createEmbeddedEntity(relatedClassType); embeddedEntity.initialize(); association.setAssociatedEntity(embeddedEntity); } } } } else { ToOne association = propertyFactory.createEmbedded(entity, context, descriptor); PersistentEntity associatedEntity = getOrCreateEmbeddedEntity(entity, context, association.getType()); association.setAssociatedEntity(associatedEntity); persistentProperties.add(association); } } else if (isCollectionType(currentPropType)) { final Association association = establishRelationshipForCollection(descriptor, entity, context, hasManyMap, mappedByMap); if (association != null) { configureOwningSide(association); persistentProperties.add(association); } } // otherwise if the type is a domain class establish relationship else if (isPersistentEntity(currentPropType)) { final ToOne association = establishDomainClassRelationship(entity, descriptor, context, hasOneMap); if (association != null) { configureOwningSide(association); persistentProperties.add(association); } } else if (Enum.class.isAssignableFrom(currentPropType) || propertyFactory.isSimpleType(propertyType)) { persistentProperties.add(propertyFactory.createSimple(entity, context, descriptor)); } else if (MappingFactory.isCustomType(propertyType)) { persistentProperties.add(propertyFactory.createCustom(entity, context, descriptor)); } } return persistentProperties; }
From source file:org.kuali.kfs.module.ar.businessobject.lookup.GenerateDunningLettersLookupableHelperServiceImpl.java
/** * @param element/*from w w w . j a v a 2 s .com*/ * @param attributeName * @return Column */ protected Column setupResultsColumn(BusinessObject element, String attributeName, BusinessObjectRestrictions businessObjectRestrictions) { Column col = new Column(); col.setPropertyName(attributeName); String columnTitle = getDataDictionaryService().getAttributeLabel(element.getClass(), attributeName); if (StringUtils.isBlank(columnTitle)) { columnTitle = getDataDictionaryService().getCollectionLabel(element.getClass(), attributeName); } col.setColumnTitle(columnTitle); col.setMaxLength(getDataDictionaryService().getAttributeMaxLength(element.getClass(), attributeName)); try { Class formatterClass = getDataDictionaryService().getAttributeFormatter(element.getClass(), attributeName); Formatter formatter = null; if (ObjectUtils.isNotNull(formatterClass)) { formatter = (Formatter) formatterClass.newInstance(); col.setFormatter(formatter); } // Pick off result column from result list, do formatting String propValue = KFSConstants.EMPTY_STRING; Object prop = ObjectUtils.getPropertyValue(element, attributeName); // Set comparator and formatter based on property type Class propClass = null; PropertyDescriptor propDescriptor = PropertyUtils.getPropertyDescriptor(element, col.getPropertyName()); if (ObjectUtils.isNotNull(propDescriptor)) { propClass = propDescriptor.getPropertyType(); } // Formatters if (ObjectUtils.isNotNull(prop)) { propValue = getContractsGrantsReportHelperService().formatByType(prop, formatter); } // Comparator col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass)); col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass)); propValue = super.maskValueIfNecessary(element.getClass(), col.getPropertyName(), propValue, businessObjectRestrictions); col.setPropertyValue(propValue); if (StringUtils.isNotBlank(propValue)) { col.setColumnAnchor(getInquiryUrl(element, col.getPropertyName())); } } catch (InstantiationException ie) { throw new RuntimeException( "Unable to get new instance of formatter class for property " + col.getPropertyName(), ie); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new RuntimeException("Cannot access PropertyType for property " + "'" + col.getPropertyName() + "' " + " on an instance of '" + element.getClass().getName() + "'.", ex); } return col; }
From source file:org.kuali.kra.award.awardhierarchy.sync.helpers.AwardSyncHelperBase.java
/** * Recursively sets values on this syncable working way down in the object tree found in the values map. * @param syncable/* w ww . j ava 2s . c o m*/ * @param values * @param change * @throws NoSuchFieldException * @throws IllegalAccessException * @throws InvocationTargetException * @throws ClassNotFoundException * @throws NoSuchMethodException * @throws InstantiationException */ @SuppressWarnings("unchecked") protected void setValuesOnSyncable(PersistableBusinessObject syncable, Map<String, Object> values, AwardSyncChange change) throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, InstantiationException { Class clazz = syncable.getClass(); boolean setEntry = false; for (Map.Entry<String, Object> entry : values.entrySet()) { setEntry = false; for (PropertyDescriptor propDescriptor : PropertyUtils.getPropertyDescriptors(clazz)) { if (StringUtils.equals(propDescriptor.getName(), entry.getKey())) { if (entry.getValue() instanceof AwardSyncXmlExport) { AwardSyncXmlExport xmlExport = (AwardSyncXmlExport) entry.getValue(); applySyncChange(syncable, change, entry.getKey(), xmlExport); setEntry = true; } else if (Collection.class.isAssignableFrom(propDescriptor.getPropertyType()) && entry.getValue() instanceof List) { applySyncChange(syncable, change, entry.getKey(), (Collection<AwardSyncXmlExport>) entry.getValue()); setEntry = true; } else { Method setter = propDescriptor.getWriteMethod(); setter.invoke(syncable, entry.getValue()); setEntry = true; } } } if (!setEntry) { throw new NoSuchFieldException(); } } }