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 an activity instance. The states and their
054: * descriptions are taken from WfMC Interface 2/3.
055: *
056: * @author Adrian Price
057: */
058: public final class WMActivityInstanceState extends WMObjectState {
059: private static final long serialVersionUID = 4045832288521538819L;
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: * Execution of the activity instance has not started yet.
116: */
117: public static final WMActivityInstanceState OPEN_NOTRUNNING = new WMActivityInstanceState(
118: OPEN_NOTRUNNING_INT);
119: /**
120: * Execution of the activity instance was temporarily suspended.
121: */
122: public static final WMActivityInstanceState OPEN_SUSPENDED = new WMActivityInstanceState(
123: OPEN_SUSPENDED_INT);
124: /**
125: * The activity instance is executing.
126: */
127: public static final WMActivityInstanceState OPEN_RUNNING = new WMActivityInstanceState(
128: OPEN_RUNNING_INT);
129: /**
130: * Enactment of the activity instance 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 WMActivityInstanceState CLOSED_ABORTED = new WMActivityInstanceState(
136: CLOSED_ABORTED_INT);
137: /**
138: * Enactment of the activity instance 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 WMActivityInstanceState CLOSED_TERMINATED = new WMActivityInstanceState(
144: CLOSED_TERMINATED_INT);
145: /**
146: * Enactment of the activity instance 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 WMActivityInstanceState CLOSED_COMPLETED = new WMActivityInstanceState(
150: CLOSED_COMPLETED_INT);
151: private static final WMActivityInstanceState[] VALUES = {
152: OPEN_NOTRUNNING, OPEN_SUSPENDED, OPEN_RUNNING,
153: CLOSED_ABORTED, CLOSED_TERMINATED, CLOSED_COMPLETED };
154:
155: /**
156: * Abort the instance.
157: */
158: public static final int ABORT_ACTION = 0;
159: /**
160: * Complete the instance.
161: */
162: public static final int COMPLETE_ACTION = 1;
163: /**
164: * Create the instance.
165: */
166: public static final int CREATE_ACTION = 2;
167: /**
168: * Resume the instance.
169: */
170: public static final int RESUME_ACTION = 3;
171: /**
172: * Start the instance.
173: */
174: public static final int START_ACTION = 4;
175: /**
176: * Stop the instance.
177: */
178: public static final int STOP_ACTION = 5;
179: /**
180: * Suspend the instance.
181: */
182: public static final int SUSPEND_ACTION = 6;
183: /**
184: * Terminate the instance.
185: */
186: public static final int TERMINATE_ACTION = 7;
187:
188: // The following state transitions apply to ActivityInstance and WorkItem
189: // new state = STATES[state][action]
190: private static final int[][] STATES = {
191: //ABORT, COMPLETE CREATE, RESUME, START, STOP, SUSPEND, TERMINATE,
192: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
193: ILLEGAL_ACTION, OPEN_RUNNING_INT,
194: OPEN_NOTRUNNING_INT, OPEN_SUSPENDED_INT,
195: CLOSED_TERMINATED_INT }, // NOTRUNNING
196: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
197: OPEN_RUNNING_INT, OPEN_RUNNING_INT,
198: OPEN_NOTRUNNING_INT, OPEN_SUSPENDED_INT,
199: CLOSED_TERMINATED_INT }, // SUSPENDED
200: { CLOSED_ABORTED_INT, CLOSED_COMPLETED_INT, ILLEGAL_ACTION,
201: OPEN_RUNNING_INT, OPEN_RUNNING_INT,
202: OPEN_NOTRUNNING_INT, OPEN_SUSPENDED_INT,
203: CLOSED_TERMINATED_INT }, // RUNNING
204: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
205: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
206: ILLEGAL_ACTION, ILLEGAL_ACTION },
207: // ABORTED
208: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
209: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
210: ILLEGAL_ACTION, CLOSED_TERMINATED_INT }, // TERMINATED
211: { ILLEGAL_ACTION, CLOSED_COMPLETED_INT, ILLEGAL_ACTION,
212: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
213: ILLEGAL_ACTION, ILLEGAL_ACTION }
214: // COMPLETED
215: };
216: // action = ACTIONS[state][newState]
217: private static final int[][] ACTIONS = {
218: // NOTRUNNING, SUSPENDED, RUNNING, ABORTED, TERMINATED, COMPLETED
219: { NO_ACTION, SUSPEND_ACTION, START_ACTION, ABORT_ACTION,
220: TERMINATE_ACTION, ILLEGAL_ACTION }, // NOTRUNNING
221: { STOP_ACTION, NO_ACTION, RESUME_ACTION, ABORT_ACTION,
222: TERMINATE_ACTION, ILLEGAL_ACTION }, // SUSPENDED
223: { STOP_ACTION, SUSPEND_ACTION, NO_ACTION, ABORT_ACTION,
224: TERMINATE_ACTION, COMPLETE_ACTION }, // RUNNING
225: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
226: NO_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION }, // ABORTED
227: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
228: ILLEGAL_ACTION, NO_ACTION, ILLEGAL_ACTION }, // TERMINATED
229: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
230: ILLEGAL_ACTION, ILLEGAL_ACTION, NO_ACTION } // COMPLETED
231: };
232:
233: public static WMActivityInstanceState valueOf(String state) {
234: return (WMActivityInstanceState) valueOf(TAGS, VALUES, state);
235: }
236:
237: public static WMActivityInstanceState valueOf(int state) {
238: return VALUES[state];
239: }
240:
241: public static WMActivityInstanceState[] states() {
242: return (WMActivityInstanceState[]) VALUES.clone();
243: }
244:
245: private WMActivityInstanceState(int state) {
246: super (state);
247: }
248:
249: public boolean isClosed() {
250: return _state == CLOSED_ABORTED_INT
251: || _state == CLOSED_TERMINATED_INT
252: || _state == CLOSED_COMPLETED_INT;
253: }
254:
255: public static boolean isClosed(int state) {
256: return valueOf(state).isClosed();
257: }
258:
259: public boolean isOpen() {
260: return _state == OPEN_NOTRUNNING_INT
261: || _state == OPEN_SUSPENDED_INT
262: || _state == OPEN_RUNNING_INT;
263: }
264:
265: public static boolean isOpen(int state) {
266: return valueOf(state).isOpen();
267: }
268:
269: protected String[] getTags() {
270: return TAGS;
271: }
272:
273: protected WMObjectState[] getValues() {
274: return VALUES;
275: }
276:
277: protected int[] getStatesByAction() {
278: return STATES[_state];
279: }
280:
281: protected int[] getActionsByState() {
282: return ACTIONS[_state];
283: }
284: }
|