1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.apache.commons.clazz.reflect.common; |
17 | |
|
18 | |
import java.lang.reflect.Method; |
19 | |
|
20 | |
import org.apache.commons.clazz.Clazz; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class ReflectedListProperty extends ReflectedAccessorPairProperty { |
28 | |
|
29 | |
private Class contentType; |
30 | |
private Method sizeMethod; |
31 | |
private Method getMethod; |
32 | |
private Method addMethod; |
33 | |
private Method addIndexedMethod; |
34 | |
private Method setMethod; |
35 | |
private Method removeMethod; |
36 | |
private Method removeIndexedMethod; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public ReflectedListProperty(Clazz declaringClazz, String name) { |
44 | 0 | super(declaringClazz, name); |
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public boolean isCollection() { |
51 | 0 | return true; |
52 | |
} |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public Class getContentType() { |
59 | 0 | return contentType; |
60 | |
} |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public void setContentType(Class valueType) { |
67 | 0 | this.contentType = valueType; |
68 | 0 | } |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public Method getGetMethod() { |
75 | 0 | return getMethod; |
76 | |
} |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public void setGetMethod(Method getMethod) { |
83 | 0 | this.getMethod = getMethod; |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public Method getSetMethod() { |
91 | 0 | return setMethod; |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public void setSetMethod(Method setMethod) { |
99 | 0 | this.setMethod = setMethod; |
100 | 0 | } |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public Method getAddMethod() { |
107 | 0 | return addMethod; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public void setAddMethod(Method addMethod) { |
115 | 0 | this.addMethod = addMethod; |
116 | 0 | } |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public Method getAddIndexedMethod() { |
123 | 0 | return addIndexedMethod; |
124 | |
} |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public void setAddIndexedMethod(Method addIndexedMethod) { |
131 | 0 | this.addIndexedMethod = addIndexedMethod; |
132 | 0 | } |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
public Method getRemoveMethod() { |
139 | 0 | return removeMethod; |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
public void setRemoveMethod(Method removeMethod) { |
147 | 0 | this.removeMethod = removeMethod; |
148 | 0 | } |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public Method getRemoveIndexedMethod() { |
155 | 0 | return removeIndexedMethod; |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
public void setRemoveIndexedMethod(Method removeIndexedMethod) { |
163 | 0 | this.removeIndexedMethod = removeIndexedMethod; |
164 | 0 | } |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public Method getSizeMethod() { |
171 | 0 | return sizeMethod; |
172 | |
} |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
public void setSizeMethod(Method sizeMethod) { |
179 | 0 | this.sizeMethod = sizeMethod; |
180 | 0 | } |
181 | |
|
182 | |
public String toString() { |
183 | 0 | StringBuffer buffer = new StringBuffer("[ReflectedListProperty "); |
184 | 0 | if (getType() != null) { |
185 | 0 | buffer.append(getType().getName()); |
186 | 0 | buffer.append(" "); |
187 | |
} |
188 | 0 | if (getContentType() != null) { |
189 | 0 | buffer.append("[content: "); |
190 | 0 | buffer.append(getContentType().getName()); |
191 | 0 | buffer.append("] "); |
192 | |
} |
193 | 0 | buffer.append(getName()); |
194 | 0 | if (getReadMethod() != null) { |
195 | 0 | buffer.append("\n [read method] "); |
196 | 0 | buffer.append(getReadMethod()); |
197 | |
} |
198 | 0 | if (getWriteMethod() != null) { |
199 | 0 | buffer.append("\n [write method] "); |
200 | 0 | buffer.append(getWriteMethod()); |
201 | |
} |
202 | 0 | if (getGetMethod() != null) { |
203 | 0 | buffer.append("\n [get method] "); |
204 | 0 | buffer.append(getGetMethod()); |
205 | |
} |
206 | 0 | if (getSetMethod() != null) { |
207 | 0 | buffer.append("\n [set method] "); |
208 | 0 | buffer.append(getSetMethod()); |
209 | |
} |
210 | 0 | if (getAddMethod() != null) { |
211 | 0 | buffer.append("\n [add method] "); |
212 | 0 | buffer.append(getAddMethod()); |
213 | |
} |
214 | 0 | if (getAddIndexedMethod() != null) { |
215 | 0 | buffer.append("\n [add(i) method] "); |
216 | 0 | buffer.append(getAddIndexedMethod()); |
217 | |
} |
218 | 0 | if (getRemoveMethod() != null) { |
219 | 0 | buffer.append("\n [remove method] "); |
220 | 0 | buffer.append(getRemoveMethod()); |
221 | |
} |
222 | 0 | if (getRemoveIndexedMethod() != null) { |
223 | 0 | buffer.append("\n [remove(i) method] "); |
224 | 0 | buffer.append(getRemoveIndexedMethod()); |
225 | |
} |
226 | 0 | if (getSizeMethod() != null) { |
227 | 0 | buffer.append("\n [size method] "); |
228 | 0 | buffer.append(getSizeMethod()); |
229 | |
} |
230 | 0 | buffer.append("]"); |
231 | 0 | return buffer.toString(); |
232 | |
} |
233 | |
|
234 | |
|
235 | |
|
236 | |
public Object get(Object instance) { |
237 | 0 | return new ReflectedList(instance, this); |
238 | |
} |
239 | |
|
240 | |
public Object getList(Object instance) { |
241 | 0 | return super.get(instance); |
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
public void set(Object instance, Object value) { |
248 | 0 | super.set(instance, value); |
249 | 0 | } |
250 | |
} |