View Javadoc

1   /**
2    * Copyright 2005-2013 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.core.framework.util.ApplicationThreadLocal;
25  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
26  import org.kuali.rice.kew.api.WorkflowRuntimeException;
27  import org.kuali.rice.kew.engine.node.RouteNodeInstance;
28  import org.kuali.rice.kew.routeheader.DocumentContent;
29  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
30  import org.kuali.rice.kew.routeheader.StandardDocumentContent;
31  
32  
33  /**
34   * Represents the current context of a Document being processed by the engine.
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class RouteContext implements Serializable {
39  
40  	private static final long serialVersionUID = -7125137491367944594L;
41  
42  	private DocumentRouteHeaderValue routeHeader;
43  
44  	private DocumentContent documentContent;
45  
46  	private RouteNodeInstance nodeInstance;
47  
48  	private EngineState engineState;
49  
50  	private ActionRequestValue actionRequest;
51  
52  	private ActivationContext activationContext = new ActivationContext(!ActivationContext.CONTEXT_IS_SIMULATION);
53  
54  	private boolean doNotSendApproveNotificationEmails = false;
55  
56  	private Map parameters = new HashMap();
57  	
58  	private boolean searchIndexingRequestedForContext = false;
59  
60  	public RouteContext() {
61  	}
62  
63  	private static ThreadLocal<List<RouteContext>> ROUTE_CONTEXT_STACK = new ApplicationThreadLocal<List<RouteContext>>() {
64  		protected List<RouteContext> initialValue() {
65  			List<RouteContext> contextStack = new LinkedList<RouteContext>();
66  			contextStack.add(0, new RouteContext());
67  			return contextStack;
68  		}
69  	};
70  
71  	public static RouteContext getCurrentRouteContext() {
72  		return ROUTE_CONTEXT_STACK.get().get(0);
73  	}
74  
75  	public static void clearCurrentRouteContext() {
76  		ROUTE_CONTEXT_STACK.get().remove(0);
77  		ROUTE_CONTEXT_STACK.get().add(0, new RouteContext());
78  	}
79  
80  	public static RouteContext createNewRouteContext() {
81  		ROUTE_CONTEXT_STACK.get().add(0, new RouteContext());
82  		return getCurrentRouteContext();
83  	}
84  
85  	public static RouteContext releaseCurrentRouteContext() {
86  		return ROUTE_CONTEXT_STACK.get().remove(0);
87  	}
88  
89  	/**
90  	 * @deprecated use getDocument() instead
91  	 */
92  	public DocumentRouteHeaderValue getRouteHeader() {
93  		return routeHeader;
94  	}
95  
96  	/**
97  	 * @deprecated user setDocument() instead
98  	 */
99  	public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
100 		this.routeHeader = routeHeader;
101 	}
102 
103 	public DocumentRouteHeaderValue getDocument() {
104 		return routeHeader;
105 	}
106 
107 	public void setDocument(DocumentRouteHeaderValue routeHeader) {
108 		this.routeHeader = routeHeader;
109 		try {
110 			setDocumentContent(new StandardDocumentContent(routeHeader.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(boolean sendNotificationEmails) {
168 		this.doNotSendApproveNotificationEmails = sendNotificationEmails;
169 	}
170 
171 	public Map getParameters() {
172 		return parameters;
173 	}
174 
175 	public void setParameters(Map parameters) {
176 		this.parameters = parameters;
177 	}
178 
179 	/**
180 	 * Determines if search indexing has already been requested during this context
181 	 * @return the searchIndexingRequestedForContext: true if search indexing has been requested, false otherwise
182 	 */
183 	public boolean isSearchIndexingRequestedForContext() {
184 		return this.searchIndexingRequestedForContext;
185 	}
186 
187 	/**
188 	 * Sets the route context to let it know that search indexing has been requested
189 	 */
190 	public void requestSearchIndexingForContext() {
191 		this.searchIndexingRequestedForContext = true;
192 	}
193 	
194 }