1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.api.extension;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.CoreConstants;
20 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
21 import org.kuali.rice.core.api.mo.ModelBuilder;
22 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
23 import org.kuali.rice.kew.api.KewApiConstants;
24 import org.w3c.dom.Element;
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.XmlRootElement;
31 import javax.xml.bind.annotation.XmlType;
32 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
33 import java.io.Serializable;
34 import java.util.Collection;
35 import java.util.Collections;
36 import java.util.HashMap;
37 import java.util.Map;
38
39
40
41
42
43
44
45 @XmlRootElement(name = ExtensionDefinition.Constants.ROOT_ELEMENT_NAME)
46 @XmlAccessorType(XmlAccessType.NONE)
47 @XmlType(name = ExtensionDefinition.Constants.TYPE_NAME, propOrder = {
48 ExtensionDefinition.Elements.ID,
49 ExtensionDefinition.Elements.NAME,
50 ExtensionDefinition.Elements.APPLICATION_ID,
51 ExtensionDefinition.Elements.LABEL,
52 ExtensionDefinition.Elements.DESCRIPTION,
53 ExtensionDefinition.Elements.TYPE,
54 ExtensionDefinition.Elements.RESOURCE_DESCRIPTOR,
55 ExtensionDefinition.Elements.CONFIGURATION,
56 CoreConstants.CommonElements.VERSION_NUMBER,
57 CoreConstants.CommonElements.FUTURE_ELEMENTS
58 })
59 public final class ExtensionDefinition extends AbstractDataTransferObject implements ExtensionDefinitionContract {
60
61 private static final long serialVersionUID = 6234968409006917945L;
62
63 @XmlElement(name = Elements.ID, required = false)
64 private final String id;
65
66 @XmlElement(name = Elements.NAME, required = true)
67 private final String name;
68
69 @XmlElement(name = Elements.APPLICATION_ID, required = false)
70 private final String applicationId;
71
72 @XmlElement(name = Elements.LABEL, required = false)
73 private final String label;
74
75 @XmlElement(name = Elements.DESCRIPTION, required = false)
76 private final String description;
77
78 @XmlElement(name = Elements.TYPE, required = true)
79 private final String type;
80
81 @XmlElement(name = Elements.RESOURCE_DESCRIPTOR, required = true)
82 private final String resourceDescriptor;
83
84 @XmlElement(name = Elements.CONFIGURATION, required = false)
85 @XmlJavaTypeAdapter(MapStringStringAdapter.class)
86 private final Map<String, String> configuration;
87
88 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
89 private final Long versionNumber;
90
91 @SuppressWarnings("unused")
92 @XmlAnyElement
93 private final Collection<Element> _futureElements = null;
94
95
96
97
98 @SuppressWarnings("unused")
99 private ExtensionDefinition() {
100 this.id = null;
101 this.name = null;
102 this.applicationId = null;
103 this.label = null;
104 this.description = null;
105 this.type = null;
106 this.resourceDescriptor = null;
107 this.configuration = null;
108 this.versionNumber = null;
109 }
110
111 private ExtensionDefinition(Builder builder) {
112 this.id = builder.getId();
113 this.name = builder.getName();
114 this.applicationId = builder.getApplicationId();
115 this.label = builder.getLabel();
116 this.description = builder.getDescription();
117 this.type = builder.getType();
118 this.resourceDescriptor = builder.getResourceDescriptor();
119 if (builder.getConfiguration() == null) {
120 this.configuration = Collections.emptyMap();
121 } else {
122 this.configuration = Collections.unmodifiableMap(new HashMap<String, String>(builder.getConfiguration()));
123 }
124 this.versionNumber = builder.getVersionNumber();
125 }
126
127 @Override
128 public String getId() {
129 return this.id;
130 }
131
132 @Override
133 public String getName() {
134 return this.name;
135 }
136
137 @Override
138 public String getApplicationId() {
139 return this.applicationId;
140 }
141
142 @Override
143 public String getLabel() {
144 return this.label;
145 }
146
147 @Override
148 public String getDescription() {
149 return this.description;
150 }
151
152 @Override
153 public String getType() {
154 return this.type;
155 }
156
157 @Override
158 public String getResourceDescriptor() {
159 return this.resourceDescriptor;
160 }
161
162 @Override
163 public Map<String, String> getConfiguration() {
164 return this.configuration;
165 }
166
167 @Override
168 public Long getVersionNumber() {
169 return this.versionNumber;
170 }
171
172
173
174
175
176 public final static class Builder implements Serializable, ModelBuilder, ExtensionDefinitionContract {
177
178 private String id;
179 private String name;
180 private String applicationId;
181 private String label;
182 private String description;
183 private String type;
184 private String resourceDescriptor;
185 private Map<String, String> configuration;
186 private Long versionNumber;
187
188 private Builder(String name, String type, String resourceDescriptor) {
189 setName(name);
190 setType(type);
191 setResourceDescriptor(resourceDescriptor);
192 setConfiguration(new HashMap<String, String>());
193 }
194
195 public static Builder create(String name, String type, String resourceDescriptor) {
196 return new Builder(name, type, resourceDescriptor);
197 }
198
199 public static Builder create(ExtensionDefinitionContract contract) {
200 if (contract == null) {
201 throw new IllegalArgumentException("contract was null");
202 }
203 Builder builder = create(contract.getName(), contract.getType(), contract.getResourceDescriptor());
204 builder.setId(contract.getId());
205 builder.setApplicationId(contract.getApplicationId());
206 builder.setLabel(contract.getLabel());
207 builder.setDescription(contract.getDescription());
208 builder.setConfiguration(contract.getConfiguration());
209 builder.setVersionNumber(contract.getVersionNumber());
210 return builder;
211 }
212
213 public ExtensionDefinition build() {
214 return new ExtensionDefinition(this);
215 }
216
217 @Override
218 public String getId() {
219 return this.id;
220 }
221
222 @Override
223 public String getName() {
224 return this.name;
225 }
226
227 @Override
228 public String getApplicationId() {
229 return this.applicationId;
230 }
231
232 @Override
233 public String getLabel() {
234 return this.label;
235 }
236
237 @Override
238 public String getDescription() {
239 return this.description;
240 }
241
242 @Override
243 public String getType() {
244 return this.type;
245 }
246
247 @Override
248 public String getResourceDescriptor() {
249 return this.resourceDescriptor;
250 }
251
252 @Override
253 public Map<String, String> getConfiguration() {
254 return this.configuration;
255 }
256
257 @Override
258 public Long getVersionNumber() {
259 return this.versionNumber;
260 }
261
262 public void setId(String id) {
263 this.id = id;
264 }
265
266 public void setName(String name) {
267 if (StringUtils.isBlank(name)) {
268 throw new IllegalArgumentException("name was null or blank");
269 }
270 this.name = name;
271 }
272
273 public void setApplicationId(String applicationId) {
274 this.applicationId = applicationId;
275 }
276
277 public void setLabel(String label) {
278 this.label = label;
279 }
280
281 public void setDescription(String description) {
282 this.description = description;
283 }
284
285 public void setType(String type) {
286 if (StringUtils.isBlank(type)) {
287 throw new IllegalArgumentException("type was null or blank");
288 }
289
290 this.type = type;
291 }
292
293 public void setResourceDescriptor(String resourceDescriptor) {
294 if (StringUtils.isBlank(resourceDescriptor)) {
295 throw new IllegalArgumentException("descriptor was null or blank");
296 }
297 this.resourceDescriptor = resourceDescriptor;
298 }
299
300 public void setConfiguration(Map<String, String> configuration) {
301 this.configuration = configuration;
302 }
303
304 public void setVersionNumber(Long versionNumber) {
305 this.versionNumber = versionNumber;
306 }
307
308 }
309
310
311
312
313 static class Constants {
314 final static String ROOT_ELEMENT_NAME = "extensionDefinition";
315 final static String TYPE_NAME = "ExtensionDefinitionType";
316 }
317
318
319
320
321 static class Elements {
322 final static String ID = "id";
323 final static String NAME = "name";
324 final static String APPLICATION_ID = "applicationId";
325 final static String LABEL = "label";
326 final static String DESCRIPTION = "description";
327 final static String TYPE = "type";
328 final static String RESOURCE_DESCRIPTOR = "resourceDescriptor";
329 final static String CONFIGURATION = "configuration";
330 }
331
332 public static class Cache {
333 public static final String NAME = KewApiConstants.Namespaces.KEW_NAMESPACE_2_0 + "/" + ExtensionDefinition.Constants.TYPE_NAME;
334 }
335 }