User: d_jencks
  Date: 01/09/08 12:32:20

  Modified:    src/main/org/jboss/resource ConnectionFactoryLoader.java
                        ConnectionFactoryLoaderMBean.java RARDeployer.java
  Log:
  Reorganized connector packaging under connector (from pool), made jca stuff into a 
sar, made default hypsersonic DefaultDS into hsql-default-service.xml, and made 
jbossmq into jbossmq-service.xml
  
  Revision  Changes    Path
  1.10      +35 -36    jbosscx/src/main/org/jboss/resource/ConnectionFactoryLoader.java
  
  Index: ConnectionFactoryLoader.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosscx/src/main/org/jboss/resource/ConnectionFactoryLoader.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ConnectionFactoryLoader.java      2001/09/03 02:16:26     1.9
  +++ ConnectionFactoryLoader.java      2001/09/08 19:32:20     1.10
  @@ -61,7 +61,7 @@
    * @author     <a href="[EMAIL PROTECTED]">Toby Allsopp</a>
    * @author     <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
    * @see        RARDeployer
  - * @version    $Revision: 1.9 $ <p>
  + * @version    $Revision: 1.10 $ <p>
    *
    *      <b>Revisions:</b> <p>
    *
  @@ -94,8 +94,8 @@
      private MBeanServer server;
   
      private String resourceAdapterName;
  -   private String factoryName;
  -   private String properties = "";
  +   private String jndiName;
  +   private String mcfProperties = "";
      private String rarDeployerName;
      private String tmName = "java:/TransactionManager";
      private String cmfName;
  @@ -134,23 +134,23 @@
      }
   
      /**
  -    *  Sets the FactoryName attribute of the ConnectionFactoryLoader object
  +    *  Sets the JndiName attribute of the ConnectionFactoryLoader object
       *
  -    * @param  name  The new FactoryName value
  +    * @param  name  The new jndiName value
       */
  -   public void setFactoryName(String name)
  +   public void setJndiName(String name)
      {
  -      this.factoryName = name.trim();
  +      this.jndiName = name.trim();
      }
   
      /**
  -    *  Sets the Properties attribute of the ConnectionFactoryLoader object
  +    *  Sets the ManagedConnectionFactoryProperties attribute of the 
ConnectionFactoryLoader object
       *
       * @param  p  The new Properties value
       */
  -   public void setProperties(String p)
  +   public void setManagedConnectionFactoryProperties(String p)
      {
  -      this.properties = p;
  +      this.mcfProperties = p;
      }
   
      /**
  @@ -238,23 +238,23 @@
      }
   
      /**
  -    *  Gets the FactoryName attribute of the ConnectionFactoryLoader object
  +    *  Gets the jndiName attribute of the ConnectionFactoryLoader object
       *
  -    * @return    The FactoryName value
  +    * @return    The jndiName value
       */
  -   public String getFactoryName()
  +   public String getJndiName()
      {
  -      return factoryName;
  +      return jndiName;
      }
   
      /**
  -    *  Gets the Properties attribute of the ConnectionFactoryLoader object
  +    *  Gets the ManagedConnectionFactoryProperties attribute of the 
ConnectionFactoryLoader object
       *
       * @return    The Properties value
       */
  -   public String getProperties()
  +   public String getManagedConnectionFactoryProperties()
      {
  -      return properties;
  +      return mcfProperties;
      }
   
      /**
  @@ -429,7 +429,7 @@
         this.server = server;
         if (name == null)
         {
  -         String nameStr = OBJECT_NAME + ",name=" + factoryName;
  +         String nameStr = OBJECT_NAME + ",name=" + jndiName;
            try
            {
               name = new ObjectName(nameStr);
  @@ -446,7 +446,7 @@
             throws Exception
      {
         //add the factory name to the category:
  -      category = (JBossCategory)JBossCategory.getInstance(getClass().getName() + 
"." + factoryName);
  +      category = (JBossCategory)JBossCategory.getInstance(getClass().getName() + 
"." + jndiName);
         rarDeployerObjectName = new ObjectName(rarDeployerName);
         server.addNotificationListener(rarDeployerObjectName, this,
               new RAFilter(category), null);
  @@ -456,7 +456,7 @@
             throws Exception
      {
         // If this factory has not already been loaded...
  -      if (!cfs.containsKey(factoryName))
  +      if (!cfs.containsKey(jndiName))
         {
            // ... and the RAR deployer exists...
            if (server.isRegistered(rarDeployerObjectName))
  @@ -480,7 +480,7 @@
      protected void stopService()
      {
         // If this factory has been loaded...
  -      if (cfs.containsKey(factoryName))
  +      if (cfs.containsKey(jndiName))
         {
            try
            {
  @@ -527,7 +527,6 @@
         // This context is used in a few places. There is no point
         // continuing if JNDI isn't working.
   
  -      System.out.println("in loadConnectionFactory");
         Context ctx;
         try
         {
  @@ -573,17 +572,17 @@
   
         // Set the properties on it
   
  -      Properties props = new Properties();
  +      Properties mcfProps = new Properties();
         try
         {
  -         parseProperties(props, properties);
  -         //props.load(
  -         //new ByteArrayInputStream(properties.getBytes("ISO-8859-1")));
  +         parseProperties(mcfProps, mcfProperties);
  +         //mcfProps.load(
  +         //new ByteArrayInputStream(mcfProperties.getBytes("ISO-8859-1")));
         }
         catch (IOException ioe)
         {
            // This shouldn't happen, so we try to carry on as if it didn't
  -         category.error("Problem converting properties string '" + properties +
  +         category.error("Problem converting properties string '" + mcfProperties +
                  "' to Properties", ioe);
         }
   
  @@ -593,7 +592,7 @@
         for (Iterator i = ddProps.values().iterator(); i.hasNext(); )
         {
            RARMetaData.Property ddProp = (RARMetaData.Property)i.next();
  -         String value = (String)props.get(ddProp.name);
  +         String value = (String)mcfProps.get(ddProp.name);
            if (value == null)
            {
               if (ddProp.value == null)
  @@ -664,7 +663,7 @@
   
         // Give it somewhere to tell people things
   
  -      PrintWriter logWriter = new 
CategoryWriter(JBossCategory.getInstance(mcf.getClass().getName() + "." + 
factoryName));
  +      PrintWriter logWriter = new 
CategoryWriter(JBossCategory.getInstance(mcf.getClass().getName() + "." + jndiName));
         try
         {
            mcf.setLogWriter(logWriter);
  @@ -704,7 +703,7 @@
            return;
         }
   
  -      principalMapping.setName(factoryName);
  +      principalMapping.setName(jndiName);
         principalMapping.setManagedConnectionFactory(mcf);
         principalMapping.setRARMetaData(metaData);
         principalMapping.setProperties(princMapProps);
  @@ -731,7 +730,7 @@
         cmConfig.isReauthenticationSupported =
               metaData.getReauthenticationSupport();
         JBossConnectionListenerImpl listener =
  -            new JBossConnectionListenerImpl(mcf, factoryName);
  +            new JBossConnectionListenerImpl(mcf, jndiName);
         cmConfig.listener = listener;
   
         Properties cmProperties = new Properties();
  @@ -749,7 +748,7 @@
   
         try
         {
  -         cm = cmf.addManagedConnectionFactory(mcf, cmConfig, factoryName);
  +         cm = cmf.addManagedConnectionFactory(mcf, cmConfig, jndiName);
         }
         catch (ResourceException re)
         {
  @@ -775,11 +774,11 @@
   
         // Bind it into JNDI
   
  -      bindName = "java:/" + factoryName;
  +      bindName = "java:/" + jndiName;
         category.debug("Binding object '" + cf + "' into JNDI at '" + bindName + "'");
         synchronized (cfs)
         {
  -         cfs.put(factoryName, cf);
  +         cfs.put(jndiName, cf);
         }
         ((Referenceable)cf).setReference(new Reference(cf.getClass().getName(),
               getClass().getName(),
  @@ -807,8 +806,8 @@
         // Destroy any managed connections
   
         cm.shutDown();
  -      cfs.remove(factoryName);
  -      category.info("Connection factory '" + factoryName + "' shut down.");
  +      cfs.remove(jndiName);
  +      category.info("Connection factory '" + jndiName + "' shut down.");
   
         // Unbind from JNDI
   
  
  
  
  1.5       +6 -6      
jbosscx/src/main/org/jboss/resource/ConnectionFactoryLoaderMBean.java
  
  Index: ConnectionFactoryLoaderMBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosscx/src/main/org/jboss/resource/ConnectionFactoryLoaderMBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConnectionFactoryLoaderMBean.java 2001/08/30 02:19:22     1.4
  +++ ConnectionFactoryLoaderMBean.java 2001/09/08 19:32:20     1.5
  @@ -17,7 +17,7 @@
    *
    * @author     Toby Allsopp ([EMAIL PROTECTED])
    * @see        RARDeployer
  - * @version    $Revision: 1.4 $
  + * @version    $Revision: 1.5 $
    */
   public interface ConnectionFactoryLoaderMBean
          extends ServiceMBean
  @@ -43,11 +43,11 @@
       *  will be prepended with "java:/" to ensure that it is only visible in the
       *  local JVM.
       *
  -    * @return    The FactoryName value
  +    * @return    The JndiName value
       */
  -   String getFactoryName();
  +   String getJndiName();
   
  -   void setFactoryName(String factoryName);
  +   void setJndiName(String jndiName);
   
      /**
       *  A string in a format parseable by {@link java.util.Properties#load} that
  @@ -56,9 +56,9 @@
       *
       * @return    The Properties value
       */
  -   String getProperties();
  +   String getManagedConnectionFactoryProperties();
   
  -   void setProperties(String properties);
  +   void setManagedConnectionFactoryProperties(String properties);
   
      /**
       *  The name of the MBean responsible for deploying the resource adapter.
  
  
  
  1.9       +496 -503  jbosscx/src/main/org/jboss/resource/RARDeployer.java
  
  Index: RARDeployer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosscx/src/main/org/jboss/resource/RARDeployer.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- RARDeployer.java  2001/08/30 02:19:22     1.8
  +++ RARDeployer.java  2001/09/08 19:32:20     1.9
  @@ -1,9 +1,9 @@
   /*
  -* JBoss, the OpenSource J2EE webOS
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * JBoss, the OpenSource J2EE webOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.resource;
   
   import java.io.File;
  @@ -46,7 +46,7 @@
   *
   * @author     Toby Allsopp ([EMAIL PROTECTED])
   * @author     <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  -* @version    $Revision: 1.8 $
  +* @version    $Revision: 1.9 $
   * @see        org.jboss.resource.ConnectionFactoryLoader <p>
   *
   *      <b>Revisions:</b> <p>
  @@ -59,502 +59,495 @@
   *
   */
   public class RARDeployer
  -extends DeployerMBeanSupport
  -implements RARDeployerMBean
  +       extends DeployerMBeanSupport
  +       implements RARDeployerMBean
   {
  -     
  -     // Package protected ---------------------------------------------
  -     
  -     // Protected -----------------------------------------------------
  -     
  -     // Private -------------------------------------------------------
  -     
  -     private static int nextNum = 0;
  -     // Constants -----------------------------------------------------
  -     
  -     // Attributes ----------------------------------------------------
  -     
  -     /*
  -     * log4j Category for logging
  -     */
  -     private JBossCategory category = 
(JBossCategory)JBossCategory.getInstance(RARDeployer.class);
  -     
  -     /**
  -     *  The directory that will contain local copies of deployed RARs
  -     */
  -     private File rarTmpDir;
  -     
  -     /**
  -     *  The next sequence number to be used in notifications about (un)deployment
  -     */
  -     private int nextMessageNum = 0;
  -     
  -     private static String generateUniqueDirName(URL u)
  -     {
  -             int thisNum = nextNum++;
  -             return "rar." + thisNum;
  -     }
  -     
  -     // Static --------------------------------------------------------
  -     
  -     // Constructors --------------------------------------------------
  -     
  -     // Public --------------------------------------------------------
  -     
  -     /**
  -     *  Gets the DeployableFilter attribute of the RARDeployer object
  -     *
  -     * @return    The DeployableFilter value
  -     */
  -     public FilenameFilter getDeployableFilter()
  -     {
  -             return
  -             new FilenameFilter()
  -             {
  -                     /**
  -                     *  #Description of the Method
  -                     *
  -                     * @param  dir       Description of Parameter
  -                     * @param  filename  Description of Parameter
  -                     * @return           Description of the Returned Value
  -                     */
  -                     public boolean accept(File dir, String filename)
  -                     {
  -                             return filename.endsWith(".rar");
  -                     }
  -             };
  -     }
  -     
  -     // RARDeployerMBean implementation -------------------------------
  -     
  -     // DeployerMBeanSupport overrides ---------------------------------
  -     
  -     /**
  -     *  Gets the Name attribute of the RARDeployer object
  -     *
  -     * @return    The Name value
  -     */
  -     public String getName()
  -     {
  -             return "RARDeployer";
  -     }
  -     
  -     /**
  -     *  Gets the MetaData attribute of the RARDeployer object
  -     *
  -     * @param  resourceAdapterName  Description of Parameter
  -     * @return                      The MetaData value
  -     */
  -     public RARMetaData getMetaData(String resourceAdapterName)
  -     {
  -             Collection dis = getDeployments().values();
  -             Iterator i = dis.iterator();
  -             while (i.hasNext())
  -             {
  -                     DeploymentInfo di = (DeploymentInfo)i.next();
  -                     if (di.metadata.getDisplayName().equals(resourceAdapterName))
  -                     {
  -                             return di.metadata;
  -                     }
  -             }
  -             return null;
  -     }
  -     
  -     /**
  -     *  #Description of the Method
  -     *
  -     * @exception  Exception  Description of Exception
  -     */
  -     public void initService()
  -     throws Exception
  -     {
  -             // find the temp directory - it contains the file
  -             // "tmp.properties"
  -             /*
  -             URL tmpPropURL = getClass().getResource("/tmp.properties");
  -             File tmpDir = new File(tmpPropURL.getFile()).getParentFile();
  -             */
  -             
  -             File jbossHomeDir = new File(System.getProperty("jboss.system.home"));
  -             File tmpDir = new File(jbossHomeDir, "tmp"+File.separator);
  -             // Create our temp directory
  -             File deployTmpDir = new File(tmpDir, "deploy");
  -             rarTmpDir = new File(deployTmpDir, getName());
  -             
  -             if (rarTmpDir.exists())
  -             {
  -                     category.info("Found a temp directory left over from a 
previous run - " +
  -                             "deleting it.");
  -                     // What could it mean?
  -                     if (!recursiveDelete(rarTmpDir))
  -                     {
  -                             category.warn("Unable to recursively delete temp 
directory '" +
  -                                     rarTmpDir + "' that appears to be left over 
from " +
  -                                     "the previous run. This might cause 
problems.");
  -                     }
  -             }
  -             if (!rarTmpDir.exists() && !rarTmpDir.mkdirs())
  -             {
  -                     throw new DeploymentException("Can't create temp directory '" +
  -                             rarTmpDir + "'");
  -             }
  -     }
  -     
  -     /**
  -     *  #Description of the Method
  -     */
  -     public void destroyService()
  -     {
  -             // Remove our temp directory
  -             if (!recursiveDelete(rarTmpDir))
  -             {
  -                     category.warn("Unable to recursively delete the temp directory 
'" +
  -                             rarTmpDir + "' - it should be cleaned up when the " +
  -                             "server is next restarted.");
  -             }
  -     }
  -     
  -     protected Object deploy(URL url)
  -     throws IOException, DeploymentException
  -     {
  -             category.info("Attempting to deploy RAR at '" + url + "'");
  -             
  -             // We want to take a local copy of the RAR so that we don't run
  -             // into problems if the original is removed/replaced. We also
  -             // need the RAR in unpacked form so that we can get at the
  -             // included JARs for classloading (I don't think URLClassLoader
  -             // deals with JARs within JARs).
  -             
  -             String unpackedDirName = generateUniqueDirName(url);
  -             File unpackedDir = new File(rarTmpDir, unpackedDirName);
  -             if (unpackedDir.exists())
  -             {
  -                     throw new DeploymentException("The application at URL '" + url 
+ "' " +
  -                             "appears to already have been " +
  -                             "deployed because the directory '" +
  -                             unpackedDir + "' exists");
  -             }
  -             unpackedDir.mkdirs();
  -             
  -             if (url.getFile().endsWith("/"))
  -             {
  -                     // this is a directory - we can only deal with directories in
  -                     // the local filesystem (because we can't get a list of files
  -                     // from a general URL)
  -                     if (!url.getProtocol().equals("file"))
  -                     {
  -                             throw new DeploymentException("Can only deploy 
directories " +
  -                                     "specified by 'file:' URLs");
  -                     }
  -                     copyDirectory(new File(url.getFile()), unpackedDir);
  -             }
  -             else
  -             {
  -                     // this is a .rar file somewhere so we copy it to the temp
  -                     // dir because otherwise we run into problems when we try to
  -                     // open it again later
  -                     File copyFile = new File(rarTmpDir, "copy" + unpackedDirName);
  -                     InputStream input = url.openStream();
  -                     try
  -                     {
  -                             OutputStream output = new FileOutputStream(copyFile);
  -                             try
  -                             {
  -                                     copy(input, output);
  -                             }
  -                             finally
  -                             {
  -                                     output.close();
  -                             }
  -                     }
  -                     finally
  -                     {
  -                             input.close();
  -                     }
  -                     // then we can inflate the copy without fear of retribution
  -                     inflateJar(copyFile.toURL(), unpackedDir);
  -             }
  -             
  -             // Right, now we can forget about URLs and just use the file
  -             // system.
  -             
  -             File ddFile = new File(unpackedDir, "META-INF/ra.xml");
  -             
  -             if (!ddFile.exists())
  -             {
  -                     throw new DeploymentException("No deployment descriptor " +
  -                             "('META-INF/ra.xml') found in alleged " +
  -                             "resource adapter at '" + url + "'");
  -             }
  -             
  -             Document dd;
  -             try
  -             {
  -                     dd = XmlFileLoader.getDocument(ddFile.toURL());
  -             }
  -             catch (org.jboss.ejb.DeploymentException de)
  -             {
  -                     throw new DeploymentException(de.getMessage(), de.getCause());
  -             }
  -             
  -             Element root = dd.getDocumentElement();
  -             
  -             RARMetaData metadata = new RARMetaData();
  -             metadata.importXml(root);
  -             
  -             // Create a class loader that can load classes from any JARs
  -             // inside the RAR. First, we need to find the JARs.
  -             
  -             Collection jars = new ArrayList();
  -             
  -             FileFilter filter =
  -             new FileFilter()
  -             {
  -                     /**
  -                     *  #Description of the Method
  -                     *
  -                     * @param  file  Description of Parameter
  -                     * @return       Description of the Returned Value
  -                     */
  -                     public boolean accept(File file)
  -                     {
  -                             return file.getName().endsWith(".jar");
  -                     }
  -             };
  -             Collection jarFiles = recursiveFind(unpackedDir, filter);
  -             category.debug("Adding the following URLs to classpath:");
  -             for (Iterator i = jarFiles.iterator(); i.hasNext(); )
  -             {
  -                     File file = (File)i.next();
  -                     URL jarUrl = file.toURL();
  -                     jars.add(jarUrl);
  -                     category.debug(jarUrl.toString());
  -             }
  -             
  -             // Ok, now we have the URLs of the JARs contained in the RAR we
  -             // can create a classloader that loads classes from them
  -             
  -             ClassLoader cl = new URLClassLoader(
  -                     (URL[])jars.toArray(new URL[0]),
  -                     Thread.currentThread().getContextClassLoader());
  -             
  -             metadata.setClassLoader(cl);
  -             
  -             // Let's tell the waiting hordes (of connection factory loaders)
  -             // that this resource adapter is available
  -             
  -             Notification notification = new Notification(
  -                     ConnectionFactoryLoaderMBean.DEPLOYMENT_NOTIFICATION +
  -                     ConnectionFactoryLoaderMBean.DEPLOY_NOTIFICATION, this,
  -                     nextMessageNum++, metadata.getDisplayName());
  -             notification.setUserData(metadata);
  -             sendNotification(notification);
  -             
  -             DeploymentInfo info = new DeploymentInfo();
  -             info.metadata = metadata;
  -             info.unpackedDir = unpackedDir;
  -             return info;
  -     }
  -     
  -     protected void undeploy(URL url, Object o)
  -     throws DeploymentException
  -     {
  -             category.info("Undeploying RAR at '" + url + "'");
  -             
  -             DeploymentInfo info = (DeploymentInfo)o;
  -             
  -             if (info == null)
  -             {
  -                     throw new DeploymentException("There doesn't appear to be a 
RAR " +
  -                             "deployed at '" + url + "'");
  -             }
  -             
  -             // Tell the waiting hordes (of connection factory loaders)
  -             // that this resource adapter is no longer available
  -             
  -             RARMetaData metadata = info.metadata;
  -             Notification notification = new Notification(
  -                     ConnectionFactoryLoaderMBean.DEPLOYMENT_NOTIFICATION +
  -                     ConnectionFactoryLoaderMBean.UNDEPLOY_NOTIFICATION, this,
  -                     nextMessageNum++, metadata.getDisplayName());
  -             sendNotification(notification);
  -             
  -             // Remove the temporary copy
  -             
  -             File unpackedDir = info.unpackedDir;
  -             if (!recursiveDelete(unpackedDir))
  -             {
  -                     category.warn("Unable to recursively delete temp directory '" +
  -                             unpackedDir + "' - this should be cleaned up either " +
  -                             "when the server is shut down or when it restarts.");
  -             }
  -     }
  -     
  -     private Collection recursiveFind(File dir, FileFilter filter)
  -     {
  -             Collection files = new ArrayList();
  -             File[] candidates = dir.listFiles();
  -             if (candidates == null)
  -             {
  -                     return null;
  -             }
  -             
  -             for (int i = 0; i < candidates.length; ++i)
  -             {
  -                     File candidate = candidates[i];
  -                     if (candidate.isDirectory())
  -                     {
  -                             files.addAll(recursiveFind(candidate, filter));
  -                     }
  -                     else if (filter.accept(candidate))
  -                     {
  -                             files.add(candidate);
  -                     }
  -             }
  -             
  -             return files;
  -     }
  -     
  -     private void copyDirectory(File srcDir, File destDir)
  -     throws DeploymentException, IOException
  -     {
  -             File[] files = srcDir.listFiles();
  -             if (files == null)
  -             {
  -                     throw new DeploymentException("Not a directory: '" +
  -                             srcDir + "'");
  -             }
  -             
  -             destDir.mkdirs();
  -             for (int i = 0; i < files.length; ++i)
  -             {
  -                     File file = files[i];
  -                     File dest = new File(destDir, file.getName());
  -                     if (file.isDirectory())
  -                     {
  -                             copyDirectory(file, dest);
  -                     }
  -                     else
  -                     {
  -                             copyFile(file, dest);
  -                     }
  -             }
  -     }
  -     
  -     private void copyFile(File src, File dest)
  -     throws IOException
  -     {
  -             InputStream in = new FileInputStream(src);
  -             try
  -             {
  -                     OutputStream out = new FileOutputStream(dest);
  -                     try
  -                     {
  -                             copy(in, out);
  -                     }
  -                     finally
  -                     {
  -                             out.close();
  -                     }
  -             }
  -             finally
  -             {
  -                     in.close();
  -             }
  -     }
  -     
  -     private void inflateJar(URL url, File destDir)
  -     throws DeploymentException, IOException
  -     {
  -             URL jarUrl;
  -             try
  -             {
  -                     jarUrl = new URL("jar:" + url.toString() + "!/");
  -             }
  -             catch (MalformedURLException mfue)
  -             {
  -                     throw new DeploymentException("Oops! Couldn't convert URL to a 
" +
  -                             "jar URL", mfue);
  -             }
  -             
  -             JarURLConnection jarConnection =
  -             (JarURLConnection)jarUrl.openConnection();
  -             JarFile jarFile = jarConnection.getJarFile();
  -             
  -             try
  -             {
  -                     for (Enumeration e = jarFile.entries(); e.hasMoreElements(); )
  -                     {
  -                             JarEntry entry = (JarEntry)e.nextElement();
  -                             String name = entry.getName();
  -                             File outFile = new File(destDir, name);
  -                             if (entry.isDirectory())
  -                             {
  -                                     outFile.mkdirs();
  -                             }
  -                             else
  -                             {
  -                                     InputStream in = jarFile.getInputStream(entry);
  -                                     try
  -                                     {
  -                                             OutputStream out = new 
FileOutputStream(outFile);
  -                                             try
  -                                             {
  -                                                     copy(in, out);
  -                                             }
  -                                             finally
  -                                             {
  -                                                     out.close();
  -                                             }
  -                                     }
  -                                     finally
  -                                     {
  -                                             in.close();
  -                                     }
  -                             }
  -                     }
  -             }
  -             finally
  -             {
  -                     jarFile.close();
  -             }
  -     }
  -     
  -     private void copy(InputStream in, OutputStream out)
  -     throws IOException
  -     {
  -             byte[] buffer = new byte[1024];
  -             int read;
  -             while ((read = in.read(buffer)) > 0)
  -             {
  -                     out.write(buffer, 0, read);
  -             }
  -     }
  -     
  -     private boolean recursiveDelete(File f)
  -     {
  -             if (f.isDirectory())
  -             {
  -                     File[] files = f.listFiles();
  -                     for (int i = 0; i < files.length; ++i)
  -                     {
  -                             if (!recursiveDelete(files[i]))
  -                             {
  -                                     return false;
  -                             }
  -                     }
  -             }
  -             return f.delete();
  -     }
  -     
  -     // Inner classes -------------------------------------------------
  -     
  -     /**
  -     * 
  -     */
  -     private static class DeploymentInfo
  -     {
  -             public RARMetaData metadata;
  -             public File unpackedDir;
  -     }
  +
  +   // Package protected ---------------------------------------------
  +
  +   // Protected -----------------------------------------------------
  +
  +   // Private -------------------------------------------------------
  +
  +   private static int nextNum = 0;
  +   // Constants -----------------------------------------------------
  +
  +   // Attributes ----------------------------------------------------
  +
  +   /*
  +    * log4j Category for logging
  +    */
  +   private JBossCategory category = 
(JBossCategory)JBossCategory.getInstance(RARDeployer.class);
  +
  +   /**
  +    *  The directory that will contain local copies of deployed RARs
  +    */
  +   private File rarTmpDir;
  +
  +   /**
  +    *  The next sequence number to be used in notifications about (un)deployment
  +    */
  +   private int nextMessageNum = 0;
  +
  +   private static String generateUniqueDirName(URL u)
  +   {
  +      int thisNum = nextNum++;
  +      return "rar." + thisNum;
  +   }
  +
  +   // Static --------------------------------------------------------
  +
  +   // Constructors --------------------------------------------------
  +
  +   // Public --------------------------------------------------------
  +
  +   /**
  +    *  Gets the DeployableFilter attribute of the RARDeployer object
  +    *
  +    * @return    The DeployableFilter value
  +    */
  +   public FilenameFilter getDeployableFilter()
  +   {
  +      return
  +         new FilenameFilter()
  +         {
  +            /**
  +             *  #Description of the Method
  +             *
  +             * @param  dir       Description of Parameter
  +             * @param  filename  Description of Parameter
  +             * @return           Description of the Returned Value
  +             */
  +            public boolean accept(File dir, String filename)
  +            {
  +               return filename.endsWith(".rar");
  +            }
  +         };
  +   }
  +
  +   // RARDeployerMBean implementation -------------------------------
  +
  +   // DeployerMBeanSupport overrides ---------------------------------
  +
  +   /**
  +    *  Gets the Name attribute of the RARDeployer object
  +    *
  +    * @return    The Name value
  +    */
  +   public String getName()
  +   {
  +      return "RARDeployer";
  +   }
  +
  +   /**
  +    *  Gets the MetaData attribute of the RARDeployer object
  +    *
  +    * @param  resourceAdapterName  Description of Parameter
  +    * @return                      The MetaData value
  +    */
  +   public RARMetaData getMetaData(String resourceAdapterName)
  +   {
  +      Collection dis = getDeployments().values();
  +      Iterator i = dis.iterator();
  +      while (i.hasNext())
  +      {
  +         DeploymentInfo di = (DeploymentInfo)i.next();
  +         if (di.metadata.getDisplayName().equals(resourceAdapterName))
  +         {
  +            return di.metadata;
  +         }
  +      }
  +      return null;
  +   }
  +
  +   /**
  +    *  #Description of the Method
  +    *
  +    * @exception  Exception  Description of Exception
  +    */
  +   public void initService()
  +          throws Exception
  +   {
  +      // find the temp directory - referenced to jboss.system.home property
  +      File jbossHomeDir = new File(System.getProperty("jboss.system.home"));
  +      File tmpDir = new File(jbossHomeDir, "tmp"+File.separator);
  +
  +      // Create our temp directory
  +      File deployTmpDir = new File(tmpDir, "deploy");
  +      rarTmpDir = new File(deployTmpDir, getName());
  +      if (rarTmpDir.exists())
  +      {
  +         category.info("Found a temp directory left over from a previous run - " +
  +               "deleting it.");
  +         // What could it mean?
  +         if (!recursiveDelete(rarTmpDir))
  +         {
  +            category.warn("Unable to recursively delete temp directory '" +
  +                  rarTmpDir + "' that appears to be left over from " +
  +                  "the previous run. This might cause problems.");
  +         }
  +      }
  +      if (!rarTmpDir.exists() && !rarTmpDir.mkdirs())
  +      {
  +         throw new DeploymentException("Can't create temp directory '" +
  +               rarTmpDir + "'");
  +      }
  +   }
  +
  +   /**
  +    *  #Description of the Method
  +    */
  +   public void destroyService()
  +   {
  +      // Remove our temp directory
  +      if (!recursiveDelete(rarTmpDir))
  +      {
  +         category.warn("Unable to recursively delete the temp directory '" +
  +               rarTmpDir + "' - it should be cleaned up when the " +
  +               "server is next restarted.");
  +      }
  +   }
  +
  +   protected Object deploy(URL url)
  +          throws IOException, DeploymentException
  +   {
  +      category.info("Attempting to deploy RAR at '" + url + "'");
  +
  +      // We want to take a local copy of the RAR so that we don't run
  +      // into problems if the original is removed/replaced. We also
  +      // need the RAR in unpacked form so that we can get at the
  +      // included JARs for classloading (I don't think URLClassLoader
  +      // deals with JARs within JARs).
  +
  +      String unpackedDirName = generateUniqueDirName(url);
  +      File unpackedDir = new File(rarTmpDir, unpackedDirName);
  +      if (unpackedDir.exists())
  +      {
  +         throw new DeploymentException("The application at URL '" + url + "' " +
  +               "appears to already have been " +
  +               "deployed because the directory '" +
  +               unpackedDir + "' exists");
  +      }
  +      unpackedDir.mkdirs();
  +
  +      if (url.getFile().endsWith("/"))
  +      {
  +         // this is a directory - we can only deal with directories in
  +         // the local filesystem (because we can't get a list of files
  +         // from a general URL)
  +         if (!url.getProtocol().equals("file"))
  +         {
  +            throw new DeploymentException("Can only deploy directories " +
  +                  "specified by 'file:' URLs");
  +         }
  +         copyDirectory(new File(url.getFile()), unpackedDir);
  +      }
  +      else
  +      {
  +         // this is a .rar file somewhere so we copy it to the temp
  +         // dir because otherwise we run into problems when we try to
  +         // open it again later
  +         File copyFile = new File(rarTmpDir, "copy" + unpackedDirName);
  +         InputStream input = url.openStream();
  +         try
  +         {
  +            OutputStream output = new FileOutputStream(copyFile);
  +            try
  +            {
  +               copy(input, output);
  +            }
  +            finally
  +            {
  +               output.close();
  +            }
  +         }
  +         finally
  +         {
  +            input.close();
  +         }
  +         // then we can inflate the copy without fear of retribution
  +         inflateJar(copyFile.toURL(), unpackedDir);
  +      }
  +
  +      // Right, now we can forget about URLs and just use the file
  +      // system.
  +
  +      File ddFile = new File(unpackedDir, "META-INF/ra.xml");
  +
  +      if (!ddFile.exists())
  +      {
  +         throw new DeploymentException("No deployment descriptor " +
  +               "('META-INF/ra.xml') found in alleged " +
  +               "resource adapter at '" + url + "'");
  +      }
  +
  +      Document dd;
  +      try
  +      {
  +         dd = XmlFileLoader.getDocument(ddFile.toURL());
  +      }
  +      catch (org.jboss.ejb.DeploymentException de)
  +      {
  +         throw new DeploymentException(de.getMessage(), de.getCause());
  +      }
  +
  +      Element root = dd.getDocumentElement();
  +
  +      RARMetaData metadata = new RARMetaData();
  +      metadata.importXml(root);
  +
  +      // Create a class loader that can load classes from any JARs
  +      // inside the RAR. First, we need to find the JARs.
  +
  +      Collection jars = new ArrayList();
  +
  +      FileFilter filter =
  +         new FileFilter()
  +         {
  +            /**
  +             *  #Description of the Method
  +             *
  +             * @param  file  Description of Parameter
  +             * @return       Description of the Returned Value
  +             */
  +            public boolean accept(File file)
  +            {
  +               return file.getName().endsWith(".jar");
  +            }
  +         };
  +      Collection jarFiles = recursiveFind(unpackedDir, filter);
  +      category.debug("Adding the following URLs to classpath:");
  +      for (Iterator i = jarFiles.iterator(); i.hasNext(); )
  +      {
  +         File file = (File)i.next();
  +         URL jarUrl = file.toURL();
  +         jars.add(jarUrl);
  +         category.debug(jarUrl.toString());
  +      }
  +
  +      // Ok, now we have the URLs of the JARs contained in the RAR we
  +      // can create a classloader that loads classes from them
  +
  +      ClassLoader cl = new URLClassLoader(
  +            (URL[])jars.toArray(new URL[0]),
  +            Thread.currentThread().getContextClassLoader());
  +
  +      metadata.setClassLoader(cl);
  +
  +      // Let's tell the waiting hordes (of connection factory loaders)
  +      // that this resource adapter is available
  +
  +      Notification notification = new Notification(
  +            ConnectionFactoryLoaderMBean.DEPLOYMENT_NOTIFICATION +
  +            ConnectionFactoryLoaderMBean.DEPLOY_NOTIFICATION, this,
  +            nextMessageNum++, metadata.getDisplayName());
  +      notification.setUserData(metadata);
  +      sendNotification(notification);
  +
  +      DeploymentInfo info = new DeploymentInfo();
  +      info.metadata = metadata;
  +      info.unpackedDir = unpackedDir;
  +      return info;
  +   }
  +
  +   protected void undeploy(URL url, Object o)
  +          throws DeploymentException
  +   {
  +      category.info("Undeploying RAR at '" + url + "'");
  +
  +      DeploymentInfo info = (DeploymentInfo)o;
  +
  +      if (info == null)
  +      {
  +         throw new DeploymentException("There doesn't appear to be a RAR " +
  +               "deployed at '" + url + "'");
  +      }
  +
  +      // Tell the waiting hordes (of connection factory loaders)
  +      // that this resource adapter is no longer available
  +
  +      RARMetaData metadata = info.metadata;
  +      Notification notification = new Notification(
  +            ConnectionFactoryLoaderMBean.DEPLOYMENT_NOTIFICATION +
  +            ConnectionFactoryLoaderMBean.UNDEPLOY_NOTIFICATION, this,
  +            nextMessageNum++, metadata.getDisplayName());
  +      sendNotification(notification);
  +
  +      // Remove the temporary copy
  +
  +      File unpackedDir = info.unpackedDir;
  +      if (!recursiveDelete(unpackedDir))
  +      {
  +         category.warn("Unable to recursively delete temp directory '" +
  +               unpackedDir + "' - this should be cleaned up either " +
  +               "when the server is shut down or when it restarts.");
  +      }
  +   }
  +
  +   private Collection recursiveFind(File dir, FileFilter filter)
  +   {
  +      Collection files = new ArrayList();
  +      File[] candidates = dir.listFiles();
  +      if (candidates == null)
  +      {
  +         return null;
  +      }
  +
  +      for (int i = 0; i < candidates.length; ++i)
  +      {
  +         File candidate = candidates[i];
  +         if (candidate.isDirectory())
  +         {
  +            files.addAll(recursiveFind(candidate, filter));
  +         }
  +         else if (filter.accept(candidate))
  +         {
  +            files.add(candidate);
  +         }
  +      }
  +
  +      return files;
  +   }
  +
  +   private void copyDirectory(File srcDir, File destDir)
  +          throws DeploymentException, IOException
  +   {
  +      File[] files = srcDir.listFiles();
  +      if (files == null)
  +      {
  +         throw new DeploymentException("Not a directory: '" +
  +               srcDir + "'");
  +      }
  +
  +      destDir.mkdirs();
  +      for (int i = 0; i < files.length; ++i)
  +      {
  +         File file = files[i];
  +         File dest = new File(destDir, file.getName());
  +         if (file.isDirectory())
  +         {
  +            copyDirectory(file, dest);
  +         }
  +         else
  +         {
  +            copyFile(file, dest);
  +         }
  +      }
  +   }
  +
  +   private void copyFile(File src, File dest)
  +          throws IOException
  +   {
  +      InputStream in = new FileInputStream(src);
  +      try
  +      {
  +         OutputStream out = new FileOutputStream(dest);
  +         try
  +         {
  +            copy(in, out);
  +         }
  +         finally
  +         {
  +            out.close();
  +         }
  +      }
  +      finally
  +      {
  +         in.close();
  +      }
  +   }
  +
  +   private void inflateJar(URL url, File destDir)
  +          throws DeploymentException, IOException
  +   {
  +      URL jarUrl;
  +      try
  +      {
  +         jarUrl = new URL("jar:" + url.toString() + "!/");
  +      }
  +      catch (MalformedURLException mfue)
  +      {
  +         throw new DeploymentException("Oops! Couldn't convert URL to a " +
  +               "jar URL", mfue);
  +      }
  +
  +      JarURLConnection jarConnection =
  +            (JarURLConnection)jarUrl.openConnection();
  +      JarFile jarFile = jarConnection.getJarFile();
  +
  +      try
  +      {
  +         for (Enumeration e = jarFile.entries(); e.hasMoreElements(); )
  +         {
  +            JarEntry entry = (JarEntry)e.nextElement();
  +            String name = entry.getName();
  +            File outFile = new File(destDir, name);
  +            if (entry.isDirectory())
  +            {
  +               outFile.mkdirs();
  +            }
  +            else
  +            {
  +               InputStream in = jarFile.getInputStream(entry);
  +               try
  +               {
  +                  OutputStream out = new FileOutputStream(outFile);
  +                  try
  +                  {
  +                     copy(in, out);
  +                  }
  +                  finally
  +                  {
  +                     out.close();
  +                  }
  +               }
  +               finally
  +               {
  +                  in.close();
  +               }
  +            }
  +         }
  +      }
  +      finally
  +      {
  +         jarFile.close();
  +      }
  +   }
  +
  +   private void copy(InputStream in, OutputStream out)
  +          throws IOException
  +   {
  +      byte[] buffer = new byte[1024];
  +      int read;
  +      while ((read = in.read(buffer)) > 0)
  +      {
  +         out.write(buffer, 0, read);
  +      }
  +   }
  +
  +   private boolean recursiveDelete(File f)
  +   {
  +      if (f.isDirectory())
  +      {
  +         File[] files = f.listFiles();
  +         for (int i = 0; i < files.length; ++i)
  +         {
  +            if (!recursiveDelete(files[i]))
  +            {
  +               return false;
  +            }
  +         }
  +      }
  +      return f.delete();
  +   }
  +
  +   // Inner classes -------------------------------------------------
  +
  +   /**
  +    */
  +   private static class DeploymentInfo
  +   {
  +      public RARMetaData metadata;
  +      public File unpackedDir;
  +   }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to