[jboss-cvs] JBossAS SVN: r102976 - in projects/scanning/trunk: plugins/src/main/java/org/jboss/scanning/annotations/spi and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 25 16:07:31 EDT 2010
Author: alesj
Date: 2010-03-25 16:07:30 -0400 (Thu, 25 Mar 2010)
New Revision: 102976
Added:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationIndex.java
Modified:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPluginFactory.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationRepository.java
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/spi/ResourcesIndex.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java
Log:
Add default annotaiton index -- per classpath entry.
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java 2010-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -25,8 +25,9 @@
import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.classloading.spi.visitor.ResourceFilter;
import org.jboss.classloading.spi.visitor.ResourceVisitor;
-import org.jboss.scanning.annotations.spi.AnnotationRepository;
+import org.jboss.scanning.annotations.spi.AnnotationIndex;
import org.jboss.scanning.plugins.AbstractScanningPlugin;
+import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
/**
@@ -34,17 +35,17 @@
*
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class AnnotationsScanningPlugin extends AbstractScanningPlugin<DefaultAnnotationRepository, AnnotationRepository>
+public class AnnotationsScanningPlugin extends AbstractScanningPlugin<DefaultAnnotationRepository, AnnotationIndex>
{
/** The repository */
private final DefaultAnnotationRepository repository;
/** The visitor */
private final ResourceVisitor visitor;
- public AnnotationsScanningPlugin(ReflectProvider provider, ClassLoader cl)
+ public AnnotationsScanningPlugin(ReflectProvider provider, ResourceOwnerFinder finder, ClassLoader cl)
{
repository = new DefaultAnnotationRepository(cl);
- visitor = new GenericAnnotationVisitor(provider, repository);
+ visitor = new GenericAnnotationVisitor(provider, finder, repository);
}
protected DefaultAnnotationRepository doCreateHandle()
@@ -53,15 +54,15 @@
}
@Override
- public void cleanupHandle(AnnotationRepository handle)
+ public void cleanupHandle(AnnotationIndex handle)
{
if (handle instanceof DefaultAnnotationRepository)
DefaultAnnotationRepository.class.cast(handle).cleanup();
}
- public Class<AnnotationRepository> getHandleInterface()
+ public Class<AnnotationIndex> getHandleInterface()
{
- return AnnotationRepository.class;
+ return AnnotationIndex.class;
}
public ResourceFilter getFilter()
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPluginFactory.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPluginFactory.java 2010-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPluginFactory.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -23,8 +23,10 @@
package org.jboss.scanning.annotations.plugins;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.scanning.annotations.spi.AnnotationRepository;
+import org.jboss.scanning.annotations.spi.AnnotationIndex;
import org.jboss.scanning.plugins.DeploymentScanningPluginFactory;
+import org.jboss.scanning.plugins.helpers.DeploymentResourceOwnerFinderFactory;
+import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
import org.jboss.scanning.plugins.visitor.JavassistReflectProvider;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
import org.jboss.scanning.spi.ScanningPlugin;
@@ -34,7 +36,7 @@
*
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class AnnotationsScanningPluginFactory implements DeploymentScanningPluginFactory<DefaultAnnotationRepository, AnnotationRepository>
+public class AnnotationsScanningPluginFactory implements DeploymentScanningPluginFactory<DefaultAnnotationRepository, AnnotationIndex>
{
public boolean isRelevant(DeploymentUnit unit)
{
@@ -43,12 +45,13 @@
return true;
}
- public ScanningPlugin<DefaultAnnotationRepository, AnnotationRepository> create(DeploymentUnit unit)
+ public ScanningPlugin<DefaultAnnotationRepository, AnnotationIndex> create(DeploymentUnit unit)
{
ReflectProvider provider = unit.getAttachment(ReflectProvider.class);
if (provider == null)
provider = new JavassistReflectProvider();
- return new AnnotationsScanningPlugin(provider, unit.getClassLoader());
+ ResourceOwnerFinder finder = DeploymentResourceOwnerFinderFactory.getFinder(unit);
+ return new AnnotationsScanningPlugin(provider, finder, unit.getClassLoader());
}
}
\ No newline at end of file
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java 2010-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -29,6 +29,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.net.URL;
import java.util.*;
import org.jboss.metadata.spi.signature.Signature;
@@ -46,7 +47,7 @@
/** The serial version UID */
private static final long serialVersionUID = 1L;
/** The info map */
- private transient Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env;
+ private transient Map<String, Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>> env;
/** The checked class names */
private transient Set<String> checkedClassNames;
/** Should we keep the annotation */
@@ -55,7 +56,7 @@
public DefaultAnnotationRepository(ClassLoader classLoader)
{
super(classLoader);
- env = new HashMap<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>();
+ env = new HashMap<String, Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>>();
checkedClassNames = new HashSet<String>();
}
@@ -83,7 +84,7 @@
*
* @return the env map
*/
- protected Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> getEnv()
+ protected Map<String, Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>> getEnv()
{
if (env == null)
throw new IllegalArgumentException("Null env, previously serialized?");
@@ -93,15 +94,19 @@
public void merge(DefaultAnnotationRepository subHandle)
{
- Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = subHandle.getEnv();
- for (Map.Entry<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> entry : env.entrySet())
+ Map<String, Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>> env = subHandle.getEnv();
+ for (Map.Entry<String, Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>> entry : env.entrySet())
{
- Map<ElementType, Set<ClassSignaturePair>> etMap = entry.getValue();
- for (Map.Entry<ElementType, Set<ClassSignaturePair>> et : etMap.entrySet())
+ Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> etMap = entry.getValue();
+ for (Map.Entry<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> et : etMap.entrySet())
{
- for (ClassSignaturePair csp : et.getValue())
+ Map<ElementType, Set<ClassSignaturePair>> map = et.getValue();
+ for (Map.Entry<ElementType, Set<ClassSignaturePair>> mapE : map.entrySet())
{
- putAnnotation(csp.getAnnotation(), entry.getKey(), et.getKey(), csp.getClassName(), csp.getSignature());
+ for (ClassSignaturePair csp : mapE.getValue())
+ {
+ putAnnotation(csp.getAnnotation(), et.getKey(), mapE.getKey(), csp.getClassName(), csp.getSignature(), entry.getKey());
+ }
}
}
}
@@ -125,10 +130,11 @@
* @param type the annotation type
* @param className the class name
* @param signature the signature
+ * @param ownerURL the class owner url
*/
- void putAnnotation(Annotation annotation, ElementType type, String className, Signature signature)
+ void putAnnotation(Annotation annotation, ElementType type, String className, Signature signature, URL ownerURL)
{
- putAnnotation(annotation, annotation.annotationType(), type, className, signature);
+ putAnnotation(annotation, annotation.annotationType(), type, className, signature, ownerURL.getPath());
}
/**
@@ -139,8 +145,9 @@
* @param type the annotation type
* @param className the class name
* @param signature the signature
+ * @param path the owner url path
*/
- void putAnnotation(Annotation annotation, Class<? extends Annotation> annClass, ElementType type, String className, Signature signature)
+ void putAnnotation(Annotation annotation, Class<? extends Annotation> annClass, ElementType type, String className, Signature signature, String path)
{
if (log.isTraceEnabled())
log.trace("Adding annotation @" + annClass.getSimpleName() + " for " + className + " at type " + type + ", signature: " + signature);
@@ -148,13 +155,20 @@
// add to checked
checkedClassNames.add(className);
- Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = getEnv();
+ Map<String, Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>> env = getEnv();
- Map<ElementType, Set<ClassSignaturePair>> elements = env.get(annClass);
+ Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> map = env.get(path);
+ if (map == null)
+ {
+ map = new HashMap<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>();
+ env.put(path, map);
+ }
+
+ Map<ElementType, Set<ClassSignaturePair>> elements = map.get(annClass);
if (elements == null)
{
elements = new HashMap<ElementType, Set<ClassSignaturePair>>();
- env.put(annClass, elements);
+ map.put(annClass, elements);
}
Set<ClassSignaturePair> classes = elements.get(type);
@@ -175,17 +189,39 @@
/**
* Get matching cs pairs.
*
+ * @param path the owner path
* @param annClass the annotation class
* @param type the annotation type
* @return class names
*/
- protected Set<ClassSignaturePair> getCSPairs(Class<? extends Annotation> annClass, ElementType type)
+ protected Set<ClassSignaturePair> getCSPairs(String path, Class<? extends Annotation> annClass, ElementType type)
{
Set<ClassSignaturePair> pairs = null;
- Map<ElementType, Set<ClassSignaturePair>> elements = getEnv().get(annClass);
- if (elements != null)
- pairs = elements.get(type);
+ if (path == null)
+ {
+ pairs = new HashSet<ClassSignaturePair>();
+ for (Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> value : getEnv().values())
+ {
+ Map<ElementType, Set<ClassSignaturePair>> elements = value.get(annClass);
+ if (elements != null)
+ {
+ Set<ClassSignaturePair> csps = elements.get(type);
+ if (csps != null)
+ pairs.addAll(csps);
+ }
+ }
+ }
+ else
+ {
+ Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> map = getEnv().get(path);
+ if (map != null)
+ {
+ Map<ElementType, Set<ClassSignaturePair>> elements = map.get(annClass);
+ if (elements != null)
+ pairs = elements.get(type);
+ }
+ }
return (pairs != null) ? pairs : Collections.<ClassSignaturePair>emptySet();
}
@@ -195,18 +231,20 @@
*
* @param <A> the annotation type
* @param <M> the annotated element type
+ * @param path the classpath entry
* @param type the annotation type
* @param annClass the annotation class
* @param aoClass the ao class
* @return classes
*/
protected <A extends Annotation, M extends AnnotatedElement> Set<Element<A, M>> transformToElements(
+ String path,
ElementType type,
Class<A> annClass,
Class<M> aoClass
)
{
- Set<ClassSignaturePair> pairs = getCSPairs(annClass, type);
+ Set<ClassSignaturePair> pairs = getCSPairs(path, annClass, type);
if (pairs.isEmpty())
return Collections.emptySet();
@@ -229,36 +267,54 @@
return elements;
}
+ public <A extends Annotation> Set<Element<A, AnnotatedElement>> getAnnotatedClasses(String path, Class<A> annotation, ElementType type)
+ {
+ if (type == null)
+ {
+ Set<Element<A, AnnotatedElement>> result = new HashSet<Element<A, AnnotatedElement>>();
+ result.addAll(transformToElements(path, ElementType.TYPE, annotation, AnnotatedElement.class));
+ result.addAll(transformToElements(path, ElementType.CONSTRUCTOR, annotation, AnnotatedElement.class));
+ result.addAll(transformToElements(path, ElementType.METHOD, annotation, AnnotatedElement.class));
+ result.addAll(transformToElements(path, ElementType.FIELD, annotation, AnnotatedElement.class));
+ result.addAll(transformToElements(path, ElementType.PARAMETER, annotation, AnnotatedElement.class));
+ return result;
+ }
+ else
+ {
+ return transformToElements(path, type, annotation, AnnotatedElement.class);
+ }
+ }
+
public boolean hasClassAnnotatedWith(Class<? extends Annotation> annotation)
{
- return getCSPairs(annotation, ElementType.TYPE).isEmpty() == false;
+ return getCSPairs(null, annotation, ElementType.TYPE).isEmpty() == false;
}
@SuppressWarnings("unchecked")
public <A extends Annotation> Set<Element<A, Class<?>>> classIsAnnotatedWith(Class<A> annotation)
{
- return (Set) transformToElements(ElementType.TYPE, annotation, Class.class);
+ return (Set) transformToElements(null, ElementType.TYPE, annotation, Class.class);
}
@SuppressWarnings("unchecked")
public <A extends Annotation> Set<Element<A, Constructor<?>>> classHasConstructorAnnotatedWith(Class<A> annotation)
{
- return (Set) transformToElements(ElementType.CONSTRUCTOR, annotation, Constructor.class);
+ return (Set) transformToElements(null, ElementType.CONSTRUCTOR, annotation, Constructor.class);
}
public <A extends Annotation> Set<Element<A, Field>> classHasFieldAnnotatedWith(Class<A> annotation)
{
- return transformToElements(ElementType.FIELD, annotation, Field.class);
+ return transformToElements(null, ElementType.FIELD, annotation, Field.class);
}
public <A extends Annotation> Set<Element<A, Method>> classHasMethodAnnotatedWith(Class<A> annotation)
{
- return transformToElements(ElementType.METHOD, annotation, Method.class);
+ return transformToElements(null, ElementType.METHOD, annotation, Method.class);
}
public <A extends Annotation> Set<Element<A, AnnotatedElement>> classHasParameterAnnotatedWith(Class<A> annotation)
{
- return transformToElements(ElementType.PARAMETER, annotation, AnnotatedElement.class);
+ return transformToElements(null, ElementType.PARAMETER, annotation, AnnotatedElement.class);
}
/**
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java 2010-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -24,11 +24,13 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
+import java.net.URL;
import org.jboss.classloading.spi.visitor.ClassFilter;
import org.jboss.classloading.spi.visitor.ResourceFilter;
import org.jboss.metadata.spi.signature.Signature;
import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
import org.jboss.scanning.plugins.visitor.ClassHierarchyResourceVisitor;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
@@ -40,9 +42,9 @@
/** The mutable repository */
private MutableAnnotationRepository repository;
- public GenericAnnotationVisitor(ReflectProvider provider, MutableAnnotationRepository repository)
+ public GenericAnnotationVisitor(ReflectProvider provider, ResourceOwnerFinder finder, MutableAnnotationRepository repository)
{
- super(provider);
+ super(provider, finder);
if (repository == null)
throw new IllegalArgumentException("Null repository");
this.repository = repository;
@@ -50,7 +52,7 @@
protected boolean isRelevant(ClassInfo classInfo)
{
- return repository.isAlreadyChecked(classInfo.getName());
+ return repository.isAlreadyChecked(classInfo.getName()) == false;
}
public ResourceFilter getFilter()
@@ -59,13 +61,13 @@
}
@Override
- protected void handleAnnotations(ElementType type, Signature signature, Annotation[] annotations, String className)
+ protected void handleAnnotations(ElementType type, Signature signature, Annotation[] annotations, String className, URL ownerURL)
{
if (annotations != null && annotations.length > 0)
{
for (Annotation annotation : annotations)
{
- repository.putAnnotation(annotation, type, className, signature);
+ repository.putAnnotation(annotation, type, className, signature, ownerURL);
}
}
}
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java 2010-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -24,9 +24,10 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
+import java.net.URL;
import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.scanning.annotations.spi.AnnotationRepository;
+import org.jboss.scanning.annotations.spi.AnnotationIndex;
import org.jboss.scanning.plugins.helpers.WeakClassLoaderHolder;
/**
@@ -34,7 +35,7 @@
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public abstract class MutableAnnotationRepository extends WeakClassLoaderHolder implements AnnotationRepository
+public abstract class MutableAnnotationRepository extends WeakClassLoaderHolder implements AnnotationIndex
{
protected MutableAnnotationRepository(ClassLoader classLoader)
{
@@ -48,8 +49,9 @@
* @param type the annotation type
* @param className the class name
* @param signature the signature
+ * @param ownerURL the class owner url
*/
- abstract void putAnnotation(Annotation annotation, ElementType type, String className, Signature signature);
+ abstract void putAnnotation(Annotation annotation, ElementType type, String className, Signature signature, URL ownerURL);
/**
* Was class name already checked.
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationIndex.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationIndex.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationIndex.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.scanning.annotations.spi;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.AnnotatedElement;
+import java.util.Set;
+
+/**
+ * New index/repository -- per classpath entry.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface AnnotationIndex extends AnnotationRepository
+{
+ /**
+ * Get all classes who have some constructor annotated with annotation param.
+ *
+ * @param <A> the annotation type
+ * @param path the classpath entry, if null all classes in classpath are checked
+ * @param annotation the annotation we're querying for
+ * @param type annotation element type, if null all types are matched
+ * @return set of matching classes
+ */
+ <A extends Annotation> Set<Element<A, AnnotatedElement>> getAnnotatedClasses(String path, Class<A> annotation, ElementType type);
+}
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationRepository.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationRepository.java 2010-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationRepository.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -29,9 +29,7 @@
import java.lang.reflect.Method;
import java.util.Set;
-import org.jboss.scanning.spi.ScanningHandle;
-
/**
* Information holder about annotation processing.
*
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-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/DefaultResourcesIndex.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -23,10 +23,13 @@
package org.jboss.scanning.web.plugins;
import java.lang.annotation.Annotation;
-import java.net.URL;
+import java.lang.reflect.AnnotatedElement;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Set;
+import org.jboss.scanning.annotations.spi.AnnotationIndex;
+import org.jboss.scanning.annotations.spi.Element;
import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
import org.jboss.scanning.web.spi.ResourcesIndex;
import org.jboss.vfs.VirtualFile;
@@ -38,17 +41,17 @@
*/
public class DefaultResourcesIndex implements ResourcesIndex
{
- /** The resource owner finder */
- private ResourceOwnerFinder finder;
+ /** The annotation index */
+ private AnnotationIndex index;
- public DefaultResourcesIndex(ResourceOwnerFinder finder)
+ public DefaultResourcesIndex(AnnotationIndex index)
{
- if (finder == null)
- throw new IllegalArgumentException("Null finder");
- this.finder = finder;
+ if (index == null)
+ throw new IllegalArgumentException("Null index");
+ this.index = index;
}
- public Set<Class<?>> getAnnotatedClasses(VirtualFile cpEntry, Class<? extends Annotation> annotationToLookFor)
+ public <A extends Annotation> Set<Class<?>> getAnnotatedClasses(VirtualFile cpEntry, Class<A> annotationToLookFor)
{
if (cpEntry == null)
throw new IllegalArgumentException("Null cp entry");
@@ -56,8 +59,11 @@
throw new IllegalArgumentException("Null annotation class");
String path = cpEntry.getPathName();
- // TODO
- return Collections.emptySet();
+ Set<Element<A, AnnotatedElement>> elements = index.getAnnotatedClasses(path, annotationToLookFor, null);
+ Set<Class<?>> results = new HashSet<Class<?>>();
+ for (Element<A, AnnotatedElement> elt : elements)
+ results.add(elt.getOwner());
+ return results;
}
public Set<Class<?>> getInheritedClasses(VirtualFile cpEntry, Class<?> superTypeToLookFor)
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/spi/ResourcesIndex.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/spi/ResourcesIndex.java 2010-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/spi/ResourcesIndex.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -19,7 +19,7 @@
* @param annotationToLookFor the annotation to look for
* @return set of annotated classes
*/
- Set<Class<?>> getAnnotatedClasses(VirtualFile cpEntry, Class<? extends Annotation> annotationToLookFor);
+ <A extends Annotation> Set<Class<?>> getAnnotatedClasses(VirtualFile cpEntry, Class<A> annotationToLookFor);
/**
* Get inherited classes.
Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java 2010-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -24,11 +24,14 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
+import java.net.URL;
+import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
import org.jboss.metadata.spi.signature.MethodParametersSignature;
import org.jboss.metadata.spi.signature.Signature;
import org.jboss.reflect.spi.*;
+import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
/**
* Class hierarchy resource visitor.
@@ -37,12 +40,16 @@
*/
public abstract class ClassHierarchyResourceVisitor extends ReflectResourceVisitor
{
+ private ResourceOwnerFinder finder;
private boolean checkInterfaces;
private boolean checkSuper;
- protected ClassHierarchyResourceVisitor(ReflectProvider provider)
+ protected ClassHierarchyResourceVisitor(ReflectProvider provider, ResourceOwnerFinder finder)
{
super(provider);
+ if (finder == null)
+ throw new IllegalArgumentException("Null finder");
+ this.finder = finder;
}
/**
@@ -53,13 +60,7 @@
*/
protected abstract boolean isRelevant(ClassInfo classInfo);
- /**
- * Handle class adapter for annotations.
- *
- * @param classInfo the class info instance
- * @throws Exception for any annotations lookup problems
- */
- protected void handleClass(ClassInfo classInfo) throws Exception
+ protected void handleClass(ResourceContext resource, ClassInfo classInfo) throws Exception
{
if (classInfo == null || isRelevant(classInfo) == false)
return;
@@ -68,12 +69,14 @@
if (log.isTraceEnabled())
log.trace("Scanning class " + className + " for annotations");
+ URL ownerURL = finder.findOwnerURL(resource);
+
Annotation[] annotations = classInfo.getUnderlyingAnnotations();
- handleAnnotations(ElementType.TYPE, (Signature)null, annotations, className);
+ handleAnnotations(ElementType.TYPE, (Signature)null, annotations, className, ownerURL);
- handleMembers(ElementType.CONSTRUCTOR, classInfo.getDeclaredConstructors(), className);
- handleMembers(ElementType.METHOD, classInfo.getDeclaredMethods(), className);
- handleMembers(ElementType.FIELD, classInfo.getDeclaredFields(), className);
+ handleMembers(ElementType.CONSTRUCTOR, classInfo.getDeclaredConstructors(), className, ownerURL);
+ handleMembers(ElementType.METHOD, classInfo.getDeclaredMethods(), className, ownerURL);
+ handleMembers(ElementType.FIELD, classInfo.getDeclaredFields(), className, ownerURL);
if (checkInterfaces || checkSuper)
{
@@ -102,9 +105,10 @@
* @param type where we found the annotations
* @param members the member instances
* @param className the className
+ * @param ownerURL the class owner url
* @throws Exception for any annotations lookup problems
*/
- protected void handleMembers(ElementType type, AnnotatedInfo[] members, String className) throws Exception
+ protected void handleMembers(ElementType type, AnnotatedInfo[] members, String className, URL ownerURL) throws Exception
{
if (members != null && members.length > 0)
{
@@ -115,14 +119,14 @@
Annotation[] annotations = ainfo.getUnderlyingAnnotations();
MemberInfo member = MemberInfo.class.cast(ainfo);
- handleAnnotations(type, member, annotations, className);
+ handleAnnotations(type, member, annotations, className, ownerURL);
if (isParametrized(ainfo))
{
Annotation[][] paramAnnotations = getParameterAnnotations(member);
for (int index = 0; index < paramAnnotations.length; index++)
{
Signature signature = getParameterSignature(member, index);
- handleAnnotations(ElementType.PARAMETER, signature, paramAnnotations[index], className);
+ handleAnnotations(ElementType.PARAMETER, signature, paramAnnotations[index], className, ownerURL);
}
}
}
@@ -186,15 +190,16 @@
* @param member the member
* @param annotations the actual annotations
* @param className the className
+ * @param ownerURL the class owner url
* @throws Exception for any annotations lookup problems
*/
- protected void handleAnnotations(ElementType type, MemberInfo member, Annotation[] annotations, String className) throws Exception
+ protected void handleAnnotations(ElementType type, MemberInfo member, Annotation[] annotations, String className, URL ownerURL) throws Exception
{
Signature signature = null;
if (member != null)
signature = Signature.getSignature(member);
- handleAnnotations(type, signature, annotations, className);
+ handleAnnotations(type, signature, annotations, className, ownerURL);
}
/**
@@ -204,8 +209,9 @@
* @param signature the signature
* @param annotations the actual annotations
* @param className the className
+ * @param ownerURL the class owner url
*/
- protected void handleAnnotations(ElementType type, Signature signature, Annotation[] annotations, String className)
+ protected void handleAnnotations(ElementType type, Signature signature, Annotation[] annotations, String className, URL ownerURL)
{
}
Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java 2010-03-25 19:44:14 UTC (rev 102975)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java 2010-03-25 20:07:30 UTC (rev 102976)
@@ -101,16 +101,36 @@
*/
protected void doVisit(ResourceContext resource) throws Throwable
{
- ClassInfo ctClass = getClassInfo(resource);
- handleClass(ctClass);
+ ClassInfo classInfo = getClassInfo(resource);
+ handleClass(resource, classInfo);
}
/**
* Handle class adapter for annotations.
*
+ * @param resource the current resource
* @param classInfo the class info instance
* @throws Exception for any annotations lookup problems
*/
+ protected void handleClass(ResourceContext resource, ClassInfo classInfo) throws Exception
+ {
+ classInfo.setAttachment(ResourceContext.class.getName(), resource);
+ try
+ {
+ handleClass(classInfo);
+ }
+ finally
+ {
+ classInfo.setAttachment(ResourceContext.class.getName(), null);
+ }
+ }
+
+ /**
+ * Handle class adapter for annotations.
+ *
+ * @param classInfo the class info instance
+ * @throws Exception for any annotations lookup problems
+ */
protected void handleClass(ClassInfo classInfo) throws Exception
{
}
More information about the jboss-cvs-commits
mailing list