KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > property > MapAccessor


1 //$Id: MapAccessor.java,v 1.5 2005/07/16 22:20:47 oneovthafew Exp $
2
package org.hibernate.property;
3
4 import java.lang.reflect.Method JavaDoc;
5 import java.util.Map JavaDoc;
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 /**
13  * @author Gavin King
14  */

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