List of usage examples for org.springframework.beans PropertyAccessorUtils getPropertyName
public static String getPropertyName(String propertyPath)
From source file:org.obiba.magma.beans.BeanVariableValueSourceFactory.java
/** * Finds the type ({@code Class}) for a given {@code propertyName} which may denote a nested property (property path * e.g: a.b.c) or mapped property (attribute[key]) or a combination of both (e.g.: a.b[c].d). * * @param propertyName/*from w w w.ja v a2 s . co m*/ * @return */ @SuppressWarnings({ "OverlyLongMethod", "PMD.NcssMethodCount" }) protected Class<?> getPropertyType(String propertyName) { // Has a property type been explicitly declared? If so, use it. Class<?> declaredPropertyType = propertyNameToPropertyType.get(propertyName); if (declaredPropertyType != null) { return declaredPropertyType; } Class<?> currentType = getBeanClass(); String propertyPath = propertyName; // Loop as long as the propertyPath designates a nested property while (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyPath)) { int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(propertyPath); String nestedProperty = pos > -1 ? propertyPath.substring(0, pos) : propertyPath; // Check whether this is a mapped property (a[b]) if (PropertyAccessorUtils.isNestedOrIndexedProperty(nestedProperty)) { // We cannot determine the type of these properties through reflection (even when they contain type parameters // i.e. Map<String, String>). // The type of these properties has to be specified through configuration currentType = getMapAttributeType(PropertyAccessorUtils.getPropertyName(nestedProperty)); if (pos == -1) { return currentType; } propertyPath = propertyPath.substring(pos + 1); } else { PropertyDescriptor currentProperty = BeanUtils.getPropertyDescriptor(currentType, nestedProperty); if (currentProperty == null) { throw new IllegalArgumentException("Invalid path '" + propertyName + "' for type " + getBeanClass().getName() + ": nested property '" + nestedProperty + "' does not exist on type " + currentType.getName()); } // Change the current type so it points to the nested type currentType = currentProperty.getPropertyType(); // Extract the nested type's property path from the original path propertyPath = propertyPath.substring(pos + 1); } } // propertyPath is a direct reference to a property of the currentType (no longer a path) PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(currentType, propertyPath); if (descriptor == null) { throw new IllegalArgumentException( "Invalid path '" + propertyName + "' for type " + getBeanClass().getName() + ": property '" + propertyPath + "' does not exist on type " + currentType.getName()); } return descriptor.getPropertyType(); }
From source file:org.kuali.rice.krad.data.util.ReferenceLinker.java
/** * Gets indexes that have been modified./*www .ja va 2 s .c o m*/ * * <p> * Returns a set of indexes which have been modified in the given collection. If the returned set contains * {@link java.lang.Integer#MAX_VALUE} then it means that it should be treated as if all items in the collection * have been modified. * </p> * * @return indexes which have been modified in the given collection */ private Set<Integer> extractModifiedIndicies(DataObjectCollection collectionMetadata, Map<String, Set<String>> decomposedPaths) { String relationshipName = collectionMetadata.getName(); Set<Integer> modifiedIndicies = Sets.newHashSet(); // if it contains *exactly* the collection relationship name, then indicate that all items modified if (decomposedPaths.containsKey(relationshipName)) { modifiedIndicies.add(Integer.valueOf(Integer.MAX_VALUE)); } for (String propertyName : decomposedPaths.keySet()) { if (relationshipName.equals(PropertyAccessorUtils.getPropertyName(relationshipName))) { Integer index = extractIndex(propertyName); if (index != null) { modifiedIndicies.add(index); } } } return modifiedIndicies; }