|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package net.sf.sojo.core.filter; |
|
17 |
| |
|
18 |
| import java.util.ArrayList; |
|
19 |
| import java.util.List; |
|
20 |
| import java.util.regex.Pattern; |
|
21 |
| |
|
22 |
| import net.sf.sojo.util.Util; |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class ClassPropertyFilter { |
|
35 |
| |
|
36 |
| |
|
37 |
| private Class filterClass = null; |
|
38 |
| private List propertyList = new ArrayList(); |
|
39 |
| private boolean support4AddClassProperty = false; |
|
40 |
| |
|
41 |
2
| public ClassPropertyFilter() { }
|
|
42 |
| |
|
43 |
57
| public ClassPropertyFilter(Class pvClass) {
|
|
44 |
57
| setFilterClass(pvClass);
|
|
45 |
| } |
|
46 |
| |
|
47 |
| |
|
48 |
13
| public ClassPropertyFilter(Class pvClass, String pvProperties[]) {
|
|
49 |
13
| setFilterClass(pvClass);
|
|
50 |
13
| addProperties(pvProperties);
|
|
51 |
| } |
|
52 |
| |
|
53 |
| |
|
54 |
59
| public Class getFilterClass() { return filterClass; }
|
|
55 |
70
| private void setFilterClass(Class pvClass) { this.filterClass = pvClass; }
|
|
56 |
| |
|
57 |
29
| public void setSupport4AddClassProperty(boolean pvSupport4AddClassProperty) { support4AddClassProperty = pvSupport4AddClassProperty; }
|
|
58 |
43
| public boolean getSupport4AddClassProperty() { return support4AddClassProperty; }
|
|
59 |
| |
|
60 |
| |
|
61 |
31
| public ClassPropertyFilter addProperties(String pvProperties[]) {
|
|
62 |
31
| if (pvProperties != null) {
|
|
63 |
29
| for (int i = 0; i < pvProperties.length; i++) {
|
|
64 |
44
| addProperty(pvProperties[i]);
|
|
65 |
| } |
|
66 |
| } |
|
67 |
31
| return this;
|
|
68 |
| } |
|
69 |
| |
|
70 |
200
| public ClassPropertyFilter addProperty(String pvProperty) {
|
|
71 |
200
| if (Util.getKeyWordClass().equals(pvProperty) == false || getSupport4AddClassProperty()) {
|
|
72 |
177
| propertyList.add(pvProperty);
|
|
73 |
| } |
|
74 |
200
| return this;
|
|
75 |
| } |
|
76 |
| |
|
77 |
18
| public ClassPropertyFilter removeProperty(String pvProperty) {
|
|
78 |
18
| for (int i=0; i<propertyList.size(); i++) {
|
|
79 |
45
| if (propertyList.get(i).equals(pvProperty)) {
|
|
80 |
14
| propertyList.remove(i);
|
|
81 |
| } |
|
82 |
| } |
|
83 |
18
| return this;
|
|
84 |
| } |
|
85 |
| |
|
86 |
3
| public ClassPropertyFilter removeProperties(String pvProperty[]) {
|
|
87 |
3
| if (pvProperty != null) {
|
|
88 |
2
| for (int i = 0; i < pvProperty.length; i++) {
|
|
89 |
6
| removeProperty(pvProperty[i]);
|
|
90 |
| } |
|
91 |
| } |
|
92 |
3
| return this;
|
|
93 |
| } |
|
94 |
| |
|
95 |
261
| public boolean isKnownProperty(String pvProperty) {
|
|
96 |
261
| for (int i=0; i<propertyList.size(); i++) {
|
|
97 |
435
| if (propertyList.get(i).equals(pvProperty)) {
|
|
98 |
81
| return true;
|
|
99 |
| } |
|
100 |
| else { |
|
101 |
354
| boolean b = Pattern.matches((String) propertyList.get(i), pvProperty);
|
|
102 |
354
| if (b == true) {
|
|
103 |
1
| return true;
|
|
104 |
| } |
|
105 |
| } |
|
106 |
| } |
|
107 |
179
| return false;
|
|
108 |
| } |
|
109 |
| |
|
110 |
17
| public int getPropertySize() {
|
|
111 |
17
| return propertyList.size();
|
|
112 |
| } |
|
113 |
| |
|
114 |
6
| public String[] getAllProperties() {
|
|
115 |
6
| return (String[]) propertyList.toArray(new String [propertyList.size()]);
|
|
116 |
| } |
|
117 |
| |
|
118 |
| } |