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.engine.WorkflowEngineUtilities;
050: import org.obe.spi.model.AttributeInstance;
051: import org.obe.spi.service.ProcessRepository;
052: import org.obe.spi.service.WorkflowEventBroker;
053: import org.obe.xpdl.model.data.DataField;
054: import org.obe.xpdl.model.workflow.WorkflowProcess;
055: import org.wfmc.audit.WMAEventCode;
056:
057: /**
058: * Delivers attribute instance event notifications.
059: *
060: * @author Adrian Price
061: */
062: public final class AttributeInstanceEvent extends WorkflowEvent {
063: private static final long serialVersionUID = -4732580987634759448L;
064: /**
065: * The attribute was created.
066: */
067: public static final int CREATED = 0;
068: /**
069: * The attribute was deleted.
070: */
071: public static final int DELETED = 1;
072: /**
073: * The attribute was updated.
074: */
075: public static final int UPDATED = 2;
076: private static final WMAEventCode[] IF5_EVENT_CODES = {
077: WMAEventCode.UNKNOWN, WMAEventCode.UNKNOWN,
078: WMAEventCode.ASSIGNED_PROCESS_INSTANCE_ATTRIBUTE };
079: private static final String[] EVENT_TYPES = {
080: "AttributeInstanceCreated", "AttributeInstanceDeleted",
081: "AttributeInstanceUpdated" };
082: private final Object _previousValue;
083: private transient DataField _definition;
084:
085: public AttributeInstanceEvent(AttributeInstance source, int id,
086: WorkflowEventBroker broker, DataField definition,
087: Object previousValue) {
088:
089: super (source, id, AttributeInstance.class, EVENT_TYPES[id],
090: source.getName(), broker);
091: _definition = definition;
092: _previousValue = previousValue;
093: }
094:
095: /**
096: * Returns the source attribute instance entity.
097: *
098: * @return The attribute instance that fired the event.
099: */
100: public AttributeInstance getAttributeInstance() {
101: return (AttributeInstance) source;
102: }
103:
104: /**
105: * Returns the definition of the source attribute.
106: *
107: * @return The data field definition from the workflow process definition
108: * or package.
109: */
110: public DataField getDataField() {
111: if (_definition == null) {
112: ProcessRepository processRepository = _broker
113: .getServiceManager().getProcessRepository();
114: try {
115: AttributeInstance attr = getAttributeInstance();
116: WorkflowProcess workflow = processRepository
117: .findWorkflowProcess(attr.getOwner()
118: .getProcessDefinitionId());
119: _definition = WorkflowEngineUtilities.findDataField(
120: workflow, attr.getName());
121: } catch (RepositoryException e) {
122: throw new OBERuntimeException(e);
123: }
124: }
125: return _definition;
126: }
127:
128: /**
129: * Returns the value of the attribute prior to this update.
130: *
131: * @return Old attribute value.
132: */
133: public Object getPreviousValue() {
134: return _previousValue;
135: }
136:
137: /**
138: * Returns the new value of the attribute.
139: *
140: * @return New attribute value.
141: */
142: public Object getNewValue() {
143: return getAttributeInstance().getValue();
144: }
145:
146: public WMAEventCode getWMAEventCode() {
147: // N.B. This only works correctly for process instance attributes.
148: return IF5_EVENT_CODES[_id];
149: }
150:
151: public String toString() {
152: return EVENT_TYPES[_id] + "[source=" + source
153: + ", previousValue=" + _previousValue + ", definition="
154: + _definition + ']';
155: }
156: }
|