KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > spi > factories > DeploymentFactoryImpl


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.deployment.spi.factories;
23
24 // $Id: DeploymentFactoryImpl.java 38480 2005-11-24 15:50:42Z tdiesler $
25

26 import java.net.URI JavaDoc;
27 import java.net.URISyntaxException JavaDoc;
28
29 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager JavaDoc;
30 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
31 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException JavaDoc;
32 import javax.enterprise.deploy.spi.factories.DeploymentFactory JavaDoc;
33
34 import org.jboss.deployment.spi.DeploymentManagerImpl;
35 import org.jboss.logging.Logger;
36
37 /**
38  * The DeploymentFactory interface is a deployment driver for a J2EE plaform product.
39  *
40  * It returns a DeploymentManager object which represents a connection to a specific J2EE platform product.
41  * Each application server vendor must provide an implementation of this class in order for the J2EE
42  * Deployment API to work with their product.
43  *
44  * The class implementing this interface should have a public no-argument constructor,
45  * and it should be stateless (two instances of the class should always behave the same).
46  * It is suggested but not required that the class have a static initializer that registers
47  * an instance of the class with the DeploymentFactoryManager class.
48  *
49  * A connected or disconnected DeploymentManager can be requested.
50  * A DeploymentManager that runs connected to the platform can provide access to J2EE resources.
51  * A DeploymentManager that runs disconnected only provides module deployment configuration support.
52  *
53  * @author Thomas.Diesler@jboss.org
54  * @author Scott.Stark@jboss.com
55  * @version $Revision: 38480 $
56  */

57 public class DeploymentFactoryImpl implements DeploymentFactory JavaDoc
58 {
59    // deployment logging
60
private static final Logger log = Logger.getLogger(DeploymentFactoryImpl.class);
61
62    // The name of the JBoss DeploymentFactory
63
private static String JavaDoc DISPLAY_NAME;
64    // The product version
65
private static String JavaDoc PRODUCT_VERSION;
66
67    /* Obtain the display name and version from the Package object for
68     org.jboss.deploy.spi.factories
69     */

70    static
71    {
72       Package JavaDoc pkg = Package.getPackage("org.jboss.deploy.spi.factories");
73       if (pkg != null)
74       {
75          DISPLAY_NAME = pkg.getImplementationVendor();
76          PRODUCT_VERSION = pkg.getImplementationVersion();
77       }
78       if (DISPLAY_NAME == null || PRODUCT_VERSION == null)
79       {
80          DISPLAY_NAME = "DeploymentFactoryImpl";
81          PRODUCT_VERSION = "1.1-DEV";
82       }
83
84       // Register this deployment factory with the manager
85
DeploymentFactoryManager JavaDoc manager = DeploymentFactoryManager.getInstance();
86       manager.registerDeploymentFactory(new DeploymentFactoryImpl());
87    }
88
89    /**
90     * Look for jboss-deployer:.... URIs. Returns true if uri is has a
91     * scheme of jboss-deployer, false otherwise.
92     *
93     * @param uri the uri
94     * @return true for jboss-deployer schemes, false otherwise.
95     */

96    public boolean handlesURI(String JavaDoc uri)
97    {
98       boolean handlesURI = DeploymentManagerImpl.DEPLOYER_URI.equals(uri);
99       if (handlesURI == false)
100       {
101          try
102          {
103             URI JavaDoc deployURI = parseURI(uri);
104             handlesURI = "jnp".equals(deployURI.getScheme());
105          }
106          catch (URISyntaxException JavaDoc e)
107          {
108             log.warn("Failed to parse uri: " + uri, e);
109          }
110       }
111
112       log.debug("handlesURI [" + uri + "]: " + handlesURI);
113       return handlesURI;
114    }
115
116    /**
117     * Get a connected deployment manager
118     *
119     * @param uri the uri of the deployment manager
120     * @param userName the user name
121     * @param password the password
122     * @return the deployment manager
123     * @throws javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException
124     *
125     */

126    public DeploymentManager JavaDoc getDeploymentManager(String JavaDoc uri, String JavaDoc userName, String JavaDoc password) throws DeploymentManagerCreationException JavaDoc
127    {
128       log.debug("getDeploymentManager (uri=" + uri + ")");
129       DeploymentManager JavaDoc mgr = null;
130
131       try
132       {
133          URI JavaDoc deployURI = parseURI(uri);
134          mgr = new DeploymentManagerImpl(deployURI, true, userName, password);
135       }
136       catch (URISyntaxException JavaDoc e)
137       {
138          DeploymentManagerCreationException JavaDoc ex = new DeploymentManagerCreationException JavaDoc("Failed to create DeploymentManagerImpl");
139          ex.initCause(e);
140          throw ex;
141       }
142       return mgr;
143    }
144
145    /**
146     * Get a disconnected version of the deployment manager
147     *
148     * @param uri the uri to connect to
149     * @return the disconnected deployment manager
150     * @throws javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException
151     *
152     */

153    public DeploymentManager JavaDoc getDisconnectedDeploymentManager(String JavaDoc uri) throws DeploymentManagerCreationException JavaDoc
154    {
155       log.debug("getDisconnectedDeploymentManager (uri=" + uri + ")");
156       DeploymentManager JavaDoc mgr = null;
157
158       try
159       {
160          URI JavaDoc deployURI = parseURI(uri);
161          mgr = new DeploymentManagerImpl(deployURI, false);
162       }
163       catch (URISyntaxException JavaDoc e)
164       {
165          DeploymentManagerCreationException JavaDoc ex = new DeploymentManagerCreationException JavaDoc("Failed to create DeploymentManagerImpl");
166          ex.initCause(e);
167          throw ex;
168       }
169       return mgr;
170    }
171
172    /**
173     * The name of the JBoss DeploymentFactory.
174     *
175     * @return the vendor name
176     */

177    public String JavaDoc getDisplayName()
178    {
179       return DISPLAY_NAME;
180    }
181
182    /**
183     * The version of the deployment manager
184     *
185     * @return the version
186     */

187    public String JavaDoc getProductVersion()
188    {
189       return PRODUCT_VERSION;
190    }
191
192    private URI JavaDoc parseURI(String JavaDoc uri) throws URISyntaxException JavaDoc
193    {
194       URI JavaDoc deployURI = new URI JavaDoc(uri);
195       return deployURI;
196    }
197 }
198
Popular Tags