001: /*
002: * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source 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, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.enterprise.deploy.shared.factories;
030:
031: import javax.enterprise.deploy.spi.DeploymentManager;
032: import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
033: import javax.enterprise.deploy.spi.factories.DeploymentFactory;
034: import java.util.ArrayList;
035:
036: /**
037: * Factory for the implementation classes.
038: */
039: public final class DeploymentFactoryManager {
040:
041: private final static DeploymentFactoryManager _manager = new DeploymentFactoryManager();
042:
043: private final ArrayList<DeploymentFactory> _deploymentFactories = new ArrayList<DeploymentFactory>();
044:
045: private DeploymentFactoryManager() {
046: }
047:
048: /**
049: * Returns the manager.
050: */
051: public static DeploymentFactoryManager getInstance() {
052: return _manager;
053: }
054:
055: /**
056: * Returns the current registered factories.
057: */
058: public DeploymentFactory[] getDeploymentFactories() {
059: synchronized (_deploymentFactories) {
060: return _deploymentFactories
061: .toArray(new DeploymentFactory[_deploymentFactories
062: .size()]);
063: }
064: }
065:
066: private DeploymentFactory getDeploymentFactory(String uri)
067: throws DeploymentManagerCreationException {
068: synchronized (_deploymentFactories) {
069: for (DeploymentFactory deploymentFactory : _deploymentFactories) {
070: if (deploymentFactory.handlesURI(uri))
071: return deploymentFactory;
072: }
073: }
074:
075: throw new DeploymentManagerCreationException("uri '" + uri
076: + "' is not supported by any known DeploymentFactory");
077: }
078:
079: /**
080: * Returns the matchnig manager.
081: */
082: public DeploymentManager getDeploymentManager(String uri,
083: String username, String password)
084: throws DeploymentManagerCreationException {
085: return getDeploymentFactory(uri).getDeploymentManager(uri,
086: username, password);
087: }
088:
089: /**
090: * Registers a factory.
091: */
092: public void registerDeploymentFactory(DeploymentFactory factory) {
093: synchronized (_deploymentFactories) {
094: _deploymentFactories.add(factory);
095: }
096: }
097:
098: /**
099: * Gets a manager.
100: */
101: public DeploymentManager getDisconnectedDeploymentManager(String uri)
102: throws DeploymentManagerCreationException {
103: return getDeploymentFactory(uri)
104: .getDisconnectedDeploymentManager(uri);
105: }
106: }
|