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.kuali.rice.krms.api.KrmsConstants;
022    import org.w3c.dom.Element;
023    import javax.xml.bind.annotation.XmlAccessType;
024    import javax.xml.bind.annotation.XmlAccessorType;
025    import javax.xml.bind.annotation.XmlAnyElement;
026    import javax.xml.bind.annotation.XmlElement;
027    import javax.xml.bind.annotation.XmlRootElement;
028    import javax.xml.bind.annotation.XmlType;
029    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
030    import java.io.Serializable;
031    import java.util.Collection;
032    import java.util.Collections;
033    import java.util.HashMap;
034    import java.util.Map;
035    
036    /**
037     * 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 
038     * Concrete model object implementation, immutable. 
039     * Instances can be (un)marshalled to and from XML.
040     * 
041     * @see NaturalLanguageTemplateContract
042     * 
043     * @author Kuali Rice Team (rice.collab@kuali.org)
044     * 
045     */
046    @XmlRootElement(name = NaturalLanguageTemplate.Constants.ROOT_ELEMENT_NAME)
047    @XmlAccessorType(XmlAccessType.NONE)
048    @XmlType(name = NaturalLanguageTemplate.Constants.TYPE_NAME, propOrder = {
049        NaturalLanguageTemplate.Elements.ATTRIBUTES,
050        NaturalLanguageTemplate.Elements.LANGUAGE_CODE,
051        NaturalLanguageTemplate.Elements.NATURAL_LANGUAGE_USAGE_ID,
052        NaturalLanguageTemplate.Elements.TYPE_ID,
053        NaturalLanguageTemplate.Elements.TEMPLATE,
054        NaturalLanguageTemplate.Elements.ID,
055        NaturalLanguageTemplate.Elements.ACTIVE,
056        CoreConstants.CommonElements.VERSION_NUMBER,
057        CoreConstants.CommonElements.FUTURE_ELEMENTS
058    })
059    public final class NaturalLanguageTemplate
060        extends AbstractDataTransferObject
061        implements NaturalLanguageTemplateContract
062    {
063    
064        @XmlJavaTypeAdapter(org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter.class)
065        @XmlElement(name = Elements.ATTRIBUTES, required = false)
066        private final Map<String, String> attributes;
067        @XmlElement(name = Elements.LANGUAGE_CODE, required = false)
068        private final String languageCode;
069        @XmlElement(name = Elements.NATURAL_LANGUAGE_USAGE_ID, required = false)
070        private final String naturalLanguageUsageId;
071        @XmlElement(name = Elements.TYPE_ID, required = false)
072        private final String typeId;
073        @XmlElement(name = Elements.TEMPLATE, required = false)
074        private final String template;
075        @XmlElement(name = Elements.ID, required = false)
076        private final String id;
077        @XmlElement(name = Elements.ACTIVE, required = false)
078        private final boolean active;
079        @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
080        private final Long versionNumber;
081        @SuppressWarnings("unused")
082        @XmlAnyElement
083        private final Collection<Element> _futureElements = null;
084    
085        /**
086         * Private constructor used only by JAXB. This constructor should never be called.
087         * It is only present for use during JAXB unmarshalling.
088         * 
089         */
090        private NaturalLanguageTemplate() {
091            this.attributes = null;
092            this.languageCode = null;
093            this.naturalLanguageUsageId = null;
094            this.typeId = null;
095            this.template = null;
096            this.id = null;
097            this.active = true;
098            this.versionNumber = null;
099        }
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    }