001: /*--
002:
003: Copyright (C) 2002 Anthony Eden, Adrian Price.
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 process instance. The states and their
054: * descriptions are taken from WfMC Interface 2/3.
055: *
056: * @author Adrian Price
057: */
058: public final class WMProcessInstanceState extends WMObjectState {
059: private static final long serialVersionUID = 8203181961666090141L;
060:
061: /**
062: * @see #OPEN_NOTRUNNING_NOTSTARTED
063: */
064: public static final int OPEN_NOTRUNNING_NOTSTARTED_INT = 0;
065: /**
066: * @see #OPEN_NOTRUNNING_SUSPENDED
067: */
068: public static final int OPEN_NOTRUNNING_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_NOTSTARTED
088: */
089: public static final String OPEN_NOTRUNNING_NOTSTARTED_TAG = "open.notRunning.notStarted";
090: /**
091: * @see #OPEN_NOTRUNNING_SUSPENDED
092: */
093: public static final String OPEN_NOTRUNNING_SUSPENDED_TAG = "open.notRunning.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 = {
111: OPEN_NOTRUNNING_NOTSTARTED_TAG,
112: OPEN_NOTRUNNING_SUSPENDED_TAG, OPEN_RUNNING_TAG,
113: CLOSED_ABORTED_TAG, CLOSED_TERMINATED_TAG,
114: CLOSED_COMPLETED_TAG };
115:
116: /**
117: * The process instance has been created, but was not started yet.
118: */
119: public static final WMProcessInstanceState OPEN_NOTRUNNING_NOTSTARTED = new WMProcessInstanceState(
120: OPEN_NOTRUNNING_NOTSTARTED_INT);
121: /**
122: * Execution of the process instance was temporarily suspended.
123: */
124: public static final WMProcessInstanceState OPEN_NOTRUNNING_SUSPENDED = new WMProcessInstanceState(
125: OPEN_NOTRUNNING_SUSPENDED_INT);
126: /**
127: * The process instance is executing.
128: */
129: public static final WMProcessInstanceState OPEN_RUNNING = new WMProcessInstanceState(
130: OPEN_RUNNING_INT);
131: /**
132: * Enactment of the process instance has been aborted by a user. (See the
133: * specification of WMAbortProcessInstance for a definition of abortion in
134: * contrast to termination).
135: */
136: public static final WMProcessInstanceState CLOSED_ABORTED = new WMProcessInstanceState(
137: CLOSED_ABORTED_INT);
138: /**
139: * Enactment of the process instance has been terminated by a user. (See
140: * the specification of WMTerminateProcessInstance for a definition of
141: * termination in contrast to abortion).
142: */
143: public static final WMProcessInstanceState CLOSED_TERMINATED = new WMProcessInstanceState(
144: CLOSED_TERMINATED_INT);
145: /**
146: * Enactment of the process instance has completed normally. (i.e., was not
147: * forced by a user).
148: */
149: public static final WMProcessInstanceState CLOSED_COMPLETED = new WMProcessInstanceState(
150: CLOSED_COMPLETED_INT);
151: private static final WMProcessInstanceState[] VALUES = {
152: OPEN_NOTRUNNING_NOTSTARTED, OPEN_NOTRUNNING_SUSPENDED,
153: OPEN_RUNNING, CLOSED_ABORTED, CLOSED_TERMINATED,
154: CLOSED_COMPLETED };
155:
156: /**
157: * Abort the instance.
158: */
159: public static final int ABORT_ACTION = 0;
160: /**
161: * Complete the instance.
162: */
163: public static final int COMPLETE_ACTION = 1;
164: /**
165: * Create the instance.
166: */
167: public static final int CREATE_ACTION = 2;
168: /**
169: * Delete the instance.
170: */
171: public static final int DELETE_ACTION = 3;
172: /**
173: * Resume the instance.
174: */
175: public static final int RESUME_ACTION = 4;
176: /**
177: * Start the instance.
178: */
179: public static final int START_ACTION = 5;
180: /**
181: * Suspend the instance.
182: */
183: public static final int SUSPEND_ACTION = 6;
184: /**
185: * Terminate the instance.
186: */
187: public static final int TERMINATE_ACTION = 7;
188:
189: // new state = STATES[state][action]
190: private static final int[][] STATES = {
191: //ABORT, COMPLETE, CREATE, DELETE, RESUME, START, SUSPEND, TERMINATE,
192: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
193: OPEN_NOTRUNNING_NOTSTARTED_INT, ILLEGAL_ACTION,
194: OPEN_RUNNING_INT, ILLEGAL_ACTION,
195: CLOSED_TERMINATED_INT }, // NOTSTARTED
196: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
197: OPEN_NOTRUNNING_SUSPENDED_INT, OPEN_RUNNING_INT,
198: OPEN_RUNNING_INT, OPEN_NOTRUNNING_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_RUNNING_INT, OPEN_NOTRUNNING_SUSPENDED_INT,
203: CLOSED_TERMINATED_INT }, // RUNNING
204: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
205: CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
206: ILLEGAL_ACTION, ILLEGAL_ACTION },
207: // ABORTED
208: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
209: CLOSED_TERMINATED_INT, ILLEGAL_ACTION,
210: ILLEGAL_ACTION, ILLEGAL_ACTION,
211: CLOSED_TERMINATED_INT }, // TERMINATED
212: { ILLEGAL_ACTION, CLOSED_COMPLETED_INT, ILLEGAL_ACTION,
213: CLOSED_COMPLETED_INT, ILLEGAL_ACTION,
214: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION } // COMPLETED
215: };
216: // action = ACTIONS[state][newState]
217: private static final int[][] ACTIONS = {
218: // NOTSTARTED, SUSPENDED, RUNNING, ABORTED, TERMINATED, COMPLETED
219: { NO_ACTION, ILLEGAL_ACTION, START_ACTION, ABORT_ACTION,
220: TERMINATE_ACTION, ILLEGAL_ACTION }, // NOTSTARTED
221: { ILLEGAL_ACTION, NO_ACTION, RESUME_ACTION, ABORT_ACTION,
222: TERMINATE_ACTION, ILLEGAL_ACTION }, // SUSPENDED
223: { ILLEGAL_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 WMProcessInstanceState valueOf(String state) {
234: return (WMProcessInstanceState) valueOf(TAGS, VALUES, state);
235: }
236:
237: public static WMProcessInstanceState valueOf(int state) {
238: return VALUES[state];
239: }
240:
241: public static WMProcessInstanceState[] states() {
242: return (WMProcessInstanceState[]) VALUES.clone();
243: }
244:
245: private WMProcessInstanceState(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_NOTSTARTED_INT
261: || _state == OPEN_NOTRUNNING_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: }
|