KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > introspector > Properties


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.introspector;
4
5 import java.lang.reflect.Method JavaDoc;
6 import java.util.ArrayList JavaDoc;
7
8 /**
9  * Bean properties
10  */

11 class Properties {
12
13     Methods getters = new Methods();
14     String JavaDoc[] getterNames = new String JavaDoc[0];
15     Methods setters = new Methods();
16     String JavaDoc[] setterNames = new String JavaDoc[0];
17
18     ArrayList JavaDoc getterNameList;
19     ArrayList JavaDoc setterNameList;
20
21     void addMethod(String JavaDoc name, Method JavaDoc method) {
22         if (name.charAt(0) == '-') {
23             name = name.substring(1);
24             getters.addMethod(name, method);
25             if (getterNameList == null) {
26                 getterNameList = new ArrayList JavaDoc();
27             }
28             getterNameList.add(name);
29         } else if (name.charAt(0) == '+') {
30             name = name.substring(1);
31             setters.addMethod(name, method);
32             if (setterNameList == null) {
33                 setterNameList = new ArrayList JavaDoc();
34             }
35             setterNameList.add(name);
36         }
37     }
38
39     void lock() {
40         if (getterNameList != null) {
41             getterNames = new String JavaDoc[getterNameList.size()];
42             for (int i = 0; i < getterNameList.size(); i++) {
43                 getterNames[i] = (String JavaDoc) getterNameList.get(i);
44             }
45             getterNameList = null;
46         }
47         if (setterNameList != null) {
48             setterNames = new String JavaDoc[setterNameList.size()];
49             for (int i = 0; i < setterNameList.size(); i++) {
50                 setterNames[i] = (String JavaDoc) setterNameList.get(i);
51             }
52             setterNameList = null;
53         }
54         getters.lock();
55         setters.lock();
56     }
57
58     public String JavaDoc[] getAllBeanGetterNames() {
59         return getterNames;
60     }
61     public String JavaDoc[] getAllBeanSetterNames() {
62         return setterNames;
63     }
64 }
Popular Tags