001: /*
002: * Bossa Workflow System
003: *
004: * $Id: ResourceEvents.java,v 1.4 2004/01/29 17:07:10 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.resource;
026:
027: import java.util.HashMap;
028: import java.util.Map;
029:
030: import com.bigbross.bossa.Bossa;
031: import com.bigbross.bossa.notify.Event;
032: import com.bigbross.bossa.notify.NotificationQueue;
033:
034: /**
035: * This class holds as static constants all ids of resource events. It also
036: * provides methods used by the resource classes to create and notify these
037: * events. <p>
038: *
039: * @author <a href="http://www.bigbross.com">BigBross Team</a>
040: */
041: public class ResourceEvents extends NotificationQueue {
042:
043: /**
044: * Constant to indicate the event of a resource creation in the
045: * resource manager. <p>
046: *
047: * This event contains the following attributes: ATTRIB_RESOURCE_ID <p>
048: *
049: * @see ResourceEvents#ATTRIB_RESOURCE_ID
050: */
051: public static final String ID_CREATE_RESOURCE = "create_resource";
052:
053: /**
054: * Constant to indicate the event of a resource removal from the
055: * resource manager. <p>
056: *
057: * This event contains the following attributes: ATTRIB_RESOURCE_ID <p>
058: *
059: * @see ResourceEvents#ATTRIB_RESOURCE_ID
060: */
061: public static final String ID_REMOVE_RESOURCE = "remove_resource";
062:
063: /**
064: * Constant to indicate the event of a resource being added to the
065: * include list of another resource. <p>
066: *
067: * This event contains the following attributes: ATTRIB_RESOURCE_ID and
068: * ATTRIB_HOST_RESOURCE_ID <p>
069: *
070: * @see ResourceEvents#ATTRIB_RESOURCE_ID
071: * @see ResourceEvents#ATTRIB_HOST_RESOURCE_ID
072: */
073: public static final String ID_INCLUDE_IN_RESOURCE = "inc_in_resource";
074:
075: /**
076: * Constant to indicate the event of a resource being added to the
077: * exclude list of another resource. <p>
078: *
079: * This event contains the following attributes: ATTRIB_RESOURCE_ID and
080: * ATTRIB_HOST_RESOURCE_ID <p>
081: *
082: * @see ResourceEvents#ATTRIB_RESOURCE_ID
083: * @see ResourceEvents#ATTRIB_HOST_RESOURCE_ID
084: */
085: public static final String ID_EXCLUDE_IN_RESOURCE = "exc_in_resource";
086:
087: /**
088: * Constant to indicate the event of a resource being removed from the
089: * lists of another resource. <p>
090: *
091: * This event contains the following attributes: ATTRIB_RESOURCE_ID and
092: * ATTRIB_HOST_RESOURCE_ID <p>
093: *
094: * @see ResourceEvents#ATTRIB_RESOURCE_ID
095: * @see ResourceEvents#ATTRIB_HOST_RESOURCE_ID
096: */
097: public static final String ID_REMOVE_FROM_RESOURCE = "rem_from_resource";
098:
099: /**
100: * Constant to indicate the resource id attribute.
101: */
102: public static final String ATTRIB_RESOURCE_ID = "resource_id";
103:
104: /**
105: * Constant to indicate the host resource id attribute.
106: */
107: public static final String ATTRIB_HOST_RESOURCE_ID = "host_resource_id";
108:
109: /**
110: * Creates a single resource event and puts it in the queue. <p>
111: *
112: * @param bossa the root of the bossa system.
113: * @param notificationId the id of this event.
114: * @param resource the resource involved.
115: */
116: void newSingleResourceEvent(Bossa bossa, String notificationId,
117: Resource resource) {
118: if (bossa != null) {
119: Map attrib = new HashMap();
120: attrib.put(ATTRIB_RESOURCE_ID, resource.getId());
121: addEvent(new Event(notificationId, Event.RESOURCE_EVENT,
122: attrib, bossa.getTimeSource().getTime()));
123: }
124: }
125:
126: /**
127: * Creates an event with two resources and puts it in the queue. <p>
128: *
129: * @param bossa the root of the bossa system.
130: * @param notificationId the id of this event.
131: * @param resource the resource being added or removed.
132: * @param host the resource being manipulated.
133: */
134: void newTwoResourcesEvent(Bossa bossa, String notificationId,
135: Resource resource, Resource host) {
136: if (bossa != null) {
137: Map attrib = new HashMap();
138: attrib.put(ATTRIB_RESOURCE_ID, resource.getId());
139: attrib.put(ATTRIB_HOST_RESOURCE_ID, host.getId());
140: addEvent(new Event(notificationId, Event.RESOURCE_EVENT,
141: attrib, bossa.getTimeSource().getTime()));
142: }
143: }
144: }
|