001: /*
002: * Bossa Workflow System
003: *
004: * $Id: Event.java,v 1.7 2004/01/15 22:13:32 gdvieira Exp $
005: *
006: * Copyright (C) 2003,2004 OpenBR Sistemas S/C Ltda.
007: *
008: * This file is part of Bossa.
009: *
010: * Bossa is free software; you can redistribute it and/or modify it
011: * under the terms of version 2 of the GNU General Public License as
012: * published by the Free Software Foundation.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public
020: * License along with this program; if not, write to the
021: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
022: * Boston, MA 02111-1307, USA.
023: */
024:
025: package com.bigbross.bossa.notify;
026:
027: import java.io.Serializable;
028: import java.util.Collections;
029: import java.util.Date;
030: import java.util.Map;
031:
032: /**
033: * This class represents an event in the notification bus. <p>
034: *
035: * @author <a href="http://www.bigbross.com">BigBross Team</a>
036: */
037: public class Event implements Comparable, Serializable {
038:
039: private String id;
040:
041: private int type;
042:
043: private Map attributes;
044:
045: private Date time;
046:
047: /**
048: * Constant to indicate a work item or activity related event type.
049: */
050: public static final int WFNET_EVENT = 1;
051:
052: /**
053: * Constant to indicate a resource manipulation event type.
054: */
055: public static final int RESOURCE_EVENT = 2;
056:
057: /**
058: * Creates an event. For a list of the possible event types, see the
059: * constants defined in this class. <p>
060: *
061: * The meaning of the id and of the attributes map are
062: * defined by the generator of the event. The only exception is that a
063: * event with type <code>WFNET_EVENT</code> <i>should</i> contain an
064: * attribute named <code>WFNetEvents.ATTRIB_RESOURCE_ID</code>,
065: * indicating the resource this event affects. Also all attribute
066: * mappings are <code>String</code> id to <code>String</code> value. <p>
067: *
068: * @param id the id of this event.
069: * @param type the type os this event.
070: * @param attributes a <code>Map</code> containing the attributes.
071: * @param time the time this event happened.
072: * @see com.bigbross.bossa.wfnet.WFNetEvents#ATTRIB_RESOURCE_ID
073: */
074: public Event(String id, int type, Map attributes, Date time) {
075: this .id = id;
076: this .type = type;
077: this .attributes = attributes;
078: this .time = (Date) time.clone();
079: }
080:
081: /**
082: * Returns the id of this event. <p>
083: *
084: * @return the id of this event.
085: */
086: public String getId() {
087: return this .id;
088: }
089:
090: /**
091: * Returns the type of this event. <p>
092: *
093: * @return the type of this event.
094: */
095: public int getType() {
096: return this .type;
097: }
098:
099: /**
100: * Returns the attributes map of this event. <p>
101: *
102: * Notice that it is not possible to change this map. If tried, an
103: * UnsupportedOperationException will be thrown.
104: *
105: * @return the attributes map of this event.
106: */
107: public Map getAttributes() {
108: return Collections.unmodifiableMap(this .attributes);
109: }
110:
111: /**
112: * Returns the time this event happened. <p>
113: *
114: * @return the time this event happened.
115: */
116: public Date getTime() {
117: return (Date) this .time.clone();
118: }
119:
120: /**
121: * Note: this class has a natural ordering that is inconsistent with
122: * equals. <p>
123: *
124: * @see java.lang.Comparable#compareTo(java.lang.Object)
125: */
126: public int compareTo(Object o) {
127: return this .time.compareTo(((Event) o).getTime());
128: }
129: }
|