List of usage examples for org.apache.commons.beanutils PropertyUtils getPropertyDescriptors
public static PropertyDescriptor[] getPropertyDescriptors(Object bean)
Retrieve the property descriptors for the specified bean, introspecting and caching them the first time a particular bean class is encountered.
For more details see PropertyUtilsBean
.
From source file:org.kuali.kra.service.impl.ObjectCopyUtils.java
public static void materializeUpdateableCollections(Object bo, int depth) throws FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (depth == 0 || ObjectUtils.isNull(bo)) { return;/* www . ja v a 2 s . c om*/ } if (depth < 0 || depth > MAX_DEPTH_FOR_PROXY_MATERILIZATION) { throw new IllegalArgumentException( "The depth passed in was out of bounds. Only values between 0 and 3, inclusively, are allowed."); } PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(bo.getClass()); for (int i = 0; i < propertyDescriptors.length; i++) { if (KNSServiceLocator.getPersistenceStructureService().hasCollection(bo.getClass(), propertyDescriptors[i].getName()) && KNSServiceLocator.getPersistenceStructureService().isCollectionUpdatable(bo.getClass(), propertyDescriptors[i].getName())) { Collection<PersistableBusinessObject> updateableCollection = (Collection<PersistableBusinessObject>) ObjectUtils .getPropertyValue(bo, propertyDescriptors[i].getName()); if ((updateableCollection != null) && ProxyHelper.isCollectionProxy(updateableCollection)) { ObjectUtils.materializeObjects(updateableCollection); for (PersistableBusinessObject elementBo : updateableCollection) { materializeUpdateableCollections(elementBo, depth - 1); } } } } }
From source file:org.kuali.rice.devtools.generators.dd.BeanDDCreator.java
/** * This method.../* w w w. j av a2s .c om*/ * @param args */ public static void main(String[] args) throws Exception { String className = args[0]; Class<? extends BusinessObject> boClass = (Class<? extends BusinessObject>) Class.forName(className); PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(boClass); StringBuffer sb = new StringBuffer(4000); sb.append("<beans xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xmlns:p=\"http://www.springframework.org/schema/p\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans\r\n" + " http://www.springframework.org/schema/beans/spring-beans-2.0.xsd\">\r\n" + "\r\n" + " <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("\" parent=\""); sb.append(boClass.getSimpleName()); sb.append("-parentBean\" />\r\n" + "\r\n" + " <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("-parentBean\" abstract=\"true\" parent=\"BusinessObjectEntry\"\r\n" + " p:businessObjectClass=\""); sb.append(boClass.getName()); sb.append("\"\r\n"); sb.append(" p:titleAttribute=\""); sb.append("FILL ME IN"); sb.append("\"\r\n"); sb.append(" p:objectLabel=\""); sb.append(camelCaseToString(boClass.getSimpleName())); sb.append("\"\r\n"); sb.append(" p:inquiryDefinition-ref=\""); sb.append(boClass.getSimpleName()); sb.append("-inquiryDefinition\"\r\n"); sb.append(" p:lookupDefinition-ref=\""); sb.append(boClass.getSimpleName()); sb.append("-lookupDefinition\" >\r\n"); sb.append(" <property name=\"attributes\" >\r\n" + " <list>\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { sb.append(" <ref bean=\"").append(boClass.getSimpleName()).append('-'); sb.append(p.getName()); sb.append("\" />\r\n"); } } sb.append(" </list>\r\n" + " </property>\r\n" + " </bean>\r\n" + "\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { if (p.getName().equals("versionNumber")) { sb.append(getSimpleParentBeanReference(boClass, p.getName())); sb.append(getSimpleAbstractInheritanceBean(boClass, p.getName(), "GenericAttributes-versionNumber")); } else if (p.getName().endsWith("chartOfAccountsCode")) { sb.append(getSimpleParentBeanReference(boClass, p.getName())); sb.append(getSimpleAbstractInheritanceBean(boClass, p.getName(), "Chart-chartOfAccountsCode")); } else if (p.getName().endsWith("organizationCode")) { sb.append(getSimpleParentBeanReference(boClass, p.getName())); sb.append(getSimpleAbstractInheritanceBean(boClass, p.getName(), "Org-organizationCode")); } else if (p.getName().endsWith("accountNumber")) { sb.append(getSimpleParentBeanReference(boClass, p.getName())); sb.append(getSimpleAbstractInheritanceBean(boClass, p.getName(), "Account-accountNumber")); } else if (p.getName().equals("active")) { sb.append(getSimpleParentBeanReference(boClass, p.getName())); sb.append(getSimpleAbstractInheritanceBean(boClass, p.getName(), "GenericAttributes-activeIndicator")); } else if (p.getName().equals("codeAndDescription")) { sb.append(getSimpleParentBeanReference(boClass, p.getName())); sb.append(getSimpleAbstractInheritanceBeanWithLabel(boClass, p.getName(), "CommonField-CodeAndDescription", camelCaseToString(boClass.getSimpleName()))); } else if (p.getPropertyType() == Boolean.TYPE) { sb.append(getSimpleParentBeanReference(boClass, p.getName())); sb.append(getSimpleAbstractInheritanceBean(boClass, p.getName(), "GenericAttributes-genericBoolean")); } else { // attribute bean sb.append(getSimpleParentBeanReference(boClass, p.getName())); // attribute parent bean sb.append(" <bean id=\"").append(boClass.getSimpleName()).append('-'); sb.append(p.getName()) .append("-parentBean\" parent=\"AttributeDefinition\" abstract=\"true\"\r\n"); sb.append(" p:name=\"").append(p.getName()).append("\"\r\n"); sb.append(" p:forceUppercase=\"false\"\r\n"); sb.append(" p:label=\"").append(camelCaseToString(p.getName())).append("\"\r\n"); sb.append(" p:shortLabel=\"").append(camelCaseToString(p.getName())).append("\"\r\n"); sb.append(" p:maxLength=\"10\"\r\n"); sb.append(" p:required=\"false\" >\r\n"); sb.append(" <property name=\"validationPattern\" >\r\n" + " <bean parent=\"AnyCharacterValidationPattern\"\r\n" + " p:allowWhitespace=\"true\" />\r\n" + " </property>\r\n" + " <property name=\"control\" >\r\n" + " <bean parent=\"TextControlDefinition\"\r\n" + " p:size=\"10\" />\r\n" + " </property>\r\n" + " </bean>\r\n"); } sb.append("\r\n"); } } // inquiry definition sb.append(getSimpleParentBeanReference(boClass, "inquiryDefinition")); sb.append("\r\n"); sb.append(" <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("-inquiryDefinition-parentBean\" abstract=\"true\" parent=\"InquiryDefinition\"\r\n" + " p:title=\""); sb.append(camelCaseToString(boClass.getSimpleName())); sb.append(" Inquiry\" >\r\n" + " <property name=\"inquirySections\" >\r\n" + " <list>\r\n" + " <bean parent=\"InquirySectionDefinition\"\r\n" + " p:title=\""); sb.append(camelCaseToString(boClass.getSimpleName())); sb.append(" Attributes\"\r\n" + " p:numberOfColumns=\"1\" >\r\n" + " <property name=\"inquiryFields\" >\r\n" + " <list>\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { sb.append(" <bean parent=\"FieldDefinition\" p:attributeName=\""); sb.append(p.getName()).append("\" />\r\n"); } } sb.append(" </list>\r\n" + " </property>\r\n" + " </bean>\r\n" + " </list>\r\n" + " </property>\r\n" + " </bean>\r\n" + "\r\n"); sb.append(getSimpleParentBeanReference(boClass, "lookupDefinition")); sb.append("\r\n"); sb.append(" <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("-lookupDefinition-parentBean\" abstract=\"true\" parent=\"LookupDefinition\"\r\n" + " p:title=\""); sb.append(camelCaseToString(boClass.getSimpleName())); sb.append(" Lookup\" \r\n"); //sb.append( " p:instructions=\"Lookup a " ); //sb.append( camelCaseToString(boClass.getSimpleName() ) ); sb.append("\" >\r\n"); sb.append(" <property name=\"defaultSort\" >\r\n" + " <bean parent=\"SortDefinition\">\r\n" + " <property name=\"attributeNames\" >\r\n" + " <list>\r\n" + " <value>FILL ME IN</value>\r\n" + " </list>\r\n" + " </property>\r\n" + " <property name=\"sortAscending\" value=\"true\" />\r\n" + " </bean>\r\n" + " </property>\r\n" + " <property name=\"lookupFields\" >\r\n" + " <list>\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { sb.append(" <bean parent=\"FieldDefinition\" p:attributeName=\""); sb.append(p.getName()).append("\" />\r\n"); } } sb.append(" </list>\r\n" + " </property>\r\n" + " <property name=\"resultFields\" >\r\n" + " <list>\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { sb.append(" <bean parent=\"FieldDefinition\" p:attributeName=\""); sb.append(p.getName()).append("\" />\r\n"); } } sb.append(" </list>\r\n" + " </property>\r\n" + " </bean>\r\n"); sb.append("\r\n</beans>"); System.out.println(sb.toString()); }
From source file:org.kuali.rice.devtools.generators.dd.MaintDocDDCreator.java
public static void main(String[] args) throws Exception { String className = args[0];//w w w .j av a2 s . c o m Class boClass = Class.forName(className); PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(boClass); StringBuffer sb = new StringBuffer(4000); sb.append("<beans xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xmlns:p=\"http://www.springframework.org/schema/p\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans\r\n" + " http://www.springframework.org/schema/beans/spring-beans-2.0.xsd\">\r\n" + "\r\n" + " <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("MaintenanceDocument\" parent=\""); sb.append(boClass.getSimpleName()); sb.append("MaintenanceDocument-parentBean\" />\r\n" + "\r\n" + " <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("MaintenanceDocument-parentBean\" abstract=\"true\" parent=\"MaintenanceDocumentEntry\"\r\n" + " p:businessObjectClass=\""); sb.append(boClass.getName()); sb.append("\"\r\n"); sb.append(" p:maintainableClass=\""); sb.append("org.kuali.core.maintenance.KualiMaintainableImpl"); sb.append("\"\r\n"); sb.append(" p:label=\""); sb.append(BeanDDCreator.camelCaseToString(boClass.getSimpleName())); sb.append(" Maintenance Document\"\r\n"); sb.append(" p:shortLabel=\""); sb.append(BeanDDCreator.camelCaseToString(boClass.getSimpleName())); sb.append(" Maint. Doc.\"\r\n"); sb.append(" p:documentTypeName=\""); sb.append(boClass.getSimpleName() + "MaintenanceDocument"); sb.append("\"\r\n"); sb.append(" p:documentTypeCode=\""); sb.append("FILLMEIN"); sb.append("\"\r\n"); sb.append(" p:businessRulesClass=\""); sb.append("org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase"); sb.append("\"\r\n"); sb.append(" p:preRulesCheckClass=\""); sb.append("FILLMEIN"); sb.append("\"\r\n"); sb.append(" p:documentAuthorizerClass=\""); sb.append("org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentAuthorizerBase"); sb.append("\"\r\n"); sb.append(" p:workflowProperties-ref=\""); sb.append(boClass.getSimpleName()); sb.append("MaintenanceDocument-workflowProperties\" >\r\n"); sb.append("\r\n"); sb.append(" <property name=\"authorizations\" >\r\n" + " <list>\r\n" + " <bean parent=\"AuthorizationDefinition\">\r\n" + " <property name=\"action\" value=\"initiate\" />\r\n" + " <property name=\"authorizedGroups\" >\r\n" + " <set>\r\n" + " <value>SY_MAINTENANCE_USERS</value>\r\n" + " </set>\r\n" + " </property>\r\n" + " </bean>\r\n" + " </list>\r\n" + " </property>\r\n" + ""); sb.append(" <property name=\"lockingKeys\" >\r\n" + " <list>\r\n" + " <value>FILLMEIN</value>\r\n" + " </list>\r\n" + " </property>\r\n" + ""); sb.append(" <property name=\"helpDefinition\" >\r\n" + " <bean parent=\"HelpDefinition\" p:parameterClass=\""); sb.append(boClass.getName()); sb.append("\" p:parameterName=\""); sb.append(camelCaseToHelpParm(boClass.getSimpleName())); sb.append("\" />\r\n" + " </property>\r\n" + ""); sb.append(" <property name=\"defaultExistenceChecks\" >\r\n" + " <list>\r\n" + ""); for (PropertyDescriptor pd : props) { if (isReferenceBoProperty(pd)) { sb.append(" <bean parent=\"ReferenceDefinition\"\r\n" + " p:attributeName=\""); sb.append(pd.getName()); sb.append("\"\r\n" + " p:activeIndicatorAttributeName=\"active\"\r\n" + " p:attributeToHighlightOnFail=\"FILLMEIN\" />\r\n" + ""); } } sb.append(" </list>\r\n" + " </property>\r\n" + ""); sb.append( " <property name=\"maintainableSections\" >\r\n" + " <list>\r\n" + " <ref bean=\""); sb.append(boClass.getSimpleName()); sb.append("MaintenanceDocument-MainSection\" />\r\n" + " </list>\r\n" + " </property>\r\n" + " </bean>\r\n\r\n"); sb.append(" <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("MaintenanceDocument-MainSection\" parent=\""); sb.append(boClass.getSimpleName()); sb.append("MaintenanceDocument-MainSection-parentBean\" />\r\n" + "\r\n" + " <bean id=\""); sb.append(boClass.getSimpleName()); sb.append( "MaintenanceDocument-MainSection-parentBean\" abstract=\"true\" parent=\"MaintainableSectionDefinition\"\r\n" + " p:title=\""); sb.append(BeanDDCreator.camelCaseToString(boClass.getSimpleName())); sb.append(" Maintenance\" >\r\n" + " <property name=\"maintainableItems\" >\r\n" + " <list>\r\n" + ""); for (PropertyDescriptor pd : props) { if (BeanDDCreator.isNormalProperty(pd) && !pd.getName().endsWith("codeAndDescription")) { sb.append(" <bean parent=\"MaintainableFieldDefinition\"\r\n" + " p:name=\""); sb.append(pd.getName()); if (pd.getName().endsWith("active")) { sb.append("\"\r\n" + " p:defaultValue=\"true\" />\r\n"); } else if (pd.getName().equals("versionNumber")) { sb.append("\" />\r\n"); } else { sb.append("\"\r\n" + " p:required=\"true\" />\r\n"); } } } sb.append(" </list>\r\n" + " </property>\r\n" + " </bean>\r\n" + ""); sb.append(" <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("MaintenanceDocument-workflowProperties\" parent=\""); sb.append(boClass.getSimpleName()); sb.append("MaintenanceDocument-workflowProperties-parentBean\" />\r\n" + "\r\n" + " <bean id=\""); sb.append(boClass.getSimpleName()); sb.append( "MaintenanceDocument-workflowProperties-parentBean\" abstract=\"true\" parent=\"CommonWorkflow-MaintenanceDocument\" />\r\n" + // " <property name=\"workflowPropertyGroups\" >\r\n" + // " <list>\r\n" + // " <bean parent=\"WorkflowPropertyGroup\">\r\n" + // " <property name=\"workflowProperties\" >\r\n" + // " <list>\r\n" + // " <bean parent=\"WorkflowProperty\" p:path=\"newMaintainableObject.businessObject\" />\r\n" + // " <bean parent=\"WorkflowProperty\" p:path=\"oldMaintainableObject.businessObject\" />\r\n" + // " </list>\r\n" + // " </property>\r\n" + // " </bean>\r\n" + // " </list>\r\n" + // " </property>\r\n" + // " </bean>\r\n" + "</beans>"); System.out.println(sb.toString()); }
From source file:org.kuali.rice.kns.maintenance.KualiMaintainableImpl.java
protected void setNewCollectionLineDefaultValues(String collectionName, PersistableBusinessObject addLine) { PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(addLine); for (int i = 0; i < descriptors.length; ++i) { PropertyDescriptor propertyDescriptor = descriptors[i]; String fieldName = propertyDescriptor.getName(); Class propertyType = propertyDescriptor.getPropertyType(); String value = getMaintenanceDocumentDictionaryService() .getCollectionFieldDefaultValue(getDocumentTypeName(), collectionName, fieldName); if (value != null) { try { ObjectUtils.setObjectProperty(addLine, fieldName, propertyType, value); } catch (Exception ex) { LOG.error("Unable to set default property of collection object: " + "\nobject: " + addLine + "\nfieldName=" + fieldName + "\npropertyType=" + propertyType + "\nvalue=" + value, ex);//from w w w .j a v a 2 s .c om } } } }
From source file:org.kuali.rice.kns.service.impl.BusinessObjectDictionaryServiceImpl.java
/** * Handles recursion for performForceUppercase in a cycle-safe manner, * keeping track of visited BusinessObjects to prevent infinite recursion. *//*ww w. j a v a 2s .co m*/ protected void performForceUppercaseCycleSafe(BusinessObject bo, Set<BusinessObject> visited) { if (visited.contains(bo)) { return; } else { visited.add(bo); } PropertyDescriptor descriptors[] = PropertyUtils.getPropertyDescriptors(bo); for (int i = 0; i < descriptors.length; ++i) { try { if (descriptors[i] instanceof IndexedPropertyDescriptor) { // Skip this case because PropertyUtils.getProperty(bo, // descriptors[i].getName()) will throw a // NoSuchMethodException on those. These // fields are usually convenience methods in the BO and in // the below code we anyway wouldn't know which index // .toUpperCase(). } else { Object nestedObject = ObjectUtils.getPropertyValue(bo, descriptors[i].getName()); if (ObjectUtils.isNotNull(nestedObject) && nestedObject instanceof BusinessObject) { if (persistenceStructureService.isPersistable(nestedObject.getClass())) { try { if (persistenceStructureService.hasReference(bo.getClass(), descriptors[i].getName())) { if (persistenceStructureService.isReferenceUpdatable(bo.getClass(), descriptors[i].getName())) { if (persistenceStructureService .getForeignKeyFieldsPopulationState((PersistableBusinessObject) bo, descriptors[i].getName()) .isAllFieldsPopulated()) { // check FKs to prevent probs caused // by referential integrity problems performForceUppercaseCycleSafe((BusinessObject) nestedObject, visited); } } } } catch (org.kuali.rice.krad.exception.ReferenceAttributeNotAnOjbReferenceException ranaore) { LOG.debug( "Propery " + descriptors[i].getName() + " is not a foreign key reference."); } } } else if (nestedObject instanceof String) { if (dataDictionaryService.isAttributeDefined(bo.getClass(), descriptors[i].getName()) .booleanValue() && dataDictionaryService .getAttributeForceUppercase(bo.getClass(), descriptors[i].getName()) .booleanValue()) { String curValue = (String) nestedObject; PropertyUtils.setProperty(bo, descriptors[i].getName(), curValue.toUpperCase()); } } else { if (ObjectUtils.isNotNull(nestedObject) && nestedObject instanceof Collection) { if (persistenceStructureService.hasCollection(bo.getClass(), descriptors[i].getName())) { if (persistenceStructureService.isCollectionUpdatable(bo.getClass(), descriptors[i].getName())) { Iterator iter = ((Collection) nestedObject).iterator(); while (iter.hasNext()) { Object collElem = iter.next(); if (collElem instanceof BusinessObject) { if (persistenceStructureService.isPersistable(collElem.getClass())) { performForceUppercaseCycleSafe((BusinessObject) collElem, visited); } } } } } } } } } catch (IllegalAccessException e) { throw new IntrospectionException("unable to performForceUppercase", e); } catch (InvocationTargetException e) { throw new IntrospectionException("unable to performForceUppercase", e); } catch (NoSuchMethodException e) { // if the getter/setter does not exist, just skip over // throw new // IntrospectionException("unable to performForceUppercase", e); } } }
From source file:org.kuali.rice.kns.service.impl.DictionaryValidationServiceImpl.java
/** * @see org.kuali.rice.kns.service.DictionaryValidationService#validateDocumentRecursively(org.kuali.rice.krad.document.Document, int) * @deprecated since 2.0//from ww w.j a v a2 s . c o m */ @Deprecated @Override public void validateDocumentRecursively(Document document, int depth) { // validate primitives of document validateDocument(document); // call method to recursively find business objects and validate validateBusinessObjectsFromDescriptors(document, PropertyUtils.getPropertyDescriptors(document.getClass()), depth); }
From source file:org.kuali.rice.kns.service.impl.DictionaryValidationServiceImpl.java
/** * @see org.kuali.rice.kns.service.DictionaryValidationService#validateDocument(org.kuali.rice.krad.document.Document) * @param document - document to validate * @deprecated since 2.1.2//from ww w .j av a 2 s . c o m */ @Deprecated @Override public void validateDocument(Document document) { String documentEntryName = document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName(); validatePrimitivesFromDescriptors(documentEntryName, document, PropertyUtils.getPropertyDescriptors(document.getClass()), "", true); }
From source file:org.kuali.rice.kns.service.impl.DictionaryValidationServiceImpl.java
@Override @Deprecated// w w w . j a va 2 s. c o m public void validateBusinessObject(Object businessObject, boolean validateRequired) { if (ObjectUtils.isNull(businessObject)) { return; } try { // validate the primitive attributes of the bo validatePrimitivesFromDescriptors(businessObject.getClass().getName(), businessObject, PropertyUtils.getPropertyDescriptors(businessObject.getClass()), "", validateRequired); } catch (RuntimeException e) { LOG.error(String.format("Exception while validating %s", businessObject.getClass().getName()), e); throw e; } }
From source file:org.kuali.rice.krad.datadictionary.DataDictionary.java
/** * @param propertyClass/*from w w w. j a va2 s . com*/ * @param propertyName * @return PropertyDescriptor for the getter for the named property of the given class, if one exists. */ public static PropertyDescriptor buildSimpleReadDescriptor(Class propertyClass, String propertyName) { if (propertyClass == null) { throw new IllegalArgumentException("invalid (null) propertyClass"); } if (StringUtils.isBlank(propertyName)) { throw new IllegalArgumentException("invalid (blank) propertyName"); } PropertyDescriptor p = null; // check to see if we've cached this descriptor already. if yes, return true. String propertyClassName = propertyClass.getName(); Map<String, PropertyDescriptor> m = cache.get(propertyClassName); if (null != m) { p = m.get(propertyName); if (null != p) { return p; } } // Use PropertyUtils.getPropertyDescriptors instead of manually constructing PropertyDescriptor because of // issues with introspection and generic/co-variant return types // See https://issues.apache.org/jira/browse/BEANUTILS-340 for more details PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(propertyClass); if (ArrayUtils.isNotEmpty(descriptors)) { for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getName().equals(propertyName)) { p = descriptor; } } } // cache the property descriptor if we found it. if (p != null) { if (m == null) { m = new TreeMap<String, PropertyDescriptor>(); cache.put(propertyClassName, m); } m.put(propertyName, p); } return p; }
From source file:org.kuali.rice.krad.datadictionary.DataDictionaryPropertyUtils.java
/** * @return PropertyDescriptor for the getter for the named property of the given class, if one exists. *//* w w w . java 2 s . c om*/ private static PropertyDescriptor buildSimpleReadDescriptor(Class propertyClass, String propertyName) { if (propertyClass == null) { throw new IllegalArgumentException("invalid (null) propertyClass"); } if (StringUtils.isBlank(propertyName)) { throw new IllegalArgumentException("invalid (blank) propertyName"); } PropertyDescriptor p = null; // check to see if we've cached this descriptor already. if yes, return true. String propertyClassName = propertyClass.getName(); Map<String, PropertyDescriptor> m = CACHE.get(propertyClassName); if (null != m) { p = m.get(propertyName); if (null != p) { return p; } } // Use PropertyUtils.getPropertyDescriptors instead of manually constructing PropertyDescriptor because of // issues with introspection and generic/co-variant return types // See https://issues.apache.org/jira/browse/BEANUTILS-340 for more details PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(propertyClass); if (ArrayUtils.isNotEmpty(descriptors)) { for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getName().equals(propertyName)) { p = descriptor; } } } // cache the property descriptor if we found it. if (p != null) { if (m == null) { m = new TreeMap<>(); CACHE.put(propertyClassName, m); } m.put(propertyName, p); } return p; }