[jboss-cvs] JBossAS SVN: r75919 - projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 16 07:44:59 EDT 2008
Author: alesj
Date: 2008-07-16 07:44:59 -0400 (Wed, 16 Jul 2008)
New Revision: 75919
Added:
projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/FilteredGenericAnnotationDeployer.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
Log:
Initial filtered GAD.
Copied: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/FilteredGenericAnnotationDeployer.java (from rev 75886, 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/FilteredGenericAnnotationDeployer.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/FilteredGenericAnnotationDeployer.java 2008-07-16 11:44:59 UTC (rev 75919)
@@ -0,0 +1,110 @@
+/*
+* 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 javassist.ClassPool;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Filtered generic annotation scanner deployer.
+ *
+ * It first checks if there are some filters present
+ * in deployment unit as attachment,
+ * else falls back to deployers filters.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FilteredGenericAnnotationDeployer extends GenericAnnotationDeployer
+{
+ private ResourceFilter resourceFilter;
+ private ClassFilter includedFilter;
+ private ClassFilter excludedFilter;
+
+ /**
+ * Get filter.
+ * Try attachment first, then deployer's filter.
+ *
+ * @param unit the deployment unit
+ * @param expectedClass the expected class
+ * @param suffix the suffix
+ * @param defaultValue the default value
+ * @return found filter or null
+ */
+ protected <T> T getFilter(DeploymentUnit unit, Class<T> expectedClass, String suffix, T defaultValue)
+ {
+ String name = expectedClass.getName() + "." + (suffix != null ? suffix : "");
+ T result = unit.getAttachment(name, expectedClass);
+ if (result == null)
+ result = defaultValue;
+ return result;
+ }
+
+ protected GenericAnnotationResourceVisitor createGenericAnnotationResourceVisitor(DeploymentUnit unit, ClassPool pool, ClassLoader classLoader)
+ {
+ GenericAnnotationResourceVisitor visitor = super.createGenericAnnotationResourceVisitor(unit, pool, classLoader);
+ ResourceFilter filter = getFilter(unit, ResourceFilter.class, null, resourceFilter);
+ if (filter != null)
+ visitor.setResourceFilter(filter);
+ return visitor;
+ }
+
+ protected Module prepareModule(DeploymentUnit unit, Module original)
+ {
+ ClassFilter included = getFilter(unit, ClassFilter.class, "included", includedFilter);
+ ClassFilter excluded = getFilter(unit, ClassFilter.class, "excluded", excludedFilter);
+ // TODO - temp set this two
+ return super.prepareModule(unit, original);
+ }
+
+ /**
+ * Set resource filter.
+ *
+ * @param resourceFilter the resource filter
+ */
+ public void setResourceFilter(ResourceFilter resourceFilter)
+ {
+ this.resourceFilter = resourceFilter;
+ }
+
+ /**
+ * Set included class filter.
+ *
+ * @param includedFilter included class filter
+ */
+ public void setIncludedFilter(ClassFilter includedFilter)
+ {
+ this.includedFilter = includedFilter;
+ }
+
+ /**
+ * Set excluded class filter.
+ *
+ * @param excludedFilter excluded class filter
+ */
+ public void setExcludedFilter(ClassFilter excludedFilter)
+ {
+ this.excludedFilter = excludedFilter;
+ }
+}
\ No newline at end of file
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-07-16 11:38:39 UTC (rev 75918)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java 2008-07-16 11:44:59 UTC (rev 75919)
@@ -72,11 +72,12 @@
* Can be used change existing GARV's filter.
* Or determin if we need to force/keep annotations.
*
+ * @param unit the deployment unit
* @param pool the class pool
* @param classLoader the classloader
* @return new generic annotation visitor
*/
- protected GenericAnnotationResourceVisitor createGenericAnnotationResourceVisitor(ClassPool pool, ClassLoader classLoader)
+ protected GenericAnnotationResourceVisitor createGenericAnnotationResourceVisitor(DeploymentUnit unit, ClassPool pool, ClassLoader classLoader)
{
GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(pool, classLoader);
visitor.setForceAnnotations(forceAnnotations);
@@ -84,6 +85,21 @@
return visitor;
}
+ /**
+ * Prepare module.
+ *
+ * Util method to add some behavior to Module
+ * before we visit it.
+ *
+ * @param unit the deployment unit
+ * @param original the original module
+ * @return prepared module
+ */
+ protected Module prepareModule(DeploymentUnit unit, Module original)
+ {
+ return original;
+ }
+
public void deploy(DeploymentUnit unit, Module module) throws DeploymentException
{
if (log.isTraceEnabled())
@@ -91,13 +107,14 @@
ClassPool pool = ClassPool.getDefault();
ClassLoader classLoader = unit.getClassLoader();
- GenericAnnotationResourceVisitor visitor = createGenericAnnotationResourceVisitor(pool, classLoader);
+ GenericAnnotationResourceVisitor visitor = createGenericAnnotationResourceVisitor(unit, pool, classLoader);
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
try
{
- module.visit(visitor);
+ Module preparedModule = prepareModule(unit, module);
+ preparedModule.visit(visitor);
}
finally
{
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-07-16 11:38:39 UTC (rev 75918)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java 2008-07-16 11:44:59 UTC (rev 75919)
@@ -53,6 +53,7 @@
{
private static final Logger log = Logger.getLogger(GenericAnnotationResourceVisitor.class);
+ private ResourceFilter resourceFilter = ClassFilter.INSTANCE;
private ClassPool pool;
private boolean forceAnnotations;
private DefaultAnnotationEnvironment env;
@@ -77,7 +78,7 @@
public ResourceFilter getFilter()
{
- return ClassFilter.INSTANCE;
+ return resourceFilter;
}
public void visit(ResourceContext resource)
@@ -261,6 +262,16 @@
}
/**
+ * 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
More information about the jboss-cvs-commits
mailing list