[jboss-cvs] JBossAS SVN: r95120 - in projects/annotations/branches/AnnEnv: core and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 19 11:58:02 EDT 2009
Author: alesj
Date: 2009-10-19 11:58:01 -0400 (Mon, 19 Oct 2009)
New Revision: 95120
Added:
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Element.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/AbstractElement.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ClassElement.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ClassSignaturePair.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/CommitElement.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/DefaultAnnotationRepository.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/DefaultElement.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/EnvPutList.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/GenericAnnotationResourceVisitor.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ParametersElement.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/WeakClassLoaderHolder.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtClassAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtConstructorAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtFieldAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtMemberAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtMethodAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/JavassistAnnotationResourceVisitor.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionAnnotationResourceVisitor.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionClassAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionConstructorAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionFieldAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionMemberAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionMethodAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/AnnotatedAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/ClassAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/MemberAdapter.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/AbstractAnnotationScanner.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/DefaultAnnotationScanner.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/JavassistAnnotationScanner.java
Removed:
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerCreator.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Configuration.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/ScanStrategy.java
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Visibility.java
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationRepositoryTests.java
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationScannerFactoryTests.java
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationTests.java
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ClassInfoTests.java
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ClassTests.java
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/InheritanceTests.java
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/InterfaceTests.java
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ScannerTests.java
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/javalangreflect/
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/javassistclasspool/
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/javassistinputstream/
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/package.html
projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/tests/
Modified:
projects/annotations/branches/AnnEnv/core/pom.xml
projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationRepository.java
projects/annotations/branches/AnnEnv/indexer/src/main/java/org/jboss/papaki/indexer/IndexerTask.java
projects/annotations/branches/AnnEnv/indexer/src/main/java/org/jboss/papaki/indexer/Main.java
projects/annotations/branches/AnnEnv/pom.xml
Log:
Initial Papaki re-write.
Modified: projects/annotations/branches/AnnEnv/core/pom.xml
===================================================================
--- projects/annotations/branches/AnnEnv/core/pom.xml 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/pom.xml 2009-10-19 15:58:01 UTC (rev 95120)
@@ -30,6 +30,14 @@
<artifactId>jboss-vfs</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>
Modified: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationRepository.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationRepository.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationRepository.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -22,61 +22,150 @@
package org.jboss.papaki;
-import java.io.Serializable;
-import java.util.Collection;
+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;
/**
- * An annotation repository
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * 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 extends Serializable
+public interface AnnotationRepository
{
+ /** The Papaki indexed file */
+ static final String PAPAKI_METADATA_BINARY = "papaki.ser";
+
/**
- * Get the settings for repository
- * @return The settings
+ * Merge repositories.
+ *
+ * @param repository the repo to merge
*/
- public Settings settings();
+ void merge(AnnotationRepository repository);
/**
- * Get the available annotation keys
- * @return The fully qualified class names of the available annotations
+ * 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)
*/
- public Set<String> getAvailableAnnotations();
+ boolean hasClassAnnotatedWith(Class<? extends Annotation> annotation);
/**
- * Does the repository contain references of the specified annotation
- * @param annotation The annotation class
- * @return True if the repository contains references
+ * 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)
*/
- public boolean hasAnnotation(Class<?> annotation);
+ boolean hasClassAnnotatedWith(String annotationName);
/**
- * Does the repository contain references of the specified annotation
- * @param annotation The fully qualified class name for the annotation
- * @return True if the repository contains references
+ * 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
*/
- public boolean hasAnnotation(String annotation);
+ <A extends Annotation> Set<Element<A, Class<?>>> classIsAnnotatedWith(Class<A> annotation);
/**
- * Get the instances of an annotation
- * @param annotation The annotation class
- * @return The collection of annotations of the specified class; <code>null</code>
- * if no annotations exists
+ * Get all classes annotated with annotation param.
+ *
+ * @param annotationName the annotation name we're querying for
+ * @return set of matching classes
*/
- public Collection<Annotation> getAnnotation(Class<?> annotation);
+ Set<Element<Annotation, Class<?>>> classIsAnnotatedWith(String annotationName);
/**
- * Get the instances of an annotation
- * @param annotation The fully qualified class name for the annotation
- * @return The collection of annotations of the specified class; <code>null</code>
- * if no annotations exists
+ * 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
*/
- public Collection<Annotation> getAnnotation(String annotation);
+ <A extends Annotation> Set<Element<A, Constructor<?>>> classHasConstructorAnnotatedWith(Class<A> annotation);
/**
- * Merge an annotation repository
- * @param ar The annotation repository
+ * 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
*/
- public void merge(AnnotationRepository ar);
+ 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);
}
Deleted: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki;
-
-import java.net.URL;
-
-/**
- * An annotation scanner
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public interface AnnotationScanner
-{
- /**
- * Configure the scanner
- * @return The configuration
- */
- Configuration configure();
-
- /**
- * Scan using the context class loader as well as the additional
- * classloaders specified to resolve annotation class definitions
- * @param urls The URLs with the .jar files
- * @param cls Additional class loaders
- * @return The annotation repository
- */
- AnnotationRepository scan(URL[] urls, ClassLoader... cls);
-}
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki;
+
+import java.net.URL;
+
+/**
+ * An annotation scanner.
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface AnnotationScanner
+{
+ /**
+ * Scan using the context class loader as well as the additional
+ * classloaders specified to resolve annotation class definitions.
+ *
+ * @param urls The URLs with the .jar files
+ * @param cls Additional class loaders
+ * @return The annotation repository
+ */
+ AnnotationRepository scan(URL[] urls, ClassLoader... cls) throws Exception;
+}
Deleted: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerCreator.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerCreator.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerCreator.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki;
-
-/**
- * Annotation scanner creator.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-abstract class AnnotationScannerCreator
-{
- /**
- * Verify if we can actually use AnnotationScanner created by this creator.
- */
- abstract void verify();
-
- /**
- * Create AnnotationScanner.
- *
- * @param configuration the configuration
- * @return new AnnotationScanner
- */
- abstract AnnotationScanner create(Configuration configuration);
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,140 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki;
-
-import java.util.Arrays;
-
-/**
- * An annotation scanner factory
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public class AnnotationScannerFactory
-{
- /**
- * Javassist using ClassPool
- */
- public static final int JAVASSIST_CLASS_POOL = ScanStrategy.JAVASSIST_CLASS_POOL.ordinal();
-
- /**
- * Javassist using InputStream
- */
- public static final int JAVASSIST_INPUT_STREAM = ScanStrategy.JAVASSIST_INPUT_STREAM.ordinal();
-
- /**
- * java.lang.reflect
- */
- public static final int JAVA_LANG_REFLECT = ScanStrategy.JAVA_LANG_REFLECT.ordinal();
-
- /**
- * Default strategy
- */
- private static ScanStrategy defaultStrategy;
-
- /**
- * Is Javassist available
- */
- static boolean haveJavassist = false;
-
- static
- {
- try
- {
- Class.forName("javassist.CtClass");
- haveJavassist = true;
- }
- catch (ClassNotFoundException ignore)
- {
- // Ok - use java.lang.reflect then
- }
-
- if (haveJavassist)
- {
- defaultStrategy = ScanStrategy.JAVASSIST_INPUT_STREAM;
- }
- else
- {
- defaultStrategy = ScanStrategy.JAVA_LANG_REFLECT;
- }
- }
-
- /**
- * Constructor
- */
- private AnnotationScannerFactory()
- {
- }
-
- /**
- * Get the default strategy for annotation scanning
- *
- * @return An instance of the annotation scanner
- */
- public static AnnotationScanner getDefault()
- {
- return getStrategy(defaultStrategy.ordinal());
- }
-
- /**
- * Get the default strategy for annotation scanning
- *
- * @param configuration the configuration
- * @return An instance of the annotation scanner
- */
- public static AnnotationScanner getDefault(Configuration configuration)
- {
- return getStrategy(defaultStrategy.ordinal(), configuration);
- }
-
- /**
- * Get the specified strategy for annotation scanning
- *
- * @param strategy The strategy
- * @return An instance of the annotation scanner
- */
- public static AnnotationScanner getStrategy(int strategy)
- {
- return getStrategy(strategy, null);
- }
-
- /**
- * Get the specified strategy for annotation scanning
- *
- * @param strategy The strategy
- * @param configuration the configuration
- * @return An instance of the annotation scanner
- */
- public static AnnotationScanner getStrategy(int strategy, Configuration configuration)
- {
- ScanStrategy[] strategies = ScanStrategy.values();
- if (strategy < 0 || strategy >= strategies.length)
- {
- String msg = "Unknown strategy key: " + strategy + ", available: " + Arrays.toString(strategies);
- throw new IllegalArgumentException(msg);
- }
-
- ScanStrategy ss = strategies[strategy];
- ss.verify(); // check if we can use this strategy
- return ss.create(configuration);
- }
-}
Copied: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java (from rev 95103, projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScanner.java)
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationScannerFactory.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki;
+
+import org.jboss.papaki.scanner.DefaultAnnotationScanner;
+import org.jboss.papaki.scanner.JavassistAnnotationScanner;
+
+/**
+ * An annotation scanner factory
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class AnnotationScannerFactory
+{
+ /**
+ * java.lang.reflect
+ */
+ public static final int JAVA_LANG_REFLECT = 0;
+
+ /**
+ * Javassist
+ */
+ public static final int JAVASSIST = 1;
+
+ /**
+ * Default strategy
+ */
+ private static int defaultStrategy;
+
+ /**
+ * Is Javassist available
+ */
+ static boolean haveJavassist = false;
+
+ static
+ {
+ try
+ {
+ Class.forName("javassist.CtClass");
+ haveJavassist = true;
+ }
+ catch (ClassNotFoundException ignore)
+ {
+ // Ok - use java.lang.reflect then
+ }
+
+ if (haveJavassist)
+ {
+ defaultStrategy = JAVASSIST;
+ }
+ else
+ {
+ defaultStrategy = JAVA_LANG_REFLECT;
+ }
+ }
+
+ /**
+ * Constructor
+ */
+ private AnnotationScannerFactory()
+ {
+ }
+
+ /**
+ * Get the default strategy for annotation scanning
+ *
+ * @return An instance of the annotation scanner
+ */
+ public static AnnotationScanner getDefault()
+ {
+ return getStrategy(defaultStrategy);
+ }
+
+ /**
+ * Get the specified strategy for annotation scanning
+ *
+ * @param strategy The strategy
+ * @return An instance of the annotation scanner
+ */
+ public static AnnotationScanner getStrategy(int strategy)
+ {
+ if (strategy == JAVA_LANG_REFLECT)
+ return new DefaultAnnotationScanner();
+ else if (strategy == JAVASSIST)
+ return new JavassistAnnotationScanner();
+ else
+ throw new IllegalArgumentException("No such strategy: "+ strategy);
+ }
+}
Deleted: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Configuration.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Configuration.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Configuration.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,147 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki;
-
-/**
- * Represents a configuration of the annotation scanner
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public interface Configuration
-{
- /**
- * Scan for annotations at class level - default is <code>true</code>
- * @param scan True if scanning should be performed; otherwise false
- * @return The configuration
- */
- public Configuration classLevel(boolean scan);
-
- /**
- * Is the class level enabled ?
- * @return True if enabled; otherwise false
- */
- public boolean isClassLevel();
-
- /**
- * Set the visibility for classes scanned - default is <code>PRIVATE</code>
- * @param v The visibility
- * @return The configuration
- */
- public Configuration classVisibility(Visibility v);
-
- /**
- * Get the class visibility setting
- * @return The visibility
- */
- public Visibility getClassVisibility();
-
- /**
- * Scan for annotations at field level - default is <code>true</code>
- * @param scan True if scanning should be performed; otherwise false
- * @return The configuration
- */
- public Configuration fieldLevel(boolean scan);
-
- /**
- * Is the field level enabled ?
- * @return True if enabled; otherwise false
- */
- public boolean isFieldLevel();
-
- /**
- * Set the visibility for fields scanned - default is <code>PRIVATE</code>
- * @param v The visibility
- * @return The configuration
- */
- public Configuration fieldVisibility(Visibility v);
-
- /**
- * Get the field visibility setting
- * @return The visibility
- */
- public Visibility getFieldVisibility();
-
- /**
- * Scan for annotations at constructor level - default is <code>true</code>
- * @param scan True if scanning should be performed; otherwise false
- * @return The configuration
- */
- public Configuration constructorLevel(boolean scan);
-
- /**
- * Is the constructor level enabled ?
- * @return True if enabled; otherwise false
- */
- public boolean isConstructorLevel();
-
- /**
- * Set the visibility for constructors scanned - default is <code>PRIVATE</code>
- * @param v The visibility
- * @return The configuration
- */
- public Configuration constructorVisibility(Visibility v);
-
- /**
- * Get the constructor visibility setting
- * @return The visibility
- */
- public Visibility getConstructorVisibility();
-
- /**
- * Scan for annotations at method level - default is <code>true</code>
- * @param scan True if scanning should be performed; otherwise false
- * @return The configuration
- */
- public Configuration methodLevel(boolean scan);
-
- /**
- * Is the method level enabled ?
- * @return True if enabled; otherwise false
- */
- public boolean isMethodLevel();
-
- /**
- * Set the visibility for methods scanned - default is <code>PRIVATE</code>
- * @param v The visibility
- * @return The configuration
- */
- public Configuration methodVisibility(Visibility v);
-
- /**
- * Get the method visibility setting
- * @return The visibility
- */
- public Visibility getMethodVisibility();
-
- /**
- * Scan for annotations at parameter level - default is <code>true</code>
- * @param scan True if scanning should be performed; otherwise false
- * @return The configuration
- */
- public Configuration parameterLevel(boolean scan);
-
- /**
- * Is the parameter level enabled ?
- * @return True if enabled; otherwise false
- */
- public boolean isParameterLevel();
-}
Copied: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Element.java (from rev 95103, projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/AnnotationRepository.java)
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Element.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Element.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.papaki;
+
+import 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();
+}
\ No newline at end of file
Deleted: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/ScanStrategy.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/ScanStrategy.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/ScanStrategy.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,156 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki;
-
-import org.jboss.papaki.javalangreflect.JavaClass;
-import org.jboss.papaki.javassistclasspool.JavassistClassPool;
-import org.jboss.papaki.javassistinputstream.JavassistInputStream;
-
-/**
- * Scan strategy.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-enum ScanStrategy
-{
- /** Javassist class pool */
- JAVASSIST_CLASS_POOL(new JavassistClassPoolScannerCreator()),
- /** Javassist input stream */
- JAVASSIST_INPUT_STREAM(new JavassistInputStreamCreator()),
- /** Plain JDK reflect */
- JAVA_LANG_REFLECT(new JavaClassScannerCreator());
-
- private transient AnnotationScannerCreator creator;
-
- /**
- * Ctor.
- *
- * @param creator the creator
- */
- ScanStrategy(AnnotationScannerCreator creator)
- {
- this.creator = creator;
- }
-
- /**
- * Do check.
- */
- private static void check()
- {
- if (!AnnotationScannerFactory.haveJavassist)
- throw new IllegalArgumentException("Javassist not available.");
- }
-
- /**
- * Verify.
- */
- void verify()
- {
- creator.verify();
- }
-
- /**
- * Get scanner.
- *
- * @param configuration the configuration
- * @return new annotation scanner
- */
- AnnotationScanner create(Configuration configuration)
- {
- return creator.create(configuration);
- }
-
- /**
- * JCPSC
- */
- static class JavassistClassPoolScannerCreator extends AnnotationScannerCreator
- {
- /**
- * Verify.
- */
- public void verify()
- {
- check();
- }
-
- /**
- * Create AnnotationScanner.
- *
- * @param configuration the configuration
- * @return new JavassistCP instance
- */
- public AnnotationScanner create(Configuration configuration)
- {
- return new JavassistClassPool(configuration);
- }
- }
-
- /**
- * JISC
- */
- static class JavassistInputStreamCreator extends AnnotationScannerCreator
- {
- /**
- * Verify.
- */
- public void verify()
- {
- check();
- }
-
- /**
- * Create AnnotationScanner.
- *
- * @param configuration the configuration
- * @return new JavassistIS instance
- */
- public AnnotationScanner create(Configuration configuration)
- {
- return new JavassistInputStream(configuration);
- }
- }
-
- /**
- * JCSC
- */
- static class JavaClassScannerCreator extends AnnotationScannerCreator
- {
- /**
- * Verify.
- */
- public void verify()
- {
- }
-
- /**
- * Create AnnotationScanner.
- *
- * @param configuration the configuration
- * @return new JavaClass instance
- */
- public AnnotationScanner create(Configuration configuration)
- {
- return new JavaClass(configuration);
- }
- }
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Visibility.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Visibility.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/Visibility.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki;
-
-/**
- * Represents a visibility
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public enum Visibility
-{
- /** PUBLIC */
- PUBLIC,
-
- /** PACKAGE */
- PACKAGE,
-
- /** PROTECTED */
- PROTECTED,
-
- /** PPRIVATE */
- PRIVATE
-}
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/AbstractElement.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/AbstractElement.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/AbstractElement.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins;
+
+import org.jboss.papaki.Element;
+
+import java.lang.annotation.Annotation;
+import java.lang.ref.SoftReference;
+import java.lang.reflect.AnnotatedElement;
+
+/**
+ * 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;
+ }
+}
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ClassElement.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ClassElement.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ClassElement.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.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;
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ClassSignaturePair.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ClassSignaturePair.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ClassSignaturePair.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.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/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/CommitElement.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/CommitElement.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/CommitElement.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins;
+
+import org.jboss.metadata.spi.signature.Signature;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+
+/**
+ * Gathering annotation information.
+ *
+ * Only push all this info into AnnotationEnvironment if
+ * complete lookup was successful.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class CommitElement
+{
+ private Annotation annotation;
+ private ElementType type;
+ private String className;
+ private Signature signature;
+
+ CommitElement(Annotation annotation, ElementType type, String className, Signature signature)
+ {
+ this.annotation = annotation;
+ this.type = type;
+ this.className = className;
+ this.signature = signature;
+ }
+
+ /**
+ * Get the annotation.
+ *
+ * @return the annotation
+ */
+ public Annotation getAnnotation()
+ {
+ return annotation;
+ }
+
+ /**
+ * Get element type.
+ *
+ * @return the element type
+ */
+ public ElementType getType()
+ {
+ return type;
+ }
+
+ /**
+ * Get class name.
+ *
+ * @return the class name
+ */
+ public String getClassName()
+ {
+ return className;
+ }
+
+ /**
+ * Get signature.
+ *
+ * @return the signature
+ */
+ public Signature getSignature()
+ {
+ return signature;
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/DefaultAnnotationRepository.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/DefaultAnnotationRepository.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/DefaultAnnotationRepository.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,307 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.papaki.AnnotationRepository;
+import org.jboss.papaki.Element;
+import org.jboss.util.collection.CollectionsFactory;
+
+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.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * DefaultAnnotationEnvironment.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DefaultAnnotationRepository extends WeakClassLoaderHolder implements AnnotationRepository, Serializable
+{
+ /** 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;
+ }
+
+ /**
+ * 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);
+ }
+
+ public void merge(AnnotationRepository repository)
+ {
+ if (repository instanceof DefaultAnnotationRepository == false)
+ log.info("Cannot merge with non DefaultAnnotationRepository repo.");
+
+ DefaultAnnotationRepository oldRepo = DefaultAnnotationRepository.class.cast(repository);
+ Map<Class<? extends Annotation>, Map<ElementType, Set<ClassSignaturePair>>> env = oldRepo.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());
+ }
+ }
+ }
+ }
+
+ /**
+ * 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
+ */
+ protected 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/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/DefaultElement.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/DefaultElement.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/DefaultElement.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.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/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/EnvPutList.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/EnvPutList.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/EnvPutList.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins;
+
+import java.util.AbstractList;
+
+/**
+ * Put elements directly into env
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class EnvPutList extends AbstractList<CommitElement>
+{
+ private DefaultAnnotationRepository repository;
+
+ EnvPutList(DefaultAnnotationRepository repository)
+ {
+ if (repository == null)
+ throw new IllegalArgumentException("Null repository.");
+ this.repository = repository;
+ }
+
+ public boolean add(CommitElement ce)
+ {
+ repository.putAnnotation(ce.getAnnotation(), ce.getType(), ce.getClassName(), ce.getSignature());
+ return true;
+ }
+
+ public CommitElement get(int index)
+ {
+ throw new UnsupportedOperationException("Should not be invoked.");
+ }
+
+ public int size()
+ {
+ return 0;
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/GenericAnnotationResourceVisitor.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/GenericAnnotationResourceVisitor.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/GenericAnnotationResourceVisitor.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,309 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins;
+
+import org.jboss.classloading.spi.visitor.ClassFilter;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.papaki.AnnotationRepository;
+import org.jboss.papaki.repository.spi.ClassAdapter;
+import org.jboss.papaki.repository.spi.MemberAdapter;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Generic annotation scanner deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class GenericAnnotationResourceVisitor implements ResourceVisitor
+{
+ private static final Logger log = Logger.getLogger(GenericAnnotationResourceVisitor.class);
+
+ private ResourceFilter resourceFilter = ClassFilter.INSTANCE;
+ private boolean forceAnnotations;
+ private boolean checkSuper;
+ private boolean checkInterfaces = true;
+ private DefaultAnnotationRepository repository;
+
+ public GenericAnnotationResourceVisitor(DefaultAnnotationRepository repository)
+ {
+ this.repository = repository;
+ }
+
+ protected abstract boolean isRelevant(ClassAdapter classAdapter);
+
+ protected abstract ClassAdapter createClassAdapter(ResourceContext context) throws Exception;
+
+ public ResourceFilter getFilter()
+ {
+ return resourceFilter;
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ try
+ {
+ ClassAdapter ctClass = createClassAdapter(resource);
+ try
+ {
+ List<CommitElement> commit = createCommitList();
+ handleCtClass(ctClass, commit);
+ if (commit.isEmpty() == false)
+ {
+ for (CommitElement ce : commit)
+ {
+ repository.putAnnotation(ce.getAnnotation(), ce.getType(), ce.getClassName(), ce.getSignature());
+ }
+ }
+ }
+ finally
+ {
+ if (ctClass != null)
+ ctClass.detach();
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ if (forceAnnotations)
+ throw new RuntimeException(e);
+
+ logThrowable(resource, e);
+ }
+ catch (Throwable t)
+ {
+ logThrowable(resource, t);
+ }
+ }
+
+ /**
+ * Create commit list.
+ *
+ * @return the commit list
+ */
+ protected List<CommitElement> createCommitList()
+ {
+ return forceAnnotations ? new EnvPutList(repository) : new ArrayList<CommitElement>();
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Handle CtClass for annotations.
+ *
+ * @param ctClass the ct class instance
+ * @param commit the commit list
+ * @throws ClassNotFoundException for any annotations lookup problems
+ * @throws javassist.NotFoundException for any annotations lookup problems
+ */
+ protected void handleCtClass(ClassAdapter ctClass, List<CommitElement> commit) throws Exception
+ {
+ if (isRelevant(ctClass) == false)
+ return;
+
+ String className = ctClass.getName();
+ if (repository.isAlreadyChecked(className))
+ {
+ if (log.isTraceEnabled())
+ log.trace("Skipping already checked class name: " + className);
+ return;
+ }
+
+ if (checkInterfaces == false && ctClass.isInterface())
+ {
+ if (log.isTraceEnabled())
+ log.trace("Skipping interface: " + className);
+ return;
+ }
+
+ if (log.isTraceEnabled())
+ log.trace("Scanning class " + className + " for annotations");
+
+ Object[] annotations = forceAnnotations ? ctClass.getAnnotations() : ctClass.getAvailableAnnotations();
+ handleAnnotations(ElementType.TYPE, (Signature)null, annotations, className, commit);
+
+ handleCtMembers(ElementType.CONSTRUCTOR, ctClass.getDeclaredConstructors(), className, commit);
+ handleCtMembers(ElementType.METHOD, ctClass.getDeclaredMethods(), className, commit);
+ handleCtMembers(ElementType.FIELD, ctClass.getDeclaredFields(), className, commit);
+
+ if (checkSuper)
+ {
+ if (checkInterfaces)
+ {
+ // interfaces
+ ClassAdapter[] interfaces = ctClass.getInterfaces();
+ if (interfaces != null && interfaces.length > 0)
+ {
+ for (ClassAdapter intf : interfaces)
+ handleCtClass(intf, commit);
+ }
+ }
+ // super class
+ handleCtClass(ctClass.getSuperclass(), commit);
+ }
+ }
+
+ /**
+ * Handle CtMembers for annotations.
+ *
+ * @param type where we found the annotations
+ * @param members the ct member instances
+ * @param className the className
+ * @param commit the commit list
+ * @throws Exception for any annotations lookup problems
+ */
+ protected void handleCtMembers(ElementType type, MemberAdapter[] members, String className, List<CommitElement> commit) throws Exception
+ {
+ if (members != null && members.length > 0)
+ {
+ for (MemberAdapter member : members)
+ {
+ Object[] annotations = forceAnnotations ? member.getAnnotations() : member.getAvailableAnnotations();
+ handleAnnotations(type, member, annotations, className, commit);
+ if (member.isParametrized())
+ {
+ Object[][] paramAnnotations = forceAnnotations ? member.getParameterAnnotations() : member.getAvailableParameterAnnotations();
+ for (int index = 0; index < paramAnnotations.length; index++)
+ {
+ handleAnnotations(ElementType.PARAMETER, member.getSignature(index), paramAnnotations[index], className, commit);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Handle annotations.
+ *
+ * @param type where we found the annotations
+ * @param member the ct member
+ * @param annotations the actual annotations
+ * @param className the className
+ * @param commit the commit list
+ * @throws Exception for any annotations lookup problems
+ */
+ protected static void handleAnnotations(ElementType type, MemberAdapter member, Object[] annotations, String className, List<CommitElement> commit) throws Exception
+ {
+ Signature signature = null;
+ if (member != null)
+ signature = member.getSignature();
+
+ handleAnnotations(type, signature, annotations, className, commit);
+ }
+
+ /**
+ * Handle annotations.
+ *
+ * @param type where we found the annotations
+ * @param signature the signature
+ * @param annotations the actual annotations
+ * @param className the className
+ * @param commit the commit list
+ */
+ protected static void handleAnnotations(ElementType type, Signature signature, Object[] annotations, String className, List<CommitElement> commit)
+ {
+ if (annotations != null && annotations.length > 0)
+ {
+ for (Object annObject : annotations)
+ {
+ Annotation annotation = Annotation.class.cast(annObject);
+ commit.add(new CommitElement(annotation, type, className, signature));
+ }
+ }
+ }
+
+ /**
+ * Set the resource filter.
+ *
+ * @param resourceFilter the resource filter
+ */
+ public void setResourceFilter(ResourceFilter resourceFilter)
+ {
+ this.resourceFilter = resourceFilter;
+ }
+
+ /**
+ * Should we force all annotations to be available.
+ *
+ * @param forceAnnotations the force annotations flag
+ */
+ public void setForceAnnotations(boolean forceAnnotations)
+ {
+ this.forceAnnotations = forceAnnotations;
+ }
+
+ /**
+ * Set the keep annotations flag.
+ *
+ * @param keepAnnotations the keep annotations flag
+ */
+ public void setKeepAnnotations(boolean keepAnnotations)
+ {
+ repository.setKeepAnnotations(keepAnnotations);
+ }
+
+ /**
+ * Should we check super class for annotations as well.
+ *
+ * @param checkSuper the check super flag
+ */
+ public void setCheckSuper(boolean checkSuper)
+ {
+ this.checkSuper = checkSuper;
+ }
+
+ /**
+ * Should we check interfaces for annotations as well.
+ *
+ * @param checkInterfaces the check interfaces flag
+ */
+ public void setCheckInterfaces(boolean checkInterfaces)
+ {
+ this.checkInterfaces = checkInterfaces;
+ }
+
+ /**
+ * Get the built environment.
+ *
+ * @return the annoattion environment
+ */
+ public AnnotationRepository getRepository()
+ {
+ return repository;
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ParametersElement.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ParametersElement.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/ParametersElement.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.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/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/WeakClassLoaderHolder.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/WeakClassLoaderHolder.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/WeakClassLoaderHolder.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.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;
+ }
+
+ /**
+ * Set ClassLoader.
+ *
+ * @param classLoader the classloader
+ */
+ void setClassLoader(ClassLoader classLoader)
+ {
+ ClassLoader oldCL = (clRef != null) ? clRef.get() : null;
+ if (oldCL != null && classLoader.equals(oldCL) == false)
+ throw new IllegalArgumentException("Trying to override existing classloader: " + oldCL + "!=" + classLoader);
+
+ clRef = new WeakReference<ClassLoader>(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);
+ }
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtClassAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtClassAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtClassAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.javassist;
+
+import org.jboss.papaki.repository.spi.ClassAdapter;
+import org.jboss.papaki.repository.spi.MemberAdapter;
+
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtMethod;
+import javassist.CtField;
+
+/**
+ * Javassist class adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class CtClassAdapter implements ClassAdapter
+{
+ private CtClass ctClass;
+
+ public CtClassAdapter(CtClass ctClass)
+ {
+ this.ctClass = ctClass;
+ }
+
+ CtClass getCtClass()
+ {
+ return ctClass;
+ }
+
+ public String getName()
+ {
+ return ctClass.getName();
+ }
+
+ public boolean isInterface()
+ {
+ return ctClass.isInterface();
+ }
+
+ public MemberAdapter[] getDeclaredConstructors()
+ {
+ CtConstructor[] ctors = ctClass.getDeclaredConstructors();
+ MemberAdapter[] adapters = new MemberAdapter[ctors.length];
+ for (int i = 0; i < ctors.length; i++)
+ adapters[i] = new CtConstructorAdapter(ctors[i]);
+ return adapters;
+ }
+
+ public MemberAdapter[] getDeclaredMethods()
+ {
+ CtMethod[] methods = ctClass.getDeclaredMethods();
+ MemberAdapter[] adapters = new MemberAdapter[methods.length];
+ for (int i = 0; i < methods.length; i++)
+ adapters[i] = new CtMethodAdapter(methods[i]);
+ return adapters;
+ }
+
+ public MemberAdapter[] getDeclaredFields()
+ {
+ CtField[] fields = ctClass.getDeclaredFields();
+ MemberAdapter[] adapters = new MemberAdapter[fields.length];
+ for (int i = 0; i < fields.length; i++)
+ adapters[i] = new CtFieldAdapter(fields[i]);
+ return adapters;
+ }
+
+ public ClassAdapter getSuperclass() throws Exception
+ {
+ CtClass superclass = ctClass.getSuperclass();
+ return superclass != null ? new CtClassAdapter(superclass) : null;
+ }
+
+ public ClassAdapter[] getInterfaces() throws Exception
+ {
+ CtClass[] ifaces = ctClass.getInterfaces();
+ CtClassAdapter[] adapters = new CtClassAdapter[ifaces.length];
+ for (int i = 0; i < ifaces.length; i++)
+ adapters[i] = new CtClassAdapter(ifaces[i]);
+ return adapters;
+ }
+
+ public void detach()
+ {
+ ctClass.detach();
+ }
+
+ public Object[] getAnnotations() throws ClassNotFoundException
+ {
+ return ctClass.getAnnotations();
+ }
+
+ public Object[] getAvailableAnnotations()
+ {
+ return ctClass.getAvailableAnnotations();
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtConstructorAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtConstructorAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtConstructorAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.javassist;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metadata.spi.signature.javassist.JavassistConstructorParametersSignature;
+import org.jboss.metadata.spi.signature.javassist.JavassistConstructorSignature;
+
+import javassist.CtConstructor;
+
+/**
+ * Javassist member adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class CtConstructorAdapter extends CtMemberAdapter<CtConstructor>
+{
+ public CtConstructorAdapter(CtConstructor ctor)
+ {
+ super(ctor);
+ }
+
+ public Signature getSignature() throws Exception
+ {
+ return new JavassistConstructorSignature(member);
+ }
+
+ public Signature getSignature(int index) throws Exception
+ {
+ return new JavassistConstructorParametersSignature(member, index);
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtFieldAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtFieldAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtFieldAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.javassist;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metadata.spi.signature.javassist.JavassistFieldSignature;
+
+import javassist.CtField;
+
+/**
+ * Javassist member adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class CtFieldAdapter extends CtMemberAdapter<CtField>
+{
+ public CtFieldAdapter(CtField field)
+ {
+ super(field);
+ }
+
+ public Signature getSignature()
+ {
+ return new JavassistFieldSignature(member);
+ }
+
+ public Signature getSignature(int index) throws Exception
+ {
+ throw new IllegalArgumentException("Fields cannot have parameters.");
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtMemberAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtMemberAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtMemberAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.javassist;
+
+import org.jboss.papaki.repository.spi.MemberAdapter;
+
+import javassist.CtBehavior;
+import javassist.CtMember;
+
+/**
+ * Javassist member adapter.
+ *
+ * @param <T> exact member type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class CtMemberAdapter<T extends CtMember> implements MemberAdapter
+{
+ protected T member;
+
+ public CtMemberAdapter(T member)
+ {
+ this.member = member;
+ }
+
+ public boolean isParametrized()
+ {
+ return (member instanceof CtBehavior);
+ }
+
+ public Object[][] getParameterAnnotations() throws ClassNotFoundException
+ {
+ CtBehavior behavior = (CtBehavior)member;
+ return behavior.getParameterAnnotations();
+ }
+
+ public Object[][] getAvailableParameterAnnotations()
+ {
+ CtBehavior behavior = (CtBehavior)member;
+ return behavior.getAvailableParameterAnnotations();
+ }
+
+ public Object[] getAnnotations() throws ClassNotFoundException
+ {
+ return member.getAnnotations();
+ }
+
+ public Object[] getAvailableAnnotations()
+ {
+ return member.getAvailableAnnotations();
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtMethodAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtMethodAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/CtMethodAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.javassist;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metadata.spi.signature.javassist.JavassistMethodParametersSignature;
+import org.jboss.metadata.spi.signature.javassist.JavassistMethodSignature;
+
+import javassist.CtMethod;
+
+/**
+ * Javassist member adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class CtMethodAdapter extends CtMemberAdapter<CtMethod>
+{
+ public CtMethodAdapter(CtMethod method)
+ {
+ super(method);
+ }
+
+ public Signature getSignature() throws Exception
+ {
+ return new JavassistMethodSignature(member);
+ }
+
+ public Signature getSignature(int index) throws Exception
+ {
+ return new JavassistMethodParametersSignature(member, index);
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/JavassistAnnotationResourceVisitor.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/JavassistAnnotationResourceVisitor.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/javassist/JavassistAnnotationResourceVisitor.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.javassist;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.papaki.repository.plugins.GenericAnnotationResourceVisitor;
+import org.jboss.papaki.repository.plugins.DefaultAnnotationRepository;
+import org.jboss.papaki.repository.spi.ClassAdapter;
+
+import java.io.InputStream;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+
+/**
+ * Javassist based annotation visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JavassistAnnotationResourceVisitor extends GenericAnnotationResourceVisitor
+{
+ private ClassPool pool;
+ private CtClass ctObject;
+
+ public JavassistAnnotationResourceVisitor(DefaultAnnotationRepository repository, ClassPool pool)
+ {
+ super(repository);
+
+ if (pool == null)
+ throw new IllegalArgumentException("Null pool");
+
+ this.pool = pool;
+ ctObject = pool.makeClass(Object.class.getName());
+ }
+
+ protected boolean isRelevant(ClassAdapter classAdapter)
+ {
+ CtClass ctCA = CtClassAdapter.class.cast(classAdapter).getCtClass();
+ return ctObject.equals(ctCA) == false;
+ }
+
+ protected ClassAdapter createClassAdapter(ResourceContext context) throws Exception
+ {
+ InputStream stream = context.getInputStream();
+ if (stream == null)
+ throw new IllegalArgumentException("Null stream: " + context);
+
+ try
+ {
+ CtClass ctClass = pool.makeClass(stream);
+ return new CtClassAdapter(ctClass);
+ }
+ finally
+ {
+ stream.close();
+ }
+ }
+}
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionAnnotationResourceVisitor.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionAnnotationResourceVisitor.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionAnnotationResourceVisitor.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.reflection;
+
+import org.jboss.papaki.repository.plugins.GenericAnnotationResourceVisitor;
+import org.jboss.papaki.repository.plugins.DefaultAnnotationRepository;
+import org.jboss.papaki.repository.spi.ClassAdapter;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+
+/**
+ * Reflection based annotation scanning.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ReflectionAnnotationResourceVisitor extends GenericAnnotationResourceVisitor
+{
+ public ReflectionAnnotationResourceVisitor(DefaultAnnotationRepository repository)
+ {
+ super(repository);
+ }
+
+ protected boolean isRelevant(ClassAdapter classAdapter)
+ {
+ ReflectionClassAdapter rca = ReflectionClassAdapter.class.cast(classAdapter);
+ return Object.class.equals(rca.getClazz()) == false;
+ }
+
+ protected ClassAdapter createClassAdapter(ResourceContext context) throws Exception
+ {
+ return new ReflectionClassAdapter(context.loadClass());
+ }
+}
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionClassAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionClassAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionClassAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.reflection;
+
+import org.jboss.papaki.repository.spi.ClassAdapter;
+import org.jboss.papaki.repository.spi.MemberAdapter;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * Reflection based class adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ReflectionClassAdapter implements ClassAdapter
+{
+ private Class<?> clazz;
+
+ public ReflectionClassAdapter(Class<?> clazz)
+ {
+ this.clazz = clazz;
+ }
+
+ Class<?> getClazz()
+ {
+ return clazz;
+ }
+
+ public String getName()
+ {
+ return clazz.getName();
+ }
+
+ public boolean isInterface()
+ {
+ return clazz.isInterface();
+ }
+
+ public MemberAdapter[] getDeclaredConstructors()
+ {
+ Constructor[] ctors = clazz.getDeclaredConstructors();
+ MemberAdapter[] adapters = new MemberAdapter[ctors.length];
+ for (int i = 0; i < ctors.length; i++)
+ adapters[i] = new ReflectionConstructorAdapter(ctors[i]);
+ return adapters;
+ }
+
+ public MemberAdapter[] getDeclaredMethods()
+ {
+ Method[] methods = clazz.getDeclaredMethods();
+ MemberAdapter[] adapters = new MemberAdapter[methods.length];
+ for (int i = 0; i < methods.length; i++)
+ adapters[i] = new ReflectionMethodAdapter(methods[i]);
+ return adapters;
+ }
+
+ public MemberAdapter[] getDeclaredFields()
+ {
+ Field[] fields = clazz.getDeclaredFields();
+ MemberAdapter[] adapters = new MemberAdapter[fields.length];
+ for (int i = 0; i < fields.length; i++)
+ adapters[i] = new ReflectionFieldAdapter(fields[i]);
+ return adapters;
+ }
+
+ public ClassAdapter getSuperclass() throws Exception
+ {
+ Class<?> superclass = clazz.getSuperclass();
+ return (superclass != null) ? new ReflectionClassAdapter(superclass) : null;
+ }
+
+ public ClassAdapter[] getInterfaces() throws Exception
+ {
+ return new ClassAdapter[0]; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void detach()
+ {
+ }
+
+ public Object[] getAnnotations() throws ClassNotFoundException
+ {
+ return getAvailableAnnotations();
+ }
+
+ public Object[] getAvailableAnnotations()
+ {
+ return clazz.getDeclaredAnnotations();
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionConstructorAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionConstructorAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionConstructorAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.reflection;
+
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * Reflection based ctor adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ReflectionConstructorAdapter extends ReflectionMemberAdapter
+{
+ private Constructor ctor;
+
+ public ReflectionConstructorAdapter(Constructor ctor)
+ {
+ this.ctor = ctor;
+ }
+
+ public boolean isParametrized()
+ {
+ return true;
+ }
+
+ public Object[][] getAvailableParameterAnnotations()
+ {
+ return ctor.getParameterAnnotations();
+ }
+
+ public Signature getSignature()
+ {
+ return new ConstructorSignature(ctor);
+ }
+
+ public Signature getSignature(int index) throws Exception
+ {
+ return new ConstructorParametersSignature(ctor, index);
+ }
+
+ public Object[] getAvailableAnnotations()
+ {
+ return ctor.getDeclaredAnnotations();
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionFieldAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionFieldAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionFieldAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.reflection;
+
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.Signature;
+
+import java.lang.reflect.Field;
+
+/**
+ * Reflection based field adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ReflectionFieldAdapter extends ReflectionMemberAdapter
+{
+ private Field field;
+
+ public ReflectionFieldAdapter(Field field)
+ {
+ this.field = field;
+ }
+
+ public boolean isParametrized()
+ {
+ return false;
+ }
+
+ public Object[][] getAvailableParameterAnnotations()
+ {
+ throw new IllegalArgumentException("Fields cannot have parameters.");
+ }
+
+ public Signature getSignature()
+ {
+ return new FieldSignature(field);
+ }
+
+ public Signature getSignature(int index) throws Exception
+ {
+ throw new IllegalArgumentException("Fields cannot have parameters.");
+ }
+
+ public Object[] getAvailableAnnotations()
+ {
+ return field.getDeclaredAnnotations();
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionMemberAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionMemberAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionMemberAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.reflection;
+
+import org.jboss.papaki.repository.spi.MemberAdapter;
+
+/**
+ * Reflection based class adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class ReflectionMemberAdapter implements MemberAdapter
+{
+ public Object[][] getParameterAnnotations() throws ClassNotFoundException
+ {
+ return getAvailableParameterAnnotations();
+ }
+
+ public Object[] getAnnotations() throws ClassNotFoundException
+ {
+ return getAvailableAnnotations();
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionMethodAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionMethodAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/plugins/reflection/ReflectionMethodAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.plugins.reflection;
+
+import org.jboss.metadata.spi.signature.MethodParametersSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
+
+import java.lang.reflect.Method;
+
+/**
+ * Reflection based method adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ReflectionMethodAdapter extends ReflectionMemberAdapter
+{
+ private Method method;
+
+ public ReflectionMethodAdapter(Method method)
+ {
+ this.method = method;
+ }
+
+ public boolean isParametrized()
+ {
+ return true;
+ }
+
+ public Object[][] getAvailableParameterAnnotations()
+ {
+ return method.getParameterAnnotations();
+ }
+
+ public Signature getSignature()
+ {
+ return new MethodSignature(method);
+ }
+
+ public Signature getSignature(int index) throws Exception
+ {
+ return new MethodParametersSignature(method, index);
+ }
+
+ public Object[] getAvailableAnnotations()
+ {
+ return method.getDeclaredAnnotations();
+ }
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/AnnotatedAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/AnnotatedAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/AnnotatedAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.spi;
+
+/**
+ * Adapt to undelying Class impl.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface AnnotatedAdapter
+{
+ Object[] getAnnotations() throws ClassNotFoundException;
+
+ Object[] getAvailableAnnotations();
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/ClassAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/ClassAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/ClassAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.spi;
+
+/**
+ * Adapt to undelying Class impl.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ClassAdapter extends AnnotatedAdapter
+{
+ String getName();
+
+ boolean isInterface();
+
+ MemberAdapter[] getDeclaredConstructors();
+
+ MemberAdapter[] getDeclaredMethods();
+
+ MemberAdapter[] getDeclaredFields();
+
+ ClassAdapter getSuperclass() throws Exception;
+
+ ClassAdapter[] getInterfaces() throws Exception;
+
+ void detach();
+}
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/MemberAdapter.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/MemberAdapter.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/repository/spi/MemberAdapter.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.repository.spi;
+
+import org.jboss.metadata.spi.signature.Signature;
+
+/**
+ * Adapt to undelying Class impl.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface MemberAdapter extends AnnotatedAdapter
+{
+ boolean isParametrized();
+
+ Object[][] getParameterAnnotations() throws ClassNotFoundException;
+
+ Object[][] getAvailableParameterAnnotations();
+
+ Signature getSignature() throws Exception;
+
+ Signature getSignature(int index) throws Exception;
+}
\ No newline at end of file
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/AbstractAnnotationScanner.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/AbstractAnnotationScanner.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/AbstractAnnotationScanner.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.scanner;
+
+import org.jboss.papaki.AnnotationRepository;
+import org.jboss.papaki.AnnotationScanner;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+import java.io.ObjectInputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * Abstract annotation scanner.
+ *
+ * @param <T> exact repository type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractAnnotationScanner<T extends AnnotationRepository> implements AnnotationScanner
+{
+ public AnnotationRepository scan(URL[] urls, ClassLoader... cls) throws Exception
+ {
+ T repository = createAnnotationRepository(cls);
+ List<URL> list = new ArrayList<URL>();
+ for (URL url : urls)
+ {
+ VFS vfs = VFS.getVFS(url);
+ VirtualFile file = vfs.getChild("META-INF/" + AnnotationRepository.PAPAKI_METADATA_BINARY);
+ if (file != null)
+ reattach(repository, file, cls);
+ else
+ list.add(url);
+ }
+
+ if (list.isEmpty() == false)
+ rescan(repository, list.toArray(new URL[list.size()]), cls);
+
+ return repository;
+ }
+
+ protected void reattach(T repo, VirtualFile papaki, ClassLoader... cls) throws Exception
+ {
+ InputStream is = papaki.openStream();
+ ObjectInputStream ois;
+ try
+ {
+ GZIPInputStream gis = new GZIPInputStream(is);
+ ois = new ObjectInputStream(gis);
+ }
+ finally
+ {
+ is.close();
+ }
+
+ AnnotationRepository oldRepo = (AnnotationRepository)ois.readObject();
+ repo.merge(oldRepo);
+ }
+
+ protected abstract T createAnnotationRepository(ClassLoader... cls);
+
+ protected abstract void rescan(T repo, URL[] urls, ClassLoader... cls) throws Exception;
+}
Added: projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/DefaultAnnotationScanner.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/DefaultAnnotationScanner.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/DefaultAnnotationScanner.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.scanner;
+
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.plugins.vfs.VFSResourceVisitor;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.papaki.repository.plugins.DefaultAnnotationRepository;
+import org.jboss.papaki.repository.plugins.reflection.ReflectionAnnotationResourceVisitor;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+import java.net.URL;
+import java.util.Arrays;
+
+/**
+ * Default annotation scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultAnnotationScanner extends AbstractAnnotationScanner<DefaultAnnotationRepository>
+{
+ private ClassFilter included;
+ private ClassFilter excluded;
+ private ResourceFilter recurseFilter;
+
+ protected DefaultAnnotationRepository createAnnotationRepository(ClassLoader... cls)
+ {
+ if (cls == null || cls.length > 1)
+ throw new IllegalArgumentException("Illegal cls length: " + Arrays.toString(cls));
+
+ return new DefaultAnnotationRepository(cls[0]);
+ }
+
+ protected void rescan(DefaultAnnotationRepository repo, URL[] urls, ClassLoader... cls) throws Exception
+ {
+ VirtualFile[] roots = new VirtualFile[urls.length];
+ for (int i = 0; i < roots.length; i++)
+ {
+ roots[i] = VFS.getRoot(urls[i]);
+ }
+ ResourceVisitor visitor = createResourceVisitor(repo);
+ ClassLoader classLoader = cls[0];
+
+ // something in javassist uses TCL
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(classLoader);
+ try
+ {
+ VFSResourceVisitor.visit(roots, null, included, excluded, cls[0], visitor, visitor.getFilter(), recurseFilter, urls);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
+ }
+
+ protected ResourceVisitor createResourceVisitor(DefaultAnnotationRepository repository)
+ {
+ return new ReflectionAnnotationResourceVisitor(repository);
+ }
+
+ 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/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/JavassistAnnotationScanner.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/JavassistAnnotationScanner.java (rev 0)
+++ projects/annotations/branches/AnnEnv/core/src/main/java/org/jboss/papaki/scanner/JavassistAnnotationScanner.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.papaki.scanner;
+
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.papaki.repository.plugins.DefaultAnnotationRepository;
+import org.jboss.papaki.repository.plugins.javassist.JavassistAnnotationResourceVisitor;
+
+import javassist.ClassPool;
+
+/**
+ * Javassist annotation scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JavassistAnnotationScanner extends DefaultAnnotationScanner
+{
+ private ClassPool pool = ClassPool.getDefault();
+
+ @Override
+ protected ResourceVisitor createResourceVisitor(DefaultAnnotationRepository repository)
+ {
+ return new JavassistAnnotationResourceVisitor(repository, pool);
+ }
+
+ public void setPool(ClassPool pool)
+ {
+ this.pool = pool;
+ }
+}
\ No newline at end of file
Deleted: projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationRepositoryTests.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationRepositoryTests.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationRepositoryTests.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,429 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki.test;
-
-import org.jboss.papaki.Annotation;
-import org.jboss.papaki.AnnotationRepository;
-import org.jboss.papaki.AnnotationScanner;
-import org.jboss.papaki.AnnotationType;
-import org.jboss.papaki.Settings;
-import org.jboss.papaki.Visibility;
-import org.jboss.papaki.impl.AnnotationRepositoryImpl;
-import org.jboss.papaki.impl.ClassInfo;
-import org.jboss.papaki.impl.SettingsImpl;
-import org.jboss.papaki.test.tests.common.MyAnnotation;
-
-import java.net.URL;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for the annotation repository
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @version $Revision: $
- */
-public abstract class AnnotationRepositoryTests extends AnnotationTests
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static Logger log = Logger.getLogger(AnnotationRepositoryTests.class.getName());
-
- /** The scanner instance */
- protected static AnnotationScanner scanner = null;
-
- // --------------------------------------------------------------------------------||
- // Tests --------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Defined
- * @throws Throwable throwable exception
- */
- @Test
- public void testDefined() throws Throwable
- {
- assertNotNull(scanner);
- }
-
- /**
- * Constructor null
- * @throws Throwable throwable exception
- */
- @Test
- public void testConstructorNullParameter1() throws Throwable
- {
- try
- {
- Map<String, ClassInfo> m = new HashMap<String, ClassInfo>();
- Settings s = new SettingsImpl(true, Visibility.PUBLIC,
- true, Visibility.PUBLIC,
- true, Visibility.PUBLIC,
- true, Visibility.PUBLIC,
- true);
-
- AnnotationRepositoryImpl ar = new AnnotationRepositoryImpl(null, m, s);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * Constructor null
- * @throws Throwable throwable exception
- */
- @Test
- public void testConstructorNullParameter2() throws Throwable
- {
- try
- {
- Map<String, Collection<String>> m = new HashMap<String, Collection<String>>();
- Settings s = new SettingsImpl(true, Visibility.PUBLIC,
- true, Visibility.PUBLIC,
- true, Visibility.PUBLIC,
- true, Visibility.PUBLIC,
- true);
-
- AnnotationRepositoryImpl ar = new AnnotationRepositoryImpl(m, null, s);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * Constructor null
- * @throws Throwable throwable exception
- */
- @Test
- public void testConstructorNullParameter3() throws Throwable
- {
- try
- {
- Map<String, Collection<String>> m1 = new HashMap<String, Collection<String>>();
- Map<String, ClassInfo> m2 = new HashMap<String, ClassInfo>();
-
- AnnotationRepositoryImpl ar = new AnnotationRepositoryImpl(m1, m2, null);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * Constructor standard
- * @throws Throwable throwable exception
- */
- @Test
- public void testConstructorStandard() throws Throwable
- {
- Map<String, Collection<String>> m1 = new HashMap<String, Collection<String>>();
- Map<String, ClassInfo> m2 = new HashMap<String, ClassInfo>();
- Settings s = new SettingsImpl(true, Visibility.PUBLIC,
- true, Visibility.PUBLIC,
- true, Visibility.PUBLIC,
- true, Visibility.PUBLIC,
- true);
-
- AnnotationRepositoryImpl ar = new AnnotationRepositoryImpl(m1, m2, s);
- assertNotNull(ar);
- }
-
- /**
- * Empty
- * @throws Throwable throwable exception
- */
- @Test
- public void testEmpty() throws Throwable
- {
- URL archive = getURL("classempty.jar");
- AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.getSize() == 0);
- }
-
- /**
- * GetAvailableAnnotations
- * @throws Throwable throwable exception
- */
- @Test
- public void testGetAvailableAnnotatitions() throws Throwable
- {
- URL archive = getURL("classlevel.jar");
- AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
- assertTrue("Size=" + ar.getAvailableAnnotations().size(), ar.getAvailableAnnotations().size() == 1);
- }
-
- /**
- * HasAnnotation null (Class)
- * @throws Throwable throwable exception
- */
- @Test
- public void testHasAnnotatitionClassNull() throws Throwable
- {
- URL archive = getURL("classlevel.jar");
- AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- try
- {
- ar.hasAnnotation((Class)null);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * HasAnnotation null (String)
- * @throws Throwable throwable exception
- */
- @Test
- public void testHasAnnotatitionStringNull() throws Throwable
- {
- URL archive = getURL("classlevel.jar");
- AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- try
- {
- ar.hasAnnotation((String)null);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * GetAnnotation null (Class)
- * @throws Throwable throwable exception
- */
- @Test
- public void testGetAnnotatitionClassNull() throws Throwable
- {
- URL archive = getURL("classlevel.jar");
- AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- try
- {
- Collection<Annotation> l = ar.getAnnotation((Class)null);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * GetAnnotation null (String)
- * @throws Throwable throwable exception
- */
- @Test
- public void testGetAnnotatitionStringNull() throws Throwable
- {
- URL archive = getURL("classlevel.jar");
- AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- try
- {
- Collection<Annotation> l = ar.getAnnotation((String)null);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * Size null
- * @throws Throwable throwable exception
- */
- @Test
- public void testSizeNull() throws Throwable
- {
- URL archive = getURL("classlevel.jar");
- AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- try
- {
- int size = ar.getSize(null);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * Size
- * @throws Throwable throwable exception
- */
- @Test
- public void testSize() throws Throwable
- {
- URL archive = getURL("classlevel.jar");
- AnnotationRepositoryImpl ar = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.getSize() == 1);
- assertTrue(ar.hasAnnotation(Deprecated.class));
- assertTrue(ar.getSize(Deprecated.class) == 1);
- assertTrue(ar.getSize(MyAnnotation.class) == 0);
- }
-
- /**
- * Result modify
- * @throws Throwable throwable exception
- */
- @Test
- public void testResultModify() throws Throwable
- {
- URL archive = getURL("classlevel.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue(l.size() == 1);
-
- Annotation annotation = new Annotation("nothing", new Object(), AnnotationType.CLASS,
- "org.jboss.papaki.test.DE", null, (String[])null, -1);
- try
- {
- l.add(annotation);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * Merge: Empty
- * @throws Throwable throwable exception
- */
- @Test
- public void testMergeEmpty() throws Throwable
- {
- URL archive = getURL("classempty.jar");
- AnnotationRepositoryImpl ar1 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive});
-
- assertNotNull(ar1);
-
- assertTrue(ar1.getSize() == 0);
-
- AnnotationRepository ar2 = scanner.scan(new URL[] {archive});
-
- ar1.merge(ar2);
-
- assertTrue(ar1.getSize() == 0);
- }
-
- /**
- * Merge
- * @throws Throwable throwable exception
- */
- @Test
- public void testMergeFullEmpty() throws Throwable
- {
- URL archive1 = getURL("classlevel.jar");
- AnnotationRepositoryImpl ar1 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive1});
-
- assertNotNull(ar1);
- assertTrue("Size=" + ar1.getSize(), ar1.getSize() == 1);
-
- URL archive2 = getURL("classempty.jar");
- AnnotationRepositoryImpl ar2 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive2});
-
- assertNotNull(ar2);
- assertTrue("Size=" + ar2.getSize(), ar2.getSize() == 0);
-
- ar1.merge(ar2);
-
- assertTrue("Size=" + ar1.getSize(), ar1.getSize() == 1);
- }
-
- /**
- * Merge
- * @throws Throwable throwable exception
- */
- @Test
- public void testMergeEmptyFull() throws Throwable
- {
- URL archive1 = getURL("classempty.jar");
- AnnotationRepositoryImpl ar1 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive1});
-
- assertNotNull(ar1);
- assertTrue("Size=" + ar1.getSize(), ar1.getSize() == 0);
-
- URL archive2 = getURL("classlevel.jar");
- AnnotationRepositoryImpl ar2 = (AnnotationRepositoryImpl)scanner.scan(new URL[] {archive2});
-
- assertNotNull(ar2);
- assertTrue("Size=" + ar2.getSize(), ar2.getSize() == 1);
-
- ar1.merge(ar2);
-
- assertTrue("Size=" + ar1.getSize(), ar1.getSize() == 1);
- }
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationScannerFactoryTests.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationScannerFactoryTests.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationScannerFactoryTests.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,107 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki.test;
-
-import org.jboss.papaki.AnnotationScanner;
-import org.jboss.papaki.AnnotationScannerFactory;
-
-import java.util.logging.Logger;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test for the annotation scanner
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @version $Revision: $
- */
-public abstract class AnnotationScannerFactoryTests extends AnnotationTests
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static Logger log = Logger.getLogger(AnnotationScannerFactoryTests.class.getName());
-
- /** The annotation scanner factory constant */
- protected static int asf;
-
- // --------------------------------------------------------------------------------||
- // Tests --------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Default
- * @throws Throwable throwable exception
- */
- @Test
- public void testDefault() throws Throwable
- {
- AnnotationScanner scanner = AnnotationScannerFactory.getDefault();
-
- assertNotNull(scanner);
- }
-
- /**
- * Constant
- * @throws Throwable throwable exception
- */
- @Test
- public void testConstant() throws Throwable
- {
- AnnotationScanner scanner = AnnotationScannerFactory.getStrategy(asf);
-
- assertNotNull(scanner);
- }
-
-
- /**
- * Illegal value
- * @throws Throwable throwable exception
- */
- @Test
- public void testIllegalValue() throws Throwable
- {
- try
- {
- AnnotationScanner scanner = AnnotationScannerFactory.getStrategy(-1);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
-
- try
- {
- AnnotationScanner scanner = AnnotationScannerFactory.getStrategy(3);
- fail("Operation success");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationTests.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationTests.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/AnnotationTests.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki.test;
-
-import java.io.File;
-import java.net.URL;
-import java.util.logging.Logger;
-
-/**
- * Base class for all annotation test cases
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @version $Revision: $
- */
-public abstract class AnnotationTests
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static Logger log = Logger.getLogger(AnnotationTests.class.getName());
-
- // --------------------------------------------------------------------------------||
- // Methods ------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Get the URL for a test archive
- * @param archive The name of the test archive
- * @return The URL to the archive
- * @throws Throwable throwable exception
- */
- public URL getURL(String archive) throws Throwable
- {
- File f = new File(System.getProperty("archives.dir") + File.separator + archive);
- return f.toURI().toURL();
- }
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ClassInfoTests.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ClassInfoTests.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ClassInfoTests.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,257 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki.test;
-
-import org.jboss.papaki.Annotation;
-import org.jboss.papaki.AnnotationType;
-import org.jboss.papaki.impl.ClassInfo;
-
-import java.util.Collection;
-import java.util.logging.Logger;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test for ClassInfo
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @version $Revision: $
- */
-public abstract class ClassInfoTests extends AnnotationTests
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static Logger log = Logger.getLogger(ClassInfoTests.class.getName());
-
- // --------------------------------------------------------------------------------||
- // Tests --------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Constructor: Null
- * @throws Throwable throwable exception
- */
- @Test
- public void testConstructorNull() throws Throwable
- {
- try
- {
- ClassInfo ci = new ClassInfo(null);
- fail("ClassName failed");
- }
- catch (Throwable t)
- {
- // Ok
- }
- }
-
- /**
- * Constructor: NotNull
- * @throws Throwable throwable exception
- */
- @Test
- public void testConstructorNotNull() throws Throwable
- {
- String name = "myclass";
-
- ClassInfo ci = new ClassInfo(name);
-
- assertNotNull(ci);
- assertEquals(name, ci.getClassName());
- }
-
- /**
- * Interface
- * @throws Throwable throwable exception
- */
- @Test
- public void testInterface() throws Throwable
- {
- String name = "myclass";
-
- ClassInfo ci = new ClassInfo(name);
-
- assertNotNull(ci);
- assertEquals(name, ci.getClassName());
- assertFalse(ci.isInterface());
-
- ci.setInterface(true);
- assertTrue(ci.isInterface());
- }
-
- /**
- * Abstract
- * @throws Throwable throwable exception
- */
- @Test
- public void testAbstract() throws Throwable
- {
- String name = "myclass";
-
- ClassInfo ci = new ClassInfo(name);
-
- assertNotNull(ci);
- assertEquals(name, ci.getClassName());
- assertFalse(ci.isAbstract());
-
- ci.setAbstract(true);
- assertTrue(ci.isAbstract());
- }
-
- /**
- * GetAnnotations: Null
- * @throws Throwable throwable exception
- */
- @Test
- public void testGetAnnotationsNull() throws Throwable
- {
- String name = "myclass";
-
- ClassInfo ci = new ClassInfo(name);
-
- assertNotNull(ci);
- assertEquals(name, ci.getClassName());
-
- assertNull(ci.getAnnotations());
- }
-
- /**
- * GetAnnotations(String): Null
- * @throws Throwable throwable exception
- */
- @Test
- public void testGetAnnotationsNameNull() throws Throwable
- {
- String name = "myclass";
-
- ClassInfo ci = new ClassInfo(name);
-
- assertNotNull(ci);
- assertEquals(name, ci.getClassName());
-
- assertNull(ci.getAnnotations("annotation"));
- }
-
- /**
- * AddAnnotation
- * @throws Throwable throwable exception
- */
- @Test
- public void testAddAnnotation() throws Throwable
- {
- String name = "myclass";
-
- ClassInfo ci = new ClassInfo(name);
-
- assertNotNull(ci);
- assertEquals(name, ci.getClassName());
-
- String key = "key";
- Annotation annotation = new Annotation(key, new Object(), AnnotationType.CLASS,
- ClassInfoTests.class.getName(), null, null, -1);
-
- try
- {
- ci.addAnnotation(null, annotation);
- fail("Key failed");
- }
- catch (Throwable t)
- {
- // Ok
- }
-
- try
- {
- ci.addAnnotation(key, null);
- fail("Annotation failed");
- }
- catch (Throwable t)
- {
- // Ok
- }
-
- ci.addAnnotation(key, annotation);
-
- Collection<Annotation> c = ci.getAnnotations();
- assertNotNull(c);
- assertTrue("Size=" + c.size(), c.size() == 1);
-
- c = ci.getAnnotations(key);
- assertNotNull(c);
- assertTrue("Size=" + c.size(), c.size() == 1);
- }
-
- /**
- * GetChildren: Null
- * @throws Throwable throwable exception
- */
- @Test
- public void testGetChildrenNull() throws Throwable
- {
- String name = "myclass";
-
- ClassInfo ci = new ClassInfo(name);
-
- assertNotNull(ci);
- assertEquals(name, ci.getClassName());
-
- assertNull(ci.getChildren());
- }
-
- /**
- * AddChild
- * @throws Throwable throwable exception
- */
- @Test
- public void testAddChild() throws Throwable
- {
- String name = "myclass";
-
- ClassInfo ci = new ClassInfo(name);
-
- assertNotNull(ci);
- assertEquals(name, ci.getClassName());
-
- String key = "key";
-
- try
- {
- ci.addChild(null);
- fail("Key failed");
- }
- catch (Throwable t)
- {
- // Ok
- }
-
- ci.addChild(key);
-
- Collection<String> c = ci.getChildren();
- assertNotNull(c);
- assertTrue("Size=" + c.size(), c.size() == 1);
- }
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ClassTests.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ClassTests.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ClassTests.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,422 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki.test;
-
-import org.jboss.papaki.Annotation;
-import org.jboss.papaki.AnnotationRepository;
-import org.jboss.papaki.AnnotationScanner;
-import org.jboss.papaki.AnnotationType;
-import org.jboss.papaki.test.tests.common.MyAnnotation;
-
-import java.net.URL;
-import java.util.Collection;
-import java.util.logging.Logger;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test for annotations on classes
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @version $Revision: $
- */
-public abstract class ClassTests extends AnnotationTests
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static Logger log = Logger.getLogger(ClassTests.class.getName());
-
- /** The scanner instance */
- protected static AnnotationScanner scanner = null;
-
- // --------------------------------------------------------------------------------||
- // Tests --------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Defined
- * @throws Throwable throwable exception
- */
- @Test
- public void testDefined() throws Throwable
- {
- assertNotNull(scanner);
- }
-
- /**
- * Class empty
- * @throws Throwable throwable exception
- */
- @Test
- public void testClassEmpty() throws Throwable
- {
- URL archive = getURL("classempty.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertFalse(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
- assertNull(l);
- }
-
- /**
- * Class abstract
- * @throws Throwable throwable exception
- */
- @Test
- public void testClassAbstract() throws Throwable
- {
- URL archive = getURL("classabstract.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertFalse(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNull(l);
- }
-
- /**
- * Class level
- * @throws Throwable throwable exception
- */
- @Test
- public void testClassLevel() throws Throwable
- {
- URL archive = getURL("classlevel.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CLASS);
- assertEquals("org.jboss.papaki.test.tests.classlevel.Test", annotation.getClassName());
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
-
- /**
- * Constructor level
- * @throws Throwable throwable exception
- */
- @Test
- public void testConstructorLevel() throws Throwable
- {
- URL archive = getURL("classconstructor.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CONSTRUCTOR);
- assertEquals("org.jboss.papaki.test.tests.classconstructor.Test", annotation.getClassName());
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
-
- /**
- * Constructor level with parameter
- * @throws Throwable throwable exception
- */
- @Test
- public void testConstructorLevelWithParameter() throws Throwable
- {
- URL archive = getURL("classconstructorwithparameter.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CONSTRUCTOR);
- assertEquals("org.jboss.papaki.test.tests.classconstructorwithparameter.Test", annotation.getClassName());
- assertNull(annotation.getMemberName());
- assertArrayEquals(new String[] {String.class.getName()}, annotation.getParameterTypes());
- }
-
- /**
- * Method level
- * @throws Throwable throwable exception
- */
- @Test
- public void testMethodLevel() throws Throwable
- {
- URL archive = getURL("classmethod.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.METHOD);
- assertEquals("org.jboss.papaki.test.tests.classmethod.Test", annotation.getClassName());
- assertEquals("myMethod", annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
-
- /**
- * Method level with parameter
- * @throws Throwable throwable exception
- */
- @Test
- public void testMethodLevelWithParameter() throws Throwable
- {
- URL archive = getURL("classmethodwithparameter.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.METHOD);
- assertEquals("org.jboss.papaki.test.tests.classmethodwithparameter.Test", annotation.getClassName());
- assertEquals("myMethod", annotation.getMemberName());
- assertArrayEquals(new String[] {String.class.getName()}, annotation.getParameterTypes());
- }
-
- /**
- * Parameter
- * @throws Throwable throwable exception
- */
- @Test
- public void testParameterClassConstrcutor() throws Throwable
- {
- URL archive = getURL("classconstructorwithparameterannotation.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(MyAnnotation.class));
-
- Collection<Annotation> l = ar.getAnnotation(MyAnnotation.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.PARAMETER);
- assertEquals("org.jboss.papaki.test.tests.classconstructorwithparameterannotation.Test",
- annotation.getClassName());
- assertNull(annotation.getMemberName());
- assertArrayEquals(new String[] {String.class.getName()}, annotation.getParameterTypes());
- assertTrue("ParameterIndex=" + annotation.getParameterIndex(), annotation.getParameterIndex() == 0);
- }
-
- /**
- * Parameter
- * @throws Throwable throwable exception
- */
- @Test
- public void testParameterClassMethod() throws Throwable
- {
- URL archive = getURL("classmethodwithparameterannotation.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(MyAnnotation.class));
-
- Collection<Annotation> l = ar.getAnnotation(MyAnnotation.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.PARAMETER);
- assertEquals("org.jboss.papaki.test.tests.classmethodwithparameterannotation.Test",
- annotation.getClassName());
- assertEquals("myMethod", annotation.getMemberName());
- assertArrayEquals(new String[] {String.class.getName()}, annotation.getParameterTypes());
- assertTrue("ParameterIndex=" + annotation.getParameterIndex(), annotation.getParameterIndex() == 0);
- }
-
- /**
- * Field level
- * @throws Throwable throwable exception
- */
- @Test
- public void testFieldLevel() throws Throwable
- {
- URL archive = getURL("classfield.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(MyAnnotation.class));
-
- Collection<Annotation> l = ar.getAnnotation(MyAnnotation.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.FIELD);
- assertEquals("org.jboss.papaki.test.tests.classfield.Test", annotation.getClassName());
- assertEquals("myField", annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
-
- /**
- * Class interface
- * @throws Throwable throwable exception
- */
- @Test
- public void testClassInterface() throws Throwable
- {
- URL archive = getURL("classinterface.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 2);
-
- for (Annotation annotation : l)
- {
- if ("org.jboss.papaki.test.tests.classinterface.Test".equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CLASS);
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else if ("org.jboss.papaki.test.tests.classinterface.ITest".equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CLASS);
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else
- {
- fail("Unknown annotation location");
- }
- }
- }
-
- /**
- * Class interface method
- * @throws Throwable throwable exception
- */
- @Test
- public void testClassInterfaceMethod() throws Throwable
- {
- URL archive = getURL("classinterfacemethod.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(MyAnnotation.class));
-
- Collection<Annotation> l = ar.getAnnotation(MyAnnotation.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 2);
-
- for (Annotation annotation : l)
- {
- if ("org.jboss.papaki.test.tests.classinterfacemethod.Test".equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.METHOD);
- assertEquals("myMethod", annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else if ("org.jboss.papaki.test.tests.classinterfacemethod.ITest".equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.METHOD);
- assertEquals("myMethod", annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else
- {
- fail("Unknown annotation location");
- }
- }
- }
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/InheritanceTests.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/InheritanceTests.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/InheritanceTests.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,230 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki.test;
-
-import org.jboss.papaki.Annotation;
-import org.jboss.papaki.AnnotationRepository;
-import org.jboss.papaki.AnnotationScanner;
-import org.jboss.papaki.AnnotationType;
-import org.jboss.papaki.test.tests.common.MyAnnotation;
-
-import java.net.URL;
-import java.util.Collection;
-import java.util.logging.Logger;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test for annotations in inheritance scenarios
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @version $Revision: $
- */
-public abstract class InheritanceTests extends AnnotationTests
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static Logger log = Logger.getLogger(InheritanceTests.class.getName());
-
- /** The scanner instance */
- protected static AnnotationScanner scanner = null;
-
- // --------------------------------------------------------------------------------||
- // Tests --------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Defined
- * @throws Throwable throwable exception
- */
- @Test
- public void testDefined() throws Throwable
- {
- assertNotNull(scanner);
- }
-
- /**
- * Abstract base class
- * @throws Throwable throwable exception
- */
- @Test
- public void testAbstractBaseClass() throws Throwable
- {
- URL archive = getURL("inheritanceclassabstract.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CLASS);
- assertEquals("org.jboss.papaki.test.tests.inheritanceclassabstract.Test", annotation.getClassName());
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
-
- /**
- * Base class
- * @throws Throwable throwable exception
- */
- @Test
- public void testBaseClass() throws Throwable
- {
- URL archive = getURL("inheritanceclassclass.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 2);
-
- for (Annotation annotation : l)
- {
- if ("org.jboss.papaki.test.tests.inheritanceclassclass.BaseTest".equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CLASS);
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else if ("org.jboss.papaki.test.tests.inheritanceclassclass.Test".equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CLASS);
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else
- {
- fail("Unknown annotation location");
- }
- }
- }
-
- /**
- * Class: Interface
- * @throws Throwable throwable exception
- */
- @Test
- public void testClassInterface() throws Throwable
- {
- URL archive = getURL("inheritanceclassinterface.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 2);
-
- for (Annotation annotation : l)
- {
- if ("org.jboss.papaki.test.tests.inheritanceclassinterface.ITest".equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CLASS);
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else if ("org.jboss.papaki.test.tests.inheritanceclassinterface.Test".equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CLASS);
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else
- {
- fail("Unknown annotation location");
- }
- }
- }
-
- /**
- * Class interface method
- * @throws Throwable throwable exception
- */
- @Test
- public void testClassInterfaceMethod() throws Throwable
- {
- URL archive = getURL("inheritanceclassinterfacemethod.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(MyAnnotation.class));
-
- Collection<Annotation> l = ar.getAnnotation(MyAnnotation.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 2);
-
- for (Annotation annotation : l)
- {
- if ("org.jboss.papaki.test.tests.inheritanceclassinterfacemethod.Test".equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.METHOD);
- assertEquals("myMethod", annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else if ("org.jboss.papaki.test.tests.inheritanceclassinterfacemethod.ITest"
- .equals(annotation.getClassName()))
- {
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.METHOD);
- assertEquals("myMethod", annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
- else
- {
- fail("Unknown annotation location");
- }
- }
- }
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/InterfaceTests.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/InterfaceTests.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/InterfaceTests.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,201 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki.test;
-
-import org.jboss.papaki.Annotation;
-import org.jboss.papaki.AnnotationRepository;
-import org.jboss.papaki.AnnotationScanner;
-import org.jboss.papaki.AnnotationType;
-import org.jboss.papaki.test.tests.common.MyAnnotation;
-
-import java.net.URL;
-import java.util.Collection;
-import java.util.logging.Logger;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test for annotations on interfaces
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @version $Revision: $
- */
-public abstract class InterfaceTests extends AnnotationTests
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static Logger log = Logger.getLogger(InterfaceTests.class.getName());
-
- /** The scanner instance */
- protected static AnnotationScanner scanner = null;
-
- // --------------------------------------------------------------------------------||
- // Tests --------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Defined
- * @throws Throwable throwable exception
- */
- @Test
- public void testDefined() throws Throwable
- {
- assertNotNull(scanner);
- }
-
- /**
- * Interface empty
- * @throws Throwable throwable exception
- */
- @Test
- public void testInterfaceEmpty() throws Throwable
- {
- URL archive = getURL("interfaceempty.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertFalse(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
- assertNull(l);
- }
-
- /**
- * Interface level
- * @throws Throwable throwable exception
- */
- @Test
- public void testInterfaceLevel() throws Throwable
- {
- URL archive = getURL("interfacelevel.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.CLASS);
- assertEquals("org.jboss.papaki.test.tests.interfacelevel.Test", annotation.getClassName());
- assertNull(annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
-
- /**
- * Method level
- * @throws Throwable throwable exception
- */
- @Test
- public void testMethodLevel() throws Throwable
- {
- URL archive = getURL("interfacemethod.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.METHOD);
- assertEquals("org.jboss.papaki.test.tests.interfacemethod.Test", annotation.getClassName());
- assertEquals("myMethod", annotation.getMemberName());
- assertNull(annotation.getParameterTypes());
- }
-
- /**
- * Method level with parameter
- * @throws Throwable throwable exception
- */
- @Test
- public void testMethodLevelWithParameter() throws Throwable
- {
- URL archive = getURL("interfacemethodwithparameter.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(Deprecated.class));
-
- Collection<Annotation> l = ar.getAnnotation(Deprecated.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.METHOD);
- assertEquals("org.jboss.papaki.test.tests.interfacemethodwithparameter.Test", annotation.getClassName());
- assertEquals("myMethod", annotation.getMemberName());
- assertArrayEquals(new String[] {String.class.getName()}, annotation.getParameterTypes());
- }
-
- /**
- * Parameter level
- * @throws Throwable throwable exception
- */
- @Test
- public void testParameter() throws Throwable
- {
- URL archive = getURL("interfacemethodwithparameterannotation.jar");
- AnnotationRepository ar = scanner.scan(new URL[] {archive});
-
- assertNotNull(ar);
-
- assertTrue(ar.hasAnnotation(MyAnnotation.class));
-
- Collection<Annotation> l = ar.getAnnotation(MyAnnotation.class);
-
- assertNotNull(l);
- assertTrue("Size=" + l.size(), l.size() == 1);
-
- Annotation annotation = l.iterator().next();
- assertNotNull(annotation.getAnnotationClassName());
- assertNotNull(annotation.getAnnotation());
- assertTrue(annotation.getType() == AnnotationType.PARAMETER);
- assertEquals("org.jboss.papaki.test.tests.interfacemethodwithparameterannotation.Test",
- annotation.getClassName());
- assertEquals("myMethod", annotation.getMemberName());
- assertArrayEquals(new String[] {String.class.getName()}, annotation.getParameterTypes());
- assertTrue("ParameterIndex=" + annotation.getParameterIndex(), annotation.getParameterIndex() == 0);
- }
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ScannerTests.java
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ScannerTests.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/ScannerTests.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,137 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.papaki.test;
-
-import org.jboss.papaki.AnnotationRepository;
-import org.jboss.papaki.AnnotationScanner;
-
-import java.net.URL;
-import java.util.logging.Logger;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test for the annotation scanner
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @version $Revision: $
- */
-public abstract class ScannerTests extends AnnotationTests
-{
- // --------------------------------------------------------------------------------||
- // Class Members ------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- private static Logger log = Logger.getLogger(ScannerTests.class.getName());
-
- /** The scanner instance */
- protected static AnnotationScanner scanner = null;
-
- // --------------------------------------------------------------------------------||
- // Tests --------------------------------------------------------------------------||
- // --------------------------------------------------------------------------------||
-
- /**
- * Defined
- * @throws Throwable throwable exception
- */
- @Test
- public void testDefined() throws Throwable
- {
- assertNotNull(scanner);
- }
-
- /**
- * Null URLs
- * @throws Throwable throwable exception
- */
- @Test
- public void testNullURLs() throws Throwable
- {
- AnnotationRepository ar = scanner.scan(null);
-
- assertNotNull(ar);
- }
-
- /**
- * Null URL
- * @throws Throwable throwable exception
- */
- @Test
- public void testNullURL() throws Throwable
- {
- AnnotationRepository ar = scanner.scan(new URL[] {null});
-
- assertNotNull(ar);
- }
-
- /**
- * Mixed URLs
- * @throws Throwable throwable exception
- */
- @Test
- public void testMixedURLs() throws Throwable
- {
- AnnotationRepository ar = scanner.scan(new URL[] {getURL("interfacelevel.jar"), null});
-
- assertNotNull(ar);
- }
-
- /**
- * Null URLs and null classloader
- * @throws Throwable throwable exception
- */
- @Test
- public void testNullURLsAndNullCL() throws Throwable
- {
- AnnotationRepository ar = scanner.scan(null, (ClassLoader)null);
-
- assertNotNull(ar);
- }
-
- /**
- * Null URL and null classloader
- * @throws Throwable throwable exception
- */
- @Test
- public void testNullURLAndNullCL() throws Throwable
- {
- AnnotationRepository ar = scanner.scan(new URL[] {null}, (ClassLoader)null);
-
- assertNotNull(ar);
- }
-
- /**
- * Mixed URLs and null classloader
- * @throws Throwable throwable exception
- */
- @Test
- public void testMixedURLsAndNullCL() throws Throwable
- {
- AnnotationRepository ar = scanner.scan(new URL[] {getURL("interfacelevel.jar"), null}, (ClassLoader)null);
-
- assertNotNull(ar);
- }
-}
Deleted: projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/package.html
===================================================================
--- projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/package.html 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/core/src/test/java/org/jboss/papaki/test/package.html 2009-10-19 15:58:01 UTC (rev 95120)
@@ -1,3 +0,0 @@
-<body>
-This package contains the test cases for the project.
-</body>
Modified: projects/annotations/branches/AnnEnv/indexer/src/main/java/org/jboss/papaki/indexer/IndexerTask.java
===================================================================
--- projects/annotations/branches/AnnEnv/indexer/src/main/java/org/jboss/papaki/indexer/IndexerTask.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/indexer/src/main/java/org/jboss/papaki/indexer/IndexerTask.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -22,15 +22,14 @@
package org.jboss.papaki.indexer;
+import org.jboss.papaki.AnnotationRepository;
import org.jboss.papaki.AnnotationScanner;
import org.jboss.papaki.AnnotationScannerFactory;
-import org.jboss.papaki.impl.AnnotationRepositoryImpl;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.StringTokenizer;
-import java.util.logging.Logger;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
@@ -41,8 +40,6 @@
*/
public class IndexerTask extends Task
{
- private static Logger log = Logger.getLogger(IndexerTask.class.getName());
-
private File input;
private File output;
private boolean update;
@@ -205,11 +202,11 @@
Main m = new Main();
AnnotationScanner as = AnnotationScannerFactory.getStrategy(AnnotationScannerFactory.JAVA_LANG_REFLECT);
- AnnotationRepositoryImpl ari = (AnnotationRepositoryImpl)as.scan(new URL[] {input.toURI().toURL()});
+ AnnotationRepository ari = as.scan(new URL[] {input.toURI().toURL()});
if (excludeAll)
{
- ari.removeAllAnnotations();
+ // TODO ari.removeAllAnnotations();
}
else
{
@@ -224,7 +221,7 @@
if (s.endsWith(".class"))
s = s.substring(0, s.indexOf(".class"));
- ari.removeAnnotations(s);
+ // TODO ari.removeAnnotations(s);
}
}
}
@@ -243,7 +240,7 @@
}
HTMLWriter.generateCSS(report);
- HTMLWriter.generateReport(report, output.getName(), ari.getAnnotationToClasses());
+ // HTMLWriter.generateReport(report, output.getName(), ari.getAnnotationToClasses());
}
if (update)
Modified: projects/annotations/branches/AnnEnv/indexer/src/main/java/org/jboss/papaki/indexer/Main.java
===================================================================
--- projects/annotations/branches/AnnEnv/indexer/src/main/java/org/jboss/papaki/indexer/Main.java 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/indexer/src/main/java/org/jboss/papaki/indexer/Main.java 2009-10-19 15:58:01 UTC (rev 95120)
@@ -22,11 +22,10 @@
package org.jboss.papaki.indexer;
+import org.jboss.papaki.AnnotationRepository;
import org.jboss.papaki.AnnotationScanner;
import org.jboss.papaki.AnnotationScannerFactory;
-import org.jboss.papaki.impl.AbstractAnnotationScanner;
-import org.jboss.papaki.impl.AnnotationRepositoryImpl;
-
+
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -57,7 +56,7 @@
* @param directory The destination directory
* @exception Exception Thrown if an error occurs
*/
- public void store(AnnotationRepositoryImpl ari, File directory) throws Exception
+ public void store(AnnotationRepository ari, File directory) throws Exception
{
if (ari == null)
throw new IllegalArgumentException("ARI is null");
@@ -65,7 +64,7 @@
if (directory == null || !directory.exists())
throw new IllegalArgumentException("Directory is null");
- File file = new File(directory, AbstractAnnotationScanner.PAPAKI_METADATA_BINARY);
+ File file = new File(directory, AnnotationRepository.PAPAKI_METADATA_BINARY);
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
GZIPOutputStream gos = new GZIPOutputStream(bos);
@@ -106,7 +105,7 @@
File destination = new File(root, "META-INF");
AnnotationScanner as = AnnotationScannerFactory.getStrategy(AnnotationScannerFactory.JAVA_LANG_REFLECT);
- AnnotationRepositoryImpl ari = (AnnotationRepositoryImpl)as.scan(new URL[] {input.toURI().toURL()});
+ AnnotationRepository ari = as.scan(new URL[] {input.toURI().toURL()});
m.store(ari, destination);
Modified: projects/annotations/branches/AnnEnv/pom.xml
===================================================================
--- projects/annotations/branches/AnnEnv/pom.xml 2009-10-19 15:50:56 UTC (rev 95119)
+++ projects/annotations/branches/AnnEnv/pom.xml 2009-10-19 15:58:01 UTC (rev 95120)
@@ -25,6 +25,7 @@
<properties>
<version.org.jboss.common.core>2.2.16.GA</version.org.jboss.common.core>
<version.org.jboss.vfs>2.1.3.SP1</version.org.jboss.vfs>
+ <version.org.jboss.classloader>2.0.7.GA</version.org.jboss.classloader>
<version.javassist>3.11.0.GA</version.javassist>
<version.ant>1.7.1</version.ant>
<version.junit>4.4</version.junit>
@@ -101,6 +102,16 @@
<version>${version.org.jboss.vfs}</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>javassist</groupId>
<artifactId>javassist</artifactId>
<version>${version.javassist}</version>
More information about the jboss-cvs-commits
mailing list