View Javadoc

1   /**
2    * Copyright 2005-2012 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.affiliation;
17  
18  import java.io.Serializable;
19  import java.util.Collection;
20  import javax.xml.bind.annotation.XmlAccessType;
21  import javax.xml.bind.annotation.XmlAccessorType;
22  import javax.xml.bind.annotation.XmlAnyElement;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.XmlRootElement;
25  import javax.xml.bind.annotation.XmlType;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.kuali.rice.core.api.CoreConstants;
29  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
30  import org.kuali.rice.core.api.mo.ModelBuilder;
31  import org.w3c.dom.Element;
32  
33  @XmlRootElement(name = EntityAffiliation.Constants.ROOT_ELEMENT_NAME)
34  @XmlAccessorType(XmlAccessType.NONE)
35  @XmlType(name = EntityAffiliation.Constants.TYPE_NAME, propOrder = {
36      EntityAffiliation.Elements.ID,
37      EntityAffiliation.Elements.ENTITY_ID,
38      EntityAffiliation.Elements.AFFILIATION_TYPE,
39      EntityAffiliation.Elements.CAMPUS_CODE,
40      EntityAffiliation.Elements.DEFAULT_VALUE,
41      EntityAffiliation.Elements.ACTIVE,
42      CoreConstants.CommonElements.VERSION_NUMBER,
43      CoreConstants.CommonElements.OBJECT_ID,
44      CoreConstants.CommonElements.FUTURE_ELEMENTS
45  })
46  public final class EntityAffiliation extends AbstractDataTransferObject
47      implements EntityAffiliationContract
48  {
49  
50      @XmlElement(name = Elements.ENTITY_ID, required = false)
51      private final String entityId;
52      @XmlElement(name = Elements.AFFILIATION_TYPE, required = false)
53      private final EntityAffiliationType affiliationType;
54      @XmlElement(name = Elements.CAMPUS_CODE, required = false)
55      private final String campusCode;
56      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
57      private final Long versionNumber;
58      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
59      private final String objectId;
60      @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
61      private final boolean defaultValue;
62      @XmlElement(name = Elements.ACTIVE, required = false)
63      private final boolean active;
64      @XmlElement(name = Elements.ID, required = false)
65      private final String id;
66      @SuppressWarnings("unused")
67      @XmlAnyElement
68      private final Collection<Element> _futureElements = null;
69  
70      /**
71       * Private constructor used only by JAXB.
72       * 
73       */
74      private EntityAffiliation() {
75          this.entityId = null;
76          this.affiliationType = null;
77          this.campusCode = null;
78          this.versionNumber = null;
79          this.objectId = null;
80          this.defaultValue = false;
81          this.active = false;
82          this.id = null;
83      }
84  
85      private EntityAffiliation(Builder builder) {
86          this.entityId = builder.getEntityId();
87          this.affiliationType = builder.getAffiliationType() != null ? builder.getAffiliationType().build() : null;
88          this.campusCode = builder.getCampusCode();
89          this.versionNumber = builder.getVersionNumber();
90          this.objectId = builder.getObjectId();
91          this.defaultValue = builder.isDefaultValue();
92          this.active = builder.isActive();
93          this.id = builder.getId();
94      }
95  
96      @Override
97      public String getEntityId() {
98          return this.entityId;
99      }
100 
101     @Override
102     public EntityAffiliationType getAffiliationType() {
103         return this.affiliationType;
104     }
105 
106     @Override
107     public String getCampusCode() {
108         return this.campusCode;
109     }
110 
111     @Override
112     public Long getVersionNumber() {
113         return this.versionNumber;
114     }
115 
116     @Override
117     public String getObjectId() {
118         return this.objectId;
119     }
120 
121     @Override
122     public boolean isDefaultValue() {
123         return this.defaultValue;
124     }
125 
126     @Override
127     public boolean isActive() {
128         return this.active;
129     }
130 
131     @Override
132     public String getId() {
133         return this.id;
134     }
135 
136     /**
137      * A builder which can be used to construct {@link EntityAffiliation} instances.  Enforces the constraints of the {@link EntityAffiliationContract}.
138      * 
139      */
140     public final static class Builder
141         implements Serializable, ModelBuilder, EntityAffiliationContract
142     {
143 
144         private String entityId;
145         private EntityAffiliationType.Builder affiliationType;
146         private String campusCode;
147         private Long versionNumber;
148         private String objectId;
149         private boolean defaultValue;
150         private boolean active;
151         private String id;
152 
153         private Builder() { }
154 
155         public static Builder create() {
156             return new Builder();
157         }
158 
159         public static Builder create(EntityAffiliationContract contract) {
160             if (contract == null) {
161                 throw new IllegalArgumentException("contract was null");
162             }
163             Builder builder = create();
164             builder.setEntityId(contract.getEntityId());
165             if (contract.getAffiliationType() != null) {
166                 builder.setAffiliationType(EntityAffiliationType.Builder.create(contract.getAffiliationType()));
167             }
168             builder.setCampusCode(contract.getCampusCode());
169             builder.setVersionNumber(contract.getVersionNumber());
170             builder.setObjectId(contract.getObjectId());
171             builder.setDefaultValue(contract.isDefaultValue());
172             builder.setActive(contract.isActive());
173             builder.setId(contract.getId());
174             return builder;
175         }
176 
177         public EntityAffiliation build() {
178             return new EntityAffiliation(this);
179         }
180 
181         @Override
182         public String getEntityId() {
183             return this.entityId;
184         }
185 
186         @Override
187         public EntityAffiliationType.Builder getAffiliationType() {
188             return this.affiliationType;
189         }
190 
191         @Override
192         public String getCampusCode() {
193             return this.campusCode;
194         }
195 
196         @Override
197         public Long getVersionNumber() {
198             return this.versionNumber;
199         }
200 
201         @Override
202         public String getObjectId() {
203             return this.objectId;
204         }
205 
206         @Override
207         public boolean isDefaultValue() {
208             return this.defaultValue;
209         }
210 
211         @Override
212         public boolean isActive() {
213             return this.active;
214         }
215 
216         @Override
217         public String getId() {
218             return this.id;
219         }
220 
221         public void setEntityId(String entityId) {
222             this.entityId = entityId;
223         }
224 
225         public void setAffiliationType(EntityAffiliationType.Builder affiliationType) {
226             this.affiliationType = affiliationType;
227         }
228 
229         public void setCampusCode(String campusCode) {
230             this.campusCode = campusCode;
231         }
232 
233         public void setVersionNumber(Long versionNumber) {
234             this.versionNumber = versionNumber;
235         }
236 
237         public void setObjectId(String objectId) {
238             this.objectId = objectId;
239         }
240 
241         public void setDefaultValue(boolean defaultValue) {
242             this.defaultValue = defaultValue;
243         }
244 
245         public void setActive(boolean active) {
246             this.active = active;
247         }
248 
249         public void setId(String id) {
250             if (StringUtils.isWhitespace(id)) {
251                 throw new IllegalArgumentException("id is blank");
252             }
253             this.id = id;
254         }
255 
256     }
257 
258 
259     /**
260      * Defines some internal constants used on this class.
261      * 
262      */
263     static class Constants {
264 
265         final static String ROOT_ELEMENT_NAME = "entityAffiliation";
266         final static String TYPE_NAME = "EntityAffiliationType";
267     }
268 
269 
270     /**
271      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
272      * 
273      */
274     static class Elements {
275 
276         final static String ENTITY_ID = "entityId";
277         final static String AFFILIATION_TYPE = "affiliationType";
278         final static String CAMPUS_CODE = "campusCode";
279         final static String DEFAULT_VALUE = "defaultValue";
280         final static String ACTIVE = "active";
281         final static String ID = "id";
282 
283     }
284 
285 }