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;
018:
019: import java.io.Serializable;
020: import java.util.HashMap;
021: import java.util.LinkedList;
022: import java.util.List;
023: import java.util.Map;
024:
025: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
026: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
027: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
028: import edu.iu.uis.eden.routeheader.DocumentContent;
029: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
030: import edu.iu.uis.eden.routeheader.StandardDocumentContent;
031:
032: /**
033: * Represents the current context of a Document being processed by the engine.
034: *
035: * @author ewestfal
036: * @author rkirkend
037: */
038: public class RouteContext implements Serializable {
039:
040: private static final long serialVersionUID = -7125137491367944594L;
041:
042: private DocumentRouteHeaderValue routeHeader;
043:
044: private DocumentContent documentContent;
045:
046: private RouteNodeInstance nodeInstance;
047:
048: private EngineState engineState;
049:
050: private ActionRequestValue actionRequest;
051:
052: private ActivationContext activationContext = new ActivationContext(
053: !ActivationContext.CONTEXT_IS_SIMULATION);
054:
055: private boolean doNotSendApproveNotificationEmails = false;
056:
057: private Map parameters = new HashMap();
058:
059: public RouteContext() {
060: }
061:
062: private static ThreadLocal<List<RouteContext>> ROUTE_CONTEXT_STACK = new ThreadLocal<List<RouteContext>>() {
063: protected List<RouteContext> initialValue() {
064: List<RouteContext> contextStack = new LinkedList<RouteContext>();
065: contextStack.add(0, new RouteContext());
066: return contextStack;
067: }
068: };
069:
070: public static RouteContext getCurrentRouteContext() {
071: return ROUTE_CONTEXT_STACK.get().get(0);
072: }
073:
074: public static void clearCurrentRouteContext() {
075: ROUTE_CONTEXT_STACK.get().remove(0);
076: ROUTE_CONTEXT_STACK.get().add(0, new RouteContext());
077: }
078:
079: public static RouteContext createNewRouteContext() {
080: ROUTE_CONTEXT_STACK.get().add(0, new RouteContext());
081: return getCurrentRouteContext();
082: }
083:
084: public static RouteContext releaseCurrentRouteContext() {
085: return ROUTE_CONTEXT_STACK.get().remove(0);
086: }
087:
088: /**
089: * @deprecated use getDocument() instead
090: */
091: public DocumentRouteHeaderValue getRouteHeader() {
092: return routeHeader;
093: }
094:
095: /**
096: * @deprecated user setDocument() instead
097: */
098: public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
099: this .routeHeader = routeHeader;
100: }
101:
102: public DocumentRouteHeaderValue getDocument() {
103: return routeHeader;
104: }
105:
106: public void setDocument(DocumentRouteHeaderValue routeHeader) {
107: this .routeHeader = routeHeader;
108: try {
109: setDocumentContent(new StandardDocumentContent(routeHeader
110: .getDocContent(), this ));
111: } catch (Exception e) {
112: throw new WorkflowRuntimeException(e);
113: }
114: }
115:
116: public DocumentContent getDocumentContent() {
117: return documentContent;
118: }
119:
120: public void setDocumentContent(DocumentContent documentContent) {
121: this .documentContent = documentContent;
122: }
123:
124: public RouteNodeInstance getNodeInstance() {
125: return nodeInstance;
126: }
127:
128: public void setNodeInstance(RouteNodeInstance nodeInstance) {
129: this .nodeInstance = nodeInstance;
130: }
131:
132: public EngineState getEngineState() {
133: return engineState;
134: }
135:
136: public void setEngineState(EngineState engineState) {
137: this .engineState = engineState;
138: }
139:
140: public ActionRequestValue getActionRequest() {
141: return actionRequest;
142: }
143:
144: public void setActionRequest(ActionRequestValue actionRequest) {
145: this .actionRequest = actionRequest;
146: }
147:
148: public boolean isSimulation() {
149: if (activationContext == null) {
150: return false;
151: }
152: return activationContext.isSimulation();
153: }
154:
155: public ActivationContext getActivationContext() {
156: return activationContext;
157: }
158:
159: public void setActivationContext(ActivationContext activationContext) {
160: this .activationContext = activationContext;
161: }
162:
163: public boolean isDoNotSendApproveNotificationEmails() {
164: return doNotSendApproveNotificationEmails;
165: }
166:
167: public void setDoNotSendApproveNotificationEmails(
168: boolean sendNotificationEmails) {
169: this .doNotSendApproveNotificationEmails = sendNotificationEmails;
170: }
171:
172: public Map getParameters() {
173: return parameters;
174: }
175:
176: public void setParameters(Map parameters) {
177: this.parameters = parameters;
178: }
179: }
|