KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > enterprise > deploy > spi > factories > JBossDeploymentFactoryManager


1 package org.jboss.enterprise.deploy.spi.factories;
2
3 import java.util.StringTokenizer JavaDoc;
4 import java.util.Vector JavaDoc;
5 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
6 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException JavaDoc;
7 import javax.enterprise.deploy.spi.factories.DeploymentFactory JavaDoc;
8 import javax.enterprise.deploy.spi.factories.DeploymentFactoryManager;
9
10 /**
11  * Description of the Class
12  *
13  * @author laurent
14  * @created 31 mars 2002
15  */

16 public class JBossDeploymentFactoryManager implements DeploymentFactoryManager
17 {
18    /** Description of the Field */
19    private static Vector JavaDoc factories = new Vector JavaDoc();
20    /** Description of the Field */
21    private static boolean initialized = false;
22
23
24    /** Constructor */
25    public JBossDeploymentFactoryManager() { }
26
27
28    /**
29     * Retrieve the lists of currently registered DeploymentFactories.
30     *
31     * @return the list of DeploymentFactory objects or 'null' if there are none.
32     */

33    public DeploymentFactory JavaDoc[] getDeploymentFactories()
34    {
35       this.initialize();
36
37       return (DeploymentFactory JavaDoc[]) this.factories.toArray(new DeploymentFactory JavaDoc[0]);
38    }
39
40
41    /**
42     * Retrieves a DeploymentManager instance to use for deployment. The caller provides a URI and optional username and password, and all registered
43     * DeploymentFactories will be checked. The first one to understand the URI provided will attempt to initiate a server connection and return a ready
44     * DeploymentManager instance.
45     *
46     * @param uri The uri to check
47     * @param username An optional username (may be <tt>null</tt> if no authentication is required for this platform).
48     * @param password An optional password (may be <tt>null</yy> if no authentication is required for this platform).
49     * @return A ready DeploymentManager instance.
50     * @throws DeploymentManagerCreationException Occurs when the factory appropriate to the specified URI was unable to initialize a DeploymentManager instance
51     * (server down, unable to authenticate, etc.).
52     */

53    public DeploymentManager JavaDoc getDeploymentManager(String JavaDoc uri, String JavaDoc username, String JavaDoc password) throws DeploymentManagerCreationException JavaDoc
54    {
55       this.initialize();
56
57       for (int i = 0; i < this.factories.size(); i++)
58       {
59          DeploymentFactory JavaDoc factory = (DeploymentFactory JavaDoc) this.factories.elementAt(i);
60          if (factory.handlesURI(uri))
61          {
62             return factory.getDeploymentManager(uri, username, password);
63          }
64       }
65
66       return null;
67    }
68
69
70    /**
71     * Return a <tt>disconnected</tt> DeploymentManager instance.
72     *
73     * @param uri identifier of the disconnected DeploymentManager to return.
74     * @return A DeploymentManager instance.
75     * @exception DeploymentManagerCreationException Description of Exception
76     * @throws DeploymentDriverException occurs if the DeploymentManager could not be created.
77     */

78    public DeploymentManager JavaDoc getDisconnectedDeploymentManager(String JavaDoc uri) throws DeploymentManagerCreationException JavaDoc
79    {
80       this.initialize();
81
82       for (int i = 0; i < this.factories.size(); i++)
83       {
84          DeploymentFactory JavaDoc factory = (DeploymentFactory JavaDoc) this.factories.elementAt(i);
85          if (factory.handlesURI(uri))
86          {
87             return factory.getDisconnectedDeploymentManager(uri);
88          }
89       }
90
91       return null;
92    }
93
94
95    /**
96     * Registers a DeploymentFactory so it will be able to handle requests.
97     *
98     * @param factory Description of Parameter
99     */

100    public void registerDeploymentFactory(DeploymentFactory JavaDoc factory)
101    {
102       this.initialize();
103
104       this.factories.add(factory);
105    }
106
107
108    /** Description of the Method */
109    private void initialize()
110    {
111       if (this.initialized)
112       {
113          return;
114       }
115       this.initialized = true;
116       this.loadInitialFactories();
117    }
118
119
120    /** Description of the Method */
121    private void loadInitialFactories()
122    {
123       String JavaDoc factoriesToLoad;
124
125       factoriesToLoad = System.getProperty("javax.enterprise.deploy.spi.factories");
126       System.out.println("ENV " + factoriesToLoad);
127
128       if (factoriesToLoad == null)
129       {
130          return;
131       }
132
133       StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(factoriesToLoad, ":");
134       while (tokenizer.hasMoreTokens())
135       {
136          String JavaDoc factoryToLoad = tokenizer.nextToken();
137          System.out.println("NEXT " + factoryToLoad);
138
139          try
140          {
141             DeploymentFactory JavaDoc factory = (DeploymentFactory JavaDoc) Class.forName(factoryToLoad).newInstance();
142             this.registerDeploymentFactory(factory);
143          }
144          catch (ClassNotFoundException JavaDoc ex)
145          {
146          }
147          catch (Exception JavaDoc ex)
148          {
149          }
150       }
151    }
152 }
153
154
Popular Tags