1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.dataprovider.bean;
17
18 import java.lang.reflect.Field;
19 import java.lang.reflect.Modifier;
20
21 import org.xulux.utils.ClassLoaderUtils;
22
23
24
25
26
27
28
29
30 public class BeanParameter {
31
32
33
34
35 private String type;
36
37
38
39 private String value;
40
41
42
43 private Object object;
44
45
46
47
48 public BeanParameter() {
49 }
50
51
52
53
54
55
56
57 public BeanParameter(String type, String value) {
58 setType(type);
59 setValue(value);
60 }
61
62
63
64
65 public String getType() {
66 return this.type;
67 }
68
69
70
71
72
73 public String getValue() {
74 return this.value;
75 }
76
77
78
79
80
81
82 public void setType(String type) {
83 this.type = type;
84 }
85
86
87
88
89
90
91 public void setValue(String value) {
92 this.value = value;
93 }
94
95
96
97
98
99
100 public Object getObject() {
101 if (this.object == null) {
102 if (getType().equalsIgnoreCase("string")) {
103 this.object = value;
104 } else if (getType().equalsIgnoreCase("static")) {
105
106
107 int lastIndex = getValue().lastIndexOf(".");
108 String field = getValue().substring(getValue().lastIndexOf('.') + 1);
109 String classString = null;
110 if (lastIndex != -1) {
111 classString = getValue().substring(0, getValue().lastIndexOf("."));
112 } else {
113
114 classString = getValue();
115 }
116 Class clazz = ClassLoaderUtils.getClass(classString);
117 if (clazz != null) {
118 try {
119 Field f = clazz.getDeclaredField(field);
120
121 if (Modifier.isStatic(f.getModifiers())) {
122 this.object = f.get(null);
123 }
124 }
125 catch (Exception e) {
126 e.printStackTrace(System.out);
127 }
128 }
129 }
130 }
131 return this.object;
132 }
133
134
135
136
137 public String toString() {
138 return getType() + ":" + getValue();
139 }
140
141 }