View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.w3c.dom.Element;
24  
25  import javax.xml.bind.annotation.XmlAccessType;
26  import javax.xml.bind.annotation.XmlAccessorType;
27  import javax.xml.bind.annotation.XmlAnyElement;
28  import javax.xml.bind.annotation.XmlElement;
29  import javax.xml.bind.annotation.XmlRootElement;
30  import javax.xml.bind.annotation.XmlType;
31  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
32  import java.io.Serializable;
33  import java.util.Collection;
34  import java.util.Collections;
35  import java.util.HashMap;
36  import java.util.Map;
37  
38  /**
39   * Immutable implementation of the {@link ExtensionDefinitionContract}.  Defines an extension to some component of
40   * Kuali Enterprise Workflow.
41   *
42   * @author Kuali Rice Team (rice.collab@kuali.org)
43   */
44  @XmlRootElement(name = ExtensionDefinition.Constants.ROOT_ELEMENT_NAME)
45  @XmlAccessorType(XmlAccessType.NONE)
46  @XmlType(name = ExtensionDefinition.Constants.TYPE_NAME, propOrder = {
47          ExtensionDefinition.Elements.ID,
48          ExtensionDefinition.Elements.NAME,
49          ExtensionDefinition.Elements.APPLICATION_ID,
50          ExtensionDefinition.Elements.LABEL,
51          ExtensionDefinition.Elements.DESCRIPTION,
52          ExtensionDefinition.Elements.TYPE,
53          ExtensionDefinition.Elements.RESOURCE_DESCRIPTOR,
54          ExtensionDefinition.Elements.CONFIGURATION,
55          CoreConstants.CommonElements.VERSION_NUMBER,
56          CoreConstants.CommonElements.FUTURE_ELEMENTS
57  })
58  public final class ExtensionDefinition extends AbstractDataTransferObject implements ExtensionDefinitionContract {
59  
60      private static final long serialVersionUID = 6234968409006917945L;
61      
62      @XmlElement(name = Elements.ID, required = false)
63      private final String id;
64  
65      @XmlElement(name = Elements.NAME, required = true)
66      private final String name;
67  
68      @XmlElement(name = Elements.APPLICATION_ID, required = false)
69      private final String applicationId;
70  
71      @XmlElement(name = Elements.LABEL, required = false)
72      private final String label;
73  
74      @XmlElement(name = Elements.DESCRIPTION, required = false)
75      private final String description;
76  
77      @XmlElement(name = Elements.TYPE, required = true)
78      private final String type;
79  
80      @XmlElement(name = Elements.RESOURCE_DESCRIPTOR, required = true)
81      private final String resourceDescriptor;
82  
83      @XmlElement(name = Elements.CONFIGURATION, required = false)
84      @XmlJavaTypeAdapter(MapStringStringAdapter.class)
85      private final Map<String, String> configuration;
86  
87      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
88      private final Long versionNumber;
89  
90      @SuppressWarnings("unused")
91      @XmlAnyElement
92      private final Collection<Element> _futureElements = null;
93  
94      /**
95       * Private constructor used only by JAXB.
96       */
97      @SuppressWarnings("unused")
98      private ExtensionDefinition() {
99          this.id = null;
100         this.name = null;
101         this.applicationId = null;
102         this.label = null;
103         this.description = null;
104         this.type = null;
105         this.resourceDescriptor = null;
106         this.configuration = null;
107         this.versionNumber = null;
108     }
109 
110     private ExtensionDefinition(Builder builder) {
111         this.id = builder.getId();
112         this.name = builder.getName();
113         this.applicationId = builder.getApplicationId();
114         this.label = builder.getLabel();
115         this.description = builder.getDescription();
116         this.type = builder.getType();
117         this.resourceDescriptor = builder.getResourceDescriptor();
118         if (builder.getConfiguration() == null) {
119             this.configuration = Collections.emptyMap();
120         } else {
121             this.configuration = Collections.unmodifiableMap(new HashMap<String, String>(builder.getConfiguration()));
122         }
123         this.versionNumber = builder.getVersionNumber();
124     }
125 
126     @Override
127     public String getId() {
128         return this.id;
129     }
130 
131     @Override
132     public String getName() {
133         return this.name;
134     }
135 
136     @Override
137     public String getApplicationId() {
138         return this.applicationId;
139     }
140 
141     @Override
142     public String getLabel() {
143         return this.label;
144     }
145 
146     @Override
147     public String getDescription() {
148         return this.description;
149     }
150 
151     @Override
152     public String getType() {
153         return this.type;
154     }
155 
156     @Override
157     public String getResourceDescriptor() {
158         return this.resourceDescriptor;
159     }
160 
161     @Override
162     public Map<String, String> getConfiguration() {
163         return this.configuration;
164     }
165 
166     @Override
167     public Long getVersionNumber() {
168         return this.versionNumber;
169     }
170 
171     /**
172      * A builder which can be used to construct {@link ExtensionDefinition} instances.  Enforces the constraints of the
173      * {@link ExtensionDefinitionContract}.
174      */
175     public final static class Builder implements Serializable, ModelBuilder, ExtensionDefinitionContract {
176 
177         private String id;
178         private String name;
179         private String applicationId;
180         private String label;
181         private String description;
182         private String type;
183         private String resourceDescriptor;
184         private Map<String, String> configuration;
185         private Long versionNumber;
186 
187         private Builder(String name, String type, String resourceDescriptor) {
188             setName(name);
189             setType(type);
190             setResourceDescriptor(resourceDescriptor);
191             setConfiguration(new HashMap<String, String>());
192         }
193 
194         public static Builder create(String name, String type, String resourceDescriptor) {
195             return new Builder(name, type, resourceDescriptor);
196         }
197 
198         public static Builder create(ExtensionDefinitionContract contract) {
199             if (contract == null) {
200                 throw new IllegalArgumentException("contract was null");
201             }
202             Builder builder = create(contract.getName(), contract.getType(), contract.getResourceDescriptor());
203             builder.setId(contract.getId());
204             builder.setApplicationId(contract.getApplicationId());
205             builder.setLabel(contract.getLabel());
206             builder.setDescription(contract.getDescription());
207             builder.setConfiguration(contract.getConfiguration());
208             builder.setVersionNumber(contract.getVersionNumber());
209             return builder;
210         }
211 
212         public ExtensionDefinition build() {
213             return new ExtensionDefinition(this);
214         }
215 
216         @Override
217         public String getId() {
218             return this.id;
219         }
220 
221         @Override
222         public String getName() {
223             return this.name;
224         }
225 
226         @Override
227         public String getApplicationId() {
228             return this.applicationId;
229         }
230 
231         @Override
232         public String getLabel() {
233             return this.label;
234         }
235 
236         @Override
237         public String getDescription() {
238             return this.description;
239         }
240 
241         @Override
242         public String getType() {
243             return this.type;
244         }
245 
246         @Override
247         public String getResourceDescriptor() {
248             return this.resourceDescriptor;
249         }
250 
251         @Override
252         public Map<String, String> getConfiguration() {
253             return this.configuration;
254         }
255 
256         @Override
257         public Long getVersionNumber() {
258             return this.versionNumber;
259         }
260 
261         public void setId(String id) {
262             this.id = id;
263         }
264 
265         public void setName(String name) {
266             if (StringUtils.isBlank(name)) {
267                 throw new IllegalArgumentException("name was null or blank");
268             }
269             this.name = name;
270         }
271 
272         public void setApplicationId(String applicationId) {
273             this.applicationId = applicationId;
274         }
275 
276         public void setLabel(String label) {
277             this.label = label;
278         }
279 
280         public void setDescription(String description) {
281             this.description = description;
282         }
283 
284         public void setType(String type) {
285             if (StringUtils.isBlank(type)) {
286                 throw new IllegalArgumentException("type was null or blank");
287             }
288 
289             this.type = type;
290         }
291 
292         public void setResourceDescriptor(String resourceDescriptor) {
293             if (StringUtils.isBlank(resourceDescriptor)) {
294                 throw new IllegalArgumentException("descriptor was null or blank");
295             }
296             this.resourceDescriptor = resourceDescriptor;
297         }
298 
299         public void setConfiguration(Map<String, String> configuration) {
300             this.configuration = configuration;
301         }
302 
303         public void setVersionNumber(Long versionNumber) {
304             this.versionNumber = versionNumber;
305         }
306 
307     }
308 
309     /**
310      * Defines some internal constants used on this class.
311      */
312     static class Constants {
313         final static String ROOT_ELEMENT_NAME = "extensionDefinition";
314         final static String TYPE_NAME = "ExtensionDefinitionType";
315     }
316 
317     /**
318      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
319      */
320     static class Elements {
321         final static String ID = "id";
322         final static String NAME = "name";
323         final static String APPLICATION_ID = "applicationId";
324         final static String LABEL = "label";
325         final static String DESCRIPTION = "description";
326         final static String TYPE = "type";
327         final static String RESOURCE_DESCRIPTOR = "resourceDescriptor";
328         final static String CONFIGURATION = "configuration";
329     }
330 
331 }