List of usage examples for org.springframework.beans PropertyAccessorUtils isNestedOrIndexedProperty
public static boolean isNestedOrIndexedProperty(@Nullable String propertyPath)
From source file:org.kuali.rice.krad.service.impl.KRADLegacyDataAdapterImpl.java
@Override /**// w w w .j ava 2 s. c o m * Recursively calls getPropertyTypeChild if nested property to allow it to properly look it up */ public Class<?> getPropertyType(Object object, String propertyName) { DataObjectWrapper wrappedObject = dataObjectService.wrap(object); if (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)) { return wrappedObject.getPropertyTypeNullSafe(wrappedObject.getWrappedClass(), propertyName); } return wrappedObject.getPropertyType(propertyName); }
From source file:org.kuali.rice.krad.service.impl.KRADLegacyDataAdapterImpl.java
@Override public Map<String, String> getInquiryParameters(Object dataObject, List<String> keys, String propertyName) { Map<String, String> inquiryParameters = new HashMap<String, String>(); org.kuali.rice.krad.data.metadata.DataObjectRelationship dataObjectRelationship = null; DataObjectMetadata objectMetadata = KRADServiceLocator.getDataObjectService().getMetadataRepository() .getMetadata(dataObject.getClass()); if (objectMetadata != null) { dataObjectRelationship = objectMetadata.getRelationshipByLastAttributeInRelationship(propertyName); }/*from w w w . j av a2 s.c o m*/ for (String keyName : keys) { String keyConversion = keyName; if (dataObjectRelationship != null) { keyConversion = dataObjectRelationship.getParentAttributeNameRelatedToChildAttributeName(keyName); } else if (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)) { String nestedAttributePrefix = KRADUtils.getNestedAttributePrefix(propertyName); keyConversion = nestedAttributePrefix + "." + keyName; } inquiryParameters.put(keyConversion, keyName); } return inquiryParameters; }
From source file:org.kuali.rice.krad.service.impl.KRADLegacyDataAdapterImpl.java
@Override public org.kuali.rice.krad.bo.DataObjectRelationship getDataObjectRelationship(Object dataObject, Class<?> dataObjectClass, String attributeName, String attributePrefix, boolean keysOnly, boolean supportsLookup, boolean supportsInquiry) { RelationshipDefinition ddReference = getDictionaryRelationship(dataObjectClass, attributeName); org.kuali.rice.krad.bo.DataObjectRelationship relationship = null; DataObjectAttributeRelationship rel = null; if (PropertyAccessorUtils.isNestedOrIndexedProperty(attributeName)) { if (ddReference != null) { if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) { relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference, attributePrefix, keysOnly); return relationship; }/*from www .j av a 2s. c om*/ } if (dataObject == null) { try { dataObject = KRADUtils.createNewObjectFromClass(dataObjectClass); } catch (RuntimeException e) { // found interface or abstract class, just swallow exception and return a null relationship return null; } } // recurse down to the next object to find the relationship int nextObjectIndex = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(attributeName); if (nextObjectIndex == StringUtils.INDEX_NOT_FOUND) { nextObjectIndex = attributeName.length(); } String localPrefix = StringUtils.substring(attributeName, 0, nextObjectIndex); String localAttributeName = StringUtils.substring(attributeName, nextObjectIndex + 1); Object nestedObject = ObjectPropertyUtils.getPropertyValue(dataObject, localPrefix); Class<?> nestedClass = null; if (nestedObject == null) { nestedClass = ObjectPropertyUtils.getPropertyType(dataObject, localPrefix); } else { nestedClass = nestedObject.getClass(); } String fullPrefix = localPrefix; if (StringUtils.isNotBlank(attributePrefix)) { fullPrefix = attributePrefix + "." + localPrefix; } relationship = getDataObjectRelationship(nestedObject, nestedClass, localAttributeName, fullPrefix, keysOnly, supportsLookup, supportsInquiry); return relationship; } // non-nested reference, get persistence relationships first int maxSize = Integer.MAX_VALUE; if (isPersistable(dataObjectClass)) { DataObjectMetadata metadata = dataObjectService.getMetadataRepository().getMetadata(dataObjectClass); DataObjectRelationship dataObjectRelationship = metadata.getRelationship(attributeName); if (dataObjectRelationship != null) { List<DataObjectAttributeRelationship> attributeRelationships = dataObjectRelationship .getAttributeRelationships(); for (DataObjectAttributeRelationship dataObjectAttributeRelationship : attributeRelationships) { if (classHasSupportedFeatures(dataObjectRelationship.getRelatedType(), supportsLookup, supportsInquiry)) { maxSize = attributeRelationships.size(); relationship = transformToDeprecatedDataObjectRelationship(dataObjectClass, attributeName, attributePrefix, dataObjectRelationship.getRelatedType(), dataObjectAttributeRelationship); break; } } } } else { ModuleService moduleService = kualiModuleService.getResponsibleModuleService(dataObjectClass); if (moduleService != null && moduleService.isExternalizable(dataObjectClass)) { relationship = getRelationshipMetadata(dataObjectClass, attributeName, attributePrefix); if ((relationship != null) && classHasSupportedFeatures(relationship.getRelatedClass(), supportsLookup, supportsInquiry)) { return relationship; } else { return null; } } } if (ddReference != null && ddReference.getPrimitiveAttributes().size() < maxSize) { if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) { relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference, null, keysOnly); } } return relationship; }
From source file:org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl.java
/** * {@inheritDoc}//from w ww . j a v a 2s.c o m */ @Override public void refreshReferences(String referencesToRefresh) { Object model = ViewLifecycle.getModel(); for (String reference : StringUtils.split(referencesToRefresh, KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR)) { if (StringUtils.isBlank(reference)) { continue; } //ToDo: handle add line if (PropertyAccessorUtils.isNestedOrIndexedProperty(reference)) { String parentPath = KRADUtils.getNestedAttributePrefix(reference); Object parentObject = ObjectPropertyUtils.getPropertyValue(model, parentPath); String referenceObjectName = KRADUtils.getNestedAttributePrimitive(reference); if (parentObject == null) { LOG.warn("Unable to refresh references for " + referencesToRefresh + ". Object not found in model. Nothing refreshed."); continue; } refreshReference(parentObject, referenceObjectName); } else { refreshReference(model, reference); } } }
From source file:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.java
/** * Apply the given property values, resolving any runtime references * to other beans in this bean factory. Must use deep copy, so we * don't permanently modify this property. * @param beanName the bean name passed for better exception information * @param mbd the merged bean definition * @param bw the BeanWrapper wrapping the target object * @param pvs the new property values//from w w w . j ava 2s .c o m */ protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs) { if (pvs.isEmpty()) { return; } if (System.getSecurityManager() != null && bw instanceof BeanWrapperImpl) { ((BeanWrapperImpl) bw).setSecurityContext(getAccessControlContext()); } MutablePropertyValues mpvs = null; List<PropertyValue> original; if (pvs instanceof MutablePropertyValues) { mpvs = (MutablePropertyValues) pvs; if (mpvs.isConverted()) { // Shortcut: use the pre-converted values as-is. try { bw.setPropertyValues(mpvs); return; } catch (BeansException ex) { throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Error setting property values", ex); } } original = mpvs.getPropertyValueList(); } else { original = Arrays.asList(pvs.getPropertyValues()); } TypeConverter converter = getCustomTypeConverter(); if (converter == null) { converter = bw; } BeanDefinitionValueResolver valueResolver = new BeanDefinitionValueResolver(this, beanName, mbd, converter); // Create a deep copy, resolving any references for values. List<PropertyValue> deepCopy = new ArrayList<>(original.size()); boolean resolveNecessary = false; for (PropertyValue pv : original) { if (pv.isConverted()) { deepCopy.add(pv); } else { String propertyName = pv.getName(); Object originalValue = pv.getValue(); Object resolvedValue = valueResolver.resolveValueIfNecessary(pv, originalValue); Object convertedValue = resolvedValue; boolean convertible = bw.isWritableProperty(propertyName) && !PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName); if (convertible) { convertedValue = convertForProperty(resolvedValue, propertyName, bw, converter); } // Possibly store converted value in merged bean definition, // in order to avoid re-conversion for every created bean instance. if (resolvedValue == originalValue) { if (convertible) { pv.setConvertedValue(convertedValue); } deepCopy.add(pv); } else if (convertible && originalValue instanceof TypedStringValue && !((TypedStringValue) originalValue).isDynamic() && !(convertedValue instanceof Collection || ObjectUtils.isArray(convertedValue))) { pv.setConvertedValue(convertedValue); deepCopy.add(pv); } else { resolveNecessary = true; deepCopy.add(new PropertyValue(pv, convertedValue)); } } } if (mpvs != null && !resolveNecessary) { mpvs.setConverted(); } // Set our (possibly massaged) deep copy. try { bw.setPropertyValues(new MutablePropertyValues(deepCopy)); } catch (BeansException ex) { throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Error setting property values", ex); } }