001 /**
002 * Copyright 2005-2011 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.kim.api.identity.residency;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.rice.core.api.CoreConstants;
020 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021 import org.kuali.rice.core.api.mo.ModelBuilder;
022 import org.w3c.dom.Element;
023
024 import javax.xml.bind.annotation.XmlAccessType;
025 import javax.xml.bind.annotation.XmlAccessorType;
026 import javax.xml.bind.annotation.XmlAnyElement;
027 import javax.xml.bind.annotation.XmlElement;
028 import javax.xml.bind.annotation.XmlRootElement;
029 import javax.xml.bind.annotation.XmlType;
030 import java.io.Serializable;
031 import java.util.Collection;
032
033 @XmlRootElement(name = EntityResidency.Constants.ROOT_ELEMENT_NAME)
034 @XmlAccessorType(XmlAccessType.NONE)
035 @XmlType(name = EntityResidency.Constants.TYPE_NAME, propOrder = {
036 EntityResidency.Elements.ID,
037 EntityResidency.Elements.ENTITY_ID,
038 EntityResidency.Elements.DETERMINATION_METHOD,
039 EntityResidency.Elements.IN_STATE,
040 CoreConstants.CommonElements.VERSION_NUMBER,
041 CoreConstants.CommonElements.OBJECT_ID,
042 CoreConstants.CommonElements.FUTURE_ELEMENTS
043 })
044 public final class EntityResidency extends AbstractDataTransferObject
045 implements EntityResidencyContract
046 {
047
048 @XmlElement(name = Elements.ENTITY_ID, required = false)
049 private final String entityId;
050 @XmlElement(name = Elements.DETERMINATION_METHOD, required = false)
051 private final String determinationMethod;
052 @XmlElement(name = Elements.IN_STATE, required = false)
053 private final String inState;
054 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
055 private final Long versionNumber;
056 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
057 private final String objectId;
058 @XmlElement(name = Elements.ID, required = false)
059 private final String id;
060 @SuppressWarnings("unused")
061 @XmlAnyElement
062 private final Collection<Element> _futureElements = null;
063
064 /**
065 * Private constructor used only by JAXB.
066 *
067 */
068 private EntityResidency() {
069 this.entityId = null;
070 this.determinationMethod = null;
071 this.inState = null;
072 this.versionNumber = null;
073 this.objectId = null;
074 this.id = null;
075 }
076
077 private EntityResidency(Builder builder) {
078 this.entityId = builder.getEntityId();
079 this.determinationMethod = builder.getDeterminationMethod();
080 this.inState = builder.getInState();
081 this.versionNumber = builder.getVersionNumber();
082 this.objectId = builder.getObjectId();
083 this.id = builder.getId();
084 }
085
086 @Override
087 public String getEntityId() {
088 return this.entityId;
089 }
090
091 @Override
092 public String getDeterminationMethod() {
093 return this.determinationMethod;
094 }
095
096 @Override
097 public String getInState() {
098 return this.inState;
099 }
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 }