001: /*
002: * Bossa Workflow System
003: *
004: * $Id: ResourceManager.java,v 1.14 2003/04/30 18:11:03 gdvieira Exp $
005: *
006: * Copyright (C) 2003 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:
032: /**
033: * This class manages the creation and removal of resources. Resources
034: * are groups of resources, indexed by a string id. Single users are
035: * empty resources, their presence indicates the id is in use. <p>
036: *
037: * @author <a href="http://www.bigbross.com">BigBross Team</a>
038: */
039: public class ResourceManager extends ResourceRegistry {
040:
041: private Bossa engine;
042:
043: private Map allRegistries;
044:
045: /**
046: * Creates a new empty resource manager. <p>
047: *
048: * @param engine the bossa engine this resorce manager is part.
049: */
050: public ResourceManager(Bossa engine) {
051: super ("root");
052: this .engine = engine;
053: this .allRegistries = new HashMap();
054: addRegistry(this );
055: }
056:
057: /**
058: * Creates a new empty resource manager. <p>
059: */
060: public ResourceManager() {
061: this (null);
062: }
063:
064: /**
065: * Returns the bossa engine this resource manager is part. <p>
066: *
067: * @return the bossa engine this resource manager is part.
068: */
069: Bossa getBossa() {
070: return engine;
071: }
072:
073: /**
074: * Returns the top level resource registry, the resource manager. <p>
075: *
076: * @return the resource manager, <code>null</code> if the root registry
077: * is not a resource manager.
078: */
079: ResourceManager getResourceManager() {
080: return this ;
081: }
082:
083: /**
084: * Adds a resource registry to the global registry index. <p>
085: *
086: * @param registry the resource registry.
087: * @return <code>true</code> if the registry was added,
088: * <code>false</code> if the registry was already present.
089: * @see com.bigbross.bossa.resource.ResourceManager#getRegistry(String)
090: * @see com.bigbross.bossa.resource.ResourceManager#removeRegistry(
091: * ResourceRegistry)
092: */
093: boolean addRegistry(ResourceRegistry registry) {
094: String id = registry.getGlobalId();
095: if (!allRegistries.containsKey(id)) {
096: allRegistries.put(id, registry);
097: return true;
098: } else {
099: return false;
100: }
101: }
102:
103: /**
104: * Returns the resource registry indexed by its global id. Using this
105: * method it is possible to retrieve any resource registry in the
106: * system.
107: *
108: * @param globalId the global id of the registry.
109: * @return the resource registry,
110: * <code>null</code> if the registry was not found.
111: * @see com.bigbross.bossa.resource.ResourceManager#addRegistry(
112: * ResourceRegistry)
113: * @see com.bigbross.bossa.resource.ResourceManager#removeRegistry(
114: * ResourceRegistry)
115: */
116: ResourceRegistry getRegistry(String globalId) {
117: return (ResourceRegistry) allRegistries.get(globalId);
118: }
119:
120: /**
121: * Removes a resource registry from the global registry index. <p>
122: *
123: * @param registry the resource registry.
124: * @return <code>true</code> if the registry was removed,
125: * <code>false</code> if the registry was not found.
126: * @see com.bigbross.bossa.resource.ResourceManager#addRegistry(
127: * ResourceRegistry)
128: * @see com.bigbross.bossa.resource.ResourceManager#getRegistry(String)
129: */
130: boolean removeRegistry(ResourceRegistry registry) {
131: String id = registry.getGlobalId();
132: return (allRegistries.remove(id) != null);
133: }
134: }
|