001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: ExtExecutionObjectLocal.java,v 1.1 2007/05/03 21:58:21 mlipp Exp $
021: *
022: * $Log: ExtExecutionObjectLocal.java,v $
023: * Revision 1.1 2007/05/03 21:58:21 mlipp
024: * Internal refactoring for making better use of local EJBs.
025: *
026: */
027: package de.danet.an.workflow.internalapi;
028:
029: import java.io.Serializable;
030:
031: import de.danet.an.workflow.localapi.ExecutionObjectLocal;
032: import de.danet.an.workflow.omgcore.InvalidPriorityException;
033: import de.danet.an.workflow.omgcore.WfAuditEvent;
034: import de.danet.an.workflow.omgcore.WfExecutionObject.NotRunningState;
035: import de.danet.an.workflow.omgcore.WfExecutionObject.OpenState;
036: import de.danet.an.workflow.omgcore.WfExecutionObject.State;
037:
038: /**
039: * This interface defines some additional methods of
040: * <code>ExecutionObject</code>s that are only available within the
041: * implementation (not part of the API).
042: *
043: * @author <a href="mailto:lipp@danet.de">Michael Lipp</a>
044: * @version $Revision: 1.1 $
045: */
046:
047: public interface ExtExecutionObjectLocal extends ExecutionObjectLocal {
048:
049: /**
050: * This class defines the sub-states of OpenState.RUNNING
051: * of a {@link de.danet.an.workflow.localcoreapi.WfExecutionObjectLocal
052: * <code>WfExecutionObject</code>}.
053: * These substates are an extention of the predefined omg states.
054: */
055: public static class RunningState extends OpenState implements
056: Serializable {
057: /**
058: * Provides a state indicating that the process is running.
059: */
060: public static final RunningState RUNNING = new RunningState(
061: "running");
062: /**
063: * Provides a state indicating that the process is about to
064: * be terminated.
065: */
066: public static final RunningState TERMINATING = new RunningState(
067: "terminating");
068: /**
069: * Provides a state indicating that an activity is
070: * abandoning.
071: */
072: public static final RunningState ABANDONING = new RunningState(
073: "abandoning");
074: /**
075: * Provides a state indicating that an activity is suspended
076: * because of a debug "breakpoint".
077: */
078: public static final RunningState DEBUG = new RunningState(
079: "debug");
080: static {
081: registerState(RUNNING);
082: registerState(TERMINATING);
083: registerState(ABANDONING);
084: registerState(DEBUG);
085: }
086:
087: /**
088: * Default constructor.
089: * @param text Textual representation of the state
090: */
091: protected RunningState(String text) {
092: super (text);
093: }
094:
095: /**
096: * Returns the parent in the state hierachy if all states
097: * defined in this class or <code>null</code>, if this states
098: * are at the top level of the hierachy.
099: * @return parent in the state hierachy
100: */
101: public State getParent() {
102: // parent is OpenState.RUNNING
103: return OpenState.RUNNING;
104: }
105:
106: /**
107: * Returns the workflow state, i.e. the great-grandparent.
108: * @return the workflow state.
109: */
110: public State workflowState() {
111: return getParent().getParent();
112: }
113:
114: /**
115: * Returns the workflow substate for open execution objects.
116: * @return the open state.
117: */
118: public State whileOpenState() {
119: return getParent();
120: }
121:
122: /**
123: * Returns the workflow substate for open, not running
124: * execution objects.
125: * @return the why not running state.
126: */
127: public State whyNotRunningState() {
128: throw new IllegalStateException();
129: }
130:
131: /**
132: * Returns the workflow substate for closed
133: * execution objects.
134: * @return the closed state.
135: */
136: public State howClosedState() {
137: throw new IllegalStateException();
138: }
139:
140: /**
141: * Perform instance substitution during serialization.
142: */
143: private Object readResolve() {
144: String repr = textRepresentation();
145: if (repr == null) {
146: throw new IllegalArgumentException(
147: "Unexpected error in deserialization");
148: }
149: if (repr.equals(RUNNING.textRepresentation())) {
150: return RUNNING;
151: }
152: if (repr.equals(TERMINATING.textRepresentation())) {
153: return TERMINATING;
154: }
155: if (repr.equals(ABANDONING.textRepresentation())) {
156: return ABANDONING;
157: }
158: if (repr.equals(DEBUG.textRepresentation())) {
159: return DEBUG;
160: }
161: throw new IllegalArgumentException(
162: "Unexpected error in serialization");
163: }
164: }
165:
166: /**
167: * This class defines the sub-states of NotRunningState.SUSPENDED
168: * of a {@link de.danet.an.workflow.localcoreapi.WfExecutionObjectLocal
169: * <code>WfExecutionObject</code>}.
170: * These substates are an extention of the predefined omg states.
171: */
172: public static class SuspendedState extends NotRunningState
173: implements Serializable {
174: /**
175: * Provides a state indicating that the process is running.
176: */
177: public static final SuspendedState SUSPENDED = new SuspendedState(
178: "suspended");
179: /**
180: * Provides a state indicating that the process is about to
181: * be aborted.
182: */
183: public static final SuspendedState ABORTING = new SuspendedState(
184: "aborting");
185: /**
186: * Provides a state indicating that the activity will be
187: * set to abandoned when resumed.
188: */
189: public static final SuspendedState ABANDONING = new SuspendedState(
190: "abandoning");
191: /**
192: * Provides a state indicating that the activity will be
193: * set to running when resumed.
194: */
195: public static final SuspendedState CLEARING_EXCEPTION = new SuspendedState(
196: "clearing_exception");
197: static {
198: registerState(SUSPENDED);
199: registerState(ABORTING);
200: registerState(ABANDONING);
201: registerState(CLEARING_EXCEPTION);
202: }
203:
204: /**
205: * Default constructor.
206: * @param text Textual representation of the state
207: */
208: protected SuspendedState(String text) {
209: super (text);
210: }
211:
212: /**
213: * Returns the parent in the state hierachy if all states
214: * defined in this class or <code>null</code>, if this states
215: * are at the top level of the hierachy.
216: * @return parent in the state hierachy
217: */
218: public State getParent() {
219: return NotRunningState.SUSPENDED;
220: }
221:
222: /**
223: * Returns the workflow state, i.e. the great-grandparent.
224: * @return the workflow state.
225: */
226: public State workflowState() {
227: return getParent().getParent().getParent();
228: }
229:
230: /**
231: * Returns the workflow substate for open execution objects.
232: * @return the open state.
233: */
234: public State whileOpenState() {
235: return getParent().getParent();
236: }
237:
238: /**
239: * Returns the workflow substate for open, not running
240: * execution objects.
241: * @return the why not running state.
242: */
243: public State whyNotRunningState() {
244: throw new IllegalStateException();
245: }
246:
247: /**
248: * Returns the workflow substate for closed
249: * execution objects.
250: * @return the closed state.
251: */
252: public State howClosedState() {
253: throw new IllegalStateException();
254: }
255:
256: /**
257: * Perform instance substitution during serialization.
258: */
259: private Object readResolve() {
260: String repr = textRepresentation();
261: if (repr == null) {
262: throw new IllegalArgumentException(
263: "Unexpected error in deserialization");
264: }
265: if (repr.equals(SUSPENDED.textRepresentation())) {
266: return SUSPENDED;
267: }
268: if (repr.equals(ABORTING.textRepresentation())) {
269: return ABORTING;
270: }
271: if (repr.equals(ABANDONING.textRepresentation())) {
272: return ABANDONING;
273: }
274: if (repr.equals(CLEARING_EXCEPTION.textRepresentation())) {
275: return CLEARING_EXCEPTION;
276: }
277: throw new IllegalArgumentException(
278: "Unexpected error in serialization");
279: }
280: }
281:
282: /**
283: * This class defines the sub-states of RunningState.DEBUG
284: * of a {@link de.danet.an.workflow.localcoreapi.WfExecutionObjectLocal
285: * <code>WfExecutionObject</code>}.
286: * These substates are an extention of the predefined omg states.
287: */
288: public static class DebugState extends RunningState implements
289: Serializable {
290: /**
291: * Provides a state indicating that the activity is about to
292: * be abandoned.
293: */
294: public static final DebugState ABANDONING = new DebugState(
295: "abandoning");
296: /**
297: * Provides a state indicating that the activity is about to
298: * be aborted.
299: */
300: public static final DebugState ABORTING = new DebugState(
301: "aborting");
302: /**
303: * Provides a state indicating that the activity is about to
304: * be completed.
305: */
306: public static final DebugState COMPLETING = new DebugState(
307: "completing");
308: /**
309: * Provides a state indicating that a tool is about to
310: * be invoked.
311: */
312: public static final DebugState INVOKING = new DebugState(
313: "invoking");
314: /**
315: * Provides a state indicating that a tool is to
316: * be skipped.
317: */
318: public static final DebugState SKIPPING = new DebugState(
319: "skipping");
320: /**
321: * Provides a state indicating that the activity is about to
322: * be terminated.
323: */
324: public static final DebugState TERMINATING = new DebugState(
325: "terminating");
326: /**
327: * Provides a state indicating that the activity expects an
328: * exception that is to be forwarded to the process.
329: */
330: public static final DebugState FORWARDING_EXCEPTION = new DebugState(
331: "forwarding_exception");
332: /**
333: * Provides a state indicating that the activity expects an
334: * exception that is to be handled as in non-debug mode.
335: */
336: public static final DebugState AWAITING_EXCEPTION = new DebugState(
337: "awaiting_exception");
338: static {
339: registerState(ABANDONING);
340: registerState(ABORTING);
341: registerState(COMPLETING);
342: registerState(INVOKING);
343: registerState(SKIPPING);
344: registerState(TERMINATING);
345: registerState(FORWARDING_EXCEPTION);
346: registerState(AWAITING_EXCEPTION);
347: }
348:
349: /**
350: * Default constructor.
351: * @param text Textual representation of the state
352: */
353: protected DebugState(String text) {
354: super (text);
355: }
356:
357: /**
358: * Returns the parent in the state hierachy if all states
359: * defined in this class or <code>null</code>, if this states
360: * are at the top level of the hierachy.
361: * @return parent in the state hierachy
362: */
363: public State getParent() {
364: return RunningState.DEBUG;
365: }
366:
367: /**
368: * Returns the workflow state, i.e. the great-grandparent.
369: * @return the workflow state.
370: */
371: public State workflowState() {
372: return getParent().getParent().getParent();
373: }
374:
375: /**
376: * Returns the workflow substate for open execution objects.
377: * @return the open state.
378: */
379: public State whileOpenState() {
380: return getParent().getParent();
381: }
382:
383: /**
384: * Returns the workflow substate for open, not running
385: * execution objects.
386: * @return the why not running state.
387: */
388: public State whyNotRunningState() {
389: return getParent().whyNotRunningState();
390: }
391:
392: /**
393: * Returns the workflow substate for closed
394: * execution objects.
395: * @return the closed state.
396: */
397: public State howClosedState() {
398: throw new IllegalStateException();
399: }
400:
401: /**
402: * Perform instance substitution during serialization.
403: */
404: private Object readResolve() {
405: String repr = textRepresentation();
406: if (repr == null) {
407: throw new IllegalArgumentException(
408: "Unexpected error in deserialization");
409: }
410: if (repr.equals(ABANDONING.textRepresentation())) {
411: return ABANDONING;
412: }
413: if (repr.equals(ABORTING.textRepresentation())) {
414: return ABORTING;
415: }
416: if (repr.equals(COMPLETING.textRepresentation())) {
417: return COMPLETING;
418: }
419: if (repr.equals(INVOKING.textRepresentation())) {
420: return INVOKING;
421: }
422: if (repr.equals(SKIPPING.textRepresentation())) {
423: return SKIPPING;
424: }
425: if (repr.equals(TERMINATING.textRepresentation())) {
426: return TERMINATING;
427: }
428: if (repr.equals(FORWARDING_EXCEPTION.textRepresentation())) {
429: return FORWARDING_EXCEPTION;
430: }
431: if (repr.equals(AWAITING_EXCEPTION.textRepresentation())) {
432: return AWAITING_EXCEPTION;
433: }
434: throw new IllegalArgumentException(
435: "Unexpected error in serialization");
436: }
437: }
438:
439: /**
440: * Defines a class for representing priorities in a type save way.
441: */
442: public static final class Priority implements Serializable {
443: // Low priority
444: /** The lowest priority. */
445: public static final Priority LOWEST = new Priority(5);
446: /** The low priority. */
447: public static final Priority LOW = new Priority(4);
448: // Normal priority
449: /** The normal priority. */
450: public static final Priority NORMAL = new Priority(3);
451: // High priority
452: /** The high priority. */
453: public static final Priority HIGH = new Priority(2);
454: /** The highest priority. */
455: public static final Priority HIGHEST = new Priority(1);
456: private static final Priority[] MAP = { HIGHEST, HIGH, NORMAL,
457: LOW, LOWEST };
458: // priority degree
459: private int priority = 0;
460:
461: /**
462: * Default constructor.
463: * @param i int value
464: */
465: private Priority(int i) {
466: priority = i;
467: }
468:
469: /**
470: * Convert to integer.
471: * @return the priority as integer.
472: */
473: public int toInt() {
474: return priority;
475: }
476:
477: /**
478: * Restore from integer.
479: * @param prio the priority as integer.
480: * @return the corresponding priority.
481: * @throws InvalidPriorityException if <code>prio</code> is invalid.
482: */
483: public static Priority fromInt(int prio)
484: throws InvalidPriorityException {
485: try {
486: return MAP[prio - 1];
487: } catch (IndexOutOfBoundsException ex) {
488: throw new InvalidPriorityException(
489: "No valid priority: " + prio);
490: }
491: }
492:
493: /**
494: * Perform instance substitution during serialization.
495: */
496: private Object readResolve() {
497: try {
498: return MAP[priority - 1];
499: } catch (IndexOutOfBoundsException ex) {
500: throw new IllegalArgumentException(
501: "Unexpected error in serialization");
502: }
503: }
504: }
505:
506: /**
507: * Handles the given audit event.
508: * @param event the event.
509: */
510: void handleAuditEvent(WfAuditEvent event);
511:
512: }
|