View Javadoc

1   /**
2    * Copyright 2005-2013 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.krms.api.repository.language;
17  
18  import org.kuali.rice.core.api.CoreConstants;
19  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
20  import org.kuali.rice.core.api.mo.ModelBuilder;
21  import org.w3c.dom.Element;
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  import javax.xml.bind.annotation.XmlAnyElement;
25  import javax.xml.bind.annotation.XmlElement;
26  import javax.xml.bind.annotation.XmlRootElement;
27  import javax.xml.bind.annotation.XmlType;
28  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
29  import java.io.Serializable;
30  import java.util.Collection;
31  import java.util.Collections;
32  import java.util.HashMap;
33  import java.util.Map;
34  
35  /**
36   * Generated using JVM arguments -DNOT_BLANK=languageCode,naturalLanguageUsageId,typeId,template -DFOREIGN_KEY=naturalLanguageUsageId:org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage,typeId:org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition 
37   * Concrete model object implementation, immutable. 
38   * Instances can be (un)marshalled to and from XML.
39   * 
40   * @see NaturalLanguageTemplateContract
41   * 
42   * @author Kuali Rice Team (rice.collab@kuali.org)
43   * 
44   */
45  @XmlRootElement(name = NaturalLanguageTemplate.Constants.ROOT_ELEMENT_NAME)
46  @XmlAccessorType(XmlAccessType.NONE)
47  @XmlType(name = NaturalLanguageTemplate.Constants.TYPE_NAME, propOrder = {
48      NaturalLanguageTemplate.Elements.ATTRIBUTES,
49      NaturalLanguageTemplate.Elements.LANGUAGE_CODE,
50      NaturalLanguageTemplate.Elements.NATURAL_LANGUAGE_USAGE_ID,
51      NaturalLanguageTemplate.Elements.TYPE_ID,
52      NaturalLanguageTemplate.Elements.TEMPLATE,
53      NaturalLanguageTemplate.Elements.ID,
54      NaturalLanguageTemplate.Elements.ACTIVE,
55      CoreConstants.CommonElements.VERSION_NUMBER,
56      CoreConstants.CommonElements.FUTURE_ELEMENTS
57  })
58  public final class NaturalLanguageTemplate
59      extends AbstractDataTransferObject
60      implements NaturalLanguageTemplateContract
61  {
62  
63      @XmlJavaTypeAdapter(org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter.class)
64      @XmlElement(name = Elements.ATTRIBUTES, required = false)
65      private final Map<String, String> attributes;
66      @XmlElement(name = Elements.LANGUAGE_CODE, required = false)
67      private final String languageCode;
68      @XmlElement(name = Elements.NATURAL_LANGUAGE_USAGE_ID, required = false)
69      private final String naturalLanguageUsageId;
70      @XmlElement(name = Elements.TYPE_ID, required = false)
71      private final String typeId;
72      @XmlElement(name = Elements.TEMPLATE, required = false)
73      private final String template;
74      @XmlElement(name = Elements.ID, required = false)
75      private final String id;
76      @XmlElement(name = Elements.ACTIVE, required = false)
77      private final boolean active;
78      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
79      private final Long versionNumber;
80      @SuppressWarnings("unused")
81      @XmlAnyElement
82      private final Collection<Element> _futureElements = null;
83  
84      /**
85       * Private constructor used only by JAXB. This constructor should never be called.
86       * It is only present for use during JAXB unmarshalling.
87       * 
88       */
89      private NaturalLanguageTemplate() {
90          this.attributes = null;
91          this.languageCode = null;
92          this.naturalLanguageUsageId = null;
93          this.typeId = null;
94          this.template = null;
95          this.id = null;
96          this.active = true;
97          this.versionNumber = null;
98      }
99  
100     /**
101      * Constructs an object from the given builder.  This constructor is private and should only ever be invoked from the builder.
102      * 
103      * @param builder the Builder from which to construct the object.
104      * 
105      */
106     private NaturalLanguageTemplate(Builder builder) {
107         this.attributes = builder.getAttributes();
108         this.languageCode = builder.getLanguageCode();
109         this.naturalLanguageUsageId = builder.getNaturalLanguageUsageId();
110         this.typeId = builder.getTypeId();
111         this.template = builder.getTemplate();
112         this.id = builder.getId();
113         this.active = builder.isActive();
114         this.versionNumber = builder.getVersionNumber();
115     }
116 
117     @Override
118     public Map<String, String> getAttributes() {
119         return this.attributes;
120     }
121 
122     @Override
123     public String getLanguageCode() {
124         return this.languageCode;
125     }
126 
127     @Override
128     public String getNaturalLanguageUsageId() {
129         return this.naturalLanguageUsageId;
130     }
131 
132     @Override
133     public String getTypeId() {
134         return this.typeId;
135     }
136 
137     @Override
138     public String getTemplate() {
139         return this.template;
140     }
141 
142     @Override
143     public String getId() {
144         return this.id;
145     }
146 
147     @Override
148     public boolean isActive() {
149         return this.active;
150     }
151 
152     @Override
153     public Long getVersionNumber() {
154         return this.versionNumber;
155     }
156 
157 
158     /**
159      * A builder which can be used to construct {@link NaturalLanguageTemplate} instances.  Enforces the constraints of the {@link NaturalLanguageTemplateContract}.
160      * 
161      */
162     public final static class Builder
163         implements Serializable, ModelBuilder, NaturalLanguageTemplateContract
164     {
165 
166         private Map<String, String> attributes;
167         private String languageCode;
168         private String naturalLanguageUsageId;
169         private String typeId;
170         private String template;
171         private String id;
172         private boolean active;
173         private Long versionNumber;
174 
175         private Builder(String languageCode, String naturalLanguageUsageId, String template, String typeId) {
176             // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods
177             setAttributes(null); // setAttributes will create empty map for null
178             setLanguageCode(languageCode);
179             setNaturalLanguageUsageId(naturalLanguageUsageId);
180             setTemplate(template);
181             setTypeId(typeId);
182         }
183 
184         public static Builder create(String languageCode, String naturalLanguageUsageId, String template, String typeId) {
185             // TODO modify as needed to pass any required values and add them to the signature of the 'create' method
186             return new Builder(languageCode, naturalLanguageUsageId, template, typeId);
187         }
188 
189         public static Builder create(NaturalLanguageTemplateContract contract) {
190             if (contract == null) {
191                 throw new IllegalArgumentException("contract was null");
192             }
193             // TODO if create() is modified to accept required parameters, this will need to be modified
194             Builder builder = create(contract.getLanguageCode(), contract.getNaturalLanguageUsageId(), contract.getTemplate(), contract.getTypeId());
195             builder.setId(contract.getId());
196             builder.setActive(contract.isActive());
197             builder.setAttributes(contract.getAttributes());
198             builder.setVersionNumber(contract.getVersionNumber());
199             return builder;
200         }
201 
202         /**
203          * Builds an instance of a NaturalLanguageTemplate based on the current state of the builder.
204          * 
205          * @return the fully-constructed NaturalLanguageTemplate.
206          * 
207          */
208         public NaturalLanguageTemplate build() {
209             return new NaturalLanguageTemplate(this);
210         }
211 
212         @Override
213         public boolean isActive() {
214             return this.active;
215         }
216 
217         @Override
218         public Map<String, String> getAttributes() {
219             return this.attributes;
220         }
221 
222         @Override
223         public String getId() {
224             return this.id;
225         }
226 
227         @Override
228         public String getLanguageCode() {
229             return this.languageCode;
230         }
231 
232         @Override
233         public String getNaturalLanguageUsageId() {
234             return this.naturalLanguageUsageId;
235         }
236 
237         @Override
238         public String getTemplate() {
239             return this.template;
240         }
241 
242         @Override
243         public String getTypeId() {
244             return this.typeId;
245         }
246 
247         @Override
248         public Long getVersionNumber() {
249             return this.versionNumber;
250         }
251 
252         /**
253          * Sets the value of active on this builder to the given value.
254          * 
255          * @param active the active value to set.
256          * 
257          */
258         public void setActive(boolean active) {
259             this.active = active;
260         }
261 
262         /**
263          * Sets the Map of attributes as name / value pairs.
264          * 
265          * @param attributes a Map of name value String pairs representing the attributes.
266          * 
267          */
268         public void setAttributes(Map<String, String> attributes) {
269             if (attributes == null){
270                 this.attributes = Collections.emptyMap();
271             } else {
272                 this.attributes = Collections.unmodifiableMap(attributes);
273             }
274         }
275 
276         /**
277          * Sets the value of id on this builder to the given value.
278          * 
279          * @param id the id value to set., may be null, representing the Object has not been persisted, but must not be blank.
280          * @throws IllegalArgumentException if the id is blank
281          * 
282          */
283         public void setId(String id) {
284             if (id != null && org.apache.commons.lang.StringUtils.isBlank(id)) {
285                 throw new IllegalArgumentException("id is blank");
286             }
287             this.id = id;
288         }
289 
290         /**
291          * Sets the value of languageCode on this builder to the given value.
292          * 
293          * @param languageCode the languageCode value to set., must not be null or blank
294          * @throws IllegalArgumentException if the languageCode is null or blank
295          * 
296          */
297         public void setLanguageCode(String languageCode) {
298             if (org.apache.commons.lang.StringUtils.isBlank(languageCode)) {
299                 throw new IllegalArgumentException("languageCode is null or blank");
300             }
301             this.languageCode = languageCode;
302         }
303 
304         /**
305          * Sets the value of naturalLanguageUsageId on this builder to the given value.
306          * 
307          * @param naturalLanguageUsageId the naturalLanguageUsageId value to set., must not be null or blank
308          * @throws IllegalArgumentException if the naturalLanguageUsageId is null or blank
309          * 
310          */
311         public void setNaturalLanguageUsageId(String naturalLanguageUsageId) {
312             if (org.apache.commons.lang.StringUtils.isBlank(naturalLanguageUsageId)) {
313                 throw new IllegalArgumentException("naturalLanguageUsageId is null or blank");
314             }
315             this.naturalLanguageUsageId = naturalLanguageUsageId;
316         }
317 
318         /**
319          * Sets the value of template on this builder to the given value.
320          * 
321          * @param template the template value to set., must not be null or blank
322          * @throws IllegalArgumentException if the template is null or blank
323          * 
324          */
325         public void setTemplate(String template) {
326             if (org.apache.commons.lang.StringUtils.isBlank(template)) {
327                 throw new IllegalArgumentException("template is null or blank");
328             }
329             this.template = template;
330         }
331 
332         /**
333          * Sets the value of typeId on this builder to the given value.
334          * 
335          * @param typeId the typeId value to set., must not be null or blank
336          * @throws IllegalArgumentException if the typeId is null or blank
337          * 
338          */
339         public void setTypeId(String typeId) {
340             if (org.apache.commons.lang.StringUtils.isBlank(typeId)) {
341                 throw new IllegalArgumentException("typeId is null or blank");
342             }
343             this.typeId = typeId;
344         }
345 
346         /**
347          * Sets the value of versionNumber on this builder to the given value.
348          * 
349          * @param versionNumber the versionNumber value to set.
350          * 
351          */
352         public void setVersionNumber(Long versionNumber) {
353             this.versionNumber = versionNumber;
354         }
355 
356     }
357 
358 
359     /**
360      * Defines some internal constants used on this class.
361      * 
362      */
363     static class Constants {
364 
365         final static String ROOT_ELEMENT_NAME = "naturalLanguageTemplate";
366         final static String TYPE_NAME = "NaturalLanguageTemplateType";
367 
368     }
369 
370 
371     /**
372      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
373      * 
374      */
375     static class Elements {
376 
377         final static String ATTRIBUTES = "attributes";
378         final static String LANGUAGE_CODE = "languageCode";
379         final static String NATURAL_LANGUAGE_USAGE_ID = "naturalLanguageUsageId";
380         final static String TYPE_ID = "typeId";
381         final static String TEMPLATE = "template";
382         final static String ID = "id";
383         final static String ACTIVE = "active";
384 
385     }
386 
387 }