001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krms.api.repository.language;
017
018 import org.kuali.rice.core.api.CoreConstants;
019 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
020 import org.kuali.rice.core.api.mo.ModelBuilder;
021 import org.w3c.dom.Element;
022 import javax.xml.bind.annotation.XmlAccessType;
023 import javax.xml.bind.annotation.XmlAccessorType;
024 import javax.xml.bind.annotation.XmlAnyElement;
025 import javax.xml.bind.annotation.XmlElement;
026 import javax.xml.bind.annotation.XmlRootElement;
027 import javax.xml.bind.annotation.XmlType;
028 import java.io.Serializable;
029 import java.util.Collection;
030
031 /**
032 * Generated using JVM arguments -DNOT_BLANK=name,typeId
033 * Concrete model object implementation, immutable.
034 * Instances can be (un)marshalled to and from XML.
035 *
036 * @see NaturalLanguageUsageContract
037 *
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 *
040 */
041 @XmlRootElement(name = NaturalLanguageUsage.Constants.ROOT_ELEMENT_NAME)
042 @XmlAccessorType(XmlAccessType.NONE)
043 @XmlType(name = NaturalLanguageUsage.Constants.TYPE_NAME, propOrder = {
044 NaturalLanguageUsage.Elements.NAME,
045 NaturalLanguageUsage.Elements.DESCRIPTION,
046 NaturalLanguageUsage.Elements.NAMESPACE,
047 NaturalLanguageUsage.Elements.ID,
048 NaturalLanguageUsage.Elements.ACTIVE,
049 CoreConstants.CommonElements.VERSION_NUMBER,
050 CoreConstants.CommonElements.FUTURE_ELEMENTS
051 })
052 public final class NaturalLanguageUsage
053 extends AbstractDataTransferObject
054 implements NaturalLanguageUsageContract
055 {
056
057 @XmlElement(name = Elements.NAME, required = false)
058 private final String name;
059 @XmlElement(name = Elements.DESCRIPTION, required = false)
060 private final String description;
061 @XmlElement(name = Elements.NAMESPACE, required = false)
062 private final String namespace;
063 @XmlElement(name = Elements.ID, required = false)
064 private final String id;
065 @XmlElement(name = Elements.ACTIVE, required = false)
066 private final boolean active;
067 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
068 private final Long versionNumber;
069 @SuppressWarnings("unused")
070 @XmlAnyElement
071 private final Collection<Element> _futureElements = null;
072
073 /**
074 * Private constructor used only by JAXB. This constructor should never be called.
075 * It is only present for use during JAXB unmarshalling.
076 *
077 */
078 private NaturalLanguageUsage() {
079 this.name = null;
080 this.description = null;
081 this.namespace = null;
082 this.id = null;
083 this.active = false;
084 this.versionNumber = null;
085 }
086
087 /**
088 * Constructs an object from the given builder. This constructor is private and should only ever be invoked from the builder.
089 *
090 * @param builder the Builder from which to construct the object.
091 *
092 */
093 private NaturalLanguageUsage(Builder builder) {
094 this.name = builder.getName();
095 this.description = builder.getDescription();
096 this.namespace = builder.getNamespace();
097 this.id = builder.getId();
098 this.active = builder.isActive();
099 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 }