001: /*--
002:
003: Copyright (C) 2002-2005 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: adrianprice@sourceforge.net.
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: Adrian Price (adrianprice@users.sourceforge.net).
027:
028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038: POSSIBILITY OF SUCH DAMAGE.
039:
040: For more information on OBE, please see
041: <http://obe.sourceforge.net/>.
042:
043: */
044:
045: package org.obe.spi.event;
046:
047: import org.obe.OBERuntimeException;
048: import org.obe.client.api.repository.RepositoryException;
049: import org.obe.spi.model.ProcessInstance;
050: import org.obe.spi.service.ProcessRepository;
051: import org.obe.spi.service.WorkflowEventBroker;
052: import org.obe.xpdl.model.workflow.WorkflowProcess;
053: import org.wfmc.audit.WMAEventCode;
054: import org.wfmc.wapi.WMProcessInstanceState;
055:
056: /**
057: * Delivers process instance event notifications.
058: *
059: * @author Adrian Price
060: * @see ProcessInstanceListener
061: */
062: public final class ProcessInstanceEvent extends WorkflowEvent {
063: private static final long serialVersionUID = -5575325141776012183L;
064: /**
065: * The process instance was aborted.
066: */
067: public static final int ABORTED = WMProcessInstanceState.ABORT_ACTION;
068: /**
069: * The process instance was completed.
070: */
071: public static final int COMPLETED = WMProcessInstanceState.COMPLETE_ACTION;
072: /**
073: * The process instance was created.
074: */
075: public static final int CREATED = WMProcessInstanceState.CREATE_ACTION;
076: /**
077: * The process instance was deleted.
078: */
079: public static final int DELETED = WMProcessInstanceState.DELETE_ACTION;
080: /**
081: * The process instance was resumed.
082: */
083: public static final int RESUMED = WMProcessInstanceState.RESUME_ACTION;
084: /**
085: * The process instance was started.
086: */
087: public static final int STARTED = WMProcessInstanceState.START_ACTION;
088: /**
089: * The process instance was suspended.
090: */
091: public static final int SUSPENDED = WMProcessInstanceState.SUSPEND_ACTION;
092: /**
093: * The process instance was terminated.
094: */
095: public static final int TERMINATED = WMProcessInstanceState.TERMINATE_ACTION;
096: private static final WMAEventCode[] IF5_EVENT_CODES = {
097: WMAEventCode.ABORTED_PROCESS_INSTANCE,
098: WMAEventCode.COMPLETED_PROCESS_INSTANCE,
099: WMAEventCode.CREATED_PROCESS_INSTANCE,
100: WMAEventCode.UNKNOWN,
101: WMAEventCode.CHANGED_PROCESS_INSTANCE_STATE,
102: WMAEventCode.STARTED_PROCESS_INSTANCE,
103: WMAEventCode.CHANGED_PROCESS_INSTANCE_STATE,
104: WMAEventCode.TERMINATED_PROCESS_INSTANCE };
105: private static final String[] EVENT_TYPES = {
106: "ProcessInstanceAborted", "ProcessInstanceCompleted",
107: "ProcessInstanceCreated", "ProcessInstanceDeleted",
108: "ProcessInstanceResumed", "ProcessInstanceStarted",
109: "ProcessInstanceSuspended", "ProcessInstanceTerminated" };
110:
111: private int _previousState;
112: private transient WorkflowProcess _definition;
113:
114: private static String valueOf(int state) {
115: return state == -1 ? null : WMProcessInstanceState.valueOf(
116: state).toString();
117: }
118:
119: /**
120: * Constructs a new process instance event.
121: *
122: * @param source
123: * @param id
124: * @param broker
125: * @param definition
126: * @param previousState
127: */
128: public ProcessInstanceEvent(ProcessInstance source, int id,
129: WorkflowEventBroker broker, WorkflowProcess definition,
130: int previousState) {
131:
132: super (source, id, ProcessInstance.class, EVENT_TYPES[id],
133: source.getProcessInstanceId(), broker);
134: _definition = definition;
135: _previousState = previousState;
136: }
137:
138: /**
139: * Returns the source process instance.
140: *
141: * @return The process instance that fired the event.
142: */
143: public ProcessInstance getProcessInstance() {
144: return (ProcessInstance) source;
145: }
146:
147: public int getPreviousState() {
148: return _previousState;
149: }
150:
151: /**
152: * Returns the definition of the source process instance.
153: *
154: * @return The workflow process definition.
155: */
156: public WorkflowProcess getProcessDefinition() {
157: if (_definition == null && _broker != null) {
158: ProcessRepository processRepository = _broker
159: .getServiceManager().getProcessRepository();
160: try {
161: _definition = processRepository
162: .findWorkflowProcess(getProcessInstance()
163: .getProcessDefinitionId());
164: } catch (RepositoryException e) {
165: throw new OBERuntimeException(e);
166: }
167: }
168: return _definition;
169: }
170:
171: public WMAEventCode getWMAEventCode() {
172: return IF5_EVENT_CODES[_id];
173: }
174:
175: public String toString() {
176: return EVENT_TYPES[_id] + "[source=" + source
177: + ", previousState=" + valueOf(_previousState)
178: + ", definition=" + _definition + ']';
179: }
180: }
|