View Javadoc
1   /**
2    * Copyright 2005-2016 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 java.io.Serializable;
30  import java.util.Collection;
31  
32  /**
33   * Generated using JVM arguments -DNOT_BLANK=name,typeId 
34   * Concrete model object implementation, immutable. 
35   * Instances can be (un)marshalled to and from XML.
36   * 
37   * @see NaturalLanguageUsageContract
38   * 
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   * 
41   */
42  @XmlRootElement(name = NaturalLanguageUsage.Constants.ROOT_ELEMENT_NAME)
43  @XmlAccessorType(XmlAccessType.NONE)
44  @XmlType(name = NaturalLanguageUsage.Constants.TYPE_NAME, propOrder = {
45      NaturalLanguageUsage.Elements.NAME,
46      NaturalLanguageUsage.Elements.DESCRIPTION,
47      NaturalLanguageUsage.Elements.NAMESPACE,
48      NaturalLanguageUsage.Elements.ID,
49      NaturalLanguageUsage.Elements.ACTIVE,
50      CoreConstants.CommonElements.VERSION_NUMBER,
51      CoreConstants.CommonElements.FUTURE_ELEMENTS
52  })
53  public final class NaturalLanguageUsage
54      extends AbstractDataTransferObject
55      implements NaturalLanguageUsageContract
56  {
57  
58      @XmlElement(name = Elements.NAME, required = false)
59      private final String name;
60      @XmlElement(name = Elements.DESCRIPTION, required = false)
61      private final String description;
62      @XmlElement(name = Elements.NAMESPACE, required = false)
63      private final String namespace;
64      @XmlElement(name = Elements.ID, required = false)
65      private final String id;
66      @XmlElement(name = Elements.ACTIVE, required = false)
67      private final boolean active;
68      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
69      private final Long versionNumber;
70      @SuppressWarnings("unused")
71      @XmlAnyElement
72      private final Collection<Element> _futureElements = null;
73  
74      /**
75       * Private constructor used only by JAXB. This constructor should never be called.
76       * It is only present for use during JAXB unmarshalling.
77       * 
78       */
79      private NaturalLanguageUsage() {
80          this.name = null;
81          this.description = null;
82          this.namespace = null;
83          this.id = null;
84          this.active = false;
85          this.versionNumber = null;
86      }
87  
88      /**
89       * Constructs an object from the given builder.  This constructor is private and should only ever be invoked from the builder.
90       * 
91       * @param builder the Builder from which to construct the object.
92       * 
93       */
94      private NaturalLanguageUsage(Builder builder) {
95          this.name = builder.getName();
96          this.description = builder.getDescription();
97          this.namespace = builder.getNamespace();
98          this.id = builder.getId();
99          this.active = builder.isActive();
100         this.versionNumber = builder.getVersionNumber();
101     }
102 
103     @Override
104     public String getName() {
105         return this.name;
106     }
107 
108     @Override
109     public String getDescription() {
110         return this.description;
111     }
112 
113     @Override
114     public String getNamespace() {
115         return this.namespace;
116     }
117 
118     @Override
119     public String getId() {
120         return this.id;
121     }
122 
123     @Override
124     public boolean isActive() {
125         return this.active;
126     }
127 
128     @Override
129     public Long getVersionNumber() {
130         return this.versionNumber;
131     }
132 
133 
134     /**
135      * A builder which can be used to construct {@link NaturalLanguageUsage} instances.  Enforces the constraints of the {@link NaturalLanguageUsageContract}.
136      * 
137      */
138     public final static class Builder
139         implements Serializable, ModelBuilder, NaturalLanguageUsageContract
140     {
141 
142         private String name;
143         private String description;
144         private String namespace;
145         private String id;
146         private boolean active;
147         private Long versionNumber;
148 
149         private Builder(String name, String namespace) {
150             // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods
151             setName(name);
152             setNamespace(namespace);
153         }
154 
155         public static Builder create(String name, String namespace) {
156             // TODO modify as needed to pass any required values and add them to the signature of the 'create' method
157             return new Builder(name, namespace);
158         }
159 
160         public static Builder create(NaturalLanguageUsageContract contract) {
161             if (contract == null) {
162                 throw new IllegalArgumentException("contract was null");
163             }
164             // TODO if create() is modified to accept required parameters, this will need to be modified
165             Builder builder = create(contract.getName(), contract.getNamespace());
166             builder.setId(contract.getId());
167             builder.setActive(contract.isActive());
168             builder.setDescription(contract.getDescription());
169             builder.setVersionNumber(contract.getVersionNumber());
170             return builder;
171         }
172 
173         /**
174          * Builds an instance of a NaturalLanguageUsage based on the current state of the builder.
175          * 
176          * @return the fully-constructed NaturalLanguageUsage.
177          * 
178          */
179         public NaturalLanguageUsage build() {
180             return new NaturalLanguageUsage(this);
181         }
182 
183         @Override
184         public boolean isActive() {
185             return this.active;
186         }
187 
188         @Override
189         public String getDescription() {
190             return this.description;
191         }
192 
193         @Override
194         public String getId() {
195             return this.id;
196         }
197 
198         @Override
199         public String getName() {
200             return this.name;
201         }
202 
203         @Override
204         public String getNamespace() {
205             return this.namespace;
206         }
207 
208         @Override
209         public Long getVersionNumber() {
210             return this.versionNumber;
211         }
212 
213         /**
214          * Sets the value of active on this builder to the given value.
215          * 
216          * @param active the active value to set.
217          * 
218          */
219         public void setActive(boolean active) {
220             this.active = active;
221         }
222 
223         /**
224          * Sets the value of description on this builder to the given value.
225          * 
226          * @param description the description value to set.
227          * 
228          */
229         public void setDescription(String description) {
230             // TODO add validation of input value if required and throw IllegalArgumentException if needed
231             this.description = description;
232         }
233 
234         /**
235          * Sets the value of id on this builder to the given value.
236          * 
237          * @param id the id value to set., may be null, representing the Object has not been persisted, but must not be blank.
238          * @throws IllegalArgumentException if the id is blank
239          * 
240          */
241         public void setId(String id) {
242             if (id != null && org.apache.commons.lang.StringUtils.isBlank(id)) {
243                 throw new IllegalArgumentException("id is blank");
244             }
245             this.id = id;
246         }
247 
248         /**
249          * Sets the value of name on this builder to the given value.
250          * 
251          * @param name the name value to set., must not be null or blank
252          * @throws IllegalArgumentException if the name is null or blank
253          * 
254          */
255         public void setName(String name) {
256             if (org.apache.commons.lang.StringUtils.isBlank(name)) {
257                 throw new IllegalArgumentException("name is null or blank");
258             }
259             this.name = name;
260         }
261 
262         /**
263          * Sets the value of namespace on this builder to the given value.
264          * 
265          * @param namespace the namespace value to set., must not be null or blank
266          * @throws IllegalArgumentException if the namespace is null or blank
267          * 
268          */
269         public void setNamespace(String namespace) {
270             if (org.apache.commons.lang.StringUtils.isBlank(namespace)) {
271                 throw new IllegalArgumentException("namespace is null or blank");
272             }
273             this.namespace = namespace;
274         }
275 
276         /**
277          * Sets the value of versionNumber on this builder to the given value.
278          * 
279          * @param versionNumber the versionNumber value to set.
280          * 
281          */
282         public void setVersionNumber(Long versionNumber) {
283             this.versionNumber = versionNumber;
284         }
285 
286     }
287 
288 
289     /**
290      * Defines some internal constants used on this class.
291      * 
292      */
293     static class Constants {
294 
295         final static String ROOT_ELEMENT_NAME = "naturalLanguageUsage";
296         final static String TYPE_NAME = "NaturalLanguageUsageType";
297 
298     }
299 
300 
301     /**
302      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
303      * 
304      */
305     static class Elements {
306 
307         final static String NAME = "name";
308         final static String DESCRIPTION = "description";
309         final static String NAMESPACE = "namespace";
310         final static String ID = "id";
311         final static String ACTIVE = "active";
312 
313     }
314 
315     public static class Cache {
316         public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + NaturalLanguageUsage.Constants.TYPE_NAME;
317     }
318 
319 }