[jboss-cvs] JBossAS SVN: r90784 - projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 2 15:22:37 EDT 2009


Author: jesper.pedersen
Date: 2009-07-02 15:22:37 -0400 (Thu, 02 Jul 2009)
New Revision: 90784

Added:
   projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JarFilter.java
Modified:
   projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/RADeployer.java
   projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/RADeployment.java
Log:
[JBJCA-100] SJC/RADeployer: Classloading

Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JarFilter.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JarFilter.java	                        (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JarFilter.java	2009-07-02 19:22:37 UTC (rev 90784)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.sjc.deployers.ra;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+/**
+ * Jar filter
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class JarFilter implements FilenameFilter
+{
+   /**
+    * Accept
+    * @param dir The directory
+    * @param name The name
+    * @return True if accepts; otherwise false
+    */
+   public boolean accept(File dir, String name)
+   {
+      return name.endsWith(".jar");
+   }
+}

Modified: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/RADeployer.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/RADeployer.java	2009-07-02 19:02:27 UTC (rev 90783)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/RADeployer.java	2009-07-02 19:22:37 UTC (rev 90784)
@@ -26,7 +26,12 @@
 import org.jboss.jca.sjc.deployers.Deployment;
 
 import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.LinkedList;
+import java.util.List;
 
 import org.jboss.logging.Logger;
 import org.jboss.metadata.rar.jboss.JBossRA10DefaultNSMetaData;
@@ -84,10 +89,13 @@
          root = f;
       }
 
+      URL[] urls = getUrls(root);
+      URLClassLoader cl = new URLClassLoader(urls, parent);
+
       ConnectorMetaData cmd = getStandardMetaData(root);
       JBossRAMetaData jrmd = getJBossMetaData(root);
 
-      return null;
+      return new RADeployment(f.getName(), cl);
    }
 
    /**
@@ -179,4 +187,31 @@
       
       return result;
    }
+
+   /**
+    * Get the URLs for the directory and all libraries located in the directory
+    * @param directrory The directory
+    * @return The URLs
+    * @exception MalformedURLException MalformedURLException
+    * @exception IOException IOException
+    */
+   private static URL[] getUrls(File directory) throws MalformedURLException, IOException
+   {
+      List<URL> list = new LinkedList<URL>();
+
+      if (directory.exists() && directory.isDirectory())
+      {
+         // Add directory
+         list.add(directory.toURI().toURL());
+
+         // Add the contents of the directory too
+         File[] jars = directory.listFiles(new JarFilter());
+
+         for (int j = 0; jars != null && j < jars.length; j++)
+         {
+            list.add(jars[j].getCanonicalFile().toURI().toURL());
+         }
+      }
+      return list.toArray(new URL[list.size()]);      
+   }
 }

Modified: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/RADeployment.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/RADeployment.java	2009-07-02 19:02:27 UTC (rev 90783)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/RADeployment.java	2009-07-02 19:22:37 UTC (rev 90784)
@@ -24,6 +24,9 @@
 
 import org.jboss.jca.sjc.deployers.Deployment;
 
+import java.io.Closeable;
+import java.io.IOException;
+
 /**
  * A resource adapter deployment for JCA/SJC
  * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
@@ -64,4 +67,22 @@
    {
       return cl;
    }
+
+   /**
+    * Destroy
+    */
+   public void destroy()
+   {
+      if (cl != null && cl instanceof Closeable)
+      {
+         try
+         {
+            ((Closeable)cl).close();
+         }
+         catch (IOException ioe)
+         {
+            // Swallow
+         }
+      }
+   }
 }




More information about the jboss-cvs-commits mailing list