1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.api.document.attribute;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import javax.xml.bind.annotation.XmlAccessType;
27 import javax.xml.bind.annotation.XmlAccessorType;
28 import javax.xml.bind.annotation.XmlAnyElement;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.XmlElementWrapper;
31 import javax.xml.bind.annotation.XmlRootElement;
32 import javax.xml.bind.annotation.XmlType;
33
34 import org.apache.commons.lang.StringUtils;
35 import org.kuali.rice.core.api.CoreConstants;
36 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
37 import org.kuali.rice.core.api.mo.ModelBuilder;
38 import org.kuali.rice.kew.api.document.PropertyDefinition;
39 import org.w3c.dom.Element;
40
41
42
43
44
45
46
47
48
49
50 @XmlRootElement(name = WorkflowAttributeDefinition.Constants.ROOT_ELEMENT_NAME)
51 @XmlAccessorType(XmlAccessType.NONE)
52 @XmlType(name = WorkflowAttributeDefinition.Constants.TYPE_NAME, propOrder = {
53 WorkflowAttributeDefinition.Elements.ATTRIBUTE_NAME,
54 WorkflowAttributeDefinition.Elements.PARAMETERS,
55 WorkflowAttributeDefinition.Elements.PROPERTY_DEFINITIONS,
56 CoreConstants.CommonElements.FUTURE_ELEMENTS
57 })
58 public final class WorkflowAttributeDefinition extends AbstractDataTransferObject {
59
60 @XmlElement(name = Elements.ATTRIBUTE_NAME, required = true)
61 private final String attributeName;
62
63 @XmlElementWrapper(name = Elements.PARAMETERS, required = false)
64 @XmlElement(name = Elements.PARAMETER, required = false)
65 private final List<String> parameters;
66
67 @XmlElementWrapper(name = Elements.PROPERTY_DEFINITIONS, required = false)
68 @XmlElement(name = Elements.PROPERTY_DEFINITION, required = false)
69 private final List<PropertyDefinition> propertyDefinitions;
70
71 @SuppressWarnings("unused")
72 @XmlAnyElement
73 private final Collection<Element> _futureElements = null;
74
75
76
77
78 private WorkflowAttributeDefinition() {
79 this.attributeName = null;
80 this.parameters = null;
81 this.propertyDefinitions = null;
82 }
83
84 private WorkflowAttributeDefinition(Builder builder) {
85 this.attributeName = builder.getAttributeName();
86 if (builder.getParameters() == null) {
87 this.parameters = Collections.emptyList();
88 } else {
89 this.parameters = new ArrayList<String>(builder.getParameters());
90 }
91 if (builder.getPropertyDefinitions() == null) {
92 this.propertyDefinitions = Collections.emptyList();
93 } else {
94 this.propertyDefinitions = new ArrayList<PropertyDefinition>(builder.getPropertyDefinitions());
95 }
96 }
97
98
99
100
101
102
103 public String getAttributeName() {
104 return attributeName;
105 }
106
107
108
109
110
111
112
113 public List<String> getParameters() {
114 return Collections.unmodifiableList(parameters);
115 }
116
117
118
119
120
121
122
123 public List<PropertyDefinition> getPropertyDefinitions() {
124 return Collections.unmodifiableList(propertyDefinitions);
125 }
126
127
128
129
130
131
132
133 public Map<String, String> getPropertyDefinitionsAsMap() {
134 Map<String, String> propertiesDefinitionsMap = new HashMap<String, String>();
135 for (PropertyDefinition propertyDefinition : getPropertyDefinitions()) {
136 propertiesDefinitionsMap.put(propertyDefinition.getName(), propertyDefinition.getValue());
137 }
138 return Collections.unmodifiableMap(propertiesDefinitionsMap);
139 }
140
141
142
143
144 public final static class Builder implements Serializable, ModelBuilder {
145
146 private static final long serialVersionUID = 7549637048594326790L;
147
148 private String attributeName;
149 private List<String> parameters;
150 private List<PropertyDefinition> propertyDefinitions;
151
152 private Builder(String attributeName) {
153 setAttributeName(attributeName);
154 setParameters(new ArrayList<String>());
155 setPropertyDefinitions(new ArrayList<PropertyDefinition>());
156 }
157
158 private Builder(WorkflowAttributeDefinition definition) {
159 setAttributeName(definition.getAttributeName());
160 setParameters(definition.getParameters());
161 setPropertyDefinitions(definition.getPropertyDefinitions());
162 }
163
164
165
166
167
168
169
170 public static Builder create(WorkflowAttributeDefinition definition) {
171 if (definition == null) {
172 throw new IllegalArgumentException("definition was null");
173 }
174 return new Builder(definition);
175 }
176
177
178
179
180
181
182
183
184
185
186
187 public static Builder create(String attributeName) {
188 return new Builder(attributeName);
189
190 }
191
192 @Override
193 public WorkflowAttributeDefinition build() {
194 return new WorkflowAttributeDefinition(this);
195 }
196
197
198
199
200
201
202 public String getAttributeName() {
203 return attributeName;
204 }
205
206
207
208
209
210
211 public List<String> getParameters() {
212 return parameters;
213 }
214
215
216
217
218
219
220 public List<PropertyDefinition> getPropertyDefinitions() {
221 return propertyDefinitions;
222 }
223
224
225
226
227
228
229
230 public void setAttributeName(String attributeName) {
231 if (StringUtils.isBlank(attributeName)) {
232 throw new IllegalArgumentException("attributeName was null or blank");
233 }
234 this.attributeName = attributeName;
235 }
236
237
238
239
240
241
242 public void addParameter(String parameter) {
243 parameters.add(parameter);
244 }
245
246
247
248
249
250
251 public void removeParameter(String parameter) {
252 parameters.remove(parameter);
253 }
254
255
256
257
258
259
260 public void setParameters(List<String> parameters) {
261 this.parameters = new ArrayList<String>(parameters);
262 }
263
264
265
266
267
268
269
270 public void addPropertyDefinition(PropertyDefinition propertyDefinition) {
271 if (propertyDefinition == null) {
272 throw new IllegalArgumentException("propertyDefinition must be non-null.");
273 }
274 propertyDefinitions.add(propertyDefinition);
275 }
276
277
278
279
280
281
282 public void setPropertyDefinitions(List<PropertyDefinition> propertyDefinitions) {
283 if (propertyDefinitions == null) {
284 setPropertyDefinitions(new ArrayList<PropertyDefinition>());
285 }
286 this.propertyDefinitions = new ArrayList<PropertyDefinition>(propertyDefinitions);
287
288 }
289
290
291
292
293
294
295
296
297
298
299 public void addPropertyDefinition(String name, String value) {
300 addPropertyDefinition(PropertyDefinition.create(name, value));
301 }
302
303
304
305
306
307
308
309
310
311
312
313 public PropertyDefinition getPropertyDefinition(String name) {
314 if (StringUtils.isBlank(name)) {
315 throw new IllegalArgumentException("name was null or blank");
316 }
317 for (PropertyDefinition propertyDefinition : propertyDefinitions) {
318 if (propertyDefinition.equals(name)) {
319 return propertyDefinition;
320 }
321 }
322 return null;
323 }
324
325
326 }
327
328
329
330
331 static class Constants {
332 final static String ROOT_ELEMENT_NAME = "workflowAttributeDefinition";
333 final static String TYPE_NAME = "WorkflowAttributeDefinitionType";
334 }
335
336
337
338
339 static class Elements {
340 final static String ATTRIBUTE_NAME = "attributeName";
341 final static String PARAMETERS = "parameters";
342 final static String PARAMETER = "parameter";
343 final static String PROPERTY_DEFINITIONS = "propertyDefinitions";
344 final static String PROPERTY_DEFINITION = "propertyDefinition";
345 }
346
347 }