User: allsopp 
  Date: 01/01/14 21:06:55

  Added:       src/main/org/jboss/deployment DeployerMBean.java
                        DeployerMBeanSupport.java DeploymentException.java
  Log:
  First cut at the J2EE Connector Architecture.
  
  Revision  Changes    Path
  1.1                  jboss/src/main/org/jboss/deployment/DeployerMBean.java
  
  Index: DeployerMBean.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.deployment;
  
  import java.io.IOException;
  import java.net.MalformedURLException;
  
  import org.jboss.util.ServiceMBean;
  
  /**
   *   The common interface for services that deploy application
   *   components.
   *
   *   @author Toby Allsopp ([EMAIL PROTECTED])
   *   @version $Revision: 1.1 $
   */
  public interface DeployerMBean
     extends ServiceMBean
  {
     // Constants -----------------------------------------------------
      
     // Public --------------------------------------------------------
     
     void deploy (String url)
        throws MalformedURLException, IOException, DeploymentException;
  
     void undeploy (String url)
        throws MalformedURLException, IOException, DeploymentException;
  
     boolean isDeployed (String url)
        throws MalformedURLException, DeploymentException;
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/deployment/DeployerMBeanSupport.java
  
  Index: DeployerMBeanSupport.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.deployment;
  
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.Map;
  
  import org.jboss.deployment.DeploymentException;
  import org.jboss.util.ServiceMBeanSupport;
  
  /**
   * <description> 
   *
   * @author Toby Allsopp ([EMAIL PROTECTED])
   * @version $Revision: 1.1 $
   */
  public abstract class DeployerMBeanSupport
     extends ServiceMBeanSupport
     implements DeployerMBean
  {
     // Constants -----------------------------------------------------
      
     // Attributes ----------------------------------------------------
  
     private Map deployments = new HashMap();
      
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     // Public --------------------------------------------------------
  
     // DeployerMBean implementation ----------------------------------
  
     public void deploy (String url)
        throws MalformedURLException, IOException, DeploymentException
     {
        URL u = new URL(url);
        synchronized (deployments)
        {
           if (deployments.containsKey(u))
           {
              Object info = deployments.get(u);
              try
              {
                 undeploy(u, info);
              }
              catch (Throwable t)
              {
                 log.exception(t);
                 if (t instanceof Exception)
                 {
                    if (t instanceof IOException) throw (IOException) t;
                    if (t instanceof DeploymentException)
                       throw (DeploymentException) t;
                    throw (RuntimeException) t;
                 }
                 throw (Error) t;
              }
           }
           try
           {
              Object info = deploy(u);
              deployments.put(u, info);
           }
           catch (Throwable t)
           {
              log.exception(t);
              if (t instanceof Exception)
              {
                 if (t instanceof IOException) throw (IOException) t;
                 if (t instanceof DeploymentException)
                    throw (DeploymentException) t;
                 throw (RuntimeException) t;
              }
              throw (Error) t;
           }
        }
     }
  
     public void undeploy (String url)
        throws MalformedURLException, IOException, DeploymentException
     {
        URL u = new URL(url);
        synchronized (deployments)
        {
           if (deployments.containsKey(u))
           {
              Object info = deployments.remove(u);
              undeploy(u, info);
           }
        }
     }
  
     public boolean isDeployed (String url)
        throws MalformedURLException, DeploymentException
     {
        URL u = new URL(url);
        synchronized (deployments)
        {
           return deployments.containsKey(u);
        }
     }
      
     // ServiceMBeanSupport overrides ---------------------------------
     
     // Package protected ---------------------------------------------
      
     // Protected -----------------------------------------------------
  
     /**
      * Retrieves the object associated with a deployment. This
      * association is made during deployment using the object returned
      * from <code>deploy(URL)</code>. If there is no such deployment,
      * null is returned. Note that this is distinguishable from the
      * case of a deployment with an null information object only using
      * <code>isDeployed(URL)</code>.
      *
      * @param url the deployment for which information is required
      * @return an object, possibly null
      */
     protected Object getInfo(URL url)
     {
        return deployments.get(url);
     }
  
     /**
      * Subclasses override to perform actual deployment.
      *
      * @param url the location to be deployed
      * @return an object, possibly null, that will be passed back to
      *         <code>undeploy</code> and can be obtained using
      *         <code>getInfo(URL)</code>
      */
     protected abstract Object deploy(URL url)
        throws IOException, DeploymentException;
  
     /**
      * Subclasses override to perform any actions neccessary for
      * undeployment.
      *
      * @param url the location to be undeployed
      * @param info the object that was returned by the corresponding
      *             <code>deploy</code>
      */
     protected abstract void undeploy(URL url, Object info)
        throws IOException, DeploymentException;
      
     // Private -------------------------------------------------------
  
     // Inner classes -------------------------------------------------
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/deployment/DeploymentException.java
  
  Index: DeploymentException.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.deployment;
  
  /**
   *   Thrown by a deployer if an application component could not be
   *   deployed.
   *
   *   @see DeployerMBean
   *   @author Rickard �berg ([EMAIL PROTECTED])
   *   @author Toby Allsopp ([EMAIL PROTECTED])
   *   @version $Revision: 1.1 $
   */
  public class DeploymentException
     extends Exception
  {
     // Attributes ----------------------------------------------------
  
     /** The root cause of this exception */
     protected Exception cause;
     
     // Static --------------------------------------------------------
  
     // Constructors --------------------------------------------------
  
     public DeploymentException(String message)
     {
        super(message);
     }
     
     public DeploymentException(String message, Exception e)
     {
        super(message);
        
        cause = e;
     }
     
     // Public --------------------------------------------------------
  
     public Exception getCause() { return cause; }
     
     public String toString()
     {
        return cause == null ? super.toString()
           : super.toString()+", Cause: "+cause;
     }
  }
  
  
  

Reply via email to