PageRenderTime 38ms CodeModel.GetById 20ms app.highlight 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ee-deployment/src/main/java/org/jboss/as/ee/deployment/spi/factories/DeploymentFactoryImpl.java

#
Java | 159 lines | 66 code | 13 blank | 80 comment | 6 complexity | 3161cde690f80339f23f7b91de1293ae MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1/*
  2 * JBoss, Home of Professional Open Source.
  3 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
  4 * as indicated by the @author tags. See the copyright.txt file in the
  5 * distribution for a 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 */
 22package org.jboss.as.ee.deployment.spi.factories;
 23
 24import org.jboss.as.ee.deployment.spi.DeploymentManagerImpl;
 25
 26import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
 27import javax.enterprise.deploy.spi.DeploymentManager;
 28import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
 29import javax.enterprise.deploy.spi.factories.DeploymentFactory;
 30import java.net.URI;
 31import java.net.URISyntaxException;
 32
 33import static org.jboss.as.ee.deployment.spi.DeploymentManagerImpl.DEPLOYER_URI;
 34import static org.jboss.as.ee.deployment.spi.DeploymentLogger.ROOT_LOGGER;
 35
 36/**
 37 * The DeploymentFactory interface is a deployment driver for a J2EE platform product.
 38 *
 39 * It returns a DeploymentManager object which represents a connection to a specific J2EE platform product. Each application
 40 * server vendor must provide an implementation of this class in order for the J2EE Deployment API to work with their product.
 41 *
 42 * The class implementing this interface should have a public no-argument constructor, and it should be stateless (two instances
 43 * of the class should always behave the same). It is suggested but not required that the class have a static initializer that
 44 * registers an instance of the class with the DeploymentFactoryManager class.
 45 *
 46 * A connected or disconnected DeploymentManager can be requested. A DeploymentManager that runs connected to the platform can
 47 * provide access to J2EE resources. A DeploymentManager that runs disconnected only provides module deployment configuration
 48 * support.
 49 *
 50 * @author Thomas.Diesler@jboss.com
 51 * @author Scott.Stark@jboss.com
 52 *
 53 */
 54public class DeploymentFactoryImpl implements DeploymentFactory {
 55
 56    // The name of the JBoss DeploymentFactory
 57    private static String DISPLAY_NAME;
 58    // The product version
 59    private static String PRODUCT_VERSION;
 60
 61    /*
 62     * Register a DeploymentFactoryImpl instance with the DeploymentFactoryManager. This obtains the display name and version
 63     * from the Package object for org.jboss.deploy.spi.factories
 64     */
 65    static {
 66        DeploymentFactoryManager manager = DeploymentFactoryManager.getInstance();
 67        manager.registerDeploymentFactory(new DeploymentFactoryImpl());
 68        Package pkg = DeploymentFactoryImpl.class.getPackage();
 69        if (pkg != null) {
 70            DISPLAY_NAME = pkg.getImplementationVendor();
 71            PRODUCT_VERSION = pkg.getImplementationVersion();
 72        }
 73        if (DISPLAY_NAME == null || PRODUCT_VERSION == null) {
 74            DISPLAY_NAME = "DeploymentFactoryImpl";
 75            PRODUCT_VERSION = "1.1-DEV";
 76        }
 77    }
 78
 79    /**
 80     * Register this deployment factory with the manager
 81     */
 82    public static synchronized void register() {
 83        // registration is actually done in the static block above
 84    }
 85
 86    /**
 87     * Tests whether the factory can create a manager for the URI
 88     */
 89    public boolean handlesURI(String uri) {
 90        boolean handlesURI = uri.startsWith(DEPLOYER_URI);
 91        ROOT_LOGGER.debugf("handlesURI [%s]: %s", uri, handlesURI);
 92        return handlesURI;
 93    }
 94
 95    /**
 96     * Get a connected deployment manager
 97     *
 98     * @param uri the uri of the deployment manager
 99     * @param userName the user name
100     * @param password the password
101     * @return the deployment manager
102     * @throws javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException
103     *
104     */
105    public DeploymentManager getDeploymentManager(String uri, String userName, String password) throws DeploymentManagerCreationException {
106        ROOT_LOGGER.debugf("getDeploymentManager (uri=%s)", uri);
107        try {
108            URI deployURI = parseURI(uri);
109            return new DeploymentManagerImpl(deployURI, true, userName, password);
110        } catch (URISyntaxException e) {
111            DeploymentManagerCreationException ex = new DeploymentManagerCreationException("Failed to create DeploymentManagerImpl");
112            ex.initCause(e);
113            throw ex;
114        }
115    }
116
117    /**
118     * Get a disconnected version of the deployment manager
119     *
120     * @param uri the uri to connect to
121     * @return the disconnected deployment manager
122     * @throws javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException
123     *
124     */
125    public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException {
126        ROOT_LOGGER.debugf("getDisconnectedDeploymentManager (uri=%s)", uri);
127        try {
128            URI deployURI = parseURI(uri);
129            return new DeploymentManagerImpl(deployURI, false);
130        } catch (URISyntaxException e) {
131            DeploymentManagerCreationException ex = new DeploymentManagerCreationException("Failed to create DeploymentManagerImpl");
132            ex.initCause(e);
133            throw ex;
134        }
135    }
136
137    /**
138     * The name of the JBoss DeploymentFactory.
139     *
140     * @return the vendor name
141     */
142    public String getDisplayName() {
143        return DISPLAY_NAME;
144    }
145
146    /**
147     * The version of the deployment manager
148     *
149     * @return the version
150     */
151    public String getProductVersion() {
152        return PRODUCT_VERSION;
153    }
154
155    private URI parseURI(String uri) throws URISyntaxException {
156        URI deployURI = new URI(uri);
157        return deployURI;
158    }
159}