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 | 0 | super(declaringClazz, name); |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public boolean isMap() { |
52 | 0 | return true; |
53 | |
} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public Class getKeyType() { |
60 | 0 | return keyType; |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public void setKeyType(Class keyType) { |
68 | 0 | this.keyType = keyType; |
69 | 0 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public Class getContentType() { |
76 | 0 | return contentType; |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public void setContentType(Class valueType) { |
84 | 0 | this.contentType = valueType; |
85 | 0 | } |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public Method getGetMethod() { |
92 | 0 | return getMethod; |
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public void setGetMethod(Method getMethod) { |
100 | 0 | this.getMethod = getMethod; |
101 | 0 | } |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
public Method getPutMethod() { |
108 | 0 | return putMethod; |
109 | |
} |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public void setPutMethod(Method putMethod) { |
116 | 0 | this.putMethod = putMethod; |
117 | 0 | } |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public Method getRemoveMethod() { |
124 | 0 | return removeMethod; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
public void setRemoveMethod(Method removeMethod) { |
132 | 0 | this.removeMethod = removeMethod; |
133 | 0 | } |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public Method getKeySetMethod() { |
140 | 0 | return keySetMethod; |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
public void setKeySetMethod(Method keySetMethod) { |
148 | 0 | this.keySetMethod = keySetMethod; |
149 | 0 | } |
150 | |
|
151 | |
public String toString() { |
152 | 0 | StringBuffer buffer = new StringBuffer("[ReflectedMappedProperty "); |
153 | 0 | if (getType() != null) { |
154 | 0 | buffer.append(getType().getName()); |
155 | 0 | buffer.append(" "); |
156 | |
} |
157 | 0 | if (getKeyType() != null) { |
158 | 0 | buffer.append("[key: "); |
159 | 0 | buffer.append(getKeyType().getName()); |
160 | 0 | buffer.append("] "); |
161 | |
} |
162 | 0 | if (getContentType() != null) { |
163 | 0 | buffer.append("[content: "); |
164 | 0 | buffer.append(getContentType().getName()); |
165 | 0 | buffer.append("] "); |
166 | |
} |
167 | 0 | buffer.append(getName()); |
168 | 0 | if (getReadMethod() != null) { |
169 | 0 | buffer.append("\n [read method] "); |
170 | 0 | buffer.append(getReadMethod()); |
171 | |
} |
172 | 0 | if (getWriteMethod() != null) { |
173 | 0 | buffer.append("\n [write method] "); |
174 | 0 | buffer.append(getWriteMethod()); |
175 | |
} |
176 | 0 | if (getGetMethod() != null) { |
177 | 0 | buffer.append("\n [get method] "); |
178 | 0 | buffer.append(getGetMethod()); |
179 | |
} |
180 | 0 | if (getPutMethod() != null) { |
181 | 0 | buffer.append("\n [put method] "); |
182 | 0 | buffer.append(getPutMethod()); |
183 | |
} |
184 | 0 | if (getRemoveMethod() != null) { |
185 | 0 | buffer.append("\n [remove method] "); |
186 | 0 | buffer.append(getRemoveMethod()); |
187 | |
} |
188 | 0 | if (getKeySetMethod() != null) { |
189 | 0 | buffer.append("\n [keySet method] "); |
190 | 0 | buffer.append(getKeySetMethod()); |
191 | |
} |
192 | 0 | buffer.append("]"); |
193 | 0 | return buffer.toString(); |
194 | |
} |
195 | |
|
196 | |
|
197 | |
|
198 | |
public Object get(Object instance) { |
199 | 0 | return new ReflectedMap(instance, this); |
200 | |
} |
201 | |
|
202 | |
public Map getMap(Object instance) { |
203 | 0 | if (getReadMethod() == null) { |
204 | 0 | return null; |
205 | |
} |
206 | |
|
207 | 0 | return (Map) super.get(instance); |
208 | |
} |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
public void set(Object instance, Object value) { |
214 | 0 | super.set(instance, value); |
215 | 0 | } |
216 | |
} |