[jboss-cvs] JBossAS SVN: r72864 - in projects/jboss-deployers/trunk: deployers-impl/src/tests/org/jboss/test/deployers and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 29 10:02:32 EDT 2008
Author: alesj
Date: 2008-04-29 10:02:31 -0400 (Tue, 29 Apr 2008)
New Revision: 72864
Added:
projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java
projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/
projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/DeployersAnnotationsTestSuite.java
projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/support/
projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/
projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationEnvTestCase.java
projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationsTest.java
projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/
projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java
Modified:
projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java
projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java
projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java
Log:
[JBDEPLOY-13]; annotation env introduction.
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/DefaultAnnotationEnvironment.java 2008-04-29 14:02:31 UTC (rev 72864)
@@ -0,0 +1,140 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.plugins.annotations;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashMap;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
+import org.jboss.util.collection.CollectionsFactory;
+
+/**
+ * DefaultAnnotationEnvironment.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DefaultAnnotationEnvironment implements AnnotationEnvironment
+{
+ private ClassLoader classLoader;
+ private Map<Class<? extends Annotation>, Map<ElementType, Set<String>>> env;
+
+ public DefaultAnnotationEnvironment(ClassLoader classLoader)
+ {
+ if (classLoader == null)
+ throw new IllegalArgumentException("Null classloader");
+ this.classLoader = classLoader;
+ this.env = new HashMap<Class<? extends Annotation>, Map<ElementType, Set<String>>>();
+ }
+
+ /**
+ * Put the annotation info.
+ *
+ * @param annClass the annotation class
+ * @param type the annotation type
+ * @param className the class name
+ */
+ void putAnnotation(Class<? extends Annotation> annClass, ElementType type, String className)
+ {
+ Map<ElementType, Set<String>> elements = env.get(annClass);
+ if (elements == null)
+ {
+ elements = new HashMap<ElementType, Set<String>>();
+ env.put(annClass, elements);
+ }
+ Set<String> classes = elements.get(type);
+ if (classes == null)
+ {
+ classes = CollectionsFactory.createLazySet();
+ elements.put(type, classes);
+ }
+ classes.add(className);
+ }
+
+ /**
+ * Get matching class names.
+ *
+ * @param annClass the annotation class
+ * @param type the annotation type
+ * @return class names
+ */
+ protected Set<String> getClassNames(Class<? extends Annotation> annClass, ElementType type)
+ {
+ Set<String> classNames = null;
+
+ Map<ElementType, Set<String>> elements = env.get(annClass);
+ if (elements != null)
+ classNames = elements.get(type);
+
+ return (classNames != null) ? classNames : Collections.<String>emptySet();
+ }
+
+ /**
+ * Transform class names into classes.
+ *
+ * @param classNames the class names
+ * @return classes
+ */
+ protected Set<Class<?>> transform(Set<String> classNames)
+ {
+ try
+ {
+ Set<Class<?>> classes = new HashSet<Class<?>>(classNames.size());
+ for (String className : classNames)
+ classes.add(classLoader.loadClass(className));
+ return classes;
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Set<Class<?>> classIsAnnotatedWith(Class<? extends Annotation> annotation)
+ {
+ return transform(getClassNames(annotation, ElementType.TYPE));
+ }
+
+ public Set<Class<?>> classHasConstructorAnnotatedWith(Class<? extends Annotation> annotation)
+ {
+ return transform(getClassNames(annotation, ElementType.CONSTRUCTOR));
+ }
+
+ public Set<Class<?>> classHasFieldAnnotatedWith(Class<? extends Annotation> annotation)
+ {
+ return transform(getClassNames(annotation, ElementType.FIELD));
+ }
+
+ public Set<Class<?>> classHasMethodAnnotatedWith(Class<? extends Annotation> annotation)
+ {
+ return transform(getClassNames(annotation, ElementType.METHOD));
+ }
+
+ public Set<Class<?>> classHasParameterAnnotatedWith(Class<? extends Annotation> annotation)
+ {
+ return transform(getClassNames(annotation, ElementType.PARAMETER));
+ }
+}
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java 2008-04-29 13:15:57 UTC (rev 72863)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java 2008-04-29 14:02:31 UTC (rev 72864)
@@ -21,19 +21,29 @@
*/
package org.jboss.deployers.plugins.annotations;
-import org.jboss.deployers.plugins.classloading.AbstractResourceVisitorDeployer;
+import javassist.ClassPath;
+import javassist.ClassPool;
+import javassist.LoaderClassPath;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.classloading.spi.visitor.ResourceVisitor;
/**
* Generic annotation scanner deployer.
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class GenericAnnotationDeployer extends AbstractResourceVisitorDeployer
+public class GenericAnnotationDeployer extends AbstractSimpleRealDeployer<Module>
{
private boolean forceAnnotations;
+ public GenericAnnotationDeployer()
+ {
+ super(Module.class);
+ }
+
/**
* Should we force all annotations to be available.
*
@@ -44,10 +54,24 @@
this.forceAnnotations = forceAnnotations;
}
- protected ResourceVisitor createVisitor(DeploymentUnit unit)
+ public void deploy(DeploymentUnit unit, Module module) throws DeploymentException
{
- GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(unit);
- visitor.setForceAnnotations(forceAnnotations);
- return visitor;
+ ClassPool pool = ClassPool.getDefault();
+ ClassLoader classLoader = unit.getClassLoader();
+ ClassPath classPath = new LoaderClassPath(classLoader);
+ pool.insertClassPath(classPath);
+ try
+ {
+ GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(pool, classLoader);
+ visitor.setForceAnnotations(forceAnnotations);
+
+ module.visit(visitor);
+
+ unit.addAttachment(AnnotationEnvironment.class, visitor.getEnv());
+ }
+ finally
+ {
+ pool.removeClassPath(classPath);
+ }
}
}
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java 2008-04-29 13:15:57 UTC (rev 72863)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java 2008-04-29 14:02:31 UTC (rev 72864)
@@ -21,17 +21,19 @@
*/
package org.jboss.deployers.plugins.annotations;
+import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMember;
import javassist.NotFoundException;
+import javassist.CtBehavior;
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.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
import org.jboss.logging.Logger;
/**
@@ -42,16 +44,20 @@
public class GenericAnnotationResourceVisitor implements ResourceVisitor
{
private static final Logger log = Logger.getLogger(GenericAnnotationResourceVisitor.class);
- private static final ClassPool pool = ClassPool.getDefault();
- private DeploymentUnit unit;
+ private ClassPool pool;
private boolean forceAnnotations;
+ private DefaultAnnotationEnvironment env;
- public GenericAnnotationResourceVisitor(DeploymentUnit unit)
+ public GenericAnnotationResourceVisitor(ClassPool pool, ClassLoader classLoader)
{
- if (unit == null)
- throw new IllegalArgumentException("Null deployment unit");
- this.unit = unit;
+ if (pool == null)
+ throw new IllegalArgumentException("Null pool");
+ if (classLoader == null)
+ throw new IllegalArgumentException("Null classloader");
+
+ this.pool = pool;
+ this.env = new DefaultAnnotationEnvironment(classLoader);
}
public ResourceFilter getFilter()
@@ -144,6 +150,13 @@
{
Object[] annotations = forceAnnotations ? member.getAnnotations() : member.getAvailableAnnotations();
handleAnnotations(type, annotations, resource);
+ if (member instanceof CtBehavior)
+ {
+ CtBehavior behavior = (CtBehavior)member;
+ Object[][] paramAnnotations = forceAnnotations ? behavior.getParameterAnnotations() : behavior.getAvailableParameterAnnotations();
+ for (Object[] paramAnn : paramAnnotations)
+ handleAnnotations(ElementType.PARAMETER, paramAnn, resource);
+ }
}
}
}
@@ -157,7 +170,14 @@
*/
protected void handleAnnotations(ElementType type, Object[] annotations, ResourceContext resource)
{
- // todo
+ if (annotations != null && annotations.length > 0)
+ {
+ for (Object annObject : annotations)
+ {
+ Annotation annotation = Annotation.class.cast(annObject);
+ env.putAnnotation(annotation.annotationType(), type, resource.getClassName());
+ }
+ }
}
/**
@@ -169,4 +189,9 @@
{
this.forceAnnotations = forceAnnotations;
}
+
+ AnnotationEnvironment getEnv()
+ {
+ return env;
+ }
}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java 2008-04-29 13:15:57 UTC (rev 72863)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java 2008-04-29 14:02:31 UTC (rev 72864)
@@ -26,6 +26,7 @@
import org.jboss.test.deployers.managed.DeployersManagedTestSuite;
import org.jboss.test.deployers.scope.DeployersScopeTestSuite;
import org.jboss.test.deployers.main.DeployersMainTestSuite;
+import org.jboss.test.deployers.annotations.DeployersAnnotationsTestSuite;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -53,6 +54,7 @@
suite.addTest(DeployersClassLoadingTestSuite.suite());
suite.addTest(DeployersScopeTestSuite.suite());
suite.addTest(DeployersMainTestSuite.suite());
+ suite.addTest(DeployersAnnotationsTestSuite.suite());
return suite;
}
Copied: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/DeployersAnnotationsTestSuite.java (from rev 72861, projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/DeployersClassLoadingTestSuite.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/DeployersAnnotationsTestSuite.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/DeployersAnnotationsTestSuite.java 2008-04-29 14:02:31 UTC (rev 72864)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.deployers.annotations;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.jboss.test.deployers.annotations.test.AnnotationEnvTestCase;
+
+/**
+ * Annotations scanning Test Suite.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DeployersAnnotationsTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Annotations Scanning Tests");
+
+ suite.addTest(AnnotationEnvTestCase.suite());
+
+ return suite;
+ }
+}
\ No newline at end of file
Added: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationEnvTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationEnvTestCase.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationEnvTestCase.java 2008-04-29 14:02:31 UTC (rev 72864)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.deployers.annotations.test;
+
+import junit.framework.Test;
+
+/**
+ * AnnotationEnvTestCase.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AnnotationEnvTestCase extends AnnotationsTest
+{
+ public AnnotationEnvTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(AnnotationEnvTestCase.class);
+ }
+
+ public void testSimpleUsage() throws Exception
+ {
+ // todo
+ }
+}
Added: projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationsTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationsTest.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/tests/org/jboss/test/deployers/annotations/test/AnnotationsTest.java 2008-04-29 14:02:31 UTC (rev 72864)
@@ -0,0 +1,143 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.deployers.annotations.test;
+
+import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.plugins.classloading.AbstractClassLoaderDescribeDeployer;
+import org.jboss.deployers.plugins.annotations.GenericAnnotationDeployer;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments;
+import org.jboss.deployers.spi.deployer.Deployer;
+import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.classloading.support.MockClassLoaderDescribeDeployer;
+import org.jboss.test.deployers.classloading.support.MockLevelClassLoaderSystemDeployer;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AnnotationsTest extends AbstractDeployerTest
+{
+ private static ClassLoadingMetaDataFactory classLoadingMetaDataFactory = ClassLoadingMetaDataFactory.getInstance();
+
+ protected AbstractClassLoaderDescribeDeployer deployer1;
+ protected MockLevelClassLoaderSystemDeployer deployer2;
+
+ protected AnnotationsTest(String name)
+ {
+ super(name);
+ }
+
+ protected static ClassLoadingMetaData addClassLoadingMetaData(PredeterminedManagedObjectAttachments deployment, String name, Version version, Class<?>... packages)
+ {
+ return addClassLoadingMetaData(deployment, name, version, false, packages);
+ }
+
+ protected static ClassLoadingMetaData addClassLoadingMetaData(PredeterminedManagedObjectAttachments deployment, String name, Version version, boolean useVersionOnPackages, Class<?>... packages)
+ {
+ ClassLoadingMetaData classLoadingMetaData = createMetaData(deployment, name, version, useVersionOnPackages, packages);
+ addMetaData(deployment, classLoadingMetaData);
+ return classLoadingMetaData;
+ }
+
+ protected static ClassLoadingMetaData createMetaData(PredeterminedManagedObjectAttachments deployment, String name, Version version, Class<?>... packages)
+ {
+ return createMetaData(deployment, name, version, false, packages);
+ }
+
+ protected static ClassLoadingMetaData createMetaData(PredeterminedManagedObjectAttachments deployment, String name, Version version, boolean useVersionOnPackages, Class<?>... packages)
+ {
+ MockClassLoadingMetaData classLoadingMetaData = new MockClassLoadingMetaData(name, version);
+
+ classLoadingMetaData.setPaths(packages);
+
+ CapabilitiesMetaData capabilities = classLoadingMetaData.getCapabilities();
+ Capability capability = classLoadingMetaDataFactory.createModule(name, version);
+ capabilities.addCapability(capability);
+
+ if (packages != null)
+ {
+ for (Class<?> pkg : packages)
+ {
+ if (useVersionOnPackages)
+ capability = classLoadingMetaDataFactory.createPackage(pkg.getPackage().getName(), version);
+ else
+ capability = classLoadingMetaDataFactory.createPackage(pkg.getPackage().getName());
+ capabilities.addCapability(capability);
+ }
+ }
+
+ classLoadingMetaData.setCapabilities(capabilities);
+ return classLoadingMetaData;
+ }
+
+ protected static void addMetaData(PredeterminedManagedObjectAttachments attachments, ClassLoadingMetaData md)
+ {
+ MutableAttachments mutable = (MutableAttachments) attachments.getPredeterminedManagedObjects();
+ mutable.addAttachment(ClassLoadingMetaData.class, md);
+ }
+
+ protected AnnotationEnvironment getAnnotationEnvironment(PredeterminedManagedObjectAttachments attachments)
+ {
+ AnnotationEnvironment env = attachments.getPredeterminedManagedObjects().getAttachment(AnnotationEnvironment.class);
+ assertNotNull(env);
+ return env;
+ }
+
+ protected DeployerClient getMainDeployer(Deployer... deployers)
+ {
+ ClassLoading classLoading = new ClassLoading();
+ ClassLoaderSystem system = new DefaultClassLoaderSystem();
+ system.getDefaultDomain().setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
+
+ deployer1 = new MockClassLoaderDescribeDeployer();
+ deployer1.setClassLoading(classLoading);
+
+ deployer2 = new MockLevelClassLoaderSystemDeployer();
+ deployer2.setClassLoading(classLoading);
+ deployer2.setSystem(system);
+
+ Deployer deployer3 = new GenericAnnotationDeployer();
+
+ if (deployers != null && deployers.length > 0)
+ {
+ Deployer[] allDeployers = new Deployer[deployers.length + 3];
+ allDeployers[0] = deployer1;
+ allDeployers[1] = deployer2;
+ allDeployers[2] = deployer3;
+ System.arraycopy(deployers, 0, allDeployers, 3, deployers.length);
+ return createMainDeployer(allDeployers);
+ }
+
+ return createMainDeployer(deployer1, deployer2, deployer3);
+ }
+}
Added: projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/org/jboss/deployers/spi/annotations/AnnotationEnvironment.java 2008-04-29 14:02:31 UTC (rev 72864)
@@ -0,0 +1,73 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.spi.annotations;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+/**
+ * Information holder about annotation processing.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface AnnotationEnvironment
+{
+ /**
+ * Get all classes annotated with annotation param.
+ *
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ Set<Class<?>> classIsAnnotatedWith(Class<? extends Annotation> annotation);
+
+ /**
+ * Get all classes who have some constructor annotated with annotation param.
+ *
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ Set<Class<?>> classHasConstructorAnnotatedWith(Class<? extends Annotation> annotation);
+
+ /**
+ * Get all classes who have some field annotated with annotation param.
+ *
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ Set<Class<?>> classHasFieldAnnotatedWith(Class<? extends Annotation> annotation);
+
+ /**
+ * Get all classes who have some method annotated with annotation param.
+ *
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ Set<Class<?>> classHasMethodAnnotatedWith(Class<? extends Annotation> annotation);
+
+ /**
+ * Get all classes who have some method's/constructor's parameter annotated with annotation param.
+ *
+ * @param annotation the annotation we're querying for
+ * @return set of matching classes
+ */
+ Set<Class<?>> classHasParameterAnnotatedWith(Class<? extends Annotation> annotation);
+}
More information about the jboss-cvs-commits
mailing list