001: /*
002: * $Id: ProcessContext.java,v 1.22 2004/12/10 09:36:00 fornp1 Exp $
003: *
004: * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
005: * Berne University of Applied Sciences
006: * School of Engineering and Information Technology
007: * All rights reserved.
008: */
009: package bexee.core;
010:
011: import java.io.Serializable;
012: import java.util.HashMap;
013: import java.util.Map;
014: import java.util.Set;
015:
016: import bexee.event.Event;
017: import bexee.model.activity.Activity;
018: import bexee.model.elements.Variable;
019:
020: /**
021: * The ProcessContext contains state information about a very specific process
022: * instance. This includes:
023: * <ul>
024: * <li>Link states</li>
025: * <li>Global and local variable values</li>
026: * <li>Detailed event information about each processed activity. This
027: * information is vital for the <code>ProcessController</code> to be able to
028: * resume asynchronous process execution. Another optional use of this
029: * information might be a later process execution tracing (e.g. for graphical
030: * representations of an executing or finished process).</li>
031: * </ul>
032: * <p>
033: * The <code>ProcessContext</code> need to be made persistent for later
034: * retrieval of asynchronous or long-running processes.
035: *
036: * @version $Revision: 1.22 $, $Date: 2004/12/10 09:36:00 $
037: * @author Patric Fornasier
038: * @author Pawel Kowalski
039: */
040: public class ProcessContext implements Serializable {
041:
042: private Map variables;
043:
044: private Map events;
045:
046: private Object result;
047:
048: private BexeeMessage currentMessage;
049:
050: private String id;
051:
052: /**
053: * Creates a new <code>ProcessContext</code>.
054: */
055: public ProcessContext() {
056: variables = new HashMap();
057: events = new HashMap();
058: }
059:
060: /**
061: * Get the result of this process instance.
062: *
063: * @return
064: */
065: public Object getResult() {
066: return result;
067: }
068:
069: /**
070: * Provides a place to store the result of BPEL process instance that has
071: * terminated it's execution.
072: * <p>
073: * After setting the result this method will call <code>notify()</code> on
074: * itself to indicate locking threads that the result is available.
075: *
076: * @param message
077: */
078: public synchronized void setResult(Object result) {
079:
080: this .result = result;
081: this .notify();
082: }
083:
084: /**
085: * Set the current message.
086: *
087: * @param message
088: */
089: public void setMessage(BexeeMessage message) {
090: this .currentMessage = message;
091: }
092:
093: /**
094: * Get the current message.
095: *
096: * @return currentMessage
097: */
098: public BexeeMessage getMessage() {
099: return currentMessage;
100: }
101:
102: /**
103: * Stores the parts of a given <code>Variable</code>.
104: *
105: * @param variable
106: * the <code>Variable</code> that will be used as the key
107: * @param parts
108: * a <code>Map</code> containing the parts associated with the
109: * given <code>Variable</code>. The part names are used as
110: * keys in the parts <code>Map</code>.
111: */
112: public void setVariable(Variable variable, Map parts) {
113: variables.put(variable, parts);
114: }
115:
116: /**
117: * Gets the parts associated with a given <code>Variable</code>.
118: *
119: * @param variable
120: * the <code>Variable</code> that will be used as the key
121: *
122: * @return a <code>Map</code> containing the parts associated with the
123: * given <code>Variable</code>. The part names are used as keys
124: * in the returned <code>Map</code>.
125: */
126: public Map getVariable(Variable variable) {
127: return (Map) variables.get(variable);
128: }
129:
130: /**
131: * It is possible to retrieve all variable identifiers included in this
132: * context (Variable class instances).
133: *
134: * @return set a Set of <code>Variable</code> instances.
135: */
136: public Set getVariablesIdentifiers() {
137: return variables.keySet();
138: }
139:
140: /**
141: * Set a variable part identified by a <code>Variable</code> identifier
142: * and a part name.
143: *
144: * @param variable
145: * the variable identifier
146: * @param part
147: * the part name
148: * @param value
149: * part value
150: */
151: public void setVariablePart(Variable variable, String part,
152: Object value) {
153: Map parts = getVariable(variable);
154: if (parts == null) {
155: parts = new HashMap();
156: }
157: parts.put(part, value);
158: setVariable(variable, parts);
159: }
160:
161: /**
162: * Get a variable part identified by a <code>Variable</code> identifier
163: * and a part name.
164: *
165: * @param variable
166: * the variable identifier
167: * @param part
168: * the part name
169: * @return value
170: */
171: public Object getVariablePart(Variable variable, String part) {
172: Map parts = getVariable(variable);
173: return parts == null ? null : parts.get(part);
174: }
175:
176: /**
177: * Remove the current message. This method will be called in order to
178: * retrieve the current message and remove it from the
179: * <code>ProcessContext</code> at the same time.
180: *
181: * @return bexeeMessage a BexeeMessage
182: */
183: public BexeeMessage removeMessage() {
184: BexeeMessage message = currentMessage;
185: currentMessage = null;
186: return message;
187: }
188:
189: /**
190: * Add an Event to this <code>ProcessContext</code>. The
191: * <code>Event</code> s represent processed activities in bexee. It is
192: * possible to reconstruct states of the process by analyzing those
193: * <code>Event</code>s.
194: *
195: * @param event
196: */
197: public void addEvent(Event event) {
198: events.put(event.getActivity(), event);
199: }
200:
201: /**
202: * Get an <code>Event</code> for the given <code>Activity</code>.
203: *
204: * @param activity
205: * @return Event
206: */
207: public Event getEvent(Activity activity) {
208: return (Event) events.get(activity);
209: }
210:
211: /**
212: * Set the id of this <code>ProcessContext</code>.
213: *
214: * @param id
215: */
216: public void setId(String id) {
217: this .id = id;
218: }
219:
220: /**
221: * Get the id of this <code>ProcessContext</code>.
222: *
223: * @return
224: */
225: public String getId() {
226: return id;
227: }
228: }
|