View Javadoc

1   /**
2    * Copyright 2005-2013 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;
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  
24  import javax.xml.bind.annotation.XmlAccessType;
25  import javax.xml.bind.annotation.XmlAccessorType;
26  import javax.xml.bind.annotation.XmlAnyElement;
27  import javax.xml.bind.annotation.XmlElement;
28  import javax.xml.bind.annotation.XmlRootElement;
29  import javax.xml.bind.annotation.XmlType;
30  import java.io.Serializable;
31  import java.util.Collection;
32  
33  /**
34   * Concrete model object implementation of a natural language tree immutable.
35   * Instances of natural language tree can be (un)marshalled to and from XML.
36   *
37   * @see NaturalLanguageContract
38   */
39  @XmlRootElement(name = NaturalLanguage.Constants.ROOT_ELEMENT_NAME)
40  @XmlAccessorType(XmlAccessType.NONE)
41  @XmlType(name = NaturalLanguage.Constants.TYPE_NAME, propOrder = {
42          NaturalLanguage.Elements.KRMS_OBJECT_ID,
43          NaturalLanguage.Elements.NATURAL_LANGUAGE,
44          CoreConstants.CommonElements.FUTURE_ELEMENTS
45  })
46  public class NaturalLanguage extends AbstractDataTransferObject implements NaturalLanguageContract {
47  
48      private static final long serialVersionUID = 6112385261827152719L;
49  
50      @XmlElement(name = NaturalLanguage.Elements.KRMS_OBJECT_ID, required = false)
51      private String krmsObjectId;
52      @XmlElement(name = NaturalLanguage.Elements.NATURAL_LANGUAGE, required = false)
53      private String naturalLanguage;
54      @SuppressWarnings("unused")
55      @XmlAnyElement
56      private final Collection<Element> _futureElements = null;
57  
58      /**
59       * This constructor should never be called. It is only present for use
60       * during JAXB unmarshalling.
61       */
62      public NaturalLanguage() {
63          this.krmsObjectId = null;
64          this.naturalLanguage = null;
65      }
66  
67      @Override
68      public String getKrmsObjectId() {
69          return krmsObjectId;
70      }
71  
72      @Override
73      public String getNaturalLanguage() {
74          return naturalLanguage;
75      }
76  
77      /**
78       * Constructs a KRMS Repository Agenda object from the given builder. This
79       * constructor is private and should only ever be invoked from the builder.
80       *
81       * @param builder the Builder from which to construct the Agenda
82       */
83      private NaturalLanguage(Builder builder) {
84          this.krmsObjectId = builder.getKrmsObjectId();
85          this.naturalLanguage = builder.getNaturalLanguage();
86      }
87  
88      /**
89       * This builder is used to construct instances of KRMS Repository Agenda. It
90       * enforces the constraints of the {@link NaturalLanguageContract}.
91       */
92      public static class Builder implements NaturalLanguageContract, ModelBuilder, Serializable {
93  
94          private static final long serialVersionUID = -2354545388959879306L;
95  
96          private String krmsObjectId;
97          private String naturalLanguage;
98  
99          /**
100          * Private constructor for creating a builder with all of it's required
101          * attributes.
102          */
103         private Builder() {
104         }
105 
106         /**
107          * Private constructor for creating a builder with all of it's required
108          * attributes.
109          */
110         private Builder(String naturalLanguage, String krmsObjectId) {
111             setNaturalLanguage(naturalLanguage);
112             setKrmsObjectId(krmsObjectId);
113         }
114 
115         @Override
116         public String getKrmsObjectId() {
117             return krmsObjectId;
118         }
119 
120         public void setKrmsObjectId(String krmsObjectId) {
121             this.krmsObjectId = krmsObjectId;
122         }
123 
124         @Override
125         public String getNaturalLanguage() {
126             return naturalLanguage;
127         }
128 
129         public void setNaturalLanguage(String naturalLanguage) {
130             this.naturalLanguage = naturalLanguage;
131         }
132 
133         /**
134          * Creates a builder by populating it with data from the given
135          * {@link NaturalLanguageContract}.
136          *
137          * @return an instance of the builder populated with data from the
138          * contract
139          * @throws IllegalArgumentException if the contract is null
140          */
141         public static NaturalLanguage.Builder create() {
142             NaturalLanguage.Builder builder = new NaturalLanguage.Builder();
143             return builder;
144         }
145         /**
146          * Creates a builder by populating it with data from the given
147          * {@link NaturalLanguageContract}.
148          *
149          * @param contract the contract from which to populate this builder
150          * @return an instance of the builder populated with data from the
151          * contract
152          * @throws IllegalArgumentException if the contract is null
153          */
154         public static NaturalLanguage.Builder create(NaturalLanguageContract contract) {
155             if (contract == null) {
156                 throw new IllegalArgumentException("contract is null");
157             }
158             NaturalLanguage.Builder builder = new NaturalLanguage.Builder(contract.getNaturalLanguage(), contract.getKrmsObjectId());
159 
160             return builder;
161         }
162 
163         /**
164          * Builds an instance of a Natural Language Tree based on the current state of the
165          * builder.
166          *
167          * @return the fully-constructed Agenda
168          */
169         @Override
170         public NaturalLanguage build() {
171             return new NaturalLanguage(this);
172         }
173     }
174 
175     /**
176      * Defines some constants used on this class.
177      */
178     public static class Constants {
179 
180         final static String ROOT_ELEMENT_NAME = "naturalLanguage";
181         final static String TYPE_NAME = "NaturalLanguageType";
182         final static String[] HASH_CODE_EQUALS_EXCLUDE = {"_futureElements"};
183         public final static String EVENT = "Event";   // key for event attribute
184     }
185 
186     /**
187      * A private class which exposes constants which define the XML element
188      * names to use when this object is marshalled to XML.
189      */
190     public static class Elements {
191 
192         final static String KRMS_OBJECT_ID = "krmsObjectId";
193         final static String NATURAL_LANGUAGE = "naturalLanguage";
194     }
195 
196     public static class Cache {
197 
198         public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + NaturalLanguage.Constants.TYPE_NAME;
199     }
200 }