1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.clazz.reflect.extended;
17
18 import java.lang.reflect.Method;
19 import java.util.Map;
20
21 import org.apache.commons.clazz.Clazz;
22 import org.apache.commons.clazz.reflect.common.ReflectedAccessorPairProperty;
23
24
25
26
27
28
29 public class ReflectedMappedProperty extends ReflectedAccessorPairProperty {
30
31 private Class keyType;
32 private Class contentType;
33 private Method sizeMethod;
34 private Method getMethod;
35 private Method putMethod;
36 private Method removeMethod;
37 private Method keySetMethod;
38
39
40
41
42
43
44 public ReflectedMappedProperty(Clazz declaringClazz, String name) {
45 super(declaringClazz, name);
46 }
47
48
49
50
51 public boolean isMap() {
52 return true;
53 }
54
55
56
57
58
59 public Class getKeyType() {
60 return keyType;
61 }
62
63
64
65
66
67 public void setKeyType(Class keyType) {
68 this.keyType = keyType;
69 }
70
71
72
73
74
75 public Class getContentType() {
76 return contentType;
77 }
78
79
80
81
82
83 public void setContentType(Class valueType) {
84 this.contentType = valueType;
85 }
86
87
88
89
90
91 public Method getGetMethod() {
92 return getMethod;
93 }
94
95
96
97
98
99 public void setGetMethod(Method getMethod) {
100 this.getMethod = getMethod;
101 }
102
103
104
105
106
107 public Method getPutMethod() {
108 return putMethod;
109 }
110
111
112
113
114
115 public void setPutMethod(Method putMethod) {
116 this.putMethod = putMethod;
117 }
118
119
120
121
122
123 public Method getRemoveMethod() {
124 return removeMethod;
125 }
126
127
128
129
130
131 public void setRemoveMethod(Method removeMethod) {
132 this.removeMethod = removeMethod;
133 }
134
135
136
137
138
139 public Method getKeySetMethod() {
140 return keySetMethod;
141 }
142
143
144
145
146
147 public void setKeySetMethod(Method keySetMethod) {
148 this.keySetMethod = keySetMethod;
149 }
150
151 public String toString() {
152 StringBuffer buffer = new StringBuffer("[ReflectedMappedProperty ");
153 if (getType() != null) {
154 buffer.append(getType().getName());
155 buffer.append(" ");
156 }
157 if (getKeyType() != null) {
158 buffer.append("[key: ");
159 buffer.append(getKeyType().getName());
160 buffer.append("] ");
161 }
162 if (getContentType() != null) {
163 buffer.append("[content: ");
164 buffer.append(getContentType().getName());
165 buffer.append("] ");
166 }
167 buffer.append(getName());
168 if (getReadMethod() != null) {
169 buffer.append("\n [read method] ");
170 buffer.append(getReadMethod());
171 }
172 if (getWriteMethod() != null) {
173 buffer.append("\n [write method] ");
174 buffer.append(getWriteMethod());
175 }
176 if (getGetMethod() != null) {
177 buffer.append("\n [get method] ");
178 buffer.append(getGetMethod());
179 }
180 if (getPutMethod() != null) {
181 buffer.append("\n [put method] ");
182 buffer.append(getPutMethod());
183 }
184 if (getRemoveMethod() != null) {
185 buffer.append("\n [remove method] ");
186 buffer.append(getRemoveMethod());
187 }
188 if (getKeySetMethod() != null) {
189 buffer.append("\n [keySet method] ");
190 buffer.append(getKeySetMethod());
191 }
192 buffer.append("]");
193 return buffer.toString();
194 }
195
196
197
198 public Object get(Object instance) {
199 return new ReflectedMap(instance, this);
200 }
201
202 public Map getMap(Object instance) {
203 if (getReadMethod() == null) {
204 return null;
205 }
206
207 return (Map) super.get(instance);
208 }
209
210
211
212
213 public void set(Object instance, Object value) {
214 super.set(instance, value);
215 }
216 }