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