View Javadoc

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