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.enhydra.shark.api.client.wfmc.wapi;
051:
052: import org.enhydra.shark.api.common.SharkConstants;
053:
054: /**
055: * Describes the supported states of a process instance. The states and their
056: * descriptions are taken from WfMC Interface 2/3.
057: * @author Adrian Price
058: */
059: public final class WMProcessInstanceState extends WMObjectState {
060: static final long serialVersionUID = 8203181961666090141L;
061:
062: /** @see #OPEN_NOTRUNNING_NOTSTARTED */
063: public static final int OPEN_NOTRUNNING_NOTSTARTED_INT = 0;
064: /** @see #OPEN_NOTRUNNING_SUSPENDED */
065: public static final int OPEN_NOTRUNNING_SUSPENDED_INT = 1;
066: /** @see #OPEN_RUNNING */
067: public static final int OPEN_RUNNING_INT = 2;
068: /** @see #CLOSED_ABORTED */
069: public static final int CLOSED_ABORTED_INT = 3;
070: /** @see #CLOSED_TERMINATED */
071: public static final int CLOSED_TERMINATED_INT = 4;
072: /** @see #CLOSED_COMPLETED */
073: public static final int CLOSED_COMPLETED_INT = 5;
074:
075: /** @see #OPEN_NOTRUNNING_NOTSTARTED */
076: public static final String OPEN_NOTRUNNING_NOTSTARTED_TAG = SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED;
077: // "open.notRunning.notStarted";
078: /** @see #OPEN_NOTRUNNING_SUSPENDED */
079: public static final String OPEN_NOTRUNNING_SUSPENDED_TAG = SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED;
080: // "open.notRunning.suspended";
081: /** @see #OPEN_RUNNING */
082: public static final String OPEN_RUNNING_TAG = SharkConstants.STATE_OPEN_RUNNING; // "open.running";
083: /** @see #CLOSED_ABORTED */
084: public static final String CLOSED_ABORTED_TAG = SharkConstants.STATE_CLOSED_ABORTED; // "closed.aborted";
085: /** @see #CLOSED_TERMINATED */
086: public static final String CLOSED_TERMINATED_TAG = SharkConstants.STATE_CLOSED_TERMINATED; // "closed.terminated";
087: /** @see #CLOSED_COMPLETED */
088: public static final String CLOSED_COMPLETED_TAG = SharkConstants.STATE_CLOSED_COMPLETED; // "closed.completed";
089: private static final String[] TAGS = {
090: OPEN_NOTRUNNING_NOTSTARTED_TAG,
091: OPEN_NOTRUNNING_SUSPENDED_TAG, OPEN_RUNNING_TAG,
092: CLOSED_ABORTED_TAG, CLOSED_TERMINATED_TAG,
093: CLOSED_COMPLETED_TAG };
094:
095: /** The process instance has been created, but was not started yet. */
096: public static final WMProcessInstanceState OPEN_NOTRUNNING_NOTSTARTED = new WMProcessInstanceState(
097: OPEN_NOTRUNNING_NOTSTARTED_INT);
098: /** Execution of the process instance was temporarily suspended. */
099: public static final WMProcessInstanceState OPEN_NOTRUNNING_SUSPENDED = new WMProcessInstanceState(
100: OPEN_NOTRUNNING_SUSPENDED_INT);
101: /** The process instance is executing. */
102: public static final WMProcessInstanceState OPEN_RUNNING = new WMProcessInstanceState(
103: OPEN_RUNNING_INT);
104: /**
105: * Enactment of the process instance has been aborted by a user. (See the
106: * specification of WMAbortProcessInstance for a definition of abortion in
107: * contrast to termination).
108: */
109: public static final WMProcessInstanceState CLOSED_ABORTED = new WMProcessInstanceState(
110: CLOSED_ABORTED_INT);
111: /**
112: * Enactment of the process instance has been terminated by a user. (See
113: * the specification of WMTerminateProcessInstance for a definition of
114: * termination in contrast to abortion).
115: */
116: public static final WMProcessInstanceState CLOSED_TERMINATED = new WMProcessInstanceState(
117: CLOSED_TERMINATED_INT);
118: /**
119: * Enactment of the process instance has completed normally. (i.e., was not
120: * forced by a user).
121: */
122: public static final WMProcessInstanceState CLOSED_COMPLETED = new WMProcessInstanceState(
123: CLOSED_COMPLETED_INT);
124: private static final WMProcessInstanceState[] VALUES = {
125: OPEN_NOTRUNNING_NOTSTARTED, OPEN_NOTRUNNING_SUSPENDED,
126: OPEN_RUNNING, CLOSED_ABORTED, CLOSED_TERMINATED,
127: CLOSED_COMPLETED };
128:
129: /** Abort the instance. */
130: public static final int ABORT_ACTION = 0;
131: /** Complete the instance. */
132: public static final int COMPLETE_ACTION = 1;
133: /** Create the instance. */
134: public static final int CREATE_ACTION = 2;
135: /** Delete the instance. */
136: public static final int DELETE_ACTION = 3;
137: /** Resume the instance. */
138: public static final int RESUME_ACTION = 4;
139: /** Start the instance. */
140: public static final int START_ACTION = 5;
141: /** Suspend the instance. */
142: public static final int SUSPEND_ACTION = 6;
143: /** Terminate the instance. */
144: public static final int TERMINATE_ACTION = 7;
145:
146: // new state = STATES[state][action]
147: private static final int[][] STATES = {
148: //ABORT, COMPLETE, CREATE, DELETE, RESUME, START, SUSPEND, TERMINATE,
149: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
150: OPEN_NOTRUNNING_NOTSTARTED_INT, ILLEGAL_ACTION,
151: OPEN_RUNNING_INT, ILLEGAL_ACTION,
152: CLOSED_TERMINATED_INT }, // NOTSTARTED
153: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
154: OPEN_NOTRUNNING_SUSPENDED_INT, OPEN_RUNNING_INT,
155: OPEN_RUNNING_INT, OPEN_NOTRUNNING_SUSPENDED_INT,
156: CLOSED_TERMINATED_INT }, // SUSPENDED
157: { CLOSED_ABORTED_INT, CLOSED_COMPLETED_INT, ILLEGAL_ACTION,
158: OPEN_RUNNING_INT, OPEN_RUNNING_INT,
159: OPEN_RUNNING_INT, OPEN_NOTRUNNING_SUSPENDED_INT,
160: CLOSED_TERMINATED_INT }, // RUNNING
161: { CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
162: CLOSED_ABORTED_INT, ILLEGAL_ACTION, ILLEGAL_ACTION,
163: ILLEGAL_ACTION, ILLEGAL_ACTION }, // ABORTED
164: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
165: CLOSED_TERMINATED_INT, ILLEGAL_ACTION,
166: ILLEGAL_ACTION, ILLEGAL_ACTION,
167: CLOSED_TERMINATED_INT }, // TERMINATED
168: { ILLEGAL_ACTION, CLOSED_COMPLETED_INT, ILLEGAL_ACTION,
169: CLOSED_COMPLETED_INT, ILLEGAL_ACTION,
170: ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION } // COMPLETED
171: };
172: // action = ACTIONS[state][newState]
173: private static final int[][] ACTIONS = {
174: // NOTSTARTED, SUSPENDED, RUNNING, ABORTED, TERMINATED, COMPLETED
175: { NO_ACTION, ILLEGAL_ACTION, START_ACTION, ABORT_ACTION,
176: TERMINATE_ACTION, ILLEGAL_ACTION }, // NOTSTARTED
177: { ILLEGAL_ACTION, NO_ACTION, RESUME_ACTION, ABORT_ACTION,
178: TERMINATE_ACTION, ILLEGAL_ACTION }, // SUSPENDED
179: { ILLEGAL_ACTION, SUSPEND_ACTION, NO_ACTION, ABORT_ACTION,
180: TERMINATE_ACTION, COMPLETE_ACTION }, // RUNNING
181: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
182: NO_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION }, // ABORTED
183: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
184: ILLEGAL_ACTION, NO_ACTION, ILLEGAL_ACTION }, // TERMINATED
185: { ILLEGAL_ACTION, ILLEGAL_ACTION, ILLEGAL_ACTION,
186: ILLEGAL_ACTION, ILLEGAL_ACTION, NO_ACTION } // COMPLETED
187: };
188:
189: public static WMProcessInstanceState valueOf(String state) {
190: return (WMProcessInstanceState) valueOf(TAGS, VALUES, state);
191: }
192:
193: public static WMProcessInstanceState valueOf(int state) {
194: return VALUES[state];
195: }
196:
197: public static WMProcessInstanceState[] states() {
198: return (WMProcessInstanceState[]) VALUES.clone();
199: }
200:
201: private WMProcessInstanceState(int state) {
202: super (state);
203: }
204:
205: public boolean isClosed() {
206: return _state == CLOSED_ABORTED_INT
207: || _state == CLOSED_TERMINATED_INT
208: || _state == CLOSED_COMPLETED_INT;
209: }
210:
211: public static boolean isClosed(int state) {
212: return valueOf(state).isClosed();
213: }
214:
215: public boolean isOpen() {
216: return _state == OPEN_NOTRUNNING_NOTSTARTED_INT
217: || _state == OPEN_NOTRUNNING_SUSPENDED_INT
218: || _state == OPEN_RUNNING_INT;
219: }
220:
221: public static boolean isOpen(int state) {
222: return valueOf(state).isOpen();
223: }
224:
225: protected String[] getTags() {
226: return TAGS;
227: }
228:
229: protected WMObjectState[] getValues() {
230: return VALUES;
231: }
232:
233: protected int[] getStatesByAction() {
234: return STATES[_state];
235: }
236:
237: protected int[] getActionsByState() {
238: return ACTIONS[_state];
239: }
240:
241: public WMProcessInstanceState() {
242: }
243: }
|