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