View Javadoc

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