Clover coverage report - J2EE Deployment - 1.0.0
Coverage timestamp: sam. déc. 27 2003 15:14:34 CET
file stats: LOC: 181   Methods: 6
NCLOC: 77   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DeploymentFactoryManager.java 65% 82,1% 100% 77,8%
coverage coverage
 1   
 /*
 2   
  * EJTools, the Enterprise Java Tools
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at www.gnu.org.
 6   
  */
 7   
 package javax.enterprise.deploy.shared.factories;
 8   
 
 9   
 import java.util.ArrayList;
 10   
 import java.util.Iterator;
 11   
 import javax.enterprise.deploy.spi.DeploymentManager;
 12   
 
 13   
 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
 14   
 import javax.enterprise.deploy.spi.factories.DeploymentFactory;
 15   
 
 16   
 /**
 17   
  * The DeploymentFactoryManager class is a central registry for J2EE DeploymentFactory
 18   
  * objects. <p>
 19   
  *
 20   
  * The DeploymentFactoryManager retains references to DeploymentFactory objects loaded
 21   
  * by a tool.</p> <p>
 22   
  *
 23   
  * A DeploymentFactory object provides a reference to a DeploymentManager.</p> <p>
 24   
  *
 25   
  * The DeploymentFactoryManager has been implemented as a singleton. A tool gets
 26   
  * a reference to the DeploymentFactoryManager via the getInstance method.</p> <p>
 27   
  *
 28   
  * The DeploymentFactoryManager can return two types of DeploymentManagers, a connected
 29   
  * DeploymentManager and a disconnected DeploymentManager.</p> <p>
 30   
  *
 31   
  * The connected DeploymentManager provides access to any product resources that
 32   
  * may be required for configurations and deployment. The method to retrieve a connected
 33   
  * DeploymentManager is getDeploymentManager. This method provides parameters for
 34   
  * user name and password that the product may require for user authentication.</p>
 35   
  * <p>
 36   
  *
 37   
  * A disconnected DeploymentManager does not provide access to a running J2EE product.
 38   
  * The method to retrieve a disconnected DeploymentManager is getDisconnectedDeploymentManager.
 39   
  * A disconnected DeploymentManager does not need user authentication information.
 40   
  * <p>
 41   
  *
 42   
  *
 43   
  *
 44   
  * @author    Laurent Etiemble
 45   
  * @version   $Revision: 1.1 $
 46   
  * @since     1.0
 47   
  * @see       javax.enterprise.deploy.spi.DeploymentManager
 48   
  * @see       javax.enterprise.deploy.spi.factories.DeploymentFactory
 49   
  */
 50   
 public final class DeploymentFactoryManager
 51   
 {
 52   
    private ArrayList factories = new ArrayList();
 53   
    private static DeploymentFactoryManager instance = new DeploymentFactoryManager();
 54   
 
 55   
 
 56   
    /** Private constructor for Singleton implementation */
 57  8
    private DeploymentFactoryManager() { }
 58   
 
 59   
 
 60   
    /**
 61   
     * Retrieve the lists of currently registered DeploymentFactories.
 62   
     *
 63   
     * @return   the list of DeploymentFactory objects or an empty array if there
 64   
     *      are none.
 65   
     */
 66  32
    public DeploymentFactory[] getDeploymentFactories()
 67   
    {
 68  32
       return (DeploymentFactory[]) this.factories.toArray(new DeploymentFactory[this.factories.size()]);
 69   
    }
 70   
 
 71   
 
 72   
    /**
 73   
     * Retrieves a DeploymentManager instance to use for deployment. <p>
 74   
     *
 75   
     * The caller provides a URI and optional username and password, and all registered
 76   
     * DeploymentFactories will be checked. The first one to understand the URI provided
 77   
     * will attempt to initiate a server connection and return a ready DeploymentManager
 78   
     * instance.</p>
 79   
     *
 80   
     * @param uri                                     The uri to check
 81   
     * @param username                                An optional username (may be
 82   
     *      null if no authentication is required for this platform).
 83   
     * @param password                                An optional password (may be
 84   
     *      null if no authentication is required for this platform).
 85   
     * @return                                        A ready DeploymentManager instance.
 86   
     * @exception DeploymentManagerCreationException  Occurs when the factory appropriate
 87   
     *      to the specified URI was unable to initialize a DeploymentManager instance
 88   
     *      (server down, unable to authenticate, etc.).
 89   
     */
 90  16
    public DeploymentManager getDeploymentManager(String uri, String username, String password)
 91   
       throws DeploymentManagerCreationException
 92   
    {
 93  16
       if (uri == null)
 94   
       {
 95  0
          throw new IllegalArgumentException("URI for DeploymentManager cannot be null");
 96   
       }
 97  16
       DeploymentManager manager = null;
 98  24
       for (Iterator i = this.factories.iterator(); i.hasNext(); )
 99   
       {
 100  24
          DeploymentFactory factory = (DeploymentFactory) i.next();
 101  24
          if (factory.handlesURI(uri))
 102   
          {
 103  16
             manager = factory.getDeploymentManager(uri, username, password);
 104  16
             break;
 105   
          }
 106   
       }
 107  16
       if (manager == null)
 108   
       {
 109  0
          throw new DeploymentManagerCreationException("Could not get a DeploymentManager; No registered DeploymentFactory handles URI '" + uri + "'.");
 110   
       }
 111  16
       return manager;
 112   
    }
 113   
 
 114   
 
 115   
    /**
 116   
     * Return a disconnected DeploymentManager instance. <p>
 117   
     *
 118   
     * The caller provides a URI, and all registered DeploymentFactories will be checked.
 119   
     * The first one to understand the URI provided will return a ready DeploymentManager
 120   
     * instance.</p>
 121   
     *
 122   
     * @param uri                                     The uri to check
 123   
     * @return                                        A ready DeploymentManager instance.
 124   
     * @exception DeploymentManagerCreationException  Occurs when the factory appropriate
 125   
     *      to the specified URI was unable to initialize a DeploymentManager instance
 126   
     *      (server down, etc.).
 127   
     */
 128  16
    public DeploymentManager getDisconnectedDeploymentManager(String uri)
 129   
       throws DeploymentManagerCreationException
 130   
    {
 131  16
       if (uri == null)
 132   
       {
 133  0
          throw new IllegalArgumentException("URI for DeploymentManager should not be null");
 134   
       }
 135  16
       DeploymentManager manager = null;
 136  24
       for (Iterator i = this.factories.iterator(); i.hasNext(); )
 137   
       {
 138  24
          DeploymentFactory factory = (DeploymentFactory) i.next();
 139  24
          if (factory.handlesURI(uri))
 140   
          {
 141  16
             manager = factory.getDisconnectedDeploymentManager(uri);
 142  16
             break;
 143   
          }
 144   
       }
 145  16
       if (manager == null)
 146   
       {
 147  0
          throw new DeploymentManagerCreationException("Could not get a DeploymentManager; No registered DeploymentFactory handles URI '" + uri + "'.");
 148   
       }
 149  16
       return manager;
 150   
    }
 151   
 
 152   
 
 153   
    /**
 154   
     * Registers a DeploymentFactory so it will be able to handle requests.
 155   
     *
 156   
     * @param factory  The DeploymentFactory to register
 157   
     */
 158  24
    public void registerDeploymentFactory(DeploymentFactory factory)
 159   
    {
 160  24
       if (factory == null)
 161   
       {
 162  0
          throw new IllegalArgumentException("DeploymentFactory to register cannot be null");
 163   
       }
 164  24
       if (!this.factories.contains(factory))
 165   
       {
 166  16
          this.factories.add(factory);
 167   
       }
 168   
    }
 169   
 
 170   
 
 171   
    /**
 172   
     * Retrieve the Singleton DeploymentFactoryManager
 173   
     *
 174   
     * @return   The DeploymentFactoryManager instance
 175   
     */
 176  16
    public static DeploymentFactoryManager getInstance()
 177   
    {
 178  16
       return DeploymentFactoryManager.instance;
 179   
    }
 180   
 }
 181