private PropertyDescriptor findExistingPropertyDescriptor( String propertyName, Class<?> propertyType) { for (PropertyDescriptor pd : this.propertyDescriptors) { final Class<?> candidateType; final String candidateName = pd.getName(); if (pd instanceof IndexedPropertyDescriptor) { IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; candidateType = ipd.getIndexedPropertyType(); if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) { return pd; } } else { candidateType = pd.getPropertyType(); if (candidateName.equals(propertyName) && (candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) { return pd; } } } return null; }
/* * See IndexedPropertyDescriptor#findIndexedPropertyType */ public static Class<?> findIndexedPropertyType( String name, Class<?> propertyType, Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException { Class<?> indexedPropertyType = null; if (indexedReadMethod != null) { Class<?> params[] = indexedReadMethod.getParameterTypes(); if (params.length != 1) { throw new IntrospectionException("bad indexed read method arg count"); } if (params[0] != Integer.TYPE) { throw new IntrospectionException("non int index to indexed read method"); } indexedPropertyType = indexedReadMethod.getReturnType(); if (indexedPropertyType == Void.TYPE) { throw new IntrospectionException("indexed read method returns void"); } } if (indexedWriteMethod != null) { Class<?> params[] = indexedWriteMethod.getParameterTypes(); if (params.length != 2) { throw new IntrospectionException("bad indexed write method arg count"); } if (params[0] != Integer.TYPE) { throw new IntrospectionException("non int index to indexed write method"); } if (indexedPropertyType != null && indexedPropertyType != params[1]) { throw new IntrospectionException( "type mismatch between indexed read and indexed write methods: " + name); } indexedPropertyType = params[1]; } if (propertyType != null && (!propertyType.isArray() || propertyType.getComponentType() != indexedPropertyType)) { throw new IntrospectionException( "type mismatch between indexed and non-indexed methods: " + name); } return indexedPropertyType; }