1 | |
package org.kuali.rice.kew.api.doctype; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
import java.util.Collection; |
5 | |
|
6 | |
import javax.xml.bind.annotation.XmlAccessType; |
7 | |
import javax.xml.bind.annotation.XmlAccessorType; |
8 | |
import javax.xml.bind.annotation.XmlAnyElement; |
9 | |
import javax.xml.bind.annotation.XmlElement; |
10 | |
import javax.xml.bind.annotation.XmlRootElement; |
11 | |
import javax.xml.bind.annotation.XmlType; |
12 | |
|
13 | |
import org.apache.commons.lang.StringUtils; |
14 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
15 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
16 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
17 | |
import org.kuali.rice.core.api.CoreConstants; |
18 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
19 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
20 | |
import org.w3c.dom.Element; |
21 | |
|
22 | |
@XmlRootElement(name = Process.Constants.ROOT_ELEMENT_NAME) |
23 | |
@XmlAccessorType(XmlAccessType.NONE) |
24 | |
@XmlType(name = Process.Constants.TYPE_NAME, propOrder = { |
25 | |
Process.Elements.ID, |
26 | |
Process.Elements.NAME, |
27 | |
Process.Elements.DOCUMENT_TYPE_ID, |
28 | |
Process.Elements.INITIAL_ROUTE_NODE, |
29 | |
Process.Elements.INITIAL, |
30 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
31 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
32 | |
}) |
33 | 0 | public final class Process implements ModelObjectComplete, ProcessContract { |
34 | |
|
35 | |
private static final long serialVersionUID = 1076976038764944504L; |
36 | |
|
37 | |
@XmlElement(name = Elements.ID, required = false) |
38 | |
private final String id; |
39 | |
|
40 | |
@XmlElement(name = Elements.NAME, required = true) |
41 | |
private final String name; |
42 | |
|
43 | |
@XmlElement(name = Elements.DOCUMENT_TYPE_ID, required = false) |
44 | |
private final String documentTypeId; |
45 | |
|
46 | |
@XmlElement(name = Elements.INITIAL_ROUTE_NODE, required = true) |
47 | |
private final RouteNode initialRouteNode; |
48 | |
|
49 | |
@XmlElement(name = Elements.INITIAL, required = true) |
50 | |
private final boolean initial; |
51 | |
|
52 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
53 | |
private final Long versionNumber; |
54 | |
|
55 | 0 | @SuppressWarnings("unused") |
56 | |
@XmlAnyElement |
57 | |
private final Collection<Element> _futureElements = null; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | 0 | private Process() { |
63 | 0 | this.id = null; |
64 | 0 | this.name = null; |
65 | 0 | this.documentTypeId = null; |
66 | 0 | this.initialRouteNode = null; |
67 | 0 | this.initial = false; |
68 | 0 | this.versionNumber = null; |
69 | 0 | } |
70 | |
|
71 | 0 | private Process(Builder builder) { |
72 | 0 | this.id = builder.getId(); |
73 | 0 | this.name = builder.getName(); |
74 | 0 | this.documentTypeId = builder.getDocumentTypeId(); |
75 | 0 | if (builder.getInitialRouteNode() != null) { |
76 | 0 | this.initialRouteNode = builder.getInitialRouteNode().build(); |
77 | |
} else { |
78 | 0 | this.initialRouteNode = null; |
79 | |
} |
80 | 0 | this.initial = builder.isInitial(); |
81 | 0 | this.versionNumber = builder.getVersionNumber(); |
82 | 0 | } |
83 | |
|
84 | |
@Override |
85 | |
public String getId() { |
86 | 0 | return this.id; |
87 | |
} |
88 | |
|
89 | |
@Override |
90 | |
public String getName() { |
91 | 0 | return this.name; |
92 | |
} |
93 | |
|
94 | |
@Override |
95 | |
public String getDocumentTypeId() { |
96 | 0 | return this.documentTypeId; |
97 | |
} |
98 | |
|
99 | |
@Override |
100 | |
public RouteNodeContract getInitialRouteNode() { |
101 | 0 | return this.initialRouteNode; |
102 | |
} |
103 | |
|
104 | |
@Override |
105 | |
public boolean isInitial() { |
106 | 0 | return this.initial; |
107 | |
} |
108 | |
|
109 | |
@Override |
110 | |
public Long getVersionNumber() { |
111 | 0 | return this.versionNumber; |
112 | |
} |
113 | |
|
114 | |
@Override |
115 | |
public int hashCode() { |
116 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
117 | |
} |
118 | |
|
119 | |
@Override |
120 | |
public boolean equals(Object object) { |
121 | 0 | return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
122 | |
} |
123 | |
|
124 | |
@Override |
125 | |
public String toString() { |
126 | 0 | return ToStringBuilder.reflectionToString(this); |
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | 0 | public final static class Builder implements Serializable, ModelBuilder, ProcessContract { |
134 | |
|
135 | |
private static final long serialVersionUID = 5897271312287857808L; |
136 | |
|
137 | |
private String id; |
138 | |
private String name; |
139 | |
private String documentTypeId; |
140 | |
private RouteNode.Builder initialRouteNode; |
141 | |
private boolean initial; |
142 | |
private Long versionNumber; |
143 | |
|
144 | 0 | private Builder(String name, RouteNode.Builder initialRouteNode, boolean initial) { |
145 | 0 | setName(name); |
146 | 0 | setInitialRouteNode(initialRouteNode); |
147 | 0 | setInitial(initial); |
148 | 0 | } |
149 | |
|
150 | |
public static Builder create(String name, RouteNode.Builder initialRouteNode, boolean initial) { |
151 | 0 | return new Builder(name, initialRouteNode, initial); |
152 | |
} |
153 | |
|
154 | |
public static Builder create(ProcessContract contract) { |
155 | 0 | if (contract == null) { |
156 | 0 | throw new IllegalArgumentException("contract was null"); |
157 | |
} |
158 | 0 | Builder builder = create(contract.getName(), RouteNode.Builder.create(contract.getInitialRouteNode()), |
159 | |
contract.isInitial()); |
160 | 0 | builder.setDocumentTypeId(contract.getDocumentTypeId()); |
161 | 0 | builder.setId(contract.getId()); |
162 | 0 | return builder; |
163 | |
} |
164 | |
|
165 | |
public Process build() { |
166 | 0 | return new Process(this); |
167 | |
} |
168 | |
|
169 | |
@Override |
170 | |
public String getId() { |
171 | 0 | return this.id; |
172 | |
} |
173 | |
|
174 | |
@Override |
175 | |
public String getName() { |
176 | 0 | return this.name; |
177 | |
} |
178 | |
|
179 | |
@Override |
180 | |
public String getDocumentTypeId() { |
181 | 0 | return this.documentTypeId; |
182 | |
} |
183 | |
|
184 | |
@Override |
185 | |
public RouteNode.Builder getInitialRouteNode() { |
186 | 0 | return this.initialRouteNode; |
187 | |
} |
188 | |
|
189 | |
@Override |
190 | |
public boolean isInitial() { |
191 | 0 | return this.initial; |
192 | |
} |
193 | |
|
194 | |
@Override |
195 | |
public Long getVersionNumber() { |
196 | 0 | return this.versionNumber; |
197 | |
} |
198 | |
|
199 | |
public void setId(String id) { |
200 | 0 | this.id = id; |
201 | 0 | } |
202 | |
|
203 | |
public void setName(String name) { |
204 | 0 | if (StringUtils.isBlank(name)) { |
205 | 0 | throw new IllegalArgumentException("name was null or blank"); |
206 | |
} |
207 | 0 | this.name = name; |
208 | 0 | } |
209 | |
|
210 | |
public void setDocumentTypeId(String documentTypeId) { |
211 | 0 | this.documentTypeId = documentTypeId; |
212 | 0 | } |
213 | |
|
214 | |
public void setInitialRouteNode(RouteNode.Builder initialRouteNode) { |
215 | 0 | if (initialRouteNode == null) { |
216 | 0 | throw new IllegalArgumentException("initialRouteNode was null"); |
217 | |
} |
218 | 0 | this.initialRouteNode = initialRouteNode; |
219 | 0 | } |
220 | |
|
221 | |
public void setInitial(boolean initial) { |
222 | 0 | this.initial = initial; |
223 | 0 | } |
224 | |
|
225 | |
public void setVersionNumber(Long versionNumber) { |
226 | 0 | this.versionNumber = versionNumber; |
227 | 0 | } |
228 | |
|
229 | |
} |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | 0 | static class Constants { |
235 | |
final static String ROOT_ELEMENT_NAME = "process"; |
236 | |
final static String TYPE_NAME = "ProcessType"; |
237 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[]{CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
238 | |
} |
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | 0 | static class Elements { |
245 | |
final static String ID = "id"; |
246 | |
final static String NAME = "name"; |
247 | |
final static String DOCUMENT_TYPE_ID = "documentTypeId"; |
248 | |
final static String INITIAL_ROUTE_NODE = "initialRouteNode"; |
249 | |
final static String INITIAL = "initial"; |
250 | |
} |
251 | |
|
252 | |
} |