01: /*
02: * Created on Oct 22, 2005
03: */
04: package uk.org.ponder.beanutil.support;
05:
06: import java.util.Map;
07:
08: import uk.org.ponder.beanutil.PropertyAccessor;
09: import uk.org.ponder.util.EnumerationConverter;
10:
11: public class MapPropertyAccessor implements PropertyAccessor {
12: // This class is completely immutable, can universally use this instance.
13: public static final MapPropertyAccessor instance = new MapPropertyAccessor();
14:
15: public boolean canSet(String name) {
16: // well, we can't know any better at this point! If the JDK were better
17: // designed it might be possible.
18: return true;
19: }
20:
21: public void setProperty(Object parent, String name, Object value) {
22: ((Map) parent).put(name, value);
23: }
24:
25: public void unlink(Object parent, String name) {
26: ((Map) parent).remove(name);
27: }
28:
29: public boolean canGet(String name) {
30: return true;
31: }
32:
33: public Object getProperty(Object parent, String name) {
34: return ((Map) parent).get(name);
35: }
36:
37: public Class getPropertyType(Object parent, String name) {
38: Object got = ((Map) parent).get(name);
39: return got == null ? Object.class : got.getClass();
40: }
41:
42: public boolean isMultiple(Object parent, String name) {
43: return EnumerationConverter.isDenumerable(getPropertyType(
44: parent, name));
45: }
46: }
|