1 package org.hibernate.property; 3 4 import java.lang.reflect.Method ; 5 import java.util.Map ; 6 7 import org.hibernate.HibernateException; 8 import org.hibernate.PropertyNotFoundException; 9 import org.hibernate.engine.SessionFactoryImplementor; 10 import org.hibernate.engine.SessionImplementor; 11 12 15 public class MapAccessor implements PropertyAccessor { 16 17 public Getter getGetter(Class theClass, String propertyName) 18 throws PropertyNotFoundException { 19 return new MapGetter(propertyName); 20 } 21 22 public Setter getSetter(Class theClass, String propertyName) 23 throws PropertyNotFoundException { 24 return new MapSetter(propertyName); 25 } 26 27 public static final class MapSetter implements Setter { 28 29 private String name; 30 31 MapSetter(String name) { 32 this.name = name; 33 } 34 35 public Method getMethod() { 36 return null; 37 } 38 39 public String getMethodName() { 40 return null; 41 } 42 43 public void set(Object target, Object value, SessionFactoryImplementor factory) 44 throws HibernateException { 45 ( (Map ) target ).put(name, value); 46 } 47 48 } 49 50 public static final class MapGetter implements Getter { 51 52 private String name; 53 54 MapGetter(String name) { 55 this.name = name; 56 } 57 58 public Method getMethod() { 59 return null; 60 } 61 62 public String getMethodName() { 63 return null; 64 } 65 66 public Object get(Object target) throws HibernateException { 67 return ( (Map ) target ).get(name); 68 } 69 70 public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) { 71 return get( target ); 72 } 73 74 public Class getReturnType() { 75 return Object .class; 76 } 77 78 } 79 80 } 81 | Popular Tags |