Class keyType = null;
Class toGetTypeFrom = (collClass != null) ? collClass : c.iterator().next().getClass();
try {
keyType = OgnlRuntime.getPropertyDescriptor(toGetTypeFrom, keyProperty).getPropertyType();
} catch (Exception exc) {
throw new OgnlException("Error getting property descriptor: " + exc.getMessage());
}
if (ReflectionContextState.isCreatingNullObjects(context)) {
Map collMap = getSetMap(context, c, keyProperty, collClass);
if (key.toString().equals(KEY_PROPERTY_FOR_CREATION)) {
//this should return the XWorkList
//for this set that contains new entries
//then the ListPropertyAccessor will be called
//to access it in the next sequence
return collMap.get(null);
}
Object realKey = xworkConverter.convertValue(context, key, keyType);
Object value = collMap.get(realKey);
if (value == null
&& ReflectionContextState.isCreatingNullObjects(context)
&& objectTypeDeterminer
.shouldCreateIfNew(lastBeanClass,lastPropertyClass,c,keyProperty,false)) {
//create a new element and
//set the value of keyProperty
//to be the given value
try {
value=objectFactory.buildBean(collClass, context);
//set the value of the keyProperty
_accessor.setProperty(context,value,keyProperty,realKey);
//add the new object to the collection
c.add(value);
//add to the Map if accessed later
collMap.put(realKey, value);
} catch (Exception exc) {
throw new OgnlException("Error adding new element to collection", exc);
}
}
return value;