001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.engine.node;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import edu.iu.uis.eden.KEWServiceLocator;
025: import edu.iu.uis.eden.doctype.DocumentType;
026: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
027:
028: /**
029: * Represents a materialized instance of a {@link RouteNode} definition on a {@link DocumentRouteHeaderValue}. Node instances
030: * are generated by the engine using the {@link RouteNode} as a prototype and connected as a
031: * Directed Acyclic Graph.
032: *
033: * @author ewestfal
034: */
035: public class RouteNodeInstance implements Serializable {
036:
037: private static final long serialVersionUID = 7183670062805580420L;
038:
039: private Long routeNodeInstanceId;
040: private Long documentId;
041: private Branch branch;
042: private RouteNode routeNode;
043: private boolean active = false;
044: private boolean complete = false;
045: private boolean initial = true;
046: private RouteNodeInstance process;
047: private List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>();
048: private List<RouteNodeInstance> previousNodeInstances = new ArrayList<RouteNodeInstance>();
049: private List<NodeState> state = new ArrayList<NodeState>();
050:
051: private Integer lockVerNbr;
052:
053: public boolean isActive() {
054: return active;
055: }
056:
057: public void setActive(boolean active) {
058: this .active = active;
059: }
060:
061: public boolean isComplete() {
062: return complete;
063: }
064:
065: public void setComplete(boolean complete) {
066: this .complete = complete;
067: }
068:
069: public Branch getBranch() {
070: return branch;
071: }
072:
073: public void setBranch(Branch branch) {
074: this .branch = branch;
075: }
076:
077: public RouteNode getRouteNode() {
078: return routeNode;
079: }
080:
081: public void setRouteNode(RouteNode node) {
082: this .routeNode = node;
083: }
084:
085: public Long getRouteNodeInstanceId() {
086: return routeNodeInstanceId;
087: }
088:
089: public void setRouteNodeInstanceId(Long routeNodeInstanceId) {
090: this .routeNodeInstanceId = routeNodeInstanceId;
091: }
092:
093: public Long getDocumentId() {
094: return documentId;
095: }
096:
097: public void setDocumentId(Long routeHeaderId) {
098: this .documentId = routeHeaderId;
099: }
100:
101: public List getNextNodeInstances() {
102: return nextNodeInstances;
103: }
104:
105: public RouteNodeInstance getNextNodeInstance(int index) {
106: while (getNextNodeInstances().size() <= index) {
107: nextNodeInstances.add(new RouteNodeInstance());
108: }
109: return (RouteNodeInstance) getNextNodeInstances().get(index);
110: }
111:
112: public void setNextNodeInstances(
113: List<RouteNodeInstance> nextNodeInstances) {
114: this .nextNodeInstances = nextNodeInstances;
115: }
116:
117: public List<RouteNodeInstance> getPreviousNodeInstances() {
118: return previousNodeInstances;
119: }
120:
121: public RouteNodeInstance getPreviousNodeInstance(int index) {
122: while (previousNodeInstances.size() <= index) {
123: previousNodeInstances.add(new RouteNodeInstance());
124: }
125: return (RouteNodeInstance) getPreviousNodeInstances()
126: .get(index);
127: }
128:
129: public void setPreviousNodeInstances(
130: List<RouteNodeInstance> previousNodeInstances) {
131: this .previousNodeInstances = previousNodeInstances;
132: }
133:
134: public boolean isInitial() {
135: return initial;
136: }
137:
138: public void setInitial(boolean initial) {
139: this .initial = initial;
140: }
141:
142: public List getState() {
143: return state;
144: }
145:
146: public void setState(List<NodeState> state) {
147: this .state = state;
148: }
149:
150: public RouteNodeInstance getProcess() {
151: return process;
152: }
153:
154: public void setProcess(RouteNodeInstance process) {
155: this .process = process;
156: }
157:
158: public Integer getLockVerNbr() {
159: return lockVerNbr;
160: }
161:
162: public void setLockVerNbr(Integer lockVerNbr) {
163: this .lockVerNbr = lockVerNbr;
164: }
165:
166: public NodeState getNodeState(String key) {
167: for (Iterator iter = getState().iterator(); iter.hasNext();) {
168: NodeState nodeState = (NodeState) iter.next();
169: if (nodeState.getKey().equals(key)) {
170: return nodeState;
171: }
172: }
173: return null;
174: }
175:
176: public void addNodeState(NodeState state) {
177: this .state.add(state);
178: state.setNodeInstance(this );
179: }
180:
181: public void removeNodeState(String key) {
182: for (Iterator iter = getState().iterator(); iter.hasNext();) {
183: NodeState nodeState = (NodeState) iter.next();
184: if (nodeState.getKey().equals(key)) {
185: iter.remove();
186: break;
187: }
188: }
189: }
190:
191: public void addNextNodeInstance(RouteNodeInstance nextNodeInstance) {
192: nextNodeInstances.add(nextNodeInstance);
193: nextNodeInstance.getPreviousNodeInstances().add(this );
194: }
195:
196: public void removeNextNodeInstance(
197: RouteNodeInstance nextNodeInstance) {
198: nextNodeInstances.remove(nextNodeInstance);
199: nextNodeInstance.getPreviousNodeInstances().remove(this );
200: }
201:
202: public void clearNextNodeInstances() {
203: for (Iterator iterator = nextNodeInstances.iterator(); iterator
204: .hasNext();) {
205: RouteNodeInstance nextNodeInstance = (RouteNodeInstance) iterator
206: .next();
207: iterator.remove();
208: nextNodeInstance.getPreviousNodeInstances().remove(this );
209: }
210: }
211:
212: public String getName() {
213: return (getRouteNode() == null ? null : getRouteNode()
214: .getRouteNodeName());
215: }
216:
217: public boolean isInProcess() {
218: return getProcess() != null;
219: }
220:
221: public DocumentType getDocumentType() {
222: return KEWServiceLocator.getDocumentTypeService().findById(
223: getDocumentId());
224: }
225:
226: /*
227: * methods used to display route node instances' data on documentoperation.jsp
228: */
229:
230: public NodeState getState(int index) {
231: while (state.size() <= index) {
232: state.add(new NodeState());
233: }
234: return (NodeState) getState().get(index);
235: }
236:
237: public void populateState(List<NodeState> state) {
238: this.state.addAll(state);
239: }
240:
241: }
|