[jboss-cvs] JBossAS SVN: r91302 - in projects/jboss-jca/trunk: sjc and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 15 11:59:53 EDT 2009
Author: jesper.pedersen
Date: 2009-07-15 11:59:53 -0400 (Wed, 15 Jul 2009)
New Revision: 91302
Added:
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/Annotation.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/AnnotationScanner.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/ClassScanner.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/ExtensionScanner.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/JarScanner.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/package.html
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/DeployException.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/Annotations.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/Metadata.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/ExtractUtil.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/JarFilter.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/package.html
projects/jboss-jca/trunk/sjc/src/main/resources/sjc-services-manifest.mf
Removed:
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/ExtractUtil.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JarFilter.java
Modified:
projects/jboss-jca/trunk/ivy.xml
projects/jboss-jca/trunk/sjc/build.xml
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/Main.java
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/SecurityActions.java
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/SecurityActions.java
projects/jboss-jca/trunk/tools/checkstyle/checkstyle.xml
Log:
[JBJCA-101] SJC/RADeployer: Annotations (Part 1)
Modified: projects/jboss-jca/trunk/ivy.xml
===================================================================
--- projects/jboss-jca/trunk/ivy.xml 2009-07-15 15:21:31 UTC (rev 91301)
+++ projects/jboss-jca/trunk/ivy.xml 2009-07-15 15:59:53 UTC (rev 91302)
@@ -38,7 +38,7 @@
<dependencies>
<dependency org="apache-log4j" name="log4j" rev="${version.apache-log4j}" conf="standalone->default;sjc->*"/>
<dependency org="apache-logging" name="commons-logging" rev="${version.apache-logging}" conf="*"/>
- <dependency org="javassist" name="javassist" rev="${version.javassist}" conf="standalone->default"/>
+ <dependency org="javassist" name="javassist" rev="${version.javassist}" conf="standalone->default;sjc->*"/>
<dependency org="javax.xml.bind" name="jaxb-api" rev="${version.jaxb.api}" conf="standalone->default;sjc->*"/>
<dependency org="javax.xml" name="jaxb-impl" rev="${version.jaxb.impl}" conf="standalone->default;sjc->*"/>
<dependency org="javax.activation" name="activation" rev="${version.activation}" conf="standalone->default;sjc->*"/>
Modified: projects/jboss-jca/trunk/sjc/build.xml
===================================================================
--- projects/jboss-jca/trunk/sjc/build.xml 2009-07-15 15:21:31 UTC (rev 91301)
+++ projects/jboss-jca/trunk/sjc/build.xml 2009-07-15 15:59:53 UTC (rev 91302)
@@ -82,7 +82,12 @@
<jar destfile="${target.dir}/jboss-jca-sjc.jar"
manifest="src/main/resources/sjc-manifest.mf"
basedir="${build.sjc.dir}/impl"
- excludes="**/*.java,**/ra/**"/>
+ excludes="**/*.java,**/annotationscanner/**,,**/hack/**,**/ra/**,**/util/**"/>
+ <jar destfile="${target.dir}/jboss-jca-sjc-services.jar"
+ manifest="src/main/resources/sjc-services-manifest.mf"
+ basedir="${build.sjc.dir}/impl"
+ includes="**/annotationscanner/**,**/hack/**,**/util/**"
+ excludes="**/*.java"/>
<jar destfile="${target.dir}/jboss-jca-sjc-ra-deployer.jar"
manifest="src/main/resources/sjc-ra-manifest.mf"
basedir="${build.sjc.dir}/impl"
Modified: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/Main.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/Main.java 2009-07-15 15:21:31 UTC (rev 91301)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/Main.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -25,14 +25,12 @@
import org.jboss.jca.sjc.boot.BeanType;
import org.jboss.jca.sjc.boot.ConstructorType;
import org.jboss.jca.sjc.boot.InjectType;
-import org.jboss.jca.sjc.boot.ParameterType;
import org.jboss.jca.sjc.boot.PropertyType;
import org.jboss.jca.sjc.deployers.Deployer;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
-import java.io.Serializable;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.MalformedURLException;
@@ -121,7 +119,7 @@
URL[] urls = mergeUrls(libUrls, confUrls);
- containerClassLoader = new URLClassLoader(urls, parent);
+ containerClassLoader = SecurityActions.createURLCLassLoader(urls, parent);
SecurityActions.setThreadContextClassLoader(containerClassLoader);
initLogging(containerClassLoader);
Modified: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/SecurityActions.java 2009-07-15 15:21:31 UTC (rev 91301)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/SecurityActions.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -22,6 +22,8 @@
package org.jboss.jca.sjc;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Properties;
@@ -117,4 +119,21 @@
}
});
}
+
+ /**
+ * Create an URLClassLoader
+ * @param urls The urls
+ * @param parent The parent class loader
+ * @return The class loader
+ */
+ static URLClassLoader createURLCLassLoader(final URL[] urls, final ClassLoader parent)
+ {
+ return (URLClassLoader)AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ return new URLClassLoader(urls, parent);
+ }
+ });
+ }
}
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/Annotation.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/Annotation.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/Annotation.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,81 @@
+/*
+ * 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.annotationscanner;
+
+import org.jboss.logging.Logger;
+
+/**
+ * An annotation for JCA/SJC
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Annotation
+{
+ private static Logger log = Logger.getLogger(Annotation.class);
+
+ private Object a;
+ private Class<?> l;
+
+ /**
+ * Constructor
+ * @param a The annotation
+ * @param l The class where the annotation is located
+ */
+ public Annotation(Object a, Class<?> l)
+ {
+ this.a = a;
+ this.l = l;
+ }
+
+ /**
+ * Get the annotation
+ * @return The annotation
+ */
+ public Object getAnnotation()
+ {
+ return a;
+ }
+
+ /**
+ * Get the location class
+ * @return The class
+ */
+ public Class<?> getLocationClass()
+ {
+ return l;
+ }
+
+ /**
+ * String representation
+ * @return The representation
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb = sb.append(getClass().getName());
+ sb = sb.append("[");
+ sb = sb.append("Annotation=" + a + ",");
+ sb = sb.append("LocationClass=" + l.getName());
+ sb = sb.append("]");
+ return sb.toString();
+ }
+}
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/AnnotationScanner.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/AnnotationScanner.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/AnnotationScanner.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,230 @@
+/*
+ * 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.annotationscanner;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.LoaderClassPath;
+import javassist.NotFoundException;
+
+/**
+ * An annotation scanner for JCA/SJC
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class AnnotationScanner
+{
+ private static Logger log = Logger.getLogger(AnnotationScanner.class);
+ private static boolean trace = log.isTraceEnabled();
+
+ /**
+ * Constructor
+ */
+ private AnnotationScanner()
+ {
+ }
+
+ /**
+ * Scan
+ * @param urls The URLs with class files
+ * @return The map of annotations
+ */
+ public static Map<Class, List<Annotation>> scan(URL[] urls)
+ {
+ Map<Class, List<Annotation>> result = new HashMap<Class, List<Annotation>>();
+
+ long start = System.currentTimeMillis();
+
+ URLClassLoader cl = new URLClassLoader(urls, null);
+
+ ClassPool cp = new ClassPool();
+ cp.appendClassPath(new LoaderClassPath(cl));
+
+ List<String> classes = getClassNames(urls);
+ if (classes != null)
+ {
+ for (String className : classes)
+ {
+ try
+ {
+ CtClass ctClass = cp.get(className);
+ Class clz = ctClass.toClass();
+
+ // Class level annotations
+ Object[] classAnnotations = ctClass.getAvailableAnnotations();
+
+ processAnnotations(classAnnotations, clz, result);
+
+ // Method level annotations
+ CtMethod[] methods = ctClass.getMethods();
+ if (methods != null)
+ {
+ for (CtMethod method : methods)
+ {
+ Object[] methodAnnotations = method.getAvailableAnnotations();
+ processAnnotations(methodAnnotations, clz, result);
+ }
+ }
+
+ // Field level annotations
+ CtField[] fields = ctClass.getFields();
+ if (fields != null)
+ {
+ for (CtField field : fields)
+ {
+ Object[] fieldAnnotations = field.getAvailableAnnotations();
+ processAnnotations(fieldAnnotations, clz, result);
+ }
+ }
+ }
+ catch (CannotCompileException cce)
+ {
+ // Shouldn't happen - nothing we can do
+ }
+ catch (NotFoundException nfe)
+ {
+ // Shouldn't happen - nothing we can do
+ }
+ }
+ }
+
+ if (cl != null && cl instanceof Closeable)
+ {
+ try
+ {
+ ((Closeable)cl).close();
+ }
+ catch (IOException ioe)
+ {
+ // Swallow
+ }
+ }
+
+ log.debug("Scanning took: " + (System.currentTimeMillis() - start) + " ms");
+
+ return result;
+ }
+
+ /**
+ * Get all the class names
+ * @param urls The urls to be scanned
+ * @return The names
+ */
+ private static List<String> getClassNames(URL[] urls)
+ {
+ List<String> result = new ArrayList<String>();
+
+ for (URL url : urls)
+ {
+ try
+ {
+ log.debug("Checking " + url);
+
+ if ("file".equals(url.getProtocol()))
+ {
+ long start = System.currentTimeMillis();
+
+ File f = new File(url.getFile());
+
+ List<String> classFiles = null;
+
+ if (url.getPath().endsWith("/"))
+ {
+ classFiles = ClassScanner.scan(f);
+ }
+ else if (url.getPath().endsWith(".jar"))
+ {
+ classFiles = JarScanner.scan(f);
+ }
+
+ if (classFiles != null)
+ {
+ result.addAll(classFiles);
+ }
+
+ long end = System.currentTimeMillis();
+ log.debug("Retrieving classes took " + (end - start) + " ms for " + url.getFile());
+ }
+ else
+ {
+ log.warn("Protocol not supported: " + url);
+ }
+ }
+ catch (Exception e)
+ {
+ // Nothing we can do
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Add annotations to the map
+ * @param annotations The annotations
+ * @param clz The location class
+ * @param map The result map
+ */
+ private static void processAnnotations(Object[] annotations, Class clz, Map<Class, List<Annotation>> map)
+ {
+ if (annotations != null)
+ {
+ // These are proxy objects
+ for (Object annotation : annotations)
+ {
+ Class annotationClass = annotation.getClass().getInterfaces()[0];
+
+ Annotation a = new Annotation(annotationClass.cast(annotation),
+ clz);
+
+ if (trace)
+ {
+ log.trace("AnnotationClass=" + annotationClass.getName());
+ log.trace("Annotation=" + annotation);
+ log.trace("Located=" + clz.getName());
+ }
+
+ List<Annotation> l = map.get(annotationClass);
+ if (l == null)
+ l = new ArrayList<Annotation>();
+
+ l.add(a);
+ map.put(annotationClass, l);
+ }
+ }
+ }
+}
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/ClassScanner.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/ClassScanner.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/ClassScanner.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,103 @@
+/*
+ * 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.annotationscanner;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Class scanner
+ * @author Jesper Pedersen <jesper.pedersen at jboss.org>
+ */
+public class ClassScanner
+{
+ private static Logger log = Logger.getLogger(ClassScanner.class);
+ private static boolean trace = log.isTraceEnabled();
+
+ /**
+ * Constructor
+ */
+ private ClassScanner()
+ {
+ }
+
+ /**
+ * Scan a directory for class files
+ * @param root The root directory
+ * @return The class names
+ */
+ public static List<String> scan(File root)
+ {
+ List<String> result = new ArrayList<String>();
+
+ try
+ {
+ log.debug("Scanning " + root);
+
+ String rootPath = root.getCanonicalPath();
+
+ List<File> classFiles = ExtensionScanner.scan(root, ".class");
+
+ if (classFiles != null)
+ {
+ for (File classFile : classFiles)
+ {
+ try
+ {
+ String className = classFile.getCanonicalPath();
+
+ if (className.startsWith(rootPath))
+ {
+ className = className.substring(rootPath.length() + 1);
+ }
+
+ if (className.endsWith(".class"))
+ {
+ className = className.substring(0, className.lastIndexOf(".class"));
+ }
+
+ className = className.replace(File.separatorChar, '.');
+
+ if (trace)
+ log.trace("Class=" + className);
+
+ result.add(className);
+ }
+ catch (Exception e)
+ {
+ // Nothing we can do
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ }
+
+ return result;
+ }
+}
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/ExtensionScanner.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/ExtensionScanner.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/ExtensionScanner.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,115 @@
+/*
+ * 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.annotationscanner;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Extension scanner
+ * @author Jesper Pedersen <jesper.pedersen at jboss.org>
+ */
+public class ExtensionScanner
+{
+
+ /**
+ * Constructor
+ */
+ private ExtensionScanner()
+ {
+ }
+
+ /**
+ * Scan a directory for files
+ * @param root The root directory
+ * @param extension The file extension
+ * @return The list of files
+ */
+ public static List<File> scan(File root, String extension)
+ {
+ try
+ {
+ return getFileListing(root, extension);
+ }
+ catch (Exception e)
+ {
+ System.err.println(e.getMessage());
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Recursively walk a directory tree and return a List of all
+ * Files found; the List is sorted using File.compareTo().
+ * @param aStartingDir is a valid directory, which can be read.
+ * @param extension The file extension
+ * @return The list of files
+ * @exception Exception Thrown if an error occurs
+ */
+ private static List<File> getFileListing(File aStartingDir, String extension) throws Exception
+ {
+ List<File> result = getFileListingNoSort(aStartingDir, extension);
+ Collections.sort(result);
+ return result;
+ }
+
+ /**
+ * Recursively walk a directory tree and return a List of all
+ * Files found; the List is sorted using File.compareTo().
+ * @param aStartingDir is a valid directory, which can be read.
+ * @param extension The file extension
+ * @return The list of files
+ * @exception Exception Thrown if an error occurs
+ */
+ private static List<File> getFileListingNoSort(File aStartingDir, String extension) throws Exception
+ {
+ List<File> result = new ArrayList<File>();
+
+ File[] filesAndDirs = aStartingDir.listFiles();
+
+ List<File> filesDirs = Arrays.asList(filesAndDirs);
+
+ for (File file : filesDirs)
+ {
+ if (file.isFile())
+ {
+ if (file.getName().endsWith(extension))
+ {
+ result.add(file);
+ }
+ }
+ else if (file.isDirectory())
+ {
+ List<File> deeperList = getFileListingNoSort(file, extension);
+ result.addAll(deeperList);
+ }
+ }
+
+ return result;
+ }
+}
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/JarScanner.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/JarScanner.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/JarScanner.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,113 @@
+/*
+ * 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.annotationscanner;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Jar scanner
+ * @author Jesper Pedersen <jesper.pedersen at jboss.org>
+ */
+public class JarScanner
+{
+ private static Logger log = Logger.getLogger(JarScanner.class);
+ private static boolean trace = log.isTraceEnabled();
+
+ /**
+ * Constructor
+ */
+ private JarScanner()
+ {
+ }
+
+ /**
+ * Scan a directory for JAR files
+ * @param root The root directory
+ * @return The class names
+ */
+ public static List<String> scan(File root)
+ {
+ List<String> result = new ArrayList<String>();
+
+ try
+ {
+ log.debug("Scanning " + root);
+
+ List<File> jarFiles = null;
+ if (root.isFile())
+ {
+ jarFiles = new ArrayList<File>();
+ jarFiles.add(root);
+ }
+ else
+ {
+ jarFiles = ExtensionScanner.scan(root, ".jar");
+ }
+
+ for (File jarFile : jarFiles)
+ {
+ try
+ {
+ JarFile jar = new JarFile(jarFile);
+ Enumeration<JarEntry> entries = jar.entries();
+
+ while (entries.hasMoreElements())
+ {
+ JarEntry je = entries.nextElement();
+ String name = je.getName();
+
+ if (name.endsWith(".class"))
+ {
+ name = name.replace('/', '.');
+ name = name.substring(0, name.lastIndexOf(".class"));
+
+ if (trace)
+ log.trace("Class=" + name);
+
+ result.add(name);
+ }
+ }
+
+ jar.close();
+ }
+ catch (Exception e)
+ {
+ // Nothing we can do
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ }
+
+ return result;
+ }
+}
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/package.html
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/package.html (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/annotationscanner/package.html 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,3 @@
+<body>
+This package contains an annotation scanner.
+</body>
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/DeployException.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/DeployException.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/DeployException.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+/**
+ * The deploy exception for JCA/SJC
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class DeployException extends Exception
+{
+ /** Serial version UID */
+ static final long serialVersionUID = 3820032266224196804L;
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ * @param message The message
+ */
+ public DeployException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ * @param message The message
+ * @param cause The cause
+ */
+ public DeployException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/Annotations.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/Annotations.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/Annotations.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,407 @@
+/*
+ * 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 org.jboss.jca.sjc.annotationscanner.Annotation;
+import org.jboss.jca.sjc.deployers.DeployException;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.resource.spi.Activation;
+import javax.resource.spi.AdministeredObject;
+import javax.resource.spi.AuthenticationMechanism;
+import javax.resource.spi.ConfigProperty;
+import javax.resource.spi.ConnectionDefinition;
+import javax.resource.spi.ConnectionDefinitions;
+import javax.resource.spi.Connector;
+import javax.resource.spi.SecurityPermission;
+
+import org.jboss.logging.Logger;
+
+import org.jboss.metadata.rar.spec.ConnectorMetaData;
+import org.jboss.metadata.rar.spec.JCA16MetaData;
+
+/**
+ * The annotation processor for JCA 1.6
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Annotations
+{
+ private static Logger log = Logger.getLogger(Annotations.class);
+ private static boolean trace = log.isTraceEnabled();
+
+ /**
+ * Constructor
+ */
+ private Annotations()
+ {
+ }
+
+ /**
+ * Process annotations
+ * @param md The metadata
+ * @param annotations The annotations
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ public static ConnectorMetaData process(ConnectorMetaData md, Map<Class, List<Annotation>> annotations)
+ throws Exception
+ {
+ /* Process
+ -------
+ javax.resource.spi.Activation
+ javax.resource.spi.AdministeredObject
+ javax.resource.spi.AuthenticationMechanism
+ javax.resource.spi.ConfigProperty
+ javax.resource.spi.ConnectionDefinition
+ javax.resource.spi.ConnectionDefinitions
+ javax.resource.spi.Connector
+ javax.resource.spi.SecurityPermission
+ */
+
+ if (md == null)
+ md = new JCA16MetaData();
+
+ // @Connector
+ md = processConnector(md, annotations);
+
+ // @ConnectionDefinitions
+ md = processConnectionDefinitions(md, annotations);
+
+ // @ConnectionDefinition (outside of @ConnectionDefinitions)
+ md = processConnectionDefinition(md, annotations);
+
+ // @ConfigProperty
+ md = processConfigProperty(md, annotations);
+
+ // @AuthenticationMechanism
+ md = processAuthenticationMechanism(md, annotations);
+
+ // @AdministeredObject
+ md = processAdministeredObject(md, annotations);
+
+ // @Activation
+ md = processActivation(md, annotations);
+
+ return md;
+ }
+
+ /**
+ * Process: @Connector
+ * @param md The metadata
+ * @param annotations The annotations
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData processConnector(ConnectorMetaData md, Map<Class, List<Annotation>> annotations)
+ throws Exception
+ {
+ List<Annotation> values = annotations.get(Connector.class);
+ if (values != null)
+ {
+ if (values.size() == 1)
+ {
+ Annotation annotation = values.get(0);
+ Connector c = (Connector)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + c);
+
+ md = attachConnector(md, c);
+ }
+ else
+ throw new DeployException("More than one @Connector defined");
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @Connector
+ * @param md The metadata
+ * @param c The connector
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData attachConnector(ConnectorMetaData md, Connector c)
+ throws Exception
+ {
+ SecurityPermission[] securityPermissions = c.securityPermissions();
+
+ return md;
+ }
+
+ /**
+ * Process: @ConnectionDefinitions
+ * @param md The metadata
+ * @param annotations The annotations
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData processConnectionDefinitions(ConnectorMetaData md,
+ Map<Class, List<Annotation>> annotations)
+ throws Exception
+ {
+ List<Annotation> values = annotations.get(ConnectionDefinitions.class);
+ if (values != null)
+ {
+ if (values.size() == 1)
+ {
+ Annotation annotation = values.get(0);
+ ConnectionDefinitions c = (ConnectionDefinitions)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + c);
+
+ md = attachConnectionDefinitions(md , c);
+ }
+ else
+ throw new DeployException("More than one @ConnectionDefinitions defined");
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @ConnectionDefinitions
+ * @param md The metadata
+ * @param cds The connection definitions
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData attachConnectionDefinitions(ConnectorMetaData md,
+ ConnectionDefinitions cds)
+ throws Exception
+ {
+ return md;
+ }
+
+ /**
+ * Process: @ConnectionDefinition
+ * @param md The metadata
+ * @param annotations The annotations
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData processConnectionDefinition(ConnectorMetaData md,
+ Map<Class, List<Annotation>> annotations)
+ throws Exception
+ {
+ List<Annotation> values = annotations.get(ConnectionDefinition.class);
+ if (values != null)
+ {
+ for (Annotation annotation : values)
+ {
+ ConnectionDefinition c = (ConnectionDefinition)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + c);
+
+ md = attachConnectionDefinition(md, c);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @ConnectionDefinition
+ * @param md The metadata
+ * @param cd The connection definition
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData attachConnectionDefinition(ConnectorMetaData md,
+ ConnectionDefinition cd)
+ throws Exception
+ {
+ return md;
+ }
+
+ /**
+ * Process: @ConfigProperty
+ * @param md The metadata
+ * @param annotations The annotations
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData processConfigProperty(ConnectorMetaData md,
+ Map<Class, List<Annotation>> annotations)
+ throws Exception
+ {
+ List<Annotation> values = annotations.get(ConfigProperty.class);
+ if (values != null)
+ {
+ for (Annotation annotation : values)
+ {
+ ConfigProperty c = (ConfigProperty)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + c);
+
+ md = attachConfigProperty(md, c);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @ConfigProperty
+ * @param md The metadata
+ * @param configProperty The config property
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData attachConfigProperty(ConnectorMetaData md,
+ ConfigProperty configProperty)
+ throws Exception
+ {
+ return md;
+ }
+
+ /**
+ * Process: @AuthenticationMechanism
+ * @param md The metadata
+ * @param annotations The annotations
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData processAuthenticationMechanism(ConnectorMetaData md,
+ Map<Class, List<Annotation>> annotations)
+ throws Exception
+ {
+ List<Annotation> values = annotations.get(AuthenticationMechanism.class);
+ if (values != null)
+ {
+ for (Annotation annotation : values)
+ {
+ AuthenticationMechanism a = (AuthenticationMechanism)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + a);
+
+ md = attachAuthenticationMechanism(md, a);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @AuthenticationMechanism
+ * @param md The metadata
+ * @param authenticationmechanism The authentication mechanism
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData attachAuthenticationMechanism(ConnectorMetaData md,
+ AuthenticationMechanism authenticationmechanism)
+ throws Exception
+ {
+ return md;
+ }
+
+ /**
+ * Process: @AdministeredObject
+ * @param md The metadata
+ * @param annotations The annotations
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData processAdministeredObject(ConnectorMetaData md,
+ Map<Class, List<Annotation>> annotations)
+ throws Exception
+ {
+ List<Annotation> values = annotations.get(AdministeredObject.class);
+ if (values != null)
+ {
+ for (Annotation annotation : values)
+ {
+ AdministeredObject a = (AdministeredObject)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + a);
+
+ md = attachAdministeredObject(md, a);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @AdministeredObject
+ * @param md The metadata
+ * @param a The administered object
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData attachAdministeredObject(ConnectorMetaData md, AdministeredObject a)
+ throws Exception
+ {
+ return md;
+ }
+
+ /**
+ * Process: @Activation
+ * @param md The metadata
+ * @param annotations The annotations
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData processActivation(ConnectorMetaData md,
+ Map<Class, List<Annotation>> annotations)
+ throws Exception
+ {
+ List<Annotation> values = annotations.get(Activation.class);
+ if (values != null)
+ {
+ for (Annotation annotation : values)
+ {
+ Activation a = (Activation)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + a);
+
+ md = attachActivation(md, a);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @Activation
+ * @param md The metadata
+ * @param activation The activation
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private static ConnectorMetaData attachActivation(ConnectorMetaData md, Activation activation)
+ throws Exception
+ {
+ return md;
+ }
+}
Deleted: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/ExtractUtil.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/ExtractUtil.java 2009-07-15 15:21:31 UTC (rev 91301)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/ExtractUtil.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -1,136 +0,0 @@
-/*
- * 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.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Enumeration;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import org.jboss.logging.Logger;
-
-/**
- * An extract utility for JAR type files
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public class ExtractUtil
-{
- private static Logger log = Logger.getLogger(ExtractUtil.class);
-
- /**
- * Constructor
- */
- private ExtractUtil()
- {
- }
-
- /**
- * Extract a JAR type file
- * @param file The file
- * @param directory The directory where the file should be extracted
- * @return The root of the extracted JAR file
- * @exception IOException Thrown if an error occurs
- */
- public static File extract(File file, File directory) throws IOException
- {
- if (file == null)
- throw new IllegalArgumentException("File is null");
-
- if (directory == null)
- throw new IllegalArgumentException("Directory is null");
-
- File target = new File(directory, file.getName());
-
- if (target.exists())
- recursiveDelete(target);
-
- target.mkdirs();
-
- JarFile jar = new JarFile(file);
- Enumeration<JarEntry> entries = jar.entries();
-
- while (entries.hasMoreElements())
- {
- JarEntry je = entries.nextElement();
- File copy = new File(target, je.getName());
-
- if (!je.isDirectory())
- {
- InputStream in = new BufferedInputStream(jar.getInputStream(je));
- OutputStream out = new BufferedOutputStream(new FileOutputStream(copy));
-
- byte[] buffer = new byte[4096];
- for (;;)
- {
- int nBytes = in.read(buffer);
- if (nBytes <= 0)
- break;
-
- out.write(buffer, 0, nBytes);
- }
- out.flush();
- out.close();
- in.close();
- }
- else
- {
- copy.mkdirs();
- }
- }
-
- return target;
- }
-
- /**
- * Recursive delete
- * @param f The file handler
- */
- public static void recursiveDelete(File f)
- {
- if (f.exists())
- {
- File[] files = f.listFiles();
- if (files != null)
- {
- for (int i = 0; i < files.length; i++)
- {
- if (files[i].isDirectory())
- {
- recursiveDelete(files[i]);
- }
- else
- {
- files[i].delete();
- }
- }
- }
- f.delete();
- }
- }
-}
Deleted: 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 2009-07-15 15:21:31 UTC (rev 91301)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JarFilter.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -1,44 +0,0 @@
-/*
- * 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");
- }
-}
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/Metadata.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/Metadata.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/Metadata.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,150 @@
+/*
+ * 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 org.jboss.logging.Logger;
+import org.jboss.metadata.rar.jboss.JBossRA10DefaultNSMetaData;
+import org.jboss.metadata.rar.jboss.JBossRA10MetaData;
+import org.jboss.metadata.rar.jboss.JBossRAMetaData;
+import org.jboss.metadata.rar.spec.ConnectorMetaData;
+import org.jboss.metadata.rar.spec.JCA15DTDMetaData;
+import org.jboss.metadata.rar.spec.JCA15MetaData;
+import org.jboss.metadata.rar.spec.JCA16DTDMetaData;
+import org.jboss.metadata.rar.spec.JCA16DefaultNSMetaData;
+import org.jboss.metadata.rar.spec.JCA16MetaData;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.resolver.MutableSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+
+/**
+ * The metadata processor for JCA 1.x
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:jeff.zhang at redhat.com">Jeff Zhang</a>
+ */
+public class Metadata
+{
+ private static Logger log = Logger.getLogger(Metadata.class);
+ private static boolean trace = log.isTraceEnabled();
+
+ /**
+ * Constructor
+ */
+ private Metadata()
+ {
+ }
+
+ /**
+ * Get the JCA standard metadata
+ * @param root The root of the deployment
+ * @return The metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ public static ConnectorMetaData getStandardMetaData(File root) throws Exception
+ {
+ ConnectorMetaData result = null;
+
+ UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+ Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+
+ MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+ resolver.mapLocationToClass("connector_1_6.xsd", JCA16MetaData.class);
+ resolver.mapLocationToClass("connector_1_5.xsd", JCA15MetaData.class);
+ resolver.mapLocationToClass("connector_1_5.dtd", JCA15DTDMetaData.class);
+ resolver.mapLocationToClass("connector_1_6.dtd", JCA16DTDMetaData.class);
+ resolver.mapLocationToClass("connector", JCA16DefaultNSMetaData.class);
+
+ File metadataFile = new File(root, "/META-INF/ra.xml");
+
+ if (metadataFile.exists())
+ {
+ String url = metadataFile.getAbsolutePath();
+ try
+ {
+ long start = System.currentTimeMillis();
+
+ result = (ConnectorMetaData)unmarshaller.unmarshal(url, resolver);
+
+ log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
+
+ if (trace)
+ {
+ log.trace("successful parse " + result.getVersion() + " rar package " + result);
+ }
+
+ }
+ catch (Exception e)
+ {
+ log.error("Error during parsing: " + url, e);
+ throw e;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Get the JBoss specific metadata
+ * @param root The root of the deployment
+ * @return The metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ public static JBossRAMetaData getJBossMetaData(File root) throws Exception
+ {
+ JBossRAMetaData result = null;
+
+ UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+ Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+
+ MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+ resolver.mapLocationToClass("http://www.jboss.org/schema/jboss-ra_1_0.xsd", JBossRA10MetaData.class);
+ resolver.mapLocationToClass("jboss-ra", JBossRA10DefaultNSMetaData.class);
+
+ File metadataFile = new File(root, "/META-INF/jboss-ra.xml");
+
+ if (metadataFile.exists())
+ {
+ String url = metadataFile.getAbsolutePath();
+ try
+ {
+ long start = System.currentTimeMillis();
+
+ result = (JBossRAMetaData)unmarshaller.unmarshal(url, resolver);
+
+ log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
+
+ if (trace)
+ log.trace(result);
+ }
+ catch (Exception e)
+ {
+ log.error("Error during parsing: " + url, e);
+ throw e;
+ }
+ }
+
+ return result;
+ }
+}
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-15 15:21:31 UTC (rev 91301)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/RADeployer.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -22,8 +22,12 @@
package org.jboss.jca.sjc.deployers.ra;
+import org.jboss.jca.sjc.annotationscanner.Annotation;
+import org.jboss.jca.sjc.annotationscanner.AnnotationScanner;
import org.jboss.jca.sjc.deployers.Deployer;
import org.jboss.jca.sjc.deployers.Deployment;
+import org.jboss.jca.sjc.util.ExtractUtil;
+import org.jboss.jca.sjc.util.JarFilter;
import java.io.File;
import java.io.IOException;
@@ -32,21 +36,14 @@
import java.net.URLClassLoader;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.jboss.logging.Logger;
-import org.jboss.metadata.rar.jboss.JBossRA10DefaultNSMetaData;
-import org.jboss.metadata.rar.jboss.JBossRA10MetaData;
import org.jboss.metadata.rar.jboss.JBossRAMetaData;
import org.jboss.metadata.rar.spec.ConnectorMetaData;
-import org.jboss.metadata.rar.spec.JCA15DTDMetaData;
-import org.jboss.metadata.rar.spec.JCA15MetaData;
import org.jboss.metadata.rar.spec.JCA16DTDMetaData;
import org.jboss.metadata.rar.spec.JCA16DefaultNSMetaData;
import org.jboss.metadata.rar.spec.JCA16MetaData;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
-import org.jboss.xb.binding.resolver.MutableSchemaResolver;
-import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
/**
* The RA deployer for JCA/SJC
@@ -55,7 +52,6 @@
public class RADeployer implements Deployer
{
private static Logger log = Logger.getLogger(RADeployer.class);
-
private static boolean trace = log.isTraceEnabled();
/**
@@ -90,106 +86,57 @@
{
root = f;
}
-
+
+ // Create classloader
URL[] urls = getUrls(root);
- URLClassLoader cl = new URLClassLoader(urls, parent);
+ URLClassLoader cl = SecurityActions.createURLCLassLoader(urls, parent);
- ConnectorMetaData cmd = getStandardMetaData(root);
- JBossRAMetaData jrmd = getJBossMetaData(root);
+ // Parse metadata
+ ConnectorMetaData cmd = Metadata.getStandardMetaData(root);
+ JBossRAMetaData jrmd = Metadata.getJBossMetaData(root);
- return new RADeployment(f.getName(), cl);
- }
-
- /**
- * Get the JCA standard metadata
- * @param root The root of the deployment
- * @return The metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData getStandardMetaData(File root) throws Exception
- {
- ConnectorMetaData result = null;
-
- UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
- Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
-
- MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
- resolver.mapLocationToClass("connector_1_6.xsd", JCA16MetaData.class);
- resolver.mapLocationToClass("connector_1_5.xsd", JCA15MetaData.class);
- resolver.mapLocationToClass("connector_1_5.dtd", JCA15DTDMetaData.class);
- resolver.mapLocationToClass("connector_1_6.dtd", JCA16DTDMetaData.class);
- resolver.mapLocationToClass("connector", JCA16DefaultNSMetaData.class);
-
- File metadataFile = new File(root, "/META-INF/ra.xml");
-
- if (metadataFile.exists())
+ // Process annotations
+ if (cmd == null || cmd.is16())
{
- String url = metadataFile.getAbsolutePath();
- try
- {
- long start = System.currentTimeMillis();
+ Map<Class, List<Annotation>> annotations = AnnotationScanner.scan(cl.getURLs());
- result = (ConnectorMetaData)unmarshaller.unmarshal(url, resolver);
-
- log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
-
- if (trace)
+ boolean isMetadataComplete = false;
+ if (cmd != null)
+ {
+ if (cmd instanceof JCA16MetaData)
{
- log.trace("successful parse " + result.getVersion() + " rar package " + result);
+ JCA16MetaData jmd = (JCA16MetaData)cmd;
+ isMetadataComplete = jmd.isMetadataComplete();
}
-
+ else if (cmd instanceof JCA16DefaultNSMetaData)
+ {
+ JCA16DefaultNSMetaData jmd = (JCA16DefaultNSMetaData)cmd;
+ isMetadataComplete = jmd.isMetadataComplete();
+ }
+ else if (cmd instanceof JCA16DTDMetaData)
+ {
+ JCA16DTDMetaData jmd = (JCA16DTDMetaData)cmd;
+ isMetadataComplete = jmd.isMetadataComplete();
+ }
}
- catch (Exception e)
- {
- log.error("Error during parsing: " + url, e);
- throw e;
- }
+
+ if (cmd == null || !isMetadataComplete)
+ cmd = Annotations.process(cmd, annotations);
}
-
- return result;
- }
- /**
- * Get the JBoss specific metadata
- * @param root The root of the deployment
- * @return The metadata
- * @exception Exception Thrown if an error occurs
- */
- private JBossRAMetaData getJBossMetaData(File root) throws Exception
- {
- JBossRAMetaData result = null;
+ // Merge metadata
- UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
- Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+ // Validate metadata
- MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
- resolver.mapLocationToClass("http://www.jboss.org/schema/jboss-ra_1_0.xsd", JBossRA10MetaData.class);
- resolver.mapLocationToClass("jboss-ra", JBossRA10DefaultNSMetaData.class);
+ // Create objects
- File metadataFile = new File(root, "/META-INF/jboss-ra.xml");
+ // Inject values
- if (metadataFile.exists())
- {
- String url = metadataFile.getAbsolutePath();
- try
- {
- long start = System.currentTimeMillis();
+ // Bean validation
- result = (JBossRAMetaData)unmarshaller.unmarshal(url, resolver);
-
- log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
+ // Activate deployment
- if (trace)
- log.trace(result);
- }
- catch (Exception e)
- {
- log.error("Error during parsing: " + url, e);
- throw e;
- }
- }
-
- return result;
+ return new RADeployment(f.getName(), cl);
}
/**
@@ -199,7 +146,7 @@
* @exception MalformedURLException MalformedURLException
* @exception IOException IOException
*/
- private static URL[] getUrls(File directory) throws MalformedURLException, IOException
+ private URL[] getUrls(File directory) throws MalformedURLException, IOException
{
List<URL> list = new LinkedList<URL>();
Modified: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/SecurityActions.java 2009-07-15 15:21:31 UTC (rev 91301)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/SecurityActions.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -22,6 +22,8 @@
package org.jboss.jca.sjc.deployers.ra;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Properties;
@@ -117,4 +119,21 @@
}
});
}
+
+ /**
+ * Create an URLClassLoader
+ * @param urls The urls
+ * @param parent The parent class loader
+ * @return The class loader
+ */
+ static URLClassLoader createURLCLassLoader(final URL[] urls, final ClassLoader parent)
+ {
+ return (URLClassLoader)AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ return new URLClassLoader(urls, parent);
+ }
+ });
+ }
}
Copied: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/ExtractUtil.java (from rev 91178, projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/ExtractUtil.java)
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/ExtractUtil.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/ExtractUtil.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,136 @@
+/*
+ * 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.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.jboss.logging.Logger;
+
+/**
+ * An extract utility for JAR type files
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class ExtractUtil
+{
+ private static Logger log = Logger.getLogger(ExtractUtil.class);
+
+ /**
+ * Constructor
+ */
+ private ExtractUtil()
+ {
+ }
+
+ /**
+ * Extract a JAR type file
+ * @param file The file
+ * @param directory The directory where the file should be extracted
+ * @return The root of the extracted JAR file
+ * @exception IOException Thrown if an error occurs
+ */
+ public static File extract(File file, File directory) throws IOException
+ {
+ if (file == null)
+ throw new IllegalArgumentException("File is null");
+
+ if (directory == null)
+ throw new IllegalArgumentException("Directory is null");
+
+ File target = new File(directory, file.getName());
+
+ if (target.exists())
+ recursiveDelete(target);
+
+ target.mkdirs();
+
+ JarFile jar = new JarFile(file);
+ Enumeration<JarEntry> entries = jar.entries();
+
+ while (entries.hasMoreElements())
+ {
+ JarEntry je = entries.nextElement();
+ File copy = new File(target, je.getName());
+
+ if (!je.isDirectory())
+ {
+ InputStream in = new BufferedInputStream(jar.getInputStream(je));
+ OutputStream out = new BufferedOutputStream(new FileOutputStream(copy));
+
+ byte[] buffer = new byte[4096];
+ for (;;)
+ {
+ int nBytes = in.read(buffer);
+ if (nBytes <= 0)
+ break;
+
+ out.write(buffer, 0, nBytes);
+ }
+ out.flush();
+ out.close();
+ in.close();
+ }
+ else
+ {
+ copy.mkdirs();
+ }
+ }
+
+ return target;
+ }
+
+ /**
+ * Recursive delete
+ * @param f The file handler
+ */
+ public static void recursiveDelete(File f)
+ {
+ if (f.exists())
+ {
+ File[] files = f.listFiles();
+ if (files != null)
+ {
+ for (int i = 0; i < files.length; i++)
+ {
+ if (files[i].isDirectory())
+ {
+ recursiveDelete(files[i]);
+ }
+ else
+ {
+ files[i].delete();
+ }
+ }
+ }
+ f.delete();
+ }
+ }
+}
Property changes on: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/ExtractUtil.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/JarFilter.java (from rev 91178, 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/util/JarFilter.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/JarFilter.java 2009-07-15 15:59:53 UTC (rev 91302)
@@ -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.util;
+
+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");
+ }
+}
Property changes on: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/JarFilter.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/package.html
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/package.html (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/util/package.html 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,3 @@
+<body>
+This package contains various utilities for the JBoss JCA/SJC container.
+</body>
Added: projects/jboss-jca/trunk/sjc/src/main/resources/sjc-services-manifest.mf
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/resources/sjc-services-manifest.mf (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/resources/sjc-services-manifest.mf 2009-07-15 15:59:53 UTC (rev 91302)
@@ -0,0 +1,4 @@
+Implementation-Title: JBoss JCA SJC Services
+Implementation-Vendor: Red Hat Middleware LLC
+Implementation-Vendor-Id: org.jboss
+Implementation-Version: 0.1
Modified: projects/jboss-jca/trunk/tools/checkstyle/checkstyle.xml
===================================================================
--- projects/jboss-jca/trunk/tools/checkstyle/checkstyle.xml 2009-07-15 15:21:31 UTC (rev 91301)
+++ projects/jboss-jca/trunk/tools/checkstyle/checkstyle.xml 2009-07-15 15:59:53 UTC (rev 91302)
@@ -103,7 +103,7 @@
<!-- Simplify your code -->
<module name="AvoidStarImport"/>
<module name="RedundantImport"/>
- <!-- <module name="UnusedImports"/> -->
+ <module name="UnusedImports"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
More information about the jboss-cvs-commits
mailing list