1 | |
package org.kuali.rice.kim.api.identity.principal; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
import java.util.Collection; |
5 | |
import javax.xml.bind.annotation.XmlAccessType; |
6 | |
import javax.xml.bind.annotation.XmlAccessorType; |
7 | |
import javax.xml.bind.annotation.XmlAnyElement; |
8 | |
import javax.xml.bind.annotation.XmlElement; |
9 | |
import javax.xml.bind.annotation.XmlRootElement; |
10 | |
import javax.xml.bind.annotation.XmlType; |
11 | |
|
12 | |
import org.apache.commons.lang.StringUtils; |
13 | |
import org.kuali.rice.core.api.CoreConstants; |
14 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
15 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
16 | |
import org.w3c.dom.Element; |
17 | |
|
18 | |
@XmlRootElement(name = Principal.Constants.ROOT_ELEMENT_NAME) |
19 | |
@XmlAccessorType(XmlAccessType.NONE) |
20 | |
@XmlType(name = Principal.Constants.TYPE_NAME, propOrder = { |
21 | |
Principal.Elements.PRINCIPAL_ID, |
22 | |
Principal.Elements.PRINCIPAL_NAME, |
23 | |
Principal.Elements.ENTITY_ID, |
24 | |
Principal.Elements.PASSWORD, |
25 | |
Principal.Elements.ACTIVE, |
26 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
27 | |
CoreConstants.CommonElements.OBJECT_ID, |
28 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
29 | |
}) |
30 | 6 | public final class Principal extends AbstractDataTransferObject |
31 | |
implements PrincipalContract |
32 | |
{ |
33 | |
|
34 | |
@XmlElement(name = Elements.PASSWORD, required = false) |
35 | |
private final String password; |
36 | |
@XmlElement(name = Elements.PRINCIPAL_ID, required = false) |
37 | |
private final String principalId; |
38 | |
@XmlElement(name = Elements.PRINCIPAL_NAME, required = false) |
39 | |
private final String principalName; |
40 | |
@XmlElement(name = Elements.ENTITY_ID, required = false) |
41 | |
private final String entityId; |
42 | |
@XmlElement(name = Elements.ACTIVE, required = false) |
43 | |
private final boolean active; |
44 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
45 | |
private final Long versionNumber; |
46 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
47 | |
private final String objectId; |
48 | 10 | @SuppressWarnings("unused") |
49 | |
@XmlAnyElement |
50 | |
private final Collection<Element> _futureElements = null; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | 4 | private Principal() { |
57 | 4 | this.password = null; |
58 | 4 | this.principalId = null; |
59 | 4 | this.principalName = null; |
60 | 4 | this.entityId = null; |
61 | 4 | this.active = false; |
62 | 4 | this.versionNumber = null; |
63 | 4 | this.objectId = null; |
64 | 4 | } |
65 | |
|
66 | 6 | private Principal(Builder builder) { |
67 | 6 | this.password = builder.getPassword(); |
68 | 6 | this.principalId = builder.getPrincipalId(); |
69 | 6 | this.principalName = builder.getPrincipalName(); |
70 | 6 | this.entityId = builder.getEntityId(); |
71 | 6 | this.active = builder.isActive(); |
72 | 6 | this.versionNumber = builder.getVersionNumber(); |
73 | 6 | this.objectId = builder.getObjectId(); |
74 | 6 | } |
75 | |
|
76 | |
@Override |
77 | |
public String getPassword() { |
78 | 4 | return this.password; |
79 | |
} |
80 | |
|
81 | |
@Override |
82 | |
public String getPrincipalId() { |
83 | 4 | return this.principalId; |
84 | |
} |
85 | |
|
86 | |
@Override |
87 | |
public String getPrincipalName() { |
88 | 4 | return this.principalName; |
89 | |
} |
90 | |
|
91 | |
@Override |
92 | |
public String getEntityId() { |
93 | 4 | return this.entityId; |
94 | |
} |
95 | |
|
96 | |
@Override |
97 | |
public boolean isActive() { |
98 | 4 | return this.active; |
99 | |
} |
100 | |
|
101 | |
@Override |
102 | |
public Long getVersionNumber() { |
103 | 4 | return this.versionNumber; |
104 | |
} |
105 | |
|
106 | |
@Override |
107 | |
public String getObjectId() { |
108 | 4 | return this.objectId; |
109 | |
} |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | 4 | public final static class Builder |
116 | |
implements Serializable, ModelBuilder, PrincipalContract |
117 | |
{ |
118 | |
|
119 | |
private String password; |
120 | |
private String principalId; |
121 | |
private String principalName; |
122 | |
private String entityId; |
123 | |
private boolean active; |
124 | |
private Long versionNumber; |
125 | |
private String objectId; |
126 | |
|
127 | 8 | private Builder(String principalName) { |
128 | 8 | setPrincipalName(principalName); |
129 | 7 | } |
130 | |
|
131 | |
public static Builder create(String principalName) { |
132 | |
|
133 | 8 | return new Builder(principalName); |
134 | |
} |
135 | |
|
136 | |
public static Builder create(PrincipalContract contract) { |
137 | 6 | if (contract == null) { |
138 | 1 | throw new IllegalArgumentException("contract was null"); |
139 | |
} |
140 | |
|
141 | 5 | Builder builder = create(contract.getPrincipalName()); |
142 | 5 | builder.setPassword(contract.getPassword()); |
143 | 5 | builder.setPrincipalId(contract.getPrincipalId()); |
144 | 5 | builder.setEntityId(contract.getEntityId()); |
145 | 5 | builder.setActive(contract.isActive()); |
146 | 5 | builder.setVersionNumber(contract.getVersionNumber()); |
147 | 5 | builder.setObjectId(contract.getObjectId()); |
148 | 5 | return builder; |
149 | |
} |
150 | |
|
151 | |
public Principal build() { |
152 | 6 | return new Principal(this); |
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public String getPassword() { |
157 | 6 | return this.password; |
158 | |
} |
159 | |
|
160 | |
@Override |
161 | |
public String getPrincipalId() { |
162 | 6 | return this.principalId; |
163 | |
} |
164 | |
|
165 | |
@Override |
166 | |
public String getPrincipalName() { |
167 | 6 | return this.principalName; |
168 | |
} |
169 | |
|
170 | |
@Override |
171 | |
public String getEntityId() { |
172 | 6 | return this.entityId; |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
public boolean isActive() { |
177 | 6 | return this.active; |
178 | |
} |
179 | |
|
180 | |
@Override |
181 | |
public Long getVersionNumber() { |
182 | 6 | return this.versionNumber; |
183 | |
} |
184 | |
|
185 | |
@Override |
186 | |
public String getObjectId() { |
187 | 6 | return this.objectId; |
188 | |
} |
189 | |
|
190 | |
public void setPassword(String password) { |
191 | 5 | this.password = password; |
192 | 5 | } |
193 | |
|
194 | |
public void setPrincipalId(String principalId) { |
195 | 5 | if (StringUtils.isWhitespace(principalId)) { |
196 | 0 | throw new IllegalArgumentException("principalId is blank"); |
197 | |
} |
198 | 5 | this.principalId = principalId; |
199 | 5 | } |
200 | |
|
201 | |
public void setPrincipalName(String principalName) { |
202 | 8 | if (StringUtils.isEmpty(principalName)) { |
203 | 1 | throw new IllegalArgumentException("principalName is blank"); |
204 | |
} |
205 | 7 | this.principalName = principalName; |
206 | 7 | } |
207 | |
|
208 | |
public void setEntityId(String entityId) { |
209 | 5 | this.entityId = entityId; |
210 | 5 | } |
211 | |
|
212 | |
public void setActive(boolean active) { |
213 | 5 | this.active = active; |
214 | 5 | } |
215 | |
|
216 | |
public void setVersionNumber(Long versionNumber) { |
217 | 5 | this.versionNumber = versionNumber; |
218 | 5 | } |
219 | |
|
220 | |
public void setObjectId(String objectId) { |
221 | 5 | this.objectId = objectId; |
222 | 5 | } |
223 | |
|
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | 0 | static class Constants { |
232 | |
|
233 | |
final static String ROOT_ELEMENT_NAME = "principal"; |
234 | |
final static String TYPE_NAME = "PrincipalType"; |
235 | |
} |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | 0 | static class Elements { |
243 | |
|
244 | |
final static String PASSWORD = "password"; |
245 | |
final static String PRINCIPAL_ID = "principalId"; |
246 | |
final static String PRINCIPAL_NAME = "principalName"; |
247 | |
final static String ENTITY_ID = "entityId"; |
248 | |
final static String ACTIVE = "active"; |
249 | |
|
250 | |
} |
251 | |
|
252 | |
} |