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