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.WorkItem;
050: import org.obe.spi.service.ProcessRepository;
051: import org.obe.spi.service.WorkflowEventBroker;
052: import org.obe.util.WorkflowUtilities;
053: import org.obe.xpdl.model.activity.Activity;
054: import org.obe.xpdl.model.workflow.WorkflowProcess;
055: import org.wfmc.audit.WMAEventCode;
056: import org.wfmc.wapi.WMInvalidActivityNameException;
057: import org.wfmc.wapi.WMWorkItemState;
058:
059: /**
060: * Delivers work item event notifications.
061: *
062: * @author Adrian Price
063: */
064: public final class WorkItemEvent extends WorkflowEvent {
065: private static final long serialVersionUID = -638304336588033226L;
066: /**
067: * The work item was aborted.
068: */
069: public static final int ABORTED = WMWorkItemState.ABORT_ACTION;
070: /**
071: * The work item was assigned or reassigned.
072: */
073: public static final int ASSIGNED = WMWorkItemState.ASSIGN_ACTION;
074: /**
075: * The work item was completed.
076: */
077: public static final int COMPLETED = WMWorkItemState.COMPLETE_ACTION;
078: /**
079: * The work item was created.
080: */
081: public static final int CREATED = WMWorkItemState.CREATE_ACTION;
082: /**
083: * The work item was resumed.
084: */
085: public static final int RESUMED = WMWorkItemState.RESUME_ACTION;
086: /**
087: * The work item was started.
088: */
089: public static final int STARTED = WMWorkItemState.START_ACTION;
090: /**
091: * The work item was stopped.
092: */
093: public static final int STOPPED = WMWorkItemState.STOP_ACTION;
094: /**
095: * The work item was suspended.
096: */
097: public static final int SUSPENDED = WMWorkItemState.SUSPEND_ACTION;
098: /**
099: * The work item was terminated.
100: */
101: public static final int TERMINATED = WMWorkItemState.TERMINATE_ACTION;
102: private static final WMAEventCode[] IF5_EVENT_CODES = {
103: WMAEventCode.CHANGED_WORK_ITEM_STATE,
104: WMAEventCode.ASSIGNED_WORK_ITEM,
105: WMAEventCode.COMPLETED_WORK_ITEM, WMAEventCode.UNKNOWN,
106: WMAEventCode.CHANGED_WORK_ITEM_STATE,
107: WMAEventCode.STARTED_WORK_ITEM,
108: WMAEventCode.CHANGED_WORK_ITEM_STATE,
109: WMAEventCode.CHANGED_WORK_ITEM_STATE,
110: WMAEventCode.CHANGED_WORK_ITEM_STATE };
111: private static final String[] EVENT_TYPES = { "WorkItemAborted",
112: "WorkItemAssigned", "WorkItemCompleted", "WorkItemCreated",
113: "WorkItemResumed", "WorkItemStarted", "WorkItemStopped",
114: "WorkItemSuspended", "WorkItemTerminated" };
115:
116: private int _previousState;
117: private transient Activity _definition;
118:
119: private static String valueOf(int state) {
120: return state == -1 ? null : WMWorkItemState.valueOf(state)
121: .toString();
122: }
123:
124: public WorkItemEvent(WorkItem source, int id,
125: WorkflowEventBroker broker, Activity definition,
126: int previousState) {
127:
128: super (source, id, WorkItem.class, EVENT_TYPES[id], source
129: .getWorkItemId(), broker);
130: _definition = definition;
131: _previousState = previousState;
132: }
133:
134: public WorkItem getWorkItem() {
135: return (WorkItem) source;
136: }
137:
138: public int getPreviousState() {
139: return _previousState;
140: }
141:
142: public Activity getActivityDefinition() {
143: if (_definition == null && _broker != null) {
144: ProcessRepository processRepository = _broker
145: .getServiceManager().getProcessRepository();
146: try {
147: WorkItem workItem = getWorkItem();
148: WorkflowProcess workflow = processRepository
149: .findWorkflowProcess(workItem
150: .getProcessDefinitionId());
151: _definition = WorkflowUtilities.findActivity(workflow,
152: workItem.getActivityDefinitionId());
153: } catch (RepositoryException e) {
154: throw new OBERuntimeException(e);
155: } catch (WMInvalidActivityNameException e) {
156: throw new OBERuntimeException(e);
157: }
158: }
159: return _definition;
160: }
161:
162: public WMAEventCode getWMAEventCode() {
163: return IF5_EVENT_CODES[_id];
164: }
165:
166: public String toString() {
167: return EVENT_TYPES[_id] + "[source=" + source
168: + ", previousState=" + valueOf(_previousState)
169: + ", definition=" + _definition + ']';
170: }
171: }
|