/** * Determines the key class by looking for the value of @Key annotation for the given class. * If no annotation is found, the key class is determined by using the generic parametrics. * * As fallback, it determines the key class by looking for the value of Key_${property} in the properties * file for the given class. * * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. * @param property the property of the Map or Collection for the given parent class * @see com.opensymphony.xwork2.conversion.ObjectTypeDeterminer#getKeyClass(Class, String) */ public Class getKeyClass(Class parentClass, String property) { Key annotation = getAnnotation(parentClass, property, Key.class); if (annotation != null) { return annotation.value(); } Class clazz = getClass(parentClass, property, false); if (clazz != null) { return clazz; } return (Class) xworkConverter.getConverter(parentClass, KEY_PREFIX + property); }
/** * Retrieves an annotation for the specified property of field, setter or getter. * * @param <T> the annotation type to be retrieved * @param parentClass the class * @param property the property * @param annotationClass the annotation * @return the field or setter/getter annotation or <code>null</code> if not found */ protected <T extends Annotation> T getAnnotation(Class parentClass, String property, Class<T> annotationClass) { T annotation = null; Field field = reflectionProvider.getField(parentClass, property); if (field != null) { annotation = field.getAnnotation(annotationClass); } if (annotation == null) { // HINT: try with setter annotation = getAnnotationFromSetter(parentClass, property, annotationClass); } if (annotation == null) { // HINT: try with getter annotation = getAnnotationFromGetter(parentClass, property, annotationClass); } return annotation; }
/** * Determines the key property for a Collection by getting it from the @KeyProperty annotation. * * As fallback, it determines the String key property for a Collection by getting it from the conversion properties * file using the KeyProperty_ prefix. KeyProperty_${property}=somePropertyOfBeansInTheSet * * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. * @param property the property of the Map or Collection for the given parent class * @see com.opensymphony.xwork2.conversion.ObjectTypeDeterminer#getKeyProperty(Class, String) */ public String getKeyProperty(Class parentClass, String property) { KeyProperty annotation = getAnnotation(parentClass, property, KeyProperty.class); if (annotation != null) { return annotation.value(); } return (String) xworkConverter.getConverter(parentClass, KEY_PROPERTY_PREFIX + property); }
CreateIfNull annotation = getAnnotation(parentClass, property, CreateIfNull.class); if (annotation != null) { return annotation.value();
/** * Determines the element class by looking for the value of @Element annotation for the given * class. * If no annotation is found, the element class is determined by using the generic parametrics. * * As fallback, it determines the key class by looking for the value of Element_${property} in the properties * file for the given class. Also looks for the deprecated Collection_${property} * * @param parentClass the Class which contains as a property the Map or Collection we are finding the key for. * @param property the property of the Map or Collection for the given parent class * @see com.opensymphony.xwork2.conversion.ObjectTypeDeterminer#getElementClass(Class, String, Object) */ public Class getElementClass(Class parentClass, String property, Object key) { Element annotation = getAnnotation(parentClass, property, Element.class); if (annotation != null) { return annotation.value(); } Class clazz = getClass(parentClass, property, true); if (clazz != null) { return clazz; } clazz = (Class) xworkConverter.getConverter(parentClass, ELEMENT_PREFIX + property); if (clazz == null) { clazz = (Class) xworkConverter.getConverter(parentClass, DEPRECATED_ELEMENT_PREFIX + property); if (LOG.isInfoEnabled() && clazz != null) { LOG.info("The Collection_xxx pattern for collection type conversion is deprecated. Please use Element_xxx!"); } } return clazz; }