[jboss-cvs] JBossAS SVN: r95131 - in projects/annotations/trunk: core/src/main/java/org/jboss/papaki/impl and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 19 14:47:10 EDT 2009


Author: jesper.pedersen
Date: 2009-10-19 14:47:10 -0400 (Mon, 19 Oct 2009)
New Revision: 95131

Removed:
   projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScannerCreator.java
   projects/annotations/trunk/core/src/main/java/org/jboss/papaki/ResourceFilter.java
   projects/annotations/trunk/core/src/main/java/org/jboss/papaki/ScanStrategy.java
Modified:
   projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScanner.java
   projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java
   projects/annotations/trunk/core/src/main/java/org/jboss/papaki/impl/AbstractAnnotationScanner.java
   projects/annotations/trunk/core/src/main/java/org/jboss/papaki/javassistclasspool/JavassistClassPool.java
   projects/annotations/trunk/doc/userguide/en/modules/about.xml
Log:
[JBANN-41] Support existing Configuration in AnnotationScannerFactory

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScanner.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScanner.java	2009-10-19 18:29:38 UTC (rev 95130)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScanner.java	2009-10-19 18:47:10 UTC (rev 95131)
@@ -34,14 +34,21 @@
     * Configure the scanner
     * @return The configuration
     */
-   Configuration configure();
+   public Configuration configure();
 
    /**
+    * Scan using the context class loader to resolve annotation class definitions
+    * @param urls The URLs with the .jar files
+    * @return The annotation repository
+    */
+   public AnnotationRepository scan(URL[] urls);
+
+   /**
     * Scan using the context class loader as well as the additional 
     * classloaders specified to resolve annotation class definitions
     * @param urls The URLs with the .jar files
     * @param cls Additional class loaders
     * @return The annotation repository
     */
-   AnnotationRepository scan(URL[] urls, ClassLoader... cls);
+   public AnnotationRepository scan(URL[] urls, ClassLoader... cls);
 }

Deleted: projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScannerCreator.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScannerCreator.java	2009-10-19 18:29:38 UTC (rev 95130)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScannerCreator.java	2009-10-19 18:47:10 UTC (rev 95131)
@@ -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.papaki;
-
-/**
- * Annotation scanner creator.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-abstract class AnnotationScannerCreator
-{
-   /**
-    * Verify if we can actually use AnnotationScanner created by this creator.
-    */
-   abstract void verify();
-
-   /**
-    * Create AnnotationScanner.
-    *
-    * @param configuration the configuration
-    * @return new AnnotationScanner
-    */
-   abstract AnnotationScanner create(Configuration configuration);
-}

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java	2009-10-19 18:29:38 UTC (rev 95130)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java	2009-10-19 18:47:10 UTC (rev 95131)
@@ -22,34 +22,39 @@
 
 package org.jboss.papaki;
 
+import org.jboss.papaki.javalangreflect.JavaClass;
+import org.jboss.papaki.javassistclasspool.JavassistClassPool;
+import org.jboss.papaki.javassistinputstream.JavassistInputStream;
+
 import java.util.Arrays;
 
 /**
  * An annotation scanner factory
  *
  * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
 public class AnnotationScannerFactory
 {
    /**
     * Javassist using ClassPool
     */
-   public static final int JAVASSIST_CLASS_POOL = ScanStrategy.JAVASSIST_CLASS_POOL.ordinal();
+   public static final int JAVASSIST_CLASS_POOL = 0;
 
    /**
     * Javassist using InputStream
     */
-   public static final int JAVASSIST_INPUT_STREAM = ScanStrategy.JAVASSIST_INPUT_STREAM.ordinal();
+   public static final int JAVASSIST_INPUT_STREAM = 1;
 
    /**
     * java.lang.reflect
     */
-   public static final int JAVA_LANG_REFLECT = ScanStrategy.JAVA_LANG_REFLECT.ordinal();
+   public static final int JAVA_LANG_REFLECT = 2;
 
    /**
     * Default strategy
     */
-   private static ScanStrategy defaultStrategy;
+   private static int defaultStrategy;
 
    /**
     * Is Javassist available
@@ -70,11 +75,11 @@
 
       if (haveJavassist)
       {
-         defaultStrategy = ScanStrategy.JAVASSIST_INPUT_STREAM;
+         defaultStrategy = JAVASSIST_INPUT_STREAM;
       }
       else
       {
-         defaultStrategy = ScanStrategy.JAVA_LANG_REFLECT;
+         defaultStrategy = JAVA_LANG_REFLECT;
       }
    }
 
@@ -92,7 +97,7 @@
     */
    public static AnnotationScanner getDefault()
    {
-      return getStrategy(defaultStrategy.ordinal());
+      return getStrategy(defaultStrategy);
    }
 
    /**
@@ -103,7 +108,7 @@
     */
    public static AnnotationScanner getDefault(Configuration configuration)
    {
-      return getStrategy(defaultStrategy.ordinal(), configuration);
+      return getStrategy(defaultStrategy, configuration);
    }
 
    /**
@@ -126,15 +131,34 @@
     */
    public static AnnotationScanner getStrategy(int strategy, Configuration configuration)
    {
-      ScanStrategy[] strategies = ScanStrategy.values();
-      if (strategy < 0 || strategy >= strategies.length)
+      if (strategy < 0 || strategy > 2)
+         throw new IllegalArgumentException("Unknown strategy key");
+
+      if (strategy == JAVASSIST_CLASS_POOL)
       {
-         String msg = "Unknown strategy key: " + strategy + ", available: " + Arrays.toString(strategies);
-         throw new IllegalArgumentException(msg);
+         if (haveJavassist)
+         {
+            return new JavassistClassPool(configuration);
+         }
+         else
+         {
+            throw new IllegalArgumentException("Javassist not available");
+         }
       }
-
-      ScanStrategy ss = strategies[strategy];
-      ss.verify(); // check if we can use this strategy
-      return ss.create(configuration);
+      else if (strategy == JAVASSIST_INPUT_STREAM)
+      {
+         if (haveJavassist)
+         {
+            return new JavassistInputStream(configuration);
+         }
+         else
+         {
+            throw new IllegalArgumentException("Javassist not available");
+         }
+      }
+      else
+      {
+         return new JavaClass(configuration);
+      }
    }
 }

Deleted: projects/annotations/trunk/core/src/main/java/org/jboss/papaki/ResourceFilter.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/papaki/ResourceFilter.java	2009-10-19 18:29:38 UTC (rev 95130)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/papaki/ResourceFilter.java	2009-10-19 18:47:10 UTC (rev 95131)
@@ -1,41 +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.papaki;
-
-/**
- * Resource filter.
- *
- * TODO - use it :-)
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public interface ResourceFilter
-{
-   /**
-    * Do we accept this resource.
-    *
-    * @param resource the resource
-    * @return true if the resource is accepted, false otherwise
-    */
-   boolean accepts(String resource);
-}

Deleted: projects/annotations/trunk/core/src/main/java/org/jboss/papaki/ScanStrategy.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/papaki/ScanStrategy.java	2009-10-19 18:29:38 UTC (rev 95130)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/papaki/ScanStrategy.java	2009-10-19 18:47:10 UTC (rev 95131)
@@ -1,156 +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.papaki;
-
-import org.jboss.papaki.javalangreflect.JavaClass;
-import org.jboss.papaki.javassistclasspool.JavassistClassPool;
-import org.jboss.papaki.javassistinputstream.JavassistInputStream;
-
-/**
- * Scan strategy.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-enum ScanStrategy
-{
-   /** Javassist class pool  */
-   JAVASSIST_CLASS_POOL(new JavassistClassPoolScannerCreator()),
-   /** Javassist input stream  */
-   JAVASSIST_INPUT_STREAM(new JavassistInputStreamCreator()),
-   /** Plain JDK reflect  */
-   JAVA_LANG_REFLECT(new JavaClassScannerCreator());
-
-   private transient AnnotationScannerCreator creator;
-
-   /**
-    * Ctor.
-    *
-    * @param creator the creator
-    */
-   ScanStrategy(AnnotationScannerCreator creator)
-   {
-      this.creator = creator;
-   }
-
-   /**
-    * Do check.
-    */
-   private static void check()
-   {
-      if (!AnnotationScannerFactory.haveJavassist)
-         throw new IllegalArgumentException("Javassist not available.");
-   }
-
-   /**
-    * Verify.
-    */
-   void verify()
-   {
-      creator.verify();
-   }
-
-   /**
-    * Get scanner.
-    *
-    * @param configuration the configuration
-    * @return new annotation scanner
-    */
-   AnnotationScanner create(Configuration configuration)
-   {
-      return creator.create(configuration);
-   }
-
-   /**
-    * JCPSC
-    */
-   static class JavassistClassPoolScannerCreator extends AnnotationScannerCreator
-   {
-      /**
-       * Verify.
-       */
-      public void verify()
-      {
-         check();
-      }
-
-      /**
-       * Create AnnotationScanner.
-       *
-       * @param configuration the configuration
-       * @return new JavassistCP instance
-       */
-      public AnnotationScanner create(Configuration configuration)
-      {
-         return new JavassistClassPool(configuration);
-      }
-   }
-
-   /**
-    * JISC
-    */
-   static class JavassistInputStreamCreator extends AnnotationScannerCreator
-   {
-      /**
-       * Verify.
-       */
-      public void verify()
-      {
-         check();
-      }
-
-      /**
-       * Create AnnotationScanner.
-       *
-       * @param configuration the configuration
-       * @return new JavassistIS instance
-       */
-      public AnnotationScanner create(Configuration configuration)
-      {
-         return new JavassistInputStream(configuration);
-      }
-   }
-
-   /**
-    * JCSC
-    */
-   static class JavaClassScannerCreator extends AnnotationScannerCreator
-   {
-      /**
-       * Verify.
-       */
-      public void verify()
-      {
-      }
-
-      /**
-       * Create AnnotationScanner.
-       *
-       * @param configuration the configuration
-       * @return new JavaClass instance
-       */
-      public AnnotationScanner create(Configuration configuration)
-      {
-         return new JavaClass(configuration);
-      }
-   }
-}

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/papaki/impl/AbstractAnnotationScanner.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/papaki/impl/AbstractAnnotationScanner.java	2009-10-19 18:29:38 UTC (rev 95130)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/papaki/impl/AbstractAnnotationScanner.java	2009-10-19 18:47:10 UTC (rev 95131)
@@ -22,6 +22,7 @@
 
 package org.jboss.papaki.impl;
 
+import org.jboss.papaki.AnnotationRepository;
 import org.jboss.papaki.AnnotationScanner;
 import org.jboss.papaki.Configuration;
 import org.jboss.papaki.Settings;
@@ -353,4 +354,22 @@
 
       return include;
    }
+
+   /**
+    * Scan
+    * @param urls The URLs with class files
+    * @return The map of annotations
+    */
+   public AnnotationRepository scan(URL[] urls)
+   {
+      return scan(urls, (ClassLoader)null);
+   }
+
+   /**
+    * Scan using additional classloader to resolve annotation class definitions
+    * @param urls The URLs with .class .files
+    * @param cls Additional class loaders
+    * @return The annotation repository
+    */
+   public abstract AnnotationRepository scan(URL[] urls, ClassLoader... cls);
 }

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/papaki/javassistclasspool/JavassistClassPool.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/papaki/javassistclasspool/JavassistClassPool.java	2009-10-19 18:29:38 UTC (rev 95130)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/papaki/javassistclasspool/JavassistClassPool.java	2009-10-19 18:47:10 UTC (rev 95131)
@@ -73,7 +73,7 @@
     */
    public JavassistClassPool(Configuration configuration)
    {
-      super(JavassistClassPool.class.getName());
+      this();
       setConfiguration(configuration);
    }
 

Modified: projects/annotations/trunk/doc/userguide/en/modules/about.xml
===================================================================
--- projects/annotations/trunk/doc/userguide/en/modules/about.xml	2009-10-19 18:29:38 UTC (rev 95130)
+++ projects/annotations/trunk/doc/userguide/en/modules/about.xml	2009-10-19 18:47:10 UTC (rev 95131)
@@ -21,7 +21,7 @@
     <title>Thanks to</title>
 
     <para>
-      Jason Greene, David Lloyd, Scott Marlow, Andrew Lee Rubinger and Scott Stark.
+      Jason Greene, Ales Justin, David Lloyd, Scott Marlow, Andrew Lee Rubinger and Scott Stark.
     </para>
   </section>
 




More information about the jboss-cvs-commits mailing list