use of com.opensymphony.xwork2.conversion.ObjectTypeDeterminer in project struts by apache.
the class DefaultObjectTypeDeterminer method shouldCreateIfNew.
/**
* Determines the createIfNull property for a Collection or Map by getting it from the @CreateIfNull annotation.
*
* As fallback, it determines the boolean CreateIfNull property for a Collection or Map by getting it from the
* conversion properties file using the CreateIfNull_ prefix. CreateIfNull_${property}=true|false
*
* @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
* @param target the target object
* @param keyProperty the keyProperty value
* @param isIndexAccessed <tt>true</tt>, if the collection or map is accessed via index, <tt>false</tt> otherwise.
* @return <tt>true</tt>, if the Collection or Map should be created, <tt>false</tt> otherwise.
* @see ObjectTypeDeterminer#getKeyProperty(Class, String)
*/
public boolean shouldCreateIfNew(Class parentClass, String property, Object target, String keyProperty, boolean isIndexAccessed) {
CreateIfNull annotation = getAnnotation(parentClass, property, CreateIfNull.class);
if (annotation != null) {
return annotation.value();
}
String configValue = (String) xworkConverter.getConverter(parentClass, CREATE_IF_NULL_PREFIX + property);
// check if a value is in the config
if (configValue != null) {
return BooleanUtils.toBoolean(configValue);
}
// in the case of List
return (target instanceof Map) || isIndexAccessed;
}
Aggregations