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.client.api.model.MIMETypes;
048: import org.obe.event.AbstractListenerSupport;
049: import org.obe.spi.service.WorkflowEventBroker;
050: import org.wfmc.audit.WMAEventCode;
051:
052: import java.io.Serializable;
053:
054: /**
055: * Base class for workflow notification events. Sub-classes must follow a
056: * specific design pattern: they must supply a single, public constructor that
057: * takes the following arguments: <code>(Object source, int id,
058: * WorkflowEventBroker [, AbstractWFElement definition])</code>. The
059: * <code>source</code> and <code>definition</code> arguments are sub-classes of
060: * <code>Object</code> and <code>AbstractWFElement</code> respectively. The
061: * <code>definition</code> argument is optional. The event ids should be
062: * declared by the event subclass, and must be contiguous and 0-based.
063: *
064: * @author Adrian Price
065: * @see AbstractListenerSupport
066: */
067: public abstract class WorkflowEvent extends ApplicationEvent {
068: private static final long serialVersionUID = -1796915832725988942L;
069: protected transient WorkflowEventBroker _broker;
070: protected final long _timestamp;
071: protected final int _id;
072:
073: /**
074: * Construct a new <code>WorkflowEvent</code>.
075: *
076: * @param source The entity that is the source of this event.
077: * @param id The event ID code. <em>N.B. Event codes are defined by
078: * sub-classes; they must be contiguous and 0-based.</em>
079: * @param sourceClass The SPI interface implemented by the
080: * <code>source</code> object.
081: * @param eventType The event name. This has the form
082: * <code><event-class></code>
083: * @param key The primary key of the <code>source</code> entity.
084: * @see AbstractListenerSupport#AbstractListenerSupport
085: */
086: protected WorkflowEvent(Object source, int id, Class sourceClass,
087: String eventType, Serializable key,
088: WorkflowEventBroker broker) {
089: super (null, source, eventType, new Serializable[] { key },
090: MIMETypes.JAVA_OBJECT, sourceClass.getName(), null,
091: null);
092: _broker = broker;
093: _id = id;
094: _timestamp = System.currentTimeMillis();
095: }
096:
097: /**
098: * Returns the event id, as defined in subclasses.
099: *
100: * @return The event id.
101: */
102: public final int getId() {
103: return _id;
104: }
105:
106: /**
107: * Returns the system time at which the event occurred.
108: *
109: * @return System time in milliseconds.
110: */
111: public long getTimestamp() {
112: return _timestamp;
113: }
114:
115: /**
116: * Returns the WfMC Interface 5 audit event code (if defined).
117: *
118: * @return Audit event code.
119: */
120: public abstract WMAEventCode getWMAEventCode();
121: }
|