1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.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.STYLE_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 | 4 | public final class Style extends AbstractDataTransferObject implements StyleContract { |
54 | |
|
55 | |
private static final long serialVersionUID = -26426318682076660L; |
56 | |
|
57 | |
@XmlElement(name = Elements.STYLE_ID, required = false) |
58 | |
private final Long styleId; |
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 | 6 | @SuppressWarnings("unused") |
76 | |
@XmlAnyElement |
77 | |
private final Collection<Element> _futureElements = null; |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | 2 | private Style() { |
83 | 2 | this.styleId = null; |
84 | 2 | this.name = null; |
85 | 2 | this.xmlContent = null; |
86 | 2 | this.active = false; |
87 | 2 | this.versionNumber = null; |
88 | 2 | this.objectId = null; |
89 | 2 | } |
90 | |
|
91 | 4 | private Style(Builder builder) { |
92 | 4 | this.styleId = builder.getStyleId(); |
93 | 4 | this.name = builder.getName(); |
94 | 4 | this.xmlContent = builder.getXmlContent(); |
95 | 4 | this.active = builder.isActive(); |
96 | 4 | this.versionNumber = builder.getVersionNumber(); |
97 | 4 | this.objectId = builder.getObjectId(); |
98 | 4 | } |
99 | |
|
100 | |
@Override |
101 | |
public Long getStyleId() { |
102 | 2 | return this.styleId; |
103 | |
} |
104 | |
|
105 | |
@Override |
106 | |
public String getName() { |
107 | 2 | return this.name; |
108 | |
} |
109 | |
|
110 | |
@Override |
111 | |
public String getXmlContent() { |
112 | 2 | return this.xmlContent; |
113 | |
} |
114 | |
|
115 | |
@Override |
116 | |
public boolean isActive() { |
117 | 2 | return this.active; |
118 | |
} |
119 | |
|
120 | |
@Override |
121 | |
public Long getVersionNumber() { |
122 | 2 | return this.versionNumber; |
123 | |
} |
124 | |
|
125 | |
@Override |
126 | |
public String getObjectId() { |
127 | 2 | return this.objectId; |
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | 4 | public static final class Builder implements StyleContract, ModelBuilder, Serializable { |
138 | |
|
139 | |
private static final long serialVersionUID = -219369603932108436L; |
140 | |
|
141 | |
private Long styleId; |
142 | |
private String name; |
143 | |
private String xmlContent; |
144 | |
private boolean active; |
145 | |
private Long versionNumber; |
146 | |
private String objectId; |
147 | |
|
148 | 8 | private Builder(String name) { |
149 | 8 | setName(name); |
150 | 5 | setActive(true); |
151 | 5 | } |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
public static Builder create(String name) { |
166 | 8 | 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 | 4 | if (contract == null) { |
182 | 1 | throw new IllegalArgumentException("contract was null"); |
183 | |
} |
184 | 3 | Builder builder = create(contract.getName()); |
185 | 3 | builder.setStyleId(contract.getStyleId()); |
186 | 3 | builder.setXmlContent(contract.getXmlContent()); |
187 | 3 | builder.setActive(contract.isActive()); |
188 | 3 | builder.setVersionNumber(contract.getVersionNumber()); |
189 | 3 | builder.setObjectId(contract.getObjectId()); |
190 | 3 | return builder; |
191 | |
} |
192 | |
|
193 | |
@Override |
194 | |
public Style build() { |
195 | 4 | return new Style(this); |
196 | |
} |
197 | |
|
198 | |
@Override |
199 | |
public Long getStyleId() { |
200 | 4 | return this.styleId; |
201 | |
} |
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
public void setStyleId(Long styleId) { |
209 | 3 | this.styleId = styleId; |
210 | 3 | } |
211 | |
|
212 | |
@Override |
213 | |
public String getName() { |
214 | 4 | return this.name; |
215 | |
} |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
public void setName(String name) { |
227 | 11 | if (StringUtils.isBlank(name)) { |
228 | 6 | throw new IllegalArgumentException("name is blank"); |
229 | |
} |
230 | 5 | this.name = name; |
231 | 5 | } |
232 | |
|
233 | |
@Override |
234 | |
public String getXmlContent() { |
235 | 4 | return this.xmlContent; |
236 | |
} |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
public void setXmlContent(String xmlContent) { |
245 | 3 | this.xmlContent = xmlContent; |
246 | 3 | } |
247 | |
|
248 | |
@Override |
249 | |
public boolean isActive() { |
250 | 4 | return this.active; |
251 | |
} |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
public void setActive(boolean active) { |
260 | 8 | this.active = active; |
261 | 8 | } |
262 | |
|
263 | |
@Override |
264 | |
public Long getVersionNumber() { |
265 | 4 | return this.versionNumber; |
266 | |
} |
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
public void setVersionNumber(Long versionNumber) { |
279 | 3 | this.versionNumber = versionNumber; |
280 | 3 | } |
281 | |
|
282 | |
@Override |
283 | |
public String getObjectId() { |
284 | 4 | return objectId; |
285 | |
} |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
public void setObjectId(String objectId) { |
298 | 3 | this.objectId = objectId; |
299 | 3 | } |
300 | |
|
301 | |
} |
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | 0 | 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 | 0 | static class Elements { |
316 | |
final static String STYLE_ID = "styleId"; |
317 | |
final static String NAME = "name"; |
318 | |
final static String XML_CONTENT = "xmlContent"; |
319 | |
final static String ACTIVE = "active"; |
320 | |
} |
321 | |
|
322 | |
} |