FileDocCategorySizeDatePackage
Ejb3ClientDeployer.javaAPI DocJBoss 4.2.17317Fri Jul 13 20:53:48 BST 2007org.jboss.ejb3.deployers

Ejb3ClientDeployer

public class Ejb3ClientDeployer extends org.jboss.deployers.plugins.deployers.helpers.AbstractSimpleRealDeployer
Deploys a client application jar.
author
Carlo de Wolf
version
$Revision: $

Fields Summary
private static final Logger
log
private org.jboss.kernel.Kernel
kernel
private MBeanServer
server
Constructors Summary
public Ejb3ClientDeployer()


    
   
      super(ApplicationClientDD.class);
      // make sure we run after EJB3 deployer
      setRelativeOrder(COMPONENT_DEPLOYER + 1);
   
Methods Summary
public voiddeploy(org.jboss.deployers.spi.deployer.DeploymentUnit unit, org.jboss.ejb3.metamodel.ApplicationClientDD metaData)

      log.debug("deploy " + unit.getName());

      String appClientName = getJndiName(unit, metaData);

      try
      {
         // I create the namespace here, because I destroy it in undeploy
         InitialContext iniCtx = new InitialContext();
         Context encCtx = Util.createSubcontext(iniCtx, appClientName);
         log.debug("Creating client ENC binding under: " + appClientName);

         String mainClassName = getMainClassName(unit, true);

         Class<?> mainClass = loadClass(unit, mainClassName);

         ClientENCInjectionContainer container = new ClientENCInjectionContainer(unit, metaData, mainClass, appClientName, unit.getClassLoader(), encCtx);

         //di.deployedObject = container.getObjectName();
         unit.addAttachment(ClientENCInjectionContainer.class, container);
         getKernelAbstraction().install(container.getObjectName().getCanonicalName(), container.getDependencyPolicy(), container);
      }
      catch(Exception e)
      {
         log.error("Could not deploy " + unit.getName(), e);
         undeploy(unit, metaData);
         throw new DeploymentException("Could not deploy " + unit.getName(), e);
      }
   
private java.lang.StringgetJndiName(org.jboss.deployers.spi.deployer.DeploymentUnit unit, org.jboss.ejb3.metamodel.ApplicationClientDD dd)
If there is no deployment descriptor, or it doesn't specify a JNDI name, then we make up one. We use the basename from di.shortName.

param
unit
param
dd
return
a good JNDI name

      String jndiName = dd.getJndiName();
      if(jndiName != null)
         return jndiName;

      String shortName = unit.getDeploymentContext().getRoot().getName();
      if(shortName.endsWith(".jar/"))
         jndiName = shortName.substring(0, shortName.length() - 5);
      else if(shortName.endsWith(".jar"))
         jndiName = shortName.substring(0, shortName.length() - 4);
      else
         throw new IllegalStateException("Expected either '.jar' or '.jar/' at the end of " + shortName);

      return jndiName;
   
private org.jboss.ejb3.KernelAbstractiongetKernelAbstraction()

      return new MCKernelAbstraction(kernel, server);
   
protected java.lang.StringgetMainClassName(org.jboss.deployers.spi.deployer.DeploymentUnit unit, boolean fail)

      VirtualFile file = unit.getMetaDataFile("MANIFEST.MF");
      log.trace("parsing " + file);
      // Default to the jboss client main
      String mainClassName = "org.jboss.client.AppClientMain";

      if (file != null)
      {
         try
         {
            // TODO - use VFSUtils.readManifest .. once VFS lib is updated
            InputStream is = file.openStream();
            Manifest mf;
            try
            {
               mf = new Manifest(is);
            }
            finally
            {
               is.close();
            }
            Attributes attrs = mf.getMainAttributes();
            String className = attrs.getValue(Attributes.Name.MAIN_CLASS);
            if (className != null)
            {
               mainClassName = className;
            }
         }
         finally
         {
            file.close();
         }
      }
      return mainClassName;
   
private java.lang.ClassloadClass(org.jboss.deployers.spi.deployer.DeploymentUnit unit, java.lang.String className)

      ClassLoader old = Thread.currentThread().getContextClassLoader();
      try
      {
         Thread.currentThread().setContextClassLoader(unit.getClassLoader());
         return Thread.currentThread().getContextClassLoader().loadClass(className);
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(old);
      }
   
public voidsetKernel(org.jboss.kernel.Kernel kernel)

      this.kernel = kernel;
   
public voidsetMbeanServer(javax.management.MBeanServer server)

      this.server = server;
   
public voidundeploy(org.jboss.deployers.spi.deployer.DeploymentUnit unit, org.jboss.ejb3.metamodel.ApplicationClientDD metaData)

      log.debug("undeploy " + unit.getName());

      ClientENCInjectionContainer container = unit.getAttachment(ClientENCInjectionContainer.class);
      if(container != null)
         getKernelAbstraction().uninstall(container.getObjectName().getCanonicalName());

      String jndiName = getJndiName(unit, metaData);
      log.debug("Removing client ENC from: " + jndiName);
      try
      {
         InitialContext iniCtx = new InitialContext();
         Util.unbind(iniCtx, jndiName);
      }
      catch(NameNotFoundException e)
      {
         // make sure stop doesn't fail for no reason
         log.debug("Could not find client ENC");
      }
      catch (NamingException e)
      {
         log.error("Failed to remove client ENC", e);
      }