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