1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.core.api.style; |
18 | |
|
19 | |
import java.io.Serializable; |
20 | |
import java.util.Collection; |
21 | |
|
22 | |
import javax.xml.bind.annotation.XmlAccessType; |
23 | |
import javax.xml.bind.annotation.XmlAccessorType; |
24 | |
import javax.xml.bind.annotation.XmlAnyElement; |
25 | |
import javax.xml.bind.annotation.XmlElement; |
26 | |
import javax.xml.bind.annotation.XmlRootElement; |
27 | |
import javax.xml.bind.annotation.XmlType; |
28 | |
|
29 | |
import org.apache.commons.lang.StringUtils; |
30 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
31 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
32 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
33 | |
import org.kuali.rice.core.api.CoreConstants; |
34 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
35 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
36 | |
import org.w3c.dom.Element; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
@XmlRootElement(name = Style.Constants.ROOT_ELEMENT_NAME) |
47 | |
@XmlAccessorType(XmlAccessType.NONE) |
48 | |
@XmlType(name = Style.Constants.TYPE_NAME, propOrder = { |
49 | |
Style.Elements.STYLE_ID, |
50 | |
Style.Elements.NAME, |
51 | |
Style.Elements.XML_CONTENT, |
52 | |
Style.Elements.ACTIVE, |
53 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
54 | |
CoreConstants.CommonElements.OBJECT_ID, |
55 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
56 | |
}) |
57 | 4 | public final class Style implements StyleContract, ModelObjectComplete { |
58 | |
|
59 | |
private static final long serialVersionUID = -26426318682076660L; |
60 | |
|
61 | |
@XmlElement(name = Elements.STYLE_ID, required = false) |
62 | |
private final Long styleId; |
63 | |
|
64 | |
@XmlElement(name = Elements.NAME, required = true) |
65 | |
private final String name; |
66 | |
|
67 | |
@XmlElement(name = Elements.XML_CONTENT, required = false) |
68 | |
private final String xmlContent; |
69 | |
|
70 | |
@XmlElement(name = Elements.ACTIVE, required = true) |
71 | |
private final boolean active; |
72 | |
|
73 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
74 | |
private final Long versionNumber; |
75 | |
|
76 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
77 | |
private final String objectId; |
78 | |
|
79 | 6 | @SuppressWarnings("unused") |
80 | |
@XmlAnyElement |
81 | |
private final Collection<Element> _futureElements = null; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | 2 | private Style() { |
87 | 2 | this.styleId = null; |
88 | 2 | this.name = null; |
89 | 2 | this.xmlContent = null; |
90 | 2 | this.active = false; |
91 | 2 | this.versionNumber = null; |
92 | 2 | this.objectId = null; |
93 | 2 | } |
94 | |
|
95 | 4 | private Style(Builder builder) { |
96 | 4 | this.styleId = builder.getStyleId(); |
97 | 4 | this.name = builder.getName(); |
98 | 4 | this.xmlContent = builder.getXmlContent(); |
99 | 4 | this.active = builder.isActive(); |
100 | 4 | this.versionNumber = builder.getVersionNumber(); |
101 | 4 | this.objectId = builder.getObjectId(); |
102 | 4 | } |
103 | |
|
104 | |
@Override |
105 | |
public Long getStyleId() { |
106 | 2 | return this.styleId; |
107 | |
} |
108 | |
|
109 | |
@Override |
110 | |
public String getName() { |
111 | 2 | return this.name; |
112 | |
} |
113 | |
|
114 | |
@Override |
115 | |
public String getXmlContent() { |
116 | 2 | return this.xmlContent; |
117 | |
} |
118 | |
|
119 | |
@Override |
120 | |
public boolean isActive() { |
121 | 2 | return this.active; |
122 | |
} |
123 | |
|
124 | |
@Override |
125 | |
public Long getVersionNumber() { |
126 | 2 | return this.versionNumber; |
127 | |
} |
128 | |
|
129 | |
@Override |
130 | |
public String getObjectId() { |
131 | 2 | return this.objectId; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | 4 | public static final class Builder implements StyleContract, ModelBuilder, Serializable { |
142 | |
|
143 | |
private static final long serialVersionUID = -219369603932108436L; |
144 | |
|
145 | |
private Long styleId; |
146 | |
private String name; |
147 | |
private String xmlContent; |
148 | |
private boolean active; |
149 | |
private Long versionNumber; |
150 | |
private String objectId; |
151 | |
|
152 | 8 | private Builder(String name) { |
153 | 8 | setName(name); |
154 | 5 | setActive(true); |
155 | 5 | } |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
public static Builder create(String name) { |
170 | 8 | return new Builder(name); |
171 | |
} |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
public static Builder create(StyleContract contract) { |
185 | 4 | if (contract == null) { |
186 | 1 | throw new IllegalArgumentException("contract was null"); |
187 | |
} |
188 | 3 | Builder builder = create(contract.getName()); |
189 | 3 | builder.setStyleId(contract.getStyleId()); |
190 | 3 | builder.setXmlContent(contract.getXmlContent()); |
191 | 3 | builder.setActive(contract.isActive()); |
192 | 3 | builder.setVersionNumber(contract.getVersionNumber()); |
193 | 3 | builder.setObjectId(contract.getObjectId()); |
194 | 3 | return builder; |
195 | |
} |
196 | |
|
197 | |
@Override |
198 | |
public Style build() { |
199 | 4 | return new Style(this); |
200 | |
} |
201 | |
|
202 | |
@Override |
203 | |
public Long getStyleId() { |
204 | 4 | return this.styleId; |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
public void setStyleId(Long styleId) { |
213 | 3 | this.styleId = styleId; |
214 | 3 | } |
215 | |
|
216 | |
@Override |
217 | |
public String getName() { |
218 | 4 | return this.name; |
219 | |
} |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
public void setName(String name) { |
231 | 11 | if (StringUtils.isBlank(name)) { |
232 | 6 | throw new IllegalArgumentException("name is blank"); |
233 | |
} |
234 | 5 | this.name = name; |
235 | 5 | } |
236 | |
|
237 | |
@Override |
238 | |
public String getXmlContent() { |
239 | 4 | return this.xmlContent; |
240 | |
} |
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
public void setXmlContent(String xmlContent) { |
249 | 3 | this.xmlContent = xmlContent; |
250 | 3 | } |
251 | |
|
252 | |
@Override |
253 | |
public boolean isActive() { |
254 | 4 | return this.active; |
255 | |
} |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
public void setActive(boolean active) { |
264 | 8 | this.active = active; |
265 | 8 | } |
266 | |
|
267 | |
@Override |
268 | |
public Long getVersionNumber() { |
269 | 4 | return this.versionNumber; |
270 | |
} |
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
public void setVersionNumber(Long versionNumber) { |
283 | 3 | this.versionNumber = versionNumber; |
284 | 3 | } |
285 | |
|
286 | |
@Override |
287 | |
public String getObjectId() { |
288 | 4 | return objectId; |
289 | |
} |
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
public void setObjectId(String objectId) { |
302 | 3 | this.objectId = objectId; |
303 | 3 | } |
304 | |
|
305 | |
} |
306 | |
|
307 | |
@Override |
308 | |
public int hashCode() { |
309 | 3 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
310 | |
} |
311 | |
|
312 | |
@Override |
313 | |
public boolean equals(Object obj) { |
314 | 2 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
315 | |
} |
316 | |
|
317 | |
@Override |
318 | |
public String toString() { |
319 | 1 | return ToStringBuilder.reflectionToString(this); |
320 | |
} |
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | 0 | static class Constants { |
326 | |
final static String ROOT_ELEMENT_NAME = "style"; |
327 | |
final static String TYPE_NAME = "StyleType"; |
328 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
329 | |
} |
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | 0 | static class Elements { |
336 | |
final static String STYLE_ID = "styleId"; |
337 | |
final static String NAME = "name"; |
338 | |
final static String XML_CONTENT = "xmlContent"; |
339 | |
final static String ACTIVE = "active"; |
340 | |
} |
341 | |
|
342 | |
} |