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