[jboss-cvs] JBossAS SVN: r106025 - in projects/scanning/trunk: plugins/src/main/java/org/jboss/scanning/hierarchy/spi and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 14 05:54:26 EDT 2010


Author: alesj
Date: 2010-06-14 05:54:25 -0400 (Mon, 14 Jun 2010)
New Revision: 106025

Modified:
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/spi/HierarchyIndex.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java
   projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java
Log:
Allow for null url.

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java	2010-06-14 06:35:03 UTC (rev 106024)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java	2010-06-14 09:54:25 UTC (rev 106025)
@@ -111,14 +111,29 @@
 
    public Set<TypeInfo> getSubTypesOf(URL url, TypeInfo superTypeToLookFor)
    {
+      Set<TypeInfo> result = null;
       if (url == null)
-         throw new IllegalArgumentException("Null url");
+      {
+         Collection<Map<TypeInfo, Set<TypeInfo>>> mappings = cache.values();
+         for (Map<TypeInfo, Set<TypeInfo>> m : mappings)
+         {
+            Set<TypeInfo> tmp = m.get(superTypeToLookFor);
+            if (tmp != null)
+            {
+               if (result == null)
+                  result = new HashSet<TypeInfo>();
 
-      String path = url.getPath();
-      Set<TypeInfo> result = null;
-      Map<TypeInfo, Set<TypeInfo>> map = cache.get(fixPath(path));
-      if (map != null)
-         result = map.get(superTypeToLookFor);
+               result.addAll(tmp);
+            }
+         }
+      }
+      else
+      {
+         String path = url.getPath();
+         Map<TypeInfo, Set<TypeInfo>> map = cache.get(fixPath(path));
+         if (map != null)
+            result = map.get(superTypeToLookFor);
+      }
 
       return result == null || result.isEmpty() ? Collections.<TypeInfo>emptySet() : Collections.unmodifiableSet(result);
    }

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/spi/HierarchyIndex.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/spi/HierarchyIndex.java	2010-06-14 06:35:03 UTC (rev 106024)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/spi/HierarchyIndex.java	2010-06-14 09:54:25 UTC (rev 106025)
@@ -38,7 +38,7 @@
    /**
     * Get inherited types.
     *
-    * @param url the classpath entry path
+    * @param url the optinal classpath entry path
     * @param superTypeToLookFor the super type to inherit
     * @return set of matching inherited classes
     */
@@ -47,7 +47,7 @@
    /**
     * Get inherited types.
     *
-    * @param url the classpath entry path
+    * @param url the optional classpath entry path
     * @param superTypeToLookFor the super type to inherit
     * @return set of matching inherited classes
     */
@@ -56,7 +56,7 @@
    /**
     * Get sub classes.
     *
-    * @param url the classpath entry path
+    * @param url the optional classpath entry path
     * @param superTypeToLookFor the super type
     * @return set of sub types
     */

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java	2010-06-14 06:35:03 UTC (rev 106024)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java	2010-06-14 09:54:25 UTC (rev 106025)
@@ -52,18 +52,17 @@
          throw new IllegalArgumentException("Null annotations index");
       if (hierarchy == null)
          throw new IllegalArgumentException("Null hierarchy index");
+
       this.annotations = annotations;
       this.hierarchy = hierarchy;
    }
 
    public <A extends Annotation> Set<Class<?>> getAnnotatedClasses(VirtualFile cpEntry, Class<A> annotationToLookFor)
    {
-      if (cpEntry == null)
-         throw new IllegalArgumentException("Null cp entry");
       if (annotationToLookFor == null)
          throw new IllegalArgumentException("Null annotation class");
 
-      URL url = toURL(cpEntry);
+      URL url = cpEntry != null ? toURL(cpEntry) : null;
       Set<Element<A, AnnotatedElement>> elements = annotations.getAnnotatedClasses(url, annotationToLookFor, null);
       Set<Class<?>> results = new HashSet<Class<?>>();
       for (Element<A, AnnotatedElement> elt : elements)
@@ -74,12 +73,11 @@
    @SuppressWarnings("deprecation")
    public <T> Set<Class<? extends T>> getInheritedClasses(VirtualFile cpEntry, Class<T> superTypeToLookFor)
    {
-      if (cpEntry == null)
-         throw new IllegalArgumentException("Null cp entry");
       if (superTypeToLookFor == null)
          throw new IllegalArgumentException("Null super type");
 
-      return hierarchy.getSubClassesOf(toURL(cpEntry), superTypeToLookFor);
+      URL url = cpEntry != null ? toURL(cpEntry) : null;
+      return hierarchy.getSubClassesOf(url, superTypeToLookFor);
    }
 
    protected static URL toURL(VirtualFile file)

Modified: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java	2010-06-14 06:35:03 UTC (rev 106024)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java	2010-06-14 09:54:25 UTC (rev 106025)
@@ -22,6 +22,7 @@
 
 package org.jboss.test.scanning.hierarchy.test;
 
+import java.net.URL;
 import java.util.Set;
 
 import org.jboss.deployers.structure.spi.DeploymentUnit;
@@ -101,6 +102,11 @@
       Set<TypeInfo> inherited = getInheritedClasses(ear, utilJar, UtilSuper.class);
       assertNotNull(inherited);
       assertEquals(1, inherited.size());
+
+      inherited = getInheritedClasses(ear, null, UtilSuper.class);
+      assertNotNull(inherited);
+      assertEquals(1, inherited.size());
+
    }
 
    protected void assertJar(DeploymentUnit jar) throws Exception
@@ -108,6 +114,10 @@
       Set<TypeInfo> inherited = getInheritedClasses(jar, getRoot(jar), JarMarkOnClassSuperAnnotated.class);
       assertNotNull(inherited);
       assertEquals(3, inherited.size());
+
+      inherited = getInheritedClasses(jar, null, JarMarkOnClassSuperAnnotated.class);
+      assertNotNull(inherited);
+      assertEquals(3, inherited.size());
    }
 
    protected void assertWar(DeploymentUnit war) throws Exception
@@ -115,6 +125,10 @@
       Set<TypeInfo> inherited = getInheritedClasses(war, getRoot(war).getChild("/WEB-INF/classes"), WebMarkOnClassSuperAnnotated.class);
       assertNotNull(inherited);
       assertEquals(3, inherited.size());
+
+      inherited = getInheritedClasses(war, null, WebMarkOnClassSuperAnnotated.class);
+      assertNotNull(inherited);
+      assertEquals(3, inherited.size());
    }
 
    protected HierarchyIndex getIndex(DeploymentUnit unit)
@@ -140,7 +154,8 @@
    {
       HierarchyIndex index = getIndex(unit);
       Class<?> superType = unit.getClassLoader().loadClass(ref.getName());
-      return index.getSubTypesOf(cpEntry.toURL(), superType);
+      URL url = cpEntry != null ? cpEntry.toURL() : null;
+      return index.getSubTypesOf(url, superType);
    }
 
    protected VirtualFile createTopLevelWithUtil() throws Exception



More information about the jboss-cvs-commits mailing list