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