001: /*--
002:
003: Copyright (C) 2002 Anthony Eden.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: me@anthonyeden.com.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Anthony Eden (me@anthonyeden.com).
027:
028: In addition, I request (but do not require) that you include in the
029: end-user documentation provided with the redistribution and/or in the
030: software itself an acknowledgement equivalent to the following:
031: "This product includes software developed by
032: Anthony Eden (http://www.anthonyeden.com/)."
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
039: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
040: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
041: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
042: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
043: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
044: POSSIBILITY OF SUCH DAMAGE.
045:
046: For more information on OBE, please see <http://obe.sourceforge.net/>.
047:
048: */
049:
050: package org.wfmc.wapi;
051:
052: /**
053: * Describes the supported states of a work item. The states and their
054: * descriptions are taken from WfMC Interface 2/3.
055: *
056: * @author Adrian Price
057: */
058: public final class WMWorkItemState extends WMObjectState {
059: private static final long serialVersionUID = -8204940949573113926L;
060:
061: /**
062: * @see #OPEN_NOTRUNNING
063: */
064: public static final int OPEN_NOTRUNNING_INT = 0;
065: /**
066: * @see #OPEN_SUSPENDED
067: */
068: public static final int OPEN_SUSPENDED_INT = 1;
069: /**
070: * @see #OPEN_RUNNING
071: */
072: public static final int OPEN_RUNNING_INT = 2;
073: /**
074: * @see #CLOSED_ABORTED
075: */
076: public static final int CLOSED_ABORTED_INT = 3;
077: /**
078: * @see #CLOSED_TERMINATED
079: */
080: public static final int CLOSED_TERMINATED_INT = 4;
081: /**
082: * @see #CLOSED_COMPLETED
083: */
084: public static final int CLOSED_COMPLETED_INT = 5;
085:
086: /**
087: * @see #OPEN_NOTRUNNING
088: */
089: public static final String OPEN_NOTRUNNING_TAG = "open.notRunning";
090: /**
091: * @see #OPEN_SUSPENDED
092: */
093: public static final String OPEN_SUSPENDED_TAG = "open.suspended";
094: /**
095: * @see #OPEN_RUNNING
096: */
097: public static final String OPEN_RUNNING_TAG = "open.running";
098: /**
099: * @see #CLOSED_ABORTED
100: */
101: public static final String CLOSED_ABORTED_TAG = "closed.aborted";
102: /**
103: * @see #CLOSED_TERMINATED
104: */
105: public static final String CLOSED_TERMINATED_TAG = "closed.terminated";
106: /**
107: * @see #CLOSED_COMPLETED
108: */
109: public static final String CLOSED_COMPLETED_TAG = "closed.completed";
110: private static final String[] TAGS = { OPEN_NOTRUNNING_TAG,
111: OPEN_SUSPENDED_TAG, OPEN_RUNNING_TAG, CLOSED_ABORTED_TAG,
112: CLOSED_TERMINATED_TAG, CLOSED_COMPLETED_TAG };
113:
114: /**
115: * The work item is ready, but has not been started yet.
116: */
117: public static final WMWorkItemState OPEN_NOTRUNNING = new WMWorkItemState(
118: OPEN_NOTRUNNING_INT);
119: /**
120: * Execution of the work item was temporarily suspended.
121: */
122: public static final WMWorkItemState OPEN_SUSPENDED = new WMWorkItemState(
123: OPEN_SUSPENDED_INT);
124: /**
125: * The work item is executing.
126: */
127: public static final WMWorkItemState OPEN_RUNNING = new WMWorkItemState(
128: OPEN_RUNNING_INT);
129: /**
130: * Enactment of the work item has been aborted, probably due to
131: * abortion of the owning process instance. (See the specification of
132: * WMAbortProcessInstance for a definition of abortion in contrast to
133: * termination).
134: */
135: public static final WMWorkItemState CLOSED_ABORTED = new WMWorkItemState(
136: CLOSED_ABORTED_INT);
137: /**
138: * Enactment of the work item has been terminated , probably due to
139: * termination of the owning process instance (see the specification of
140: * WMTerminateProcessInstance for a definition of termination in contrast
141: * to abortion).
142: */
143: public static final WMWorkItemState CLOSED_TERMINATED = new WMWorkItemState(
144: CLOSED_TERMINATED_INT);
145: /**
146: * Enactment of the work item has completed normally. (i.e., was not
147: * forced by a user or by a state change of its owning process instance).
148: */
149: public static final WMWorkItemState CLOSED_COMPLETED = new WMWorkItemState(
150: CLOSED_COMPLETED_INT);
151: private static final WMWorkItemState[] VALUES = { OPEN_NOTRUNNING,
152: OPEN_SUSPENDED, OPEN_RUNNING, CLOSED_ABORTED,
153: CLOSED_TERMINATED, CLOSED_COMPLETED };
154:
155: /**
156: * Abort the work item.
157: */
158: public static final int ABORT_ACTION = 0;
159: /**
160: * Assign the work item.
161: */
162: public static final int ASSIGN_ACTION = 1;
163: /**
164: * Complete the work item.
165: */
166: public static final int COMPLETE_ACTION = 2;
167: /**
168: * Create the work item.
169: */
170: public static final int CREATE_ACTION = 3;
171: /**
172: * Resume the work item.
173: */
174: public static final int RESUME_ACTION = 4;
175: /**
176: * Start the work item.
177: */
178: public static final int START_ACTION = 5;
179: /**
180: * Stop the work item.
181: */
182: public static final int STOP_ACTION = 6;
183: /**
184: * Suspend the work item.
185: */
186: public static final int SUSPEND_ACTION = 7;
187: /**
188: * Terminate the work item.
189: */
190: public static final int TERMINATE_ACTION = 8;
191:
192: // The following state transitions apply to ActivityInstance and WorkItem
193: // new state = STATES[state][action]
194: private static final int[][] STATES = {
195: //ABORT, ASSIGN, COMPLETE CREATE, RESUME, START, STOP, SUSPEND, TERMINATE,
196: { CLOSED_ABORTED_INT, OPEN_NOTRUNNING_INT, ILLEGAL_ACTION,
197: ILLEGAL_ACTION, ILLEGAL_ACTION, OPEN_RUNNING_INT,
198: OPEN_NOTRUNNING_INT, OPEN_SUSPENDED_INT,
199: CLOSED_TERMINATED_INT },
200: // NOTRUNNING
201: { CLOSED_ABORTED_INT, OPEN_SUSPENDED_INT, ILLEGAL_ACTION,
202: ILLEGAL_ACTION, OPEN_RUNNING_INT, OPEN_RUNNING_INT,
203: OPEN_NOTRUNNING_INT, OPEN_SUSPENDED_INT,
204: CLOSED_TERMINATED_INT }, // SUSPENDED
205: { CLOSED_ABORTED_INT, OPEN_RUNNING_INT,
206: CLOSED_COMPLETED_INT, ILLEGAL_ACTION,
207: OPEN_RUNNING_INT, OPEN_RUNNING_INT,
208: OPEN_NOTRUNNING_INT, OPEN_SUSPENDED_INT,
209: CLOSED_TERMINATED_INT },
210: // RUNNING
211: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
212: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
213: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION }, // ABORTED
214: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
215: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
216: ILLEGAL_ACTION, ILLEGAL_ACTION,
217: CLOSED_TERMINATED_INT }, // TERMINATED
218: { ILLEGAL_ACTION, ILLEGAL_ACTION, CLOSED_COMPLETED_INT,
219: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
220: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION } // COMPLETED
221: };
222: // action = ACTIONS[state][newState]
223: private static final int[][] ACTIONS = {
224: // NOTRUNNING, SUSPENDED, RUNNING, ABORTED, TERMINATED, COMPLETED
225: { NO_ACTION, SUSPEND_ACTION, START_ACTION, ABORT_ACTION,
226: TERMINATE_ACTION, ILLEGAL_ACTION }, // NOTRUNNING
227: { STOP_ACTION, NO_ACTION, RESUME_ACTION, ABORT_ACTION,
228: TERMINATE_ACTION, ILLEGAL_ACTION }, // SUSPENDED
229: { STOP_ACTION, SUSPEND_ACTION, NO_ACTION, ABORT_ACTION,
230: TERMINATE_ACTION, COMPLETE_ACTION }, // RUNNING
231: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
232: NO_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION }, // ABORTED
233: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
234: ILLEGAL_ACTION, NO_ACTION, ILLEGAL_ACTION }, // TERMINATED
235: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
236: ILLEGAL_ACTION, ILLEGAL_ACTION, NO_ACTION } // COMPLETED
237: };
238:
239: // N.B. Although the tags, actions and state transitions for this class are
240: // identical to those of WMActivityInstance, WMWorkItem cannot be a subclass
241: // of WMActivityInstance because the static valueOf(String) and
242: // valueOf(int) methods have different signatures. The compiler does not
243: // permit static methods to be overridden in this way.
244:
245: public static WMWorkItemState valueOf(String state) {
246: return (WMWorkItemState) valueOf(TAGS, VALUES, state);
247: }
248:
249: public static WMWorkItemState valueOf(int state) {
250: return VALUES[state];
251: }
252:
253: public static WMWorkItemState[] states() {
254: return (WMWorkItemState[]) VALUES.clone();
255: }
256:
257: private WMWorkItemState(int state) {
258: super (state);
259: }
260:
261: public boolean isClosed() {
262: return _state == CLOSED_ABORTED_INT
263: || _state == CLOSED_TERMINATED_INT
264: || _state == CLOSED_COMPLETED_INT;
265: }
266:
267: public static boolean isClosed(int state) {
268: return valueOf(state).isClosed();
269: }
270:
271: public boolean isOpen() {
272: return _state == OPEN_NOTRUNNING_INT
273: || _state == OPEN_SUSPENDED_INT
274: || _state == OPEN_RUNNING_INT;
275: }
276:
277: public static boolean isOpen(int state) {
278: return valueOf(state).isOpen();
279: }
280:
281: protected String[] getTags() {
282: return TAGS;
283: }
284:
285: protected WMObjectState[] getValues() {
286: return VALUES;
287: }
288:
289: protected int[] getStatesByAction() {
290: return STATES[_state];
291: }
292:
293: protected int[] getActionsByState() {
294: return ACTIONS[_state];
295: }
296: }
|