org.oddjob.arooa.standard.MapItemRuntime Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arooa Show documentation
Show all versions of arooa Show documentation
A Rip Off Of Ant - A drag and drop component framework.
/**
*
*/
package org.oddjob.arooa.standard;
import java.util.Map;
import java.util.Set;
import org.oddjob.arooa.ArooaException;
import org.oddjob.arooa.convert.ArooaConversionException;
import org.oddjob.arooa.convert.ArooaConverter;
import org.oddjob.arooa.parsing.ArooaContext;
import org.oddjob.arooa.reflect.ArooaPropertyException;
import org.oddjob.arooa.runtime.RuntimeConfiguration;
class MapItemRuntime extends InstanceRuntime {
private final String key;
MapItemRuntime(
String key,
InstanceConfiguration item,
ArooaContext context) {
super(item, context);
this.key = key;
}
ParentPropertySetter getParentPropertySetter() {
return new ParentPropertySetter() {
public void parentSetProperty(Object value)
throws ArooaPropertyException {
RuntimeConfiguration parentRuntime = getParentContext().getRuntime();
if (key == null) {
if (value == null) {
// probably destroy... this needs reworking.
return;
}
// property must be map
ArooaConverter converter = getContext().getSession(
).getTools().getArooaConverter();
try {
value = converter.convert(value, Map.class);
} catch (ArooaConversionException e) {
throw new ArooaException("Key must be provided for mapped property.");
}
@SuppressWarnings("unchecked")
Map map = (Map) value;
for (Map.Entry mapEntry : (Set>) map.entrySet() ) {
parentRuntime.setMappedProperty(
null,
(String) mapEntry.getKey(),
mapEntry.getValue());
}
}
else {
parentRuntime.setMappedProperty(
null,
key,
value);
}
}
};
}
}