[jboss-cvs] JBossAS SVN: r102600 - in projects/scanning/trunk: indexer and 31 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 18 21:04:39 EDT 2010
Author: alesj
Date: 2010-03-18 21:04:37 -0400 (Thu, 18 Mar 2010)
New Revision: 102600
Added:
projects/scanning/trunk/indexer/
projects/scanning/trunk/indexer/pom.xml
projects/scanning/trunk/indexer/src/
projects/scanning/trunk/indexer/src/main/
projects/scanning/trunk/indexer/src/main/java/
projects/scanning/trunk/plugins/
projects/scanning/trunk/plugins/pom.xml
projects/scanning/trunk/plugins/src/
projects/scanning/trunk/plugins/src/main/
projects/scanning/trunk/plugins/src/main/java/
projects/scanning/trunk/plugins/src/main/java/org/
projects/scanning/trunk/plugins/src/main/java/org/jboss/
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AbstractElement.java
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/ClassElement.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ClassSignaturePair.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/DefaultElement.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/plugins/ParametersElement.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/WeakClassLoaderHolder.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/
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/Element.java
projects/scanning/trunk/pom.xml
projects/scanning/trunk/scanning-impl/
projects/scanning/trunk/scanning-impl/pom.xml
projects/scanning/trunk/scanning-impl/src/
projects/scanning/trunk/scanning-impl/src/main/
projects/scanning/trunk/scanning-impl/src/main/java/
projects/scanning/trunk/scanning-impl/src/main/java/org/
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanner.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanningPlugin.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/ScanningPluginWrapper.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/UrlScanner.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/AbstractScanningHandleAggregator.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentScanningHandleAggregator.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ConfiguratorReflectProvider.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/JavassistReflectProvider.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectProvider.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java
projects/scanning/trunk/scanning-spi/
projects/scanning/trunk/scanning-spi/pom.xml
projects/scanning/trunk/scanning-spi/src/
projects/scanning/trunk/scanning-spi/src/main/
projects/scanning/trunk/scanning-spi/src/main/java/
projects/scanning/trunk/scanning-spi/src/main/java/org/
projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/
projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/
projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/
projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/Scanner.java
projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/ScanningHandle.java
projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/ScanningPlugin.java
projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/
projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/ScanningHandleAggregator.java
Log:
Add initial scanning code
Added: projects/scanning/trunk/indexer/pom.xml
===================================================================
--- projects/scanning/trunk/indexer/pom.xml (rev 0)
+++ projects/scanning/trunk/indexer/pom.xml 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,77 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-build</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>scanning-indexer</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Scanning Indexer</name>
+ <url>http://www.jboss.org</url>
+ <description>JBoss Scanning Indexer</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-plugins</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading-vfs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test</groupId>
+ <artifactId>jboss-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: projects/scanning/trunk/plugins/pom.xml
===================================================================
--- projects/scanning/trunk/plugins/pom.xml (rev 0)
+++ projects/scanning/trunk/plugins/pom.xml 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,73 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-build</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>scanning-plugins</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Scanning Plugins</name>
+ <url>http://www.jboss.org</url>
+ <description>JBoss Scanning Plugins</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading-vfs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test</groupId>
+ <artifactId>jboss-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AbstractElement.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AbstractElement.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AbstractElement.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,130 @@
+/*
+ * 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.plugins;
+
+import java.lang.annotation.Annotation;
+import java.lang.ref.SoftReference;
+import java.lang.reflect.AnnotatedElement;
+
+import org.jboss.scanning.annotations.spi.Element;
+
+/**
+ * Abstract annotations element.
+ *
+ * @param <A> the annotation type
+ * @param <M> the annotated element type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractElement<A extends Annotation, M extends AnnotatedElement> extends WeakClassLoaderHolder implements Element<A, M>
+{
+ protected String className;
+ protected Class<A> annClass;
+ private A annotation;
+
+ private SoftReference<Class<?>> classRef;
+
+ public AbstractElement(ClassLoader classLoader, String className, Class<A> annClass, A annotation)
+ {
+ super(classLoader);
+
+ if (className == null)
+ throw new IllegalArgumentException("Null className");
+ if (annClass == null)
+ throw new IllegalArgumentException("Null annotation class");
+
+ this.className = className;
+ this.annClass = annClass;
+ this.annotation = annotation;
+ }
+
+ public String getOwnerClassName()
+ {
+ return className;
+ }
+
+ public Class<?> getOwner()
+ {
+ if (classRef != null)
+ {
+ Class<?> clazz = classRef.get();
+ if (clazz != null)
+ return clazz;
+ }
+
+ Class<?> clazz = loadClass(className);
+ classRef = new SoftReference<Class<?>>(clazz);
+ return clazz;
+ }
+
+ public A getAnnotation()
+ {
+ if (annotation == null)
+ annotation = readAnnotation();
+
+ return annotation;
+ }
+
+ /**
+ * Read the annotation.
+ *
+ * @return the read annotation
+ */
+ protected A readAnnotation()
+ {
+ AnnotatedElement annotatedElement = getAnnotatedElement();
+ return annotatedElement.getAnnotation(annClass);
+ }
+
+ public int getHashCode()
+ {
+ int hash = className.hashCode();
+ hash += 7 * annClass.hashCode();
+ if (annotation != null)
+ hash += 11 * annotation.hashCode();
+ return hash;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == null || getClass().equals(obj.getClass()) == false)
+ return false;
+
+ AbstractElement<?, ?> ae = AbstractElement.class.cast(obj);
+ if (className.equals(ae.className) == false)
+ return false;
+ if (annClass.equals(ae.annClass) == false)
+ return false;
+
+ // we don't check annotation
+ // since I doubt classname + annClass + signature + aoClass is not enough
+ // the only way this could happen is probably if class was diff version - diff annotation values
+
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return className + "@" + annClass.getName();
+ }
+}
Added: 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 (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,69 @@
+/*
+ * 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.plugins;
+
+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.plugins.AbstractScanningPlugin;
+import org.jboss.scanning.plugins.visitor.ReflectProvider;
+
+/**
+ * Annotations scanning plugin.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class AnnotationsScanningPlugin extends AbstractScanningPlugin<DefaultAnnotationRepository, AnnotationRepository>
+{
+ /** The repository */
+ private final DefaultAnnotationRepository repository;
+ /** The visitor */
+ private final ResourceVisitor visitor;
+
+ public AnnotationsScanningPlugin(ReflectProvider provider, ClassLoader cl)
+ {
+ repository = new DefaultAnnotationRepository(cl);
+ visitor = new GenericAnnotationVisitor(provider, repository);
+ }
+
+ protected DefaultAnnotationRepository doCreateHandle()
+ {
+ return repository;
+ }
+
+ public Class<AnnotationRepository> getHandleInterface()
+ {
+ return AnnotationRepository.class;
+ }
+
+ public ResourceFilter getFilter()
+ {
+ return visitor.getFilter();
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ visitor.visit(resource);
+ }
+}
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ClassElement.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ClassElement.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ClassElement.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,49 @@
+/*
+ * 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.plugins;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+
+
+/**
+ * Class annotations element.
+ *
+ * @param <A> the annotation type
+ * @param <M> the annotated element type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ClassElement<A extends Annotation, M extends AnnotatedElement> extends AbstractElement<A, M>
+{
+ public ClassElement(ClassLoader classLoader, String className, Class<A> annClass, A annotation)
+ {
+ super(classLoader, className, annClass, annotation);
+ }
+
+ @SuppressWarnings("unchecked")
+ public M getAnnotatedElement()
+ {
+ AnnotatedElement em = getOwner();
+ return (M)em;
+ }
+}
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ClassSignaturePair.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ClassSignaturePair.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ClassSignaturePair.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,109 @@
+/*
+ * 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.plugins;
+
+import org.jboss.util.JBossObject;
+import org.jboss.metadata.spi.signature.Signature;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Class name and signature pair.
+ * With those two we can re-create annotation value.
+ *
+ * If the keepAnnotations flag is on in DefaultAnnotationRepository
+ * we cache the annotation value from GenericAnnotationResourceVisitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ClassSignaturePair extends JBossObject
+{
+ private String className;
+ private Signature signature;
+ private Annotation annotation;
+
+ public ClassSignaturePair(String className, Signature signature)
+ {
+ this(className, signature, null);
+ }
+
+ public ClassSignaturePair(String className, Signature signature, Annotation annotation)
+ {
+ if (className == null)
+ throw new IllegalArgumentException("Null class name");
+
+ this.className = className;
+ this.signature = signature;
+ this.annotation = annotation;
+ }
+
+ /**
+ * Get the classname.
+ *
+ * @return the classname
+ */
+ public String getClassName()
+ {
+ return className;
+ }
+
+ /**
+ * Get the signature.
+ *
+ * @return the signature
+ */
+ public Signature getSignature()
+ {
+ return signature;
+ }
+
+ /**
+ * Get the annotation.
+ *
+ * @return the annotation
+ */
+ public Annotation getAnnotation()
+ {
+ return annotation;
+ }
+
+ protected int getHashCode()
+ {
+ int hash = className.hashCode();
+ if (signature != null)
+ hash += 7 * signature.hashCode();
+ return hash;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof ClassSignaturePair == false)
+ return false;
+
+ ClassSignaturePair csPair = (ClassSignaturePair)obj;
+ if (className.equals(csPair.getClassName()))
+ return equals(signature, csPair.getSignature());
+ else
+ return false;
+ }
+}
Added: 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 (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultAnnotationRepository.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,300 @@
+/*
+ * 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.plugins;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.*;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.scanning.annotations.spi.Element;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.util.collection.CollectionsFactory;
+
+/**
+ * DefaultAnnotationEnvironment.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DefaultAnnotationRepository extends MutableAnnotationRepository implements Serializable, ScanningHandle<DefaultAnnotationRepository>
+{
+ /** The serial version UID */
+ private static final long serialVersionUID = 1L;
+ /** The info map */
+ private transient Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env;
+ /** The checked class names */
+ private transient Set<String> checkedClassNames;
+ /** Should we keep the annotation */
+ private boolean keepAnnotations;
+
+ public DefaultAnnotationRepository(ClassLoader classLoader)
+ {
+ super(classLoader);
+ env = new HashMap<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>>();
+ checkedClassNames = new HashSet<String>();
+ }
+
+ /**
+ * Set the keep annotations flag.
+ *
+ * @param keepAnnotations the keep annotations flag
+ */
+ public void setKeepAnnotations(boolean keepAnnotations)
+ {
+ this.keepAnnotations = keepAnnotations;
+ }
+
+ /**
+ * Get env map.
+ *
+ * @return the env map
+ */
+ protected Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> getEnv()
+ {
+ if (env == null)
+ throw new IllegalArgumentException("Null env, previously serialized?");
+
+ return env;
+ }
+
+ 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<ElementType, Set<ClassSignaturePair>> etMap = entry.getValue();
+ for (Map.Entry<ElementType, Set<ClassSignaturePair>> et : etMap.entrySet())
+ {
+ for (ClassSignaturePair csp : et.getValue())
+ {
+ putAnnotation(csp.getAnnotation(), entry.getKey(), et.getKey(), csp.getClassName(), csp.getSignature());
+ }
+ }
+ }
+ }
+
+ /**
+ * Was class name already checked.
+ *
+ * @param className the class name
+ * @return true if already checked, false otherwise
+ */
+ boolean isAlreadyChecked(String className)
+ {
+ return checkedClassNames.contains(className);
+ }
+
+ /**
+ * Put the annotation info.
+ *
+ * @param annotation the annotation
+ * @param type the annotation type
+ * @param className the class name
+ * @param signature the signature
+ */
+ void putAnnotation(Annotation annotation, ElementType type, String className, Signature signature)
+ {
+ putAnnotation(annotation, annotation.annotationType(), type, className, signature);
+ }
+
+ /**
+ * Put the annotation info.
+ *
+ * @param annotation the annotation
+ * @param annClass the annotation class
+ * @param type the annotation type
+ * @param className the class name
+ * @param signature the signature
+ */
+ void putAnnotation(Annotation annotation, Class<? extends Annotation> annClass, ElementType type, String className, Signature signature)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Adding annotation @" + annClass.getSimpleName() + " for " + className + " at type " + type + ", signature: " + signature);
+
+ // add to checked
+ checkedClassNames.add(className);
+
+ Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = getEnv();
+
+ Map<ElementType, Set<ClassSignaturePair>> elements = env.get(annClass);
+ if (elements == null)
+ {
+ elements = new HashMap<ElementType, Set<ClassSignaturePair>>();
+ env.put(annClass, elements);
+ }
+
+ Set<ClassSignaturePair> classes = elements.get(type);
+ if (classes == null)
+ {
+ classes = CollectionsFactory.createLazySet();
+ elements.put(type, classes);
+ }
+
+ ClassSignaturePair pair;
+ if (keepAnnotations)
+ pair = new ClassSignaturePair(className, signature, annotation);
+ else
+ pair = new ClassSignaturePair(className, signature);
+ classes.add(pair);
+ }
+
+ /**
+ * Get matching cs pairs.
+ *
+ * @param annClass the annotation class
+ * @param type the annotation type
+ * @return class names
+ */
+ protected Set<ClassSignaturePair> getCSPairs(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);
+
+ return (pairs != null) ? pairs : Collections.<ClassSignaturePair>emptySet();
+ }
+
+ /**
+ * Transform class names into classes.
+ *
+ * @param <A> the annotation type
+ * @param <M> the annotated element type
+ * @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(
+ ElementType type,
+ Class<A> annClass,
+ Class<M> aoClass
+ )
+ {
+ Set<ClassSignaturePair> pairs = getCSPairs(annClass, type);
+ if (pairs.isEmpty())
+ return Collections.emptySet();
+
+ ClassLoader classLoader = getClassLoader();
+ Set<Element<A, M>> elements = new HashSet<Element<A, M>>();
+ for (ClassSignaturePair pair : pairs)
+ {
+ String className = pair.getClassName();
+ A annotation = annClass.cast(pair.getAnnotation());
+
+ Element<A, M> element;
+ if (type == ElementType.TYPE)
+ element = new ClassElement<A, M>(classLoader, className, annClass, annotation);
+ else if (type == ElementType.PARAMETER)
+ element = new ParametersElement<A,M>(classLoader, className, pair.getSignature(), annClass, annotation, aoClass);
+ else
+ element = new DefaultElement<A,M>(classLoader, className, pair.getSignature(), annClass, annotation, aoClass);
+ elements.add(element);
+ }
+ return elements;
+ }
+
+ public boolean hasClassAnnotatedWith(Class<? extends Annotation> annotation)
+ {
+ return getCSPairs(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);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <A extends Annotation> Set<Element<A, Constructor<?>>> classHasConstructorAnnotatedWith(Class<A> annotation)
+ {
+ return (Set) transformToElements(ElementType.CONSTRUCTOR, annotation, Constructor.class);
+ }
+
+ public <A extends Annotation> Set<Element<A, Field>> classHasFieldAnnotatedWith(Class<A> annotation)
+ {
+ return transformToElements(ElementType.FIELD, annotation, Field.class);
+ }
+
+ public <A extends Annotation> Set<Element<A, Method>> classHasMethodAnnotatedWith(Class<A> annotation)
+ {
+ return transformToElements(ElementType.METHOD, annotation, Method.class);
+ }
+
+ public <A extends Annotation> Set<Element<A, AnnotatedElement>> classHasParameterAnnotatedWith(Class<A> annotation)
+ {
+ return transformToElements(ElementType.PARAMETER, annotation, AnnotatedElement.class);
+ }
+
+ /**
+ * Load the annotation class.
+ *
+ * @param annotationName the annoation class name
+ * @return annotation class
+ */
+ @SuppressWarnings("unchecked")
+ protected Class<Annotation> getAnnotationClass(String annotationName)
+ {
+ Class<?> clazz = loadClass(annotationName);
+ if (Annotation.class.isAssignableFrom(clazz) == false)
+ throw new IllegalArgumentException("Annotation name " + annotationName + " doesn't extend Annotation class.");
+
+ return (Class<Annotation>)clazz;
+ }
+
+ public boolean hasClassAnnotatedWith(String annotationName)
+ {
+ return hasClassAnnotatedWith(getAnnotationClass(annotationName));
+ }
+
+ public Set<Element<Annotation, Class<?>>> classIsAnnotatedWith(String annotationName)
+ {
+ return classIsAnnotatedWith(getAnnotationClass(annotationName));
+ }
+
+ public Set<Element<Annotation, Constructor<?>>> classHasConstructorAnnotatedWith(String annotationName)
+ {
+ return classHasConstructorAnnotatedWith(getAnnotationClass(annotationName));
+ }
+
+ public Set<Element<Annotation, Field>> classHasFieldAnnotatedWith(String annotationName)
+ {
+ return classHasFieldAnnotatedWith(getAnnotationClass(annotationName));
+ }
+
+ public Set<Element<Annotation, Method>> classHasMethodAnnotatedWith(String annotationName)
+ {
+ return classHasMethodAnnotatedWith(getAnnotationClass(annotationName));
+ }
+
+ public Set<Element<Annotation, AnnotatedElement>> classHasParameterAnnotatedWith(String annotationName)
+ {
+ return classHasParameterAnnotatedWith(getAnnotationClass(annotationName));
+ }
+}
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultElement.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultElement.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/DefaultElement.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,121 @@
+/*
+ * 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.plugins;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.MethodParametersSignature;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.reflect.plugins.introspection.ReflectionUtils;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+
+/**
+ * Default annotations element.
+ *
+ * @param <A> the annotation type
+ * @param <M> the annotated element type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DefaultElement<A extends Annotation, M extends AnnotatedElement> extends AbstractElement<A, M>
+{
+ protected Signature signature;
+ protected Class<M> aoClass;
+
+ public DefaultElement(ClassLoader classLoader, String className, Signature signature, Class<A> annClass, A annotation, Class<M> aoClass)
+ {
+ super(classLoader, className, annClass, annotation);
+
+ if (signature == null)
+ throw new IllegalArgumentException("Null signature");
+ if (aoClass == null)
+ throw new IllegalArgumentException("Null ao class");
+
+ this.signature = signature;
+ this.aoClass = aoClass;
+ }
+
+ public M getAnnotatedElement()
+ {
+ AnnotatedElement result = null;
+
+ Class<?> clazz = getOwner();
+ if (signature instanceof ConstructorSignature || signature instanceof ConstructorParametersSignature)
+ {
+ try
+ {
+ result = clazz.getConstructor(signature.getParametersTypes(clazz));
+ }
+ catch (NoSuchMethodException ignored)
+ {
+ }
+ }
+ else if (signature instanceof MethodSignature || signature instanceof MethodParametersSignature)
+ {
+ try
+ {
+ result = clazz.getMethod(signature.getName(), signature.getParametersTypes(clazz));
+ }
+ catch (NoSuchMethodException ignored)
+ {
+ }
+ }
+ else if (signature instanceof FieldSignature)
+ {
+ result = ReflectionUtils.findField(clazz, signature.getName());
+ }
+
+ if (result == null)
+ throw new IllegalArgumentException("Expected accessible object " + className + "." + signature);
+ if (aoClass.isInstance(result) == false)
+ throw new IllegalArgumentException("Expected accessible object " + className + "." + signature + " of type " + aoClass);
+
+ return aoClass.cast(result);
+ }
+
+ public int getHashCode()
+ {
+ int hash = super.getHashCode();
+ hash += 19 * signature.hashCode();
+ hash += 37 * aoClass.hashCode();
+ return hash;
+ }
+
+ @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"})
+ public boolean equals(Object obj)
+ {
+ if (super.equals(obj) == false)
+ return false;
+
+ DefaultElement<?, ?> de = DefaultElement.class.cast(obj);
+ if (aoClass.equals(de.aoClass) == false)
+ return false;
+ if (signature.equals(de.signature) == false)
+ return false;
+
+ return true;
+ }
+}
Added: 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 (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,72 @@
+/*
+ * 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.plugins;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+
+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.visitor.ReflectProvider;
+import org.jboss.scanning.plugins.visitor.ReflectResourceVisitor;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class GenericAnnotationVisitor extends ReflectResourceVisitor
+{
+ /** The mutable repository */
+ private MutableAnnotationRepository repository;
+
+ public GenericAnnotationVisitor(ReflectProvider provider, MutableAnnotationRepository repository)
+ {
+ super(provider);
+ if (repository == null)
+ throw new IllegalArgumentException("Null repository");
+ this.repository = repository;
+ }
+
+ protected boolean isRelevant(ClassInfo classInfo)
+ {
+ return repository.isAlreadyChecked(classInfo.getName());
+ }
+
+ public ResourceFilter getFilter()
+ {
+ return ClassFilter.INSTANCE;
+ }
+
+ @Override
+ protected void handleAnnotations(ElementType type, Signature signature, Annotation[] annotations, String className)
+ {
+ if (annotations != null && annotations.length > 0)
+ {
+ for (Annotation annotation : annotations)
+ {
+ repository.putAnnotation(annotation, type, className, signature);
+ }
+ }
+ }
+}
Added: 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 (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/MutableAnnotationRepository.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,61 @@
+/*
+ * 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.plugins;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.scanning.annotations.spi.AnnotationRepository;
+import org.jboss.scanning.spi.ScanningHandle;
+
+/**
+ * Mutable annotation repository.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class MutableAnnotationRepository extends WeakClassLoaderHolder implements AnnotationRepository
+{
+ protected MutableAnnotationRepository(ClassLoader classLoader)
+ {
+ super(classLoader);
+ }
+
+ /**
+ * Put the annotation info.
+ *
+ * @param annotation the annotation
+ * @param type the annotation type
+ * @param className the class name
+ * @param signature the signature
+ */
+ abstract void putAnnotation(Annotation annotation, ElementType type, String className, Signature signature);
+
+ /**
+ * Was class name already checked.
+ *
+ * @param className the class name
+ * @return true if already checked, false otherwise
+ */
+ abstract boolean isAlreadyChecked(String className);
+}
\ No newline at end of file
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ParametersElement.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ParametersElement.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/ParametersElement.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,89 @@
+/*
+ * 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.plugins;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
+import org.jboss.metadata.spi.signature.MethodParametersSignature;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+/**
+ * Parameters annotations element.
+ *
+ * @param <A> the annotation type
+ * @param <M> the annotated element type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ParametersElement<A extends Annotation, M extends AnnotatedElement> extends DefaultElement<A, M>
+{
+ public ParametersElement(ClassLoader classLoader, String className, Signature signature, Class<A> annClass, A annotation, Class<M> aoClass)
+ {
+ super(classLoader, className, signature, annClass, annotation, aoClass);
+ }
+
+ protected A readAnnotation()
+ {
+ Annotation[] annotations = null;
+ Class<?> clazz = getOwner();
+ if (signature instanceof ConstructorParametersSignature)
+ {
+ ConstructorParametersSignature cps = (ConstructorParametersSignature)signature;
+ try
+ {
+ Constructor<?> constructor = clazz.getConstructor(signature.getParametersTypes(clazz));
+ annotations = constructor.getParameterAnnotations()[cps.getParam()];
+ }
+ catch (NoSuchMethodException ignored)
+ {
+ }
+ }
+ else if (signature instanceof MethodParametersSignature)
+ {
+ MethodParametersSignature mps = (MethodParametersSignature)signature;
+ try
+ {
+ Method method = clazz.getMethod(signature.getName(), signature.getParametersTypes(clazz));
+ annotations = method.getParameterAnnotations()[mps.getParam()];
+ }
+ catch (NoSuchMethodException ignored)
+ {
+ }
+ }
+
+ if (annotations == null || annotations.length == 0)
+ throw new IllegalArgumentException("Expected annotations " + className + "." + signature);
+
+ for(Annotation annotation : annotations)
+ {
+ if (annClass.equals(annotation.annotationType()))
+ return annClass.cast(annotation);
+ }
+
+ throw new IllegalArgumentException("No matching annotation: " + Arrays.asList(annotations));
+ }
+}
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/WeakClassLoaderHolder.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/WeakClassLoaderHolder.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/WeakClassLoaderHolder.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,80 @@
+/*
+ * 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.plugins;
+
+import org.jboss.util.JBossObject;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * ClassLoader holder helper.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+abstract class WeakClassLoaderHolder extends JBossObject
+{
+ private transient WeakReference<ClassLoader> clRef;
+
+ public WeakClassLoaderHolder(ClassLoader classLoader)
+ {
+ if (classLoader == null)
+ throw new IllegalArgumentException("Null classloader");
+
+ clRef = new WeakReference<ClassLoader>(classLoader);
+ }
+
+ /**
+ * Get the classloader from weak ref.
+ *
+ * @return the classloader
+ */
+ protected ClassLoader getClassLoader()
+ {
+ if (clRef == null)
+ throw new IllegalArgumentException("Null classloader ref, previously serialized?");
+
+ ClassLoader classLoader = clRef.get();
+ if (classLoader == null)
+ throw new IllegalArgumentException("ClassLoader was already garbage collected.");
+
+ return classLoader;
+ }
+
+ /**
+ * Load class from class name.
+ *
+ * @param className the class name
+ * @return loaded class
+ */
+ protected Class<?> loadClass(String className)
+ {
+ try
+ {
+ return Class.forName(className, false, getClassLoader());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: 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 (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/AnnotationRepository.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,164 @@
+/*
+ * 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.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Set;
+
+import org.jboss.scanning.spi.ScanningHandle;
+
+
+/**
+ * Information holder about annotation processing.
+ *
+ * Implementations should delay the actual class loading
+ * until it's absolutely necessary.
+ *
+ * All methods that have annotation name as parameter
+ * will use unit's classloader to load the actual annotation class.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface AnnotationRepository
+{
+ /**
+ * Does this annotation environment contain a class
+ * which is annotated with annotation parameter.
+ * This only applies to annotations for ElementType.TYPE level.
+ *
+ * This method should be used if we have no intention
+ * to do real lookup of annotated classes, but we're
+ * only interested in existance of the annotation.
+ * e.g. deployment unit contains @Stateful EJBs
+ *
+ * @param annotation the annotation we're querying for
+ * @return true if there exists a class with annotation param
+ * @see #hasClassAnnotatedWith(Class annotation)
+ */
+ boolean hasClassAnnotatedWith(Class<? extends Annotation> annotation);
+
+ /**
+ * Does this annotation environment contain a class
+ * which is annotated with annotation parameter.
+ * This only applies to annotations for ElementType.TYPE level.
+ *
+ * This method should be used if we have no intention
+ * to do real lookup of annotated classes, but we're
+ * only interested in existance of the annotation.
+ * e.g. deployment unit contains @Stateful EJBs
+ *
+ * @param annotationName the annotation name we're querying for
+ * @return true if there exists a class with annotation param
+ * @see #hasClassAnnotatedWith(Class annotation)
+ */
+ boolean hasClassAnnotatedWith(String annotationName);
+
+ /**
+ * Get all classes annotated with annotation param.
+ *
+ * @param <A> the annotation type
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ <A extends Annotation> Set<Element<A, Class<?>>> classIsAnnotatedWith(Class<A> annotation);
+
+ /**
+ * Get all classes annotated with annotation param.
+ *
+ * @param annotationName the annotation name we're querying for
+ * @return set of matching classes
+ */
+ Set<Element<Annotation, Class<?>>> classIsAnnotatedWith(String annotationName);
+
+ /**
+ * Get all classes who have some constructor annotated with annotation param.
+ *
+ * @param <A> the annotation type
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ <A extends Annotation> Set<Element<A, Constructor<?>>> classHasConstructorAnnotatedWith(Class<A> annotation);
+
+ /**
+ * Get all classes who have some constructor annotated with annotation param.
+ *
+ * @param annotationName the annotation name we're querying for
+ * @return set of matching classes
+ */
+ Set<Element<Annotation, Constructor<?>>> classHasConstructorAnnotatedWith(String annotationName);
+
+ /**
+ * Get all classes who have some field annotated with annotation param.
+ *
+ * @param <A> the annotation type
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ <A extends Annotation> Set<Element<A, Field>> classHasFieldAnnotatedWith(Class<A> annotation);
+
+ /**
+ * Get all classes who have some field annotated with annotation param.
+ *
+ * @param annotationName the annotation name we're querying for
+ * @return set of matching classes
+ */
+ Set<Element<Annotation, Field>> classHasFieldAnnotatedWith(String annotationName);
+
+ /**
+ * Get all classes who have some method annotated with annotation param.
+ *
+ * @param <A> the annotation type
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ <A extends Annotation> Set<Element<A, Method>> classHasMethodAnnotatedWith(Class<A> annotation);
+
+ /**
+ * Get all classes who have some method annotated with annotation param.
+ *
+ * @param annotationName the annotation name we're querying for
+ * @return set of matching classes
+ */
+ Set<Element<Annotation, Method>> classHasMethodAnnotatedWith(String annotationName);
+
+ /**
+ * Get all classes who have some method's/constructor's parameter annotated with annotation param.
+ *
+ * @param <A> the annotation type
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ <A extends Annotation> Set<Element<A, AnnotatedElement>> classHasParameterAnnotatedWith(Class<A> annotation);
+
+ /**
+ * Get all classes who have some method's/constructor's parameter annotated with annotation param.
+ *
+ * @param annotationName the annotation name we're querying for
+ * @return set of matching classes
+ */
+ Set<Element<Annotation, AnnotatedElement>> classHasParameterAnnotatedWith(String annotationName);
+}
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/Element.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/Element.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/spi/Element.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,66 @@
+/*
+ * 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.reflect.AnnotatedElement;
+
+/**
+ * Annotation holder element.
+ *
+ * @param <A> exact annotation type
+ * @param <M> exact annotated element type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface Element<A extends Annotation, M extends AnnotatedElement>
+{
+ /**
+ * Get the owner class name.
+ *
+ * Until we hit getOwner method the class should not be loaded.
+ *
+ * @return the owner classname
+ */
+ String getOwnerClassName();
+
+ /**
+ * Get the annotation owner class.
+ *
+ * @return the annotation owner class
+ */
+ Class<?> getOwner();
+
+ /**
+ * Get the annotation instance.
+ *
+ * @return the annotation instance
+ */
+ A getAnnotation();
+
+ /**
+ * Get the annotated element that holds the annotation.
+ *
+ * @return the annotated element instance
+ */
+ M getAnnotatedElement();
+}
Added: projects/scanning/trunk/pom.xml
===================================================================
--- projects/scanning/trunk/pom.xml (rev 0)
+++ projects/scanning/trunk/pom.xml 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,183 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>4</version>
+ </parent>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-build</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>JBoss Scanning Build</name>
+ <url>http://www.jboss.com/products/jbossmc</url>
+ <description>The JBoss MC Scanning implementation</description>
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/scanning/trunk/</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/scanning/trunk/</developerConnection>
+ <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/scanning/trunk/</url>
+ </scm>
+
+ <modules>
+ <module>scanning-spi</module>
+ <module>scanning-impl</module>
+ <module>plugins</module>
+ <module>indexer</module>
+ </modules>
+
+ <properties>
+ <version.org.jboss.common.core>2.2.17.GA</version.org.jboss.common.core>
+ <version.org.jboss.vfs>3.0.0.CR5</version.org.jboss.vfs>
+ <version.org.jboss.reflect>2.2.0.Alpha4</version.org.jboss.reflect>
+ <version.org.jboss.man>2.1.1.SP1</version.org.jboss.man>
+ <version.org.jboss.classloader>2.2.0.Alpha4</version.org.jboss.classloader>
+ <version.org.jboss.deployers>2.2.0.Alpha4</version.org.jboss.deployers>
+ <version.javassist>3.11.0.GA</version.javassist>
+ <version.ant>1.7.1</version.ant>
+ <version.junit>4.4</version.junit>
+ <version.org.jboss.logging>2.1.1.GA</version.org.jboss.logging>
+ <version.org.jboss.test>1.1.1.GA</version.org.jboss.test>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.0-beta-9</version>
+ <configuration>
+ <tagBase>https://svn.jboss.org/repos/jbossas/projects/scanning/tags</tagBase>
+ <autoVersionSubmodules>true</autoVersionSubmodules>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-idea-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <downloadSources>true</downloadSources>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.3</version>
+ <configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <includes>
+ <include>org/jboss/test/**/*TestCase.java</include>
+ </includes>
+ <systemProperties>
+ <property>
+ <name>xb.builder.useUnorderedSequence</name>
+ <value>true</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencyManagement>
+ <!-- The parent pom manages the inter-dependencies of the modules. -->
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-plugins</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-indexer</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ <version>${version.org.jboss.common.core}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ <version>${version.org.jboss.logging}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ <version>${version.org.jboss.vfs}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
+ <version>${version.org.jboss.reflect}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ <version>${version.org.jboss.man}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ <version>${version.org.jboss.man}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading</artifactId>
+ <version>${version.org.jboss.classloader}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading-vfs</artifactId>
+ <version>${version.org.jboss.classloader}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-spi</artifactId>
+ <version>${version.org.jboss.deployers}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.mcann</groupId>
+ <artifactId>mcann-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>${version.javassist}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>${version.ant}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${version.junit}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test</groupId>
+ <artifactId>jboss-test</artifactId>
+ <version>${version.org.jboss.test}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+</project>
+
Added: projects/scanning/trunk/scanning-impl/pom.xml
===================================================================
--- projects/scanning/trunk/scanning-impl/pom.xml (rev 0)
+++ projects/scanning/trunk/scanning-impl/pom.xml 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,73 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-build</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>scanning-impl</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Scanning Impl</name>
+ <url>http://www.jboss.org</url>
+ <description>JBoss Scanning Impl</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading-vfs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test</groupId>
+ <artifactId>jboss-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanner.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanner.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,83 @@
+/*
+ * 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.plugins;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import org.jboss.scanning.spi.Scanner;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Abstract scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractScanner implements Scanner
+{
+ /** The plugins */
+ private Set<ScanningPlugin> plugins = new CopyOnWriteArraySet<ScanningPlugin>();
+
+ /**
+ * Add plugin.
+ *
+ * @param plugin the plugin
+ */
+ public void addPlugin(ScanningPlugin plugin)
+ {
+ plugins.add(plugin);
+ }
+
+ /**
+ * Remove the plugin.
+ *
+ * @param plugin the plugin
+ */
+ public void removePlugin(ScanningPlugin plugin)
+ {
+ plugins.remove(plugin);
+ }
+
+ /**
+ * Get plugins.
+ *
+ * @return the plugins
+ */
+ public Set<ScanningPlugin> getPlugins()
+ {
+ return Collections.unmodifiableSet(plugins);
+ }
+
+ /**
+ * Set the plugins.
+ *
+ * @param plugins the plugins
+ */
+ public void setPlugins(Set<ScanningPlugin> plugins)
+ {
+ if (plugins == null)
+ throw new IllegalArgumentException("Null plugins");
+ this.plugins = plugins;
+ }
+}
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanningPlugin.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanningPlugin.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanningPlugin.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,55 @@
+/*
+ * 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.plugins;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Abstract scanning plugin wrapper
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractScanningPlugin<T extends ScanningHandle, U> implements ScanningPlugin<T, U>
+{
+ public T createHandle()
+ {
+ T handle = doCreateHandle();
+ if (getHandleInterface().isInstance(handle) == false)
+ throw new IllegalArgumentException("Illegal handle type: " + handle + " != " + getHandleInterface());
+ return handle;
+ }
+
+ protected abstract T doCreateHandle();
+
+ public String getHandleKey()
+ {
+ return getHandleInterface().getName();
+ }
+
+ public boolean accepts(ResourceContext resource)
+ {
+ return getFilter().accepts(resource);
+ }
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,98 @@
+/*
+ * 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.plugins;
+
+import java.net.URL;
+import java.util.Set;
+
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.plugins.vfs.VFSResourceVisitor;
+import org.jboss.classloading.plugins.visitor.FederatedResourceVisitor;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Default scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultScanner extends UrlScanner
+{
+ /** The class loader */
+ private ClassLoader classLoader;
+
+ protected VirtualFile[] excludedRoots;
+ protected ClassFilter included;
+ protected ClassFilter excluded;
+ protected ResourceFilter recurseFilter;
+
+ public DefaultScanner(ClassLoader classLoader, URL... roots)
+ {
+ super(roots);
+ this.classLoader = classLoader;
+ }
+
+ @Override
+ protected void scan(Set<ScanningPlugin> plugins) throws Exception
+ {
+ URL[] urls = getRoots();
+ VirtualFile[] roots = new VirtualFile[urls.length];
+ for (int i = 0; i < roots.length; i++)
+ {
+ roots[i] = VFS.getChild(urls[i]);
+ }
+ FederatedResourceVisitor visitor = new FederatedResourceVisitor(plugins.toArray(new ResourceVisitor[plugins.size()]));
+ ResourceFilter filter = visitor.getFilter();
+ VFSResourceVisitor.visit(roots, excludedRoots, included, excluded, classLoader, visitor, filter, recurseFilter, urls);
+ }
+
+ @Override
+ protected ScanningHandle createHandle(ScanningPlugin plugin)
+ {
+ return plugin.createHandle();
+ }
+
+ public void setExcludedRoots(VirtualFile[] excludedRoots)
+ {
+ this.excludedRoots = excludedRoots;
+ }
+
+ public void setIncluded(ClassFilter included)
+ {
+ this.included = included;
+ }
+
+ public void setExcluded(ClassFilter excluded)
+ {
+ this.excluded = excluded;
+ }
+
+ public void setRecurseFilter(ResourceFilter recurseFilter)
+ {
+ this.recurseFilter = recurseFilter;
+ }
+}
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,73 @@
+/*
+ * 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.plugins;
+
+import java.net.URL;
+import java.util.Set;
+
+import org.jboss.classloading.plugins.visitor.FederatedResourceVisitor;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.deployers.spi.deployer.helpers.AttachmentLocator;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Per deployment unit scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DeploymentUnitScanner extends UrlScanner
+{
+ /** The deployment unit */
+ private DeploymentUnit unit;
+
+ public DeploymentUnitScanner(DeploymentUnit unit, URL... roots)
+ {
+ super(roots);
+ if (unit == null)
+ throw new IllegalArgumentException("Null unit");
+ this.unit = unit;
+ }
+
+ protected void scan(Set<ScanningPlugin> plugins) throws Exception
+ {
+ Module module = AttachmentLocator.searchAncestors(unit, Module.class);
+ if (module == null)
+ throw new IllegalArgumentException("No module found: " + unit);
+
+ ScanningPlugin[] array = plugins.toArray(new ScanningPlugin[plugins.size()]);
+ FederatedResourceVisitor visitor = new FederatedResourceVisitor(array, array, null);
+ ResourceFilter filter = visitor.getFilter();
+ module.visit(visitor, filter, null, getRoots());
+ }
+
+ @SuppressWarnings("unchecked")
+ protected ScanningHandle createHandle(ScanningPlugin plugin)
+ {
+ ScanningHandle handle = plugin.createHandle();
+ unit.addAttachment(plugin.getHandleKey(), handle, plugin.getHandleInterface());
+ return handle;
+ }
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/ScanningPluginWrapper.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/ScanningPluginWrapper.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/ScanningPluginWrapper.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,92 @@
+/*
+ * 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.plugins;
+
+import java.net.URL;
+import java.util.List;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.util.collection.CollectionsFactory;
+
+/**
+ * Scanning plugin wrapper
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ScanningPluginWrapper<T extends ScanningHandle, U> implements ScanningPlugin<T, U>
+{
+ private ScanningPlugin<T, U> delegate;
+ private List<URL> excudedUrls = CollectionsFactory.createLazyList();
+
+ public ScanningPluginWrapper(ScanningPlugin<T, U> delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ void addURL(URL url)
+ {
+ excudedUrls.add(url);
+ }
+
+ public T createHandle()
+ {
+ return delegate.createHandle();
+ }
+
+ public Class<U> getHandleInterface()
+ {
+ return delegate.getHandleInterface();
+ }
+
+ public String getHandleKey()
+ {
+ return delegate.getHandleKey();
+ }
+
+ public boolean accepts(ResourceContext resource)
+ {
+ URL url = resource.getUrl();
+ String urlString = url.toString();
+ for (URL exceluded : excudedUrls)
+ {
+ String path = exceluded.getPath();
+ if (urlString.contains(path))
+ return false;
+ }
+
+ return delegate.accepts(resource);
+ }
+
+ public ResourceFilter getFilter()
+ {
+ return this;
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ delegate.visit(resource);
+ }
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/UrlScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/UrlScanner.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/UrlScanner.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,120 @@
+/*
+ * 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.plugins;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.zip.GZIPInputStream;
+
+import org.jboss.logging.Logger;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Url based scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class UrlScanner extends AbstractScanner
+{
+ private Logger log = Logger.getLogger(getClass());
+ private URL[] roots;
+
+ protected UrlScanner(URL... roots)
+ {
+ if (roots == null)
+ throw new IllegalArgumentException("Null roots");
+ this.roots = roots;
+ }
+
+ protected URL[] getRoots()
+ {
+ return roots;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void scan() throws Exception
+ {
+ Set<ScanningPlugin> federatedPlugins = new HashSet<ScanningPlugin>();
+ for (ScanningPlugin plugin : getPlugins())
+ {
+ ScanningHandle handle = createHandle(plugin);
+ ScanningPluginWrapper wrapper = new ScanningPluginWrapper(plugin);
+ federatedPlugins.add(wrapper);
+ String handleKey = plugin.getHandleKey();
+ for (URL root : roots)
+ {
+ InputStream is = getInputStream(root, handleKey + SUFFIX);
+ if (is != null)
+ {
+ ScanningHandle pre = readHandle(is);
+ handle.merge(pre);
+ wrapper.addURL(root); // exclude this url -- we already have pre-existing handle
+ }
+ }
+ }
+ scan(federatedPlugins);
+ }
+
+ protected abstract void scan(Set<ScanningPlugin> plugins) throws Exception;
+
+ protected InputStream getInputStream(URL url, String key)
+ {
+ try
+ {
+ String urlString = url.toExternalForm();
+ if (urlString.endsWith("/") == false)
+ urlString += "/";
+ urlString += key;
+ URL scanURL = new URL(urlString);
+ return scanURL.openStream();
+ }
+ catch (IOException e)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Cannot access mcann.ser file: " + e);
+ return null;
+ }
+ }
+
+ protected ScanningHandle readHandle(InputStream is) throws Exception
+ {
+ ObjectInputStream ois;
+ try
+ {
+ GZIPInputStream gis = new GZIPInputStream(is);
+ ois = new ObjectInputStream(gis);
+ }
+ finally
+ {
+ is.close();
+ }
+ return (ScanningHandle) ois.readObject();
+ }
+
+ protected abstract ScanningHandle createHandle(ScanningPlugin plugin);
+}
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/AbstractScanningHandleAggregator.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/AbstractScanningHandleAggregator.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/AbstractScanningHandleAggregator.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,91 @@
+/*
+ * 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.plugins.helpers;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.scanning.spi.helpers.ScanningHandleAggregator;
+
+/**
+ * Abstract scanning handle aggregator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractScanningHandleAggregator<T extends ScanningHandle, U> implements ScanningHandleAggregator<T, U>
+{
+ @SuppressWarnings("unchecked")
+ protected U aggregate(final ScanningPlugin plugin, final Set<U> handles)
+ {
+ return (U)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{plugin.getHandleInterface()}, new InvocationHandler()
+ {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ String methodName = method.getName();
+ if ("toString".equals(methodName))
+ return plugin + ".handle-aggregate";
+ else if ("getClass".equals(methodName))
+ return plugin.getHandleInterface();
+ else if ("equals".equals(methodName))
+ return proxy == args[0];
+ else if ("hashCode".equals(methodName))
+ return proxy.hashCode();
+
+ Object result = null;
+ for (U handle : handles)
+ {
+ Object tmp = method.invoke(handle, args);
+ if (tmp == null)
+ continue;
+
+ if (tmp instanceof Collection)
+ {
+ if (result == null)
+ result = tmp;
+ else
+ ((Collection)result).addAll(((Collection)tmp));
+ }
+ else if (tmp instanceof Map)
+ {
+ if (result == null)
+ result = tmp;
+ else
+ ((Map)result).putAll(((Map)tmp));
+ }
+ else
+ {
+ result = tmp;
+ break;
+ }
+ }
+ return result;
+ }
+ });
+ }
+}
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentScanningHandleAggregator.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentScanningHandleAggregator.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/DeploymentScanningHandleAggregator.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,85 @@
+/*
+ * 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.plugins.helpers;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Deployment scanning handle aggregator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DeploymentScanningHandleAggregator<T extends ScanningHandle, U> extends AbstractScanningHandleAggregator<T, U>
+{
+ /** The deployment unit */
+ private DeploymentUnit unit;
+
+ public DeploymentScanningHandleAggregator(DeploymentUnit unit)
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null unit");
+ this.unit = unit;
+ }
+
+ public U getAggregatedHandle(ScanningPlugin<T, U> plugin)
+ {
+ Set<U> handles = findHandles(plugin);
+ return aggregate(plugin, handles);
+ }
+
+ private Set<U> findHandles(ScanningPlugin<T, U> plugin)
+ {
+ DeploymentUnit top = unit;
+ while(top != null && top.isAttachmentPresent(Module.class) == false)
+ top = top.getParent();
+
+ if (top == null)
+ throw new IllegalArgumentException("No CL module: " + unit);
+
+ Set<U> handles = new HashSet<U>();
+ recurse(top, plugin, handles, true);
+ return handles;
+ }
+
+ private void recurse(DeploymentUnit current, ScanningPlugin<T, U> plugin, Set<U> handles, boolean allowModule)
+ {
+ // do not recurse into sub-deployments that have their own Module
+ if (allowModule == false && current.isAttachmentPresent(Module.class))
+ return;
+
+ U handle = current.getAttachment(plugin.getHandleKey(), plugin.getHandleInterface());
+ if (handle != null)
+ handles.add(handle);
+
+ for (DeploymentUnit child : current.getChildren())
+ {
+ recurse(child, plugin, handles, false);
+ }
+ }
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ConfiguratorReflectProvider.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ConfiguratorReflectProvider.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ConfiguratorReflectProvider.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,49 @@
+/*
+ * 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.plugins.visitor;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * Configuration based reflect provider.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ConfiguratorReflectProvider implements ReflectProvider
+{
+ private KernelConfigurator configurator;
+
+ public ConfiguratorReflectProvider(KernelConfigurator configurator)
+ {
+ if (configurator == null)
+ throw new IllegalArgumentException("Null configurator");
+ this.configurator = configurator;
+ }
+
+ public TypeInfo getTypeInfo(ResourceContext resource) throws Throwable
+ {
+ return configurator.getTypeInfo(resource.getClassName(), resource.getClassLoader());
+ }
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/JavassistReflectProvider.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/JavassistReflectProvider.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/JavassistReflectProvider.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,92 @@
+/*
+ * 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.plugins.visitor;
+
+import java.io.InputStream;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl;
+import org.jboss.reflect.plugins.javassist.JavassistUtil;
+import org.jboss.reflect.plugins.javassist.classpool.ClassPoolFactory;
+import org.jboss.reflect.spi.TypeInfo;
+
+import javassist.ClassPath;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.LoaderClassPath;
+
+/**
+ * Javassist based reflect provider.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JavassistReflectProvider implements ReflectProvider
+{
+ /** The weak class pool map */
+ private Map<ClassLoader, ClassPool> poolMap = new WeakHashMap<ClassLoader, ClassPool>();
+
+ /**
+ * Get class pool.
+ *
+ * @param cl the class loader
+ * @return class pool
+ */
+ private ClassPool getClassPool(ClassLoader cl)
+ {
+ ClassPool pool = poolMap.get(cl);
+ if (pool == null)
+ {
+ ClassPoolFactory factory = JavassistTypeInfoFactoryImpl.getPoolFactory();
+ pool = factory.getPoolForLoader(cl);
+
+ ClassPool defaultCP = ClassPool.getDefault();
+ if (pool == null || pool == defaultCP)
+ {
+ pool = new ClassPool();
+ ClassPath path = new LoaderClassPath(cl);
+ pool.appendClassPath(path);
+ }
+ poolMap.put(cl, pool);
+ }
+ return pool;
+ }
+
+ public TypeInfo getTypeInfo(ResourceContext resource) throws Throwable
+ {
+ InputStream stream = resource.getInputStream();
+ if (stream == null)
+ throw new IllegalArgumentException("Null stream: " + resource);
+
+ try
+ {
+ CtClass ctClass = getClassPool(resource.getClassLoader()).makeClassIfNew(stream);
+ return JavassistUtil.toTypeInfo(ctClass);
+ }
+ finally
+ {
+ stream.close();
+ }
+ }
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectProvider.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectProvider.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectProvider.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,43 @@
+/*
+ * 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.plugins.visitor;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * Reflect provider.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ReflectProvider
+{
+ /**
+ * Get type info.
+ *
+ * @param resource the resource context
+ * @return the type info
+ * @throws Throwable for any error
+ */
+ TypeInfo getTypeInfo(ResourceContext resource) throws Throwable;
+}
Added: 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 (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,295 @@
+/*
+ * 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.plugins.visitor;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.logging.Logger;
+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.*;
+
+/**
+ * Reflect based resource visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class ReflectResourceVisitor implements ResourceVisitor
+{
+ protected final Logger log = Logger.getLogger(getClass());
+
+ private ReflectProvider provider;
+
+ private boolean failOnError;
+ private boolean checkInterfaces;
+ private boolean checkSuper;
+
+ protected ReflectResourceVisitor(ReflectProvider provider)
+ {
+ if (provider == null)
+ throw new IllegalArgumentException("Null provider");
+ this.provider = provider;
+ }
+
+ /**
+ * Get type info.
+ *
+ * @param resource the resource
+ * @return resource's type info
+ * @throws Exception for any error
+ */
+ protected TypeInfo getTypeInfo(ResourceContext resource) throws Throwable
+ {
+ return provider.getTypeInfo(resource);
+ }
+
+ /**
+ * Get class info.
+ *
+ * @param resource the resource
+ * @return resource's type info
+ * @throws Exception for any error
+ */
+ protected ClassInfo getClassInfo(ResourceContext resource) throws Throwable
+ {
+ TypeInfo typeInfo = getTypeInfo(resource);
+ if (typeInfo instanceof ClassInfo == false)
+ throw new IllegalArgumentException("Can only handle class info: " + typeInfo);
+
+ return ClassInfo.class.cast(typeInfo);
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ if (resource.isClass() == false)
+ return;
+
+ try
+ {
+ ClassInfo ctClass = getClassInfo(resource);
+ handleClass(ctClass);
+ }
+ catch (Throwable t)
+ {
+ if (failOnError)
+ throw new RuntimeException(t);
+
+ logThrowable(resource, t);
+ }
+ }
+
+ /**
+ * Log throwable.
+ *
+ * @param resource the resource we're visiting
+ * @param t the throwable
+ */
+ protected void logThrowable(ResourceContext resource, Throwable t)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Exception reading resource: " + resource.getResourceName(), t);
+ }
+
+ /**
+ * Is this class info relevant for scanning.
+ *
+ * @param classInfo the class info
+ * @return true if relevant, false otherwise
+ */
+ 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
+ {
+ if (classInfo == null || isRelevant(classInfo) == false)
+ return;
+
+ String className = classInfo.getName();
+ if (log.isTraceEnabled())
+ log.trace("Scanning class " + className + " for annotations");
+
+ Annotation[] annotations = classInfo.getUnderlyingAnnotations();
+ handleAnnotations(ElementType.TYPE, (Signature)null, annotations, className);
+
+ handleMembers(ElementType.CONSTRUCTOR, classInfo.getDeclaredConstructors(), className);
+ handleMembers(ElementType.METHOD, classInfo.getDeclaredMethods(), className);
+ handleMembers(ElementType.FIELD, classInfo.getDeclaredFields(), className);
+
+ if (checkInterfaces || checkSuper)
+ {
+ if (checkInterfaces)
+ {
+ // interfaces
+ ClassInfo[] interfaces = classInfo.getInterfaces();
+ if (interfaces != null && interfaces.length > 0)
+ {
+ for (ClassInfo intf : interfaces)
+ handleClass(intf);
+ }
+ }
+
+ if (checkSuper)
+ {
+ // super class
+ handleClass(classInfo.getSuperclass());
+ }
+ }
+ }
+
+ /**
+ * Handle members for annotations.
+ *
+ * @param type where we found the annotations
+ * @param members the member instances
+ * @param className the className
+ * @throws Exception for any annotations lookup problems
+ */
+ protected void handleMembers(ElementType type, AnnotatedInfo[] members, String className) throws Exception
+ {
+ if (members != null && members.length > 0)
+ {
+ for (AnnotatedInfo ainfo : members)
+ {
+ if (ainfo instanceof MemberInfo == false)
+ throw new IllegalArgumentException("Can only handle member info: " + ainfo);
+
+ Annotation[] annotations = ainfo.getUnderlyingAnnotations();
+ MemberInfo member = MemberInfo.class.cast(ainfo);
+ handleAnnotations(type, member, annotations, className);
+ 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);
+ }
+ }
+ }
+ }
+ }
+
+ protected boolean isParametrized(AnnotatedInfo member)
+ {
+ return member instanceof MethodInfo || member instanceof ConstructorInfo;
+ }
+
+ protected Annotation[][] getParameterAnnotations(MemberInfo info)
+ {
+ ParameterInfo[] pinfos;
+ if (info instanceof ConstructorInfo)
+ {
+ ConstructorInfo ci = ConstructorInfo.class.cast(info);
+ pinfos = ci.getParameters();
+ }
+ else if (info instanceof MethodInfo)
+ {
+ MethodInfo mi = MethodInfo.class.cast(info);
+ pinfos = mi.getParameters();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot handle info: " + info);
+ }
+
+ Annotation[][] values = new Annotation[pinfos.length][];
+ for (int i = 0; i < pinfos.length; i++)
+ {
+ ParameterInfo pi = pinfos[i];
+ values[i] = pi.getUnderlyingAnnotations();
+ }
+ return values;
+ }
+
+ protected Signature getParameterSignature(MemberInfo info, int index)
+ {
+ if (info instanceof ConstructorInfo)
+ {
+ ConstructorInfo ci = ConstructorInfo.class.cast(info);
+ return new ConstructorParametersSignature(ci, index);
+ }
+ else if (info instanceof MethodInfo)
+ {
+ MethodInfo mi = MethodInfo.class.cast(info);
+ return new MethodParametersSignature(mi, index);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot handle info: " + info);
+ }
+ }
+
+ /**
+ * Handle annotations.
+ *
+ * @param type where we found the annotations
+ * @param member the member
+ * @param annotations the actual annotations
+ * @param className the className
+ * @throws Exception for any annotations lookup problems
+ */
+ protected void handleAnnotations(ElementType type, MemberInfo member, Annotation[] annotations, String className) throws Exception
+ {
+ Signature signature = null;
+ if (member != null)
+ signature = Signature.getSignature(member);
+
+ handleAnnotations(type, signature, annotations, className);
+ }
+
+ /**
+ * Handle annotations.
+ *
+ * @param type where we found the annotations
+ * @param signature the signature
+ * @param annotations the actual annotations
+ * @param className the className
+ */
+ protected void handleAnnotations(ElementType type, Signature signature, Annotation[] annotations, String className)
+ {
+ }
+
+ public void setFailOnError(boolean failOnError)
+ {
+ this.failOnError = failOnError;
+ }
+
+ public void setCheckInterfaces(boolean checkInterfaces)
+ {
+ this.checkInterfaces = checkInterfaces;
+ }
+
+ public void setCheckSuper(boolean checkSuper)
+ {
+ this.checkSuper = checkSuper;
+ }
+}
Added: projects/scanning/trunk/scanning-spi/pom.xml
===================================================================
--- projects/scanning/trunk/scanning-spi/pom.xml (rev 0)
+++ projects/scanning/trunk/scanning-spi/pom.xml 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,22 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.scanning</groupId>
+ <artifactId>scanning-build</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>scanning-spi</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Scanning SPI</name>
+ <url>http://www.jboss.org</url>
+ <description>JBoss Scanning SPI</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/Scanner.java
===================================================================
--- projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/Scanner.java (rev 0)
+++ projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/Scanner.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,19 @@
+package org.jboss.scanning.spi;
+
+/**
+ * Simple scanner interface.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface Scanner
+{
+ /** The pre-existing files suffix */
+ public static final String SUFFIX = ".mcs";
+
+ /**
+ * Scan handle method.
+ *
+ * @throws Exception for any error
+ */
+ void scan() throws Exception;
+}
Added: projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/ScanningHandle.java
===================================================================
--- projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/ScanningHandle.java (rev 0)
+++ projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/ScanningHandle.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,20 @@
+package org.jboss.scanning.spi;
+
+/**
+ * Scanning handle.
+ *
+ * Represents a simple interface resource scanning results must implement
+ * in order to be able to merge pre-existing results.
+ *
+ * @param <T> exact handle type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ScanningHandle<T extends ScanningHandle>
+{
+ /**
+ * Merge existing handle with sub-handle / pre-existing handle.
+ *
+ * @param subHandle the sub handle
+ */
+ void merge(T subHandle);
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/ScanningPlugin.java
===================================================================
--- projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/ScanningPlugin.java (rev 0)
+++ projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/ScanningPlugin.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,38 @@
+package org.jboss.scanning.spi;
+
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+
+/**
+ * Scanning plugin.
+ * Defines what to do with a resource.
+ *
+ * @param <T> exact handle type
+ * @param <U> exact handle interface
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ScanningPlugin<T extends ScanningHandle, U> extends ResourceFilter, ResourceVisitor
+{
+ /**
+ * Create plugins handle/utility.
+ * e.g. AnnotationRepository for annotations scanning
+ *
+ * @return new handle instance
+ */
+ T createHandle();
+
+ /**
+ * Get handle interface.
+ *
+ * @return the handle interface
+ */
+ Class<U> getHandleInterface();
+
+ /**
+ * Get handle's key.
+ * Used to attach handle to map/attachments.
+ *
+ * @return the handle's key
+ */
+ String getHandleKey();
+}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/ScanningHandleAggregator.java
===================================================================
--- projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/ScanningHandleAggregator.java (rev 0)
+++ projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/ScanningHandleAggregator.java 2010-03-19 01:04:37 UTC (rev 102600)
@@ -0,0 +1,44 @@
+/*
+ * 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.spi.helpers;
+
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Aggregate handles.
+ *
+ * @param <T> exact handle type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ScanningHandleAggregator<T extends ScanningHandle, U>
+{
+ /**
+ * Aggregte all handles.
+ * e.g. under same Module/CL.
+ *
+ * @param plugin the scanning plugin
+ * @return agregated handle
+ */
+ U getAggregatedHandle(ScanningPlugin<T, U> plugin);
+}
More information about the jboss-cvs-commits
mailing list