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.engine;
17  
18  import java.io.Serializable;
19  import java.util.HashMap;
20  import java.util.LinkedList;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
25  import org.kuali.rice.kew.api.WorkflowRuntimeException;
26  import org.kuali.rice.kew.engine.node.RouteNodeInstance;
27  import org.kuali.rice.kew.routeheader.DocumentContent;
28  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
29  import org.kuali.rice.kew.routeheader.StandardDocumentContent;
30  
31  
32  /**
33   * Represents the current context of a Document being processed by the engine.
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public class RouteContext implements Serializable {
38  
39  	private static final long serialVersionUID = -7125137491367944594L;
40  
41  	private DocumentRouteHeaderValue routeHeader;
42  
43  	private DocumentContent documentContent;
44  
45  	private RouteNodeInstance nodeInstance;
46  
47  	private EngineState engineState;
48  
49  	private ActionRequestValue actionRequest;
50  
51  	private ActivationContext activationContext = new ActivationContext(!ActivationContext.CONTEXT_IS_SIMULATION);
52  
53  	private boolean doNotSendApproveNotificationEmails = false;
54  
55  	private Map parameters = new HashMap();
56  	
57  	private boolean searchIndexingRequestedForContext = false;
58  
59  	public RouteContext() {
60  	}
61  
62  	private static ThreadLocal<List<RouteContext>> ROUTE_CONTEXT_STACK = new ThreadLocal<List<RouteContext>>() {
63  		protected List<RouteContext> initialValue() {
64  			List<RouteContext> contextStack = new LinkedList<RouteContext>();
65  			contextStack.add(0, new RouteContext());
66  			return contextStack;
67  		}
68  	};
69  
70  	public static RouteContext getCurrentRouteContext() {
71  		return ROUTE_CONTEXT_STACK.get().get(0);
72  	}
73  
74  	public static void clearCurrentRouteContext() {
75  		ROUTE_CONTEXT_STACK.get().remove(0);
76  		ROUTE_CONTEXT_STACK.get().add(0, new RouteContext());
77  	}
78  
79  	public static RouteContext createNewRouteContext() {
80  		ROUTE_CONTEXT_STACK.get().add(0, new RouteContext());
81  		return getCurrentRouteContext();
82  	}
83  
84  	public static RouteContext releaseCurrentRouteContext() {
85  		return ROUTE_CONTEXT_STACK.get().remove(0);
86  	}
87  
88  	/**
89  	 * @deprecated use getDocument() instead
90  	 */
91  	public DocumentRouteHeaderValue getRouteHeader() {
92  		return routeHeader;
93  	}
94  
95  	/**
96  	 * @deprecated user setDocument() instead
97  	 */
98  	public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
99  		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.getDocContent(), this));
110 		} catch (Exception e) {
111 			throw new WorkflowRuntimeException(e);
112 		}
113 	}
114 
115 	public DocumentContent getDocumentContent() {
116 		return documentContent;
117 	}
118 
119 	public void setDocumentContent(DocumentContent documentContent) {
120 		this.documentContent = documentContent;
121 	}
122 
123 	public RouteNodeInstance getNodeInstance() {
124 		return nodeInstance;
125 	}
126 
127 	public void setNodeInstance(RouteNodeInstance nodeInstance) {
128 		this.nodeInstance = nodeInstance;
129 	}
130 
131 	public EngineState getEngineState() {
132 		return engineState;
133 	}
134 
135 	public void setEngineState(EngineState engineState) {
136 		this.engineState = engineState;
137 	}
138 
139 	public ActionRequestValue getActionRequest() {
140 		return actionRequest;
141 	}
142 
143 	public void setActionRequest(ActionRequestValue actionRequest) {
144 		this.actionRequest = actionRequest;
145 	}
146 
147 	public boolean isSimulation() {
148 		if (activationContext == null) {
149 			return false;
150 		}
151 		return activationContext.isSimulation();
152 	}
153 
154 	public ActivationContext getActivationContext() {
155 		return activationContext;
156 	}
157 
158 	public void setActivationContext(ActivationContext activationContext) {
159 		this.activationContext = activationContext;
160 	}
161 
162 	public boolean isDoNotSendApproveNotificationEmails() {
163 		return doNotSendApproveNotificationEmails;
164 	}
165 
166 	public void setDoNotSendApproveNotificationEmails(boolean sendNotificationEmails) {
167 		this.doNotSendApproveNotificationEmails = sendNotificationEmails;
168 	}
169 
170 	public Map getParameters() {
171 		return parameters;
172 	}
173 
174 	public void setParameters(Map parameters) {
175 		this.parameters = parameters;
176 	}
177 
178 	/**
179 	 * Determines if search indexing has already been requested during this context
180 	 * @return the searchIndexingRequestedForContext: true if search indexing has been requested, false otherwise
181 	 */
182 	public boolean isSearchIndexingRequestedForContext() {
183 		return this.searchIndexingRequestedForContext;
184 	}
185 
186 	/**
187 	 * Sets the route context to let it know that search indexing has been requested
188 	 */
189 	public void requestSearchIndexingForContext() {
190 		this.searchIndexingRequestedForContext = true;
191 	}
192 	
193 }