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.kim.api.identity.residency;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.CoreConstants;
20  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
21  import org.kuali.rice.core.api.mo.ModelBuilder;
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  @XmlRootElement(name = EntityResidency.Constants.ROOT_ELEMENT_NAME)
34  @XmlAccessorType(XmlAccessType.NONE)
35  @XmlType(name = EntityResidency.Constants.TYPE_NAME, propOrder = {
36      EntityResidency.Elements.ID,
37      EntityResidency.Elements.ENTITY_ID,
38      EntityResidency.Elements.DETERMINATION_METHOD,
39      EntityResidency.Elements.IN_STATE,
40      CoreConstants.CommonElements.VERSION_NUMBER,
41      CoreConstants.CommonElements.OBJECT_ID,
42      CoreConstants.CommonElements.FUTURE_ELEMENTS
43  })
44  public final class EntityResidency extends AbstractDataTransferObject
45      implements EntityResidencyContract
46  {
47  
48      @XmlElement(name = Elements.ENTITY_ID, required = false)
49      private final String entityId;
50      @XmlElement(name = Elements.DETERMINATION_METHOD, required = false)
51      private final String determinationMethod;
52      @XmlElement(name = Elements.IN_STATE, required = false)
53      private final String inState;
54      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
55      private final Long versionNumber;
56      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
57      private final String objectId;
58      @XmlElement(name = Elements.ID, required = false)
59      private final String id;
60      @SuppressWarnings("unused")
61      @XmlAnyElement
62      private final Collection<Element> _futureElements = null;
63  
64      /**
65       * Private constructor used only by JAXB.
66       * 
67       */
68      private EntityResidency() {
69          this.entityId = null;
70          this.determinationMethod = null;
71          this.inState = null;
72          this.versionNumber = null;
73          this.objectId = null;
74          this.id = null;
75      }
76  
77      private EntityResidency(Builder builder) {
78          this.entityId = builder.getEntityId();
79          this.determinationMethod = builder.getDeterminationMethod();
80          this.inState = builder.getInState();
81          this.versionNumber = builder.getVersionNumber();
82          this.objectId = builder.getObjectId();
83          this.id = builder.getId();
84      }
85  
86      @Override
87      public String getEntityId() {
88          return this.entityId;
89      }
90  
91      @Override
92      public String getDeterminationMethod() {
93          return this.determinationMethod;
94      }
95  
96      @Override
97      public String getInState() {
98          return this.inState;
99      }
100 
101     @Override
102     public Long getVersionNumber() {
103         return this.versionNumber;
104     }
105 
106     @Override
107     public String getObjectId() {
108         return this.objectId;
109     }
110 
111     @Override
112     public String getId() {
113         return this.id;
114     }
115 
116 
117     /**
118      * A builder which can be used to construct {@link EntityResidency} instances.  Enforces the constraints of the {@link EntityResidencyContract}.
119      * 
120      */
121     public final static class Builder
122         implements Serializable, ModelBuilder, EntityResidencyContract
123     {
124 
125         private String entityId;
126         private String determinationMethod;
127         private String inState;
128         private Long versionNumber;
129         private String objectId;
130         private String id;
131 
132         private Builder() { }
133 
134         public static Builder create() {
135             return new Builder();
136         }
137 
138         public static Builder create(EntityResidencyContract contract) {
139             if (contract == null) {
140                 throw new IllegalArgumentException("contract was null");
141             }
142             Builder builder = create();
143             builder.setEntityId(contract.getEntityId());
144             builder.setDeterminationMethod(contract.getDeterminationMethod());
145             builder.setInState(contract.getInState());
146             builder.setVersionNumber(contract.getVersionNumber());
147             builder.setObjectId(contract.getObjectId());
148             builder.setId(contract.getId());
149             return builder;
150         }
151 
152         public EntityResidency build() {
153             return new EntityResidency(this);
154         }
155 
156         @Override
157         public String getEntityId() {
158             return this.entityId;
159         }
160 
161         @Override
162         public String getDeterminationMethod() {
163             return this.determinationMethod;
164         }
165 
166         @Override
167         public String getInState() {
168             return this.inState;
169         }
170 
171         @Override
172         public Long getVersionNumber() {
173             return this.versionNumber;
174         }
175 
176         @Override
177         public String getObjectId() {
178             return this.objectId;
179         }
180 
181         @Override
182         public String getId() {
183             return this.id;
184         }
185 
186         public void setEntityId(String entityId) {
187             this.entityId = entityId;
188         }
189 
190         public void setDeterminationMethod(String determinationMethod) {
191             this.determinationMethod = determinationMethod;
192         }
193 
194         public void setInState(String inState) {
195             this.inState = inState;
196         }
197 
198         public void setVersionNumber(Long versionNumber) {
199             this.versionNumber = versionNumber;
200         }
201 
202         public void setObjectId(String objectId) {
203             this.objectId = objectId;
204         }
205 
206         public void setId(String id) {
207             if (StringUtils.isWhitespace(id)) {
208                 throw new IllegalArgumentException("id is blank");
209             }
210             this.id = id;
211         }
212 
213     }
214 
215 
216     /**
217      * Defines some internal constants used on this class.
218      * 
219      */
220     static class Constants {
221 
222         final static String ROOT_ELEMENT_NAME = "entityResidency";
223         final static String TYPE_NAME = "entityResidencyType";
224     }
225 
226 
227     /**
228      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
229      * 
230      */
231     static class Elements {
232 
233         final static String ENTITY_ID = "entityId";
234         final static String DETERMINATION_METHOD = "determinationMethod";
235         final static String IN_STATE = "inState";
236         final static String ID = "id";
237 
238     }
239 
240 }