Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Style |
|
| 1.1666666666666667;1.167 | ||||
Style$1 |
|
| 1.1666666666666667;1.167 | ||||
Style$Builder |
|
| 1.1666666666666667;1.167 | ||||
Style$Constants |
|
| 1.1666666666666667;1.167 | ||||
Style$Elements |
|
| 1.1666666666666667;1.167 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
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 | * An immutable representation of a Style. A style is essentially a block of | |
36 | * XML containing and XSL stylesheet. These can be used in various places for | |
37 | * the transformation of XML data from one form to another. | |
38 | * | |
39 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
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 | 0 | 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 | 0 | @SuppressWarnings("unused") |
76 | @XmlAnyElement | |
77 | private final Collection<Element> _futureElements = null; | |
78 | ||
79 | /** | |
80 | * Private constructor used only by JAXB. | |
81 | */ | |
82 | 0 | private Style() { |
83 | 0 | this.styleId = null; |
84 | 0 | this.name = null; |
85 | 0 | this.xmlContent = null; |
86 | 0 | this.active = false; |
87 | 0 | this.versionNumber = null; |
88 | 0 | this.objectId = null; |
89 | 0 | } |
90 | ||
91 | 0 | private Style(Builder builder) { |
92 | 0 | this.styleId = builder.getStyleId(); |
93 | 0 | this.name = builder.getName(); |
94 | 0 | this.xmlContent = builder.getXmlContent(); |
95 | 0 | this.active = builder.isActive(); |
96 | 0 | this.versionNumber = builder.getVersionNumber(); |
97 | 0 | this.objectId = builder.getObjectId(); |
98 | 0 | } |
99 | ||
100 | @Override | |
101 | public Long getStyleId() { | |
102 | 0 | return this.styleId; |
103 | } | |
104 | ||
105 | @Override | |
106 | public String getName() { | |
107 | 0 | return this.name; |
108 | } | |
109 | ||
110 | @Override | |
111 | public String getXmlContent() { | |
112 | 0 | return this.xmlContent; |
113 | } | |
114 | ||
115 | @Override | |
116 | public boolean isActive() { | |
117 | 0 | return this.active; |
118 | } | |
119 | ||
120 | @Override | |
121 | public Long getVersionNumber() { | |
122 | 0 | return this.versionNumber; |
123 | } | |
124 | ||
125 | @Override | |
126 | public String getObjectId() { | |
127 | 0 | return this.objectId; |
128 | } | |
129 | ||
130 | /** | |
131 | * A builder which can be used to construct {@link Style} instances. | |
132 | * Enforces the constraints of the {@link StyleContract}. | |
133 | * | |
134 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
135 | * | |
136 | */ | |
137 | 0 | 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 | 0 | private Builder(String name) { |
149 | 0 | setName(name); |
150 | 0 | setActive(true); |
151 | 0 | } |
152 | ||
153 | /** | |
154 | * Creates a style builder with the given required values. The builder | |
155 | * is the only means by which a {@link Style} object should be created. | |
156 | * | |
157 | * <p>Will default the active flag to true. | |
158 | * | |
159 | * @param name the name of the style to create, must not be null or blank | |
160 | * | |
161 | * @return a builder with the required values already initialized | |
162 | * | |
163 | * @throws IllegalArgumentException if the given name is null or blank | |
164 | */ | |
165 | public static Builder create(String name) { | |
166 | 0 | return new Builder(name); |
167 | } | |
168 | ||
169 | /** | |
170 | * Creates a populates a builder with the data on the given StyleContract. | |
171 | * This is similar in nature to a "copy constructor" for Style. | |
172 | * | |
173 | * @param contract an object implementing the StyleContract from which | |
174 | * to copy property values | |
175 | * | |
176 | * @return a builder with the values from the contract already initialized | |
177 | * | |
178 | * @throws IllegalArgumentException if the given contract is null | |
179 | */ | |
180 | public static Builder create(StyleContract contract) { | |
181 | 0 | if (contract == null) { |
182 | 0 | throw new IllegalArgumentException("contract was null"); |
183 | } | |
184 | 0 | Builder builder = create(contract.getName()); |
185 | 0 | builder.setStyleId(contract.getStyleId()); |
186 | 0 | builder.setXmlContent(contract.getXmlContent()); |
187 | 0 | builder.setActive(contract.isActive()); |
188 | 0 | builder.setVersionNumber(contract.getVersionNumber()); |
189 | 0 | builder.setObjectId(contract.getObjectId()); |
190 | 0 | return builder; |
191 | } | |
192 | ||
193 | @Override | |
194 | public Style build() { | |
195 | 0 | return new Style(this); |
196 | } | |
197 | ||
198 | @Override | |
199 | public Long getStyleId() { | |
200 | 0 | return this.styleId; |
201 | } | |
202 | ||
203 | /** | |
204 | * Sets the styleId for the style that will be returned by this builder. | |
205 | * | |
206 | * @param styleId the styleId to set | |
207 | */ | |
208 | public void setStyleId(Long styleId) { | |
209 | 0 | this.styleId = styleId; |
210 | 0 | } |
211 | ||
212 | @Override | |
213 | public String getName() { | |
214 | 0 | return this.name; |
215 | } | |
216 | ||
217 | /** | |
218 | * Sets the name for the style that will be returned by this builder. | |
219 | * The name must not be blank or null. | |
220 | * | |
221 | * @param name the name to set on this builder, must not be null or | |
222 | * blank | |
223 | * | |
224 | * @throws IllegalArgumentException if the given name is null or blank | |
225 | */ | |
226 | public void setName(String name) { | |
227 | 0 | if (StringUtils.isBlank(name)) { |
228 | 0 | throw new IllegalArgumentException("name is blank"); |
229 | } | |
230 | 0 | this.name = name; |
231 | 0 | } |
232 | ||
233 | @Override | |
234 | public String getXmlContent() { | |
235 | 0 | return this.xmlContent; |
236 | } | |
237 | ||
238 | /** | |
239 | * Sets the XML content for the style that will be returned by this | |
240 | * builder. | |
241 | * | |
242 | * @param xmlContent the xmlContent to set on this builder | |
243 | */ | |
244 | public void setXmlContent(String xmlContent) { | |
245 | 0 | this.xmlContent = xmlContent; |
246 | 0 | } |
247 | ||
248 | @Override | |
249 | public boolean isActive() { | |
250 | 0 | return this.active; |
251 | } | |
252 | ||
253 | /** | |
254 | * Sets the active flag for the style that will be returned by this | |
255 | * builder. | |
256 | * | |
257 | * @param active the active flag to set | |
258 | */ | |
259 | public void setActive(boolean active) { | |
260 | 0 | this.active = active; |
261 | 0 | } |
262 | ||
263 | @Override | |
264 | public Long getVersionNumber() { | |
265 | 0 | return this.versionNumber; |
266 | } | |
267 | ||
268 | /** | |
269 | * Sets the version number for the style that will be returned by this | |
270 | * builder. | |
271 | * | |
272 | * <p>In general, this value should not be manually set on the builder, | |
273 | * but rather copied from an existing {@link StyleContract} when | |
274 | * invoking {@link Builder#create(StyleContract)}. | |
275 | * | |
276 | * @param versionNumber the version number to set | |
277 | */ | |
278 | public void setVersionNumber(Long versionNumber) { | |
279 | 0 | this.versionNumber = versionNumber; |
280 | 0 | } |
281 | ||
282 | @Override | |
283 | public String getObjectId() { | |
284 | 0 | return objectId; |
285 | } | |
286 | ||
287 | /** | |
288 | * Sets the globally unique object ID for the style that will be | |
289 | * returned by this builder. | |
290 | * | |
291 | * <p>In general, this value should not be manually set on the builder, | |
292 | * but rather copied from an existing {@link StyleContract} when | |
293 | * invoking {@link Builder#create(StyleContract)}. | |
294 | * | |
295 | * @param objectId the object ID to set | |
296 | */ | |
297 | public void setObjectId(String objectId) { | |
298 | 0 | this.objectId = objectId; |
299 | 0 | } |
300 | ||
301 | } | |
302 | ||
303 | /** | |
304 | * Defines some internal constants used on this class. | |
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 | * A private class which exposes constants which define the XML element names to use | |
313 | * when this object is marshalled to XML. | |
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 | } |