View Javadoc

1   /**
2    * Copyright 2005-2012 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.kew.api.document.node;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import javax.xml.bind.annotation.XmlAccessType;
25  import javax.xml.bind.annotation.XmlAccessorType;
26  import javax.xml.bind.annotation.XmlAnyElement;
27  import javax.xml.bind.annotation.XmlElement;
28  import javax.xml.bind.annotation.XmlElementWrapper;
29  import javax.xml.bind.annotation.XmlRootElement;
30  import javax.xml.bind.annotation.XmlType;
31  
32  import org.kuali.rice.core.api.CoreConstants;
33  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
34  import org.kuali.rice.core.api.mo.ModelBuilder;
35  import org.w3c.dom.Element;
36  
37  @XmlRootElement(name = RouteNodeInstance.Constants.ROOT_ELEMENT_NAME)
38  @XmlAccessorType(XmlAccessType.NONE)
39  @XmlType(name = RouteNodeInstance.Constants.TYPE_NAME, propOrder = {
40      RouteNodeInstance.Elements.ID,
41      RouteNodeInstance.Elements.NAME,
42      RouteNodeInstance.Elements.STATE,
43      RouteNodeInstance.Elements.DOCUMENT_ID,
44      RouteNodeInstance.Elements.BRANCH_ID,
45      RouteNodeInstance.Elements.ROUTE_NODE_ID,
46      RouteNodeInstance.Elements.PROCESS_ID,
47      RouteNodeInstance.Elements.ACTIVE,
48      RouteNodeInstance.Elements.COMPLETE,
49      RouteNodeInstance.Elements.INITIAL,
50      RouteNodeInstance.Elements.NEXT_NODE_INSTANCES,
51      CoreConstants.CommonElements.FUTURE_ELEMENTS
52  })
53  public final class RouteNodeInstance extends AbstractDataTransferObject
54      implements RouteNodeInstanceContract
55  {
56  
57      @XmlElement(name = Elements.NAME, required = false)
58      private final String name;
59      @XmlElementWrapper(name = Elements.STATE, required = false)
60      @XmlElement(name = Elements.ROUTE_NODE_INSTANCE_STATE, required = false)
61      private final List<RouteNodeInstanceState> state;
62      @XmlElement(name = Elements.DOCUMENT_ID, required = false)
63      private final String documentId;
64      @XmlElement(name = Elements.BRANCH_ID, required = false)
65      private final String branchId;
66      @XmlElement(name = Elements.ROUTE_NODE_ID, required = false)
67      private final String routeNodeId;
68      @XmlElement(name = Elements.PROCESS_ID, required = false)
69      private final String processId;
70      @XmlElement(name = Elements.ACTIVE, required = false)
71      private final boolean active;
72      @XmlElement(name = Elements.COMPLETE, required = false)
73      private final boolean complete;
74      @XmlElement(name = Elements.INITIAL, required = false)
75      private final boolean initial;
76      @XmlElement(name = Elements.ID, required = false)
77      private final String id;
78      @XmlElementWrapper(name = Elements.NEXT_NODE_INSTANCES, required = false)
79      @XmlElement(name = Elements.NEXT_NODE_INSTANCE, required = false)
80      private final List<RouteNodeInstance> nextNodeInstances;
81  
82      @SuppressWarnings("unused")
83      @XmlAnyElement
84      private final Collection<Element> _futureElements = null;
85  
86      /**
87       * Private constructor used only by JAXB.
88       * 
89       */
90      private RouteNodeInstance() {
91          this.name = null;
92          this.state = null;
93          this.documentId = null;
94          this.branchId = null;
95          this.routeNodeId = null;
96          this.processId = null;
97          this.active = false;
98          this.complete = false;
99          this.initial = false;
100         this.id = null;
101         this.nextNodeInstances = null;
102     }
103 
104     private RouteNodeInstance(Builder builder) {
105         this.name = builder.getName();
106         if (builder.getState() != null) {
107             List<RouteNodeInstanceState> states = new ArrayList<RouteNodeInstanceState>();
108             for(RouteNodeInstanceState.Builder stateBuilder : builder.getState()) {
109                 states.add(stateBuilder.build());
110             }
111             this.state = states;
112         } else {
113             this.state = Collections.emptyList();
114         }
115 
116         if (builder.getNextNodeInstances() != null) {
117             List<RouteNodeInstance> nextInstances = new ArrayList<RouteNodeInstance>();
118             for (RouteNodeInstance.Builder instance : builder.getNextNodeInstances()) {
119                 nextInstances.add(instance.build());
120             }
121             this.nextNodeInstances = nextInstances;
122         } else {
123             this.nextNodeInstances = Collections.emptyList();
124         }
125 
126 
127         this.documentId = builder.getDocumentId();
128         this.branchId = builder.getBranchId();
129         this.routeNodeId = builder.getRouteNodeId();
130         this.processId = builder.getProcessId();
131         this.active = builder.isActive();
132         this.complete = builder.isComplete();
133         this.initial = builder.isInitial();
134         this.id = builder.getId();
135     }
136 
137     @Override
138     public String getName() {
139         return this.name;
140     }
141 
142     @Override
143     public List<RouteNodeInstanceState> getState() {
144         return this.state;
145     }
146 
147     @Override
148     public String getDocumentId() {
149         return this.documentId;
150     }
151 
152     @Override
153     public String getBranchId() {
154         return this.branchId;
155     }
156 
157     @Override
158     public String getRouteNodeId() {
159         return this.routeNodeId;
160     }
161 
162     @Override
163     public String getProcessId() {
164         return this.processId;
165     }
166 
167     @Override
168     public boolean isActive() {
169         return this.active;
170     }
171 
172     @Override
173     public boolean isComplete() {
174         return this.complete;
175     }
176 
177     @Override
178     public boolean isInitial() {
179         return this.initial;
180     }
181 
182     @Override
183     public String getId() {
184         return this.id;
185     }
186 
187     @Override
188     public List<RouteNodeInstance> getNextNodeInstances() {
189         return this.nextNodeInstances;
190     }
191 
192 
193     /**
194      * A builder which can be used to construct {@link RouteNodeInstance} instances.  Enforces the constraints of the {@link RouteNodeInstanceContract}.
195      * 
196      */
197     public final static class Builder
198         implements Serializable, ModelBuilder, RouteNodeInstanceContract
199     {
200 
201         private String name;
202         private List<RouteNodeInstanceState.Builder> state;
203         private String documentId;
204         private String branchId;
205         private String routeNodeId;
206         private String processId;
207         private boolean active;
208         private boolean complete;
209         private boolean initial;
210         private String id;
211         private List<RouteNodeInstance.Builder> nextNodeInstances;
212 
213         private Builder() {
214             // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods
215         }
216 
217         public static Builder create() {
218             // TODO modify as needed to pass any required values and add them to the signature of the 'create' method
219             return new Builder();
220         }
221 
222         public static Builder create(RouteNodeInstanceContract contract) {
223             if (contract == null) {
224                 throw new IllegalArgumentException("contract was null");
225             }
226             // TODO if create() is modified to accept required parameters, this will need to be modified
227             Builder builder = create();
228             builder.setName(contract.getName());
229             if (contract.getState() != null) {
230                 List<RouteNodeInstanceState.Builder> stateBuilders = new ArrayList<RouteNodeInstanceState.Builder>();
231                 for (RouteNodeInstanceStateContract stateContract : contract.getState()) {
232                     stateBuilders.add(RouteNodeInstanceState.Builder.create(stateContract));
233                 }
234                 builder.setState(stateBuilders);
235             }
236 
237             builder.setDocumentId(contract.getDocumentId());
238             builder.setBranchId(contract.getBranchId());
239             builder.setRouteNodeId(contract.getRouteNodeId());
240             builder.setProcessId(contract.getProcessId());
241             builder.setActive(contract.isActive());
242             builder.setComplete(contract.isComplete());
243             builder.setInitial(contract.isInitial());
244             builder.setId(contract.getId());
245             if (contract.getNextNodeInstances() != null) {
246                 List<RouteNodeInstance.Builder> instanceBuilders = new ArrayList<RouteNodeInstance.Builder>();
247                 for(RouteNodeInstanceContract instanceContract : contract.getNextNodeInstances()) {
248                     instanceBuilders.add(RouteNodeInstance.Builder.create(instanceContract));
249                 }
250                 builder.setNextNodeInstances(instanceBuilders);
251             }
252             return builder;
253         }
254 
255         public RouteNodeInstance build() {
256             return new RouteNodeInstance(this);
257         }
258 
259         @Override
260         public String getName() {
261             return this.name;
262         }
263 
264         @Override
265         public List<RouteNodeInstanceState.Builder> getState() {
266             return this.state;
267         }
268 
269         @Override
270         public String getDocumentId() {
271             return this.documentId;
272         }
273 
274         @Override
275         public String getBranchId() {
276             return this.branchId;
277         }
278 
279         @Override
280         public String getRouteNodeId() {
281             return this.routeNodeId;
282         }
283 
284         @Override
285         public String getProcessId() {
286             return this.processId;
287         }
288 
289         @Override
290         public boolean isActive() {
291             return this.active;
292         }
293 
294         @Override
295         public boolean isComplete() {
296             return this.complete;
297         }
298 
299         @Override
300         public boolean isInitial() {
301             return this.initial;
302         }
303 
304         @Override
305         public String getId() {
306             return this.id;
307         }
308 
309         @Override
310         public List<RouteNodeInstance.Builder> getNextNodeInstances() {
311             return this.nextNodeInstances;
312         }
313 
314         public void setNextNodeInstances(List<RouteNodeInstance.Builder> nextNodeInstances) {
315             // TODO add validation of input value if required and throw IllegalArgumentException if needed
316             this.nextNodeInstances = Collections.unmodifiableList(nextNodeInstances);
317         }
318 
319         public void setName(String name) {
320             // TODO add validation of input value if required and throw IllegalArgumentException if needed
321             this.name = name;
322         }
323 
324         public void setState(List<RouteNodeInstanceState.Builder> state) {
325             // TODO add validation of input value if required and throw IllegalArgumentException if needed
326             this.state = state;
327         }
328 
329         public void setDocumentId(String documentId) {
330             // TODO add validation of input value if required and throw IllegalArgumentException if needed
331             this.documentId = documentId;
332         }
333 
334         public void setBranchId(String branchId) {
335             // TODO add validation of input value if required and throw IllegalArgumentException if needed
336             this.branchId = branchId;
337         }
338 
339         public void setRouteNodeId(String routeNodeId) {
340             // TODO add validation of input value if required and throw IllegalArgumentException if needed
341             this.routeNodeId = routeNodeId;
342         }
343 
344         public void setProcessId(String processId) {
345             // TODO add validation of input value if required and throw IllegalArgumentException if needed
346             this.processId = processId;
347         }
348 
349         public void setActive(boolean active) {
350             // TODO add validation of input value if required and throw IllegalArgumentException if needed
351             this.active = active;
352         }
353 
354         public void setComplete(boolean complete) {
355             // TODO add validation of input value if required and throw IllegalArgumentException if needed
356             this.complete = complete;
357         }
358 
359         public void setInitial(boolean initial) {
360             // TODO add validation of input value if required and throw IllegalArgumentException if needed
361             this.initial = initial;
362         }
363 
364         public void setId(String id) {
365             // TODO add validation of input value if required and throw IllegalArgumentException if needed
366             this.id = id;
367         }
368 
369     }
370 
371 
372     /**
373      * Defines some internal constants used on this class.
374      * 
375      */
376     static class Constants {
377 
378         final static String ROOT_ELEMENT_NAME = "routeNodeInstance";
379         final static String TYPE_NAME = "RouteNodeInstanceType";
380     }
381 
382 
383     /**
384      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
385      * 
386      */
387     static class Elements {
388 
389         final static String NAME = "name";
390         final static String STATE = "state";
391         final static String ROUTE_NODE_INSTANCE_STATE = "routeNodeInstanceState";
392         final static String DOCUMENT_ID = "documentId";
393         final static String BRANCH_ID = "branchId";
394         final static String ROUTE_NODE_ID = "routeNodeId";
395         final static String PROCESS_ID = "processId";
396         final static String ACTIVE = "active";
397         final static String COMPLETE = "complete";
398         final static String INITIAL = "initial";
399         final static String ID = "id";
400         final static String NEXT_NODE_INSTANCES = "nextNodeInstances";
401         final static String NEXT_NODE_INSTANCE = "nextNodeInstance";
402     }
403 
404 }