1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 package com.ivata.mask;
58 import java.beans.PropertyDescriptor;
59 import java.util.Collections;
60 import java.util.List;
61 import java.util.Set;
62 import java.util.Vector;
63
64 import org.apache.commons.beanutils.PropertyUtils;
65 import com.ivata.mask.field.Field;
66 import com.ivata.mask.group.Group;
67 import com.ivata.mask.group.GroupImpl;
68 /***
69 * <p>
70 * In the Masks display configuration, a mask extends a group to define which
71 * fields come first and last, or the fields which should appear explicitly.
72 * </p>
73 *
74 * <p>
75 * Don't try to instantiate this class - use the mask factory instead.
76 * </p>
77 *
78 * @author Colin MacLeod
79 * @since ivata masks 0.1 (2004-05-15) <a
80 * href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com </a>
81 */
82 public class MaskImpl extends GroupImpl implements Mask {
83 /***
84 * The class of the dependent value objects which will be associated with
85 * this mask.
86 */
87 private Class dOClass;
88 /***
89 * Refer to {@link Mask#getIncludePaths}.
90 */
91 private List includePaths = new Vector();
92 /***
93 * Create a mask with the specified parent.
94 *
95 * @param dOClassParam
96 * The class of the data object displayed in this mask.
97 * @param parent
98 * Group which contains this mask, or parent mask this mask
99 * extends.
100 * @param nameParam
101 * Name of the mask. This is used in combination with the class
102 * name to build the identifier for each mask uniquely.
103 */
104 public MaskImpl(final Class dOClassParam,
105 final Group parent, final String nameParam) {
106 super(nameParam, parent);
107 this.dOClass = dOClassParam;
108 }
109 /***
110 * Refer to {@link Mask#getIncludePaths}.
111 * @param includePathParam The include path to add to the list.
112 */
113 public final void addIncludePath(final String includePathParam) {
114 this.includePaths.add(includePathParam);
115 }
116 /***
117 * Get the dependent object class associated with this mask.
118 *
119 * @return The class of the data object displayed in this mask.
120 */
121 public final Class getDOClass() {
122 return dOClass;
123 }
124 /***
125 * Get all the fields which should be displayed/hidden (not excluded) in
126 * this mask, in order.
127 *
128 * @return All field names apart from those explicitly excluded.
129 */
130 public final List getFields() {
131 Set allExcludedFieldNames = getAllExcludedFieldNames();
132 List firstFieldNames = getAllFirstFieldNames();
133 List lastFieldNames = getAllLastFieldNames();
134 PropertyDescriptor[] propertyDescriptors = PropertyUtils
135 .getPropertyDescriptors(dOClass);
136 List maskFields = new java.util.ArrayList();
137
138 for (int i = 0; i < firstFieldNames.size(); ++i) {
139 String firstFieldId = (String) firstFieldNames.get(i);
140 for (int j = 0; j < propertyDescriptors.length; j++) {
141 String name = propertyDescriptors[j].getName();
142 if (name.equals(firstFieldId)) {
143
144
145 if (!allExcludedFieldNames.contains(name)) {
146 Field field = getField(name);
147 if (field != null) {
148 maskFields.add(field);
149 }
150 }
151 break;
152 }
153 }
154 }
155
156
157 for (int i = 0; i < propertyDescriptors.length; i++) {
158 String name = propertyDescriptors[i].getName();
159
160 if (!firstFieldNames.contains(name)
161 && !allExcludedFieldNames.contains(name)
162 && !lastFieldNames.contains(name)) {
163 Field field = getField(name);
164 if (field != null) {
165 maskFields.add(field);
166 }
167 }
168 }
169
170 for (int i = 0; i < lastFieldNames.size(); ++i) {
171 String lastFieldId = (String) lastFieldNames.get(i);
172 for (int j = 0; j < propertyDescriptors.length; j++) {
173 String name = propertyDescriptors[j].getName();
174 if (name.equals(lastFieldId)) {
175
176 if (!firstFieldNames.contains(name)
177 && !allExcludedFieldNames.contains(name)) {
178 Field field = getField(name);
179 if (field != null) {
180 maskFields.add(field);
181 }
182 }
183 break;
184 }
185 }
186 }
187 return maskFields;
188 }
189 /***
190 * Refer to {@link Mask#getIncludePaths}.
191 * @return Returns all include paths.
192 */
193 public List getIncludePaths() {
194 return Collections.unmodifiableList(includePaths);
195 }
196 }