[jboss-dev-forums] [Design the new POJO MicroContainer] - Temp include/exclude filter set in Module

alesj do-not-reply at jboss.com
Wed Jul 16 07:06:41 EDT 2008


To be able to dynamically (per deployment unit) filter out which resources we check in Module::visit, I need some extension/hook to the current code.

The issue came up here, where the user explicitly doesn't want to check some apps libs:
 - http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4164690#4164690

I was thinking of something in this way - in my 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 static <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);
  |    }
  | 

Since actual Module::visit is implemented in some impl detail class, I cannot do this via delegation/wrapper pattern, since I cannot override/delegate all the needed methods to underlying Module.

What can/should be done?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4164716#4164716

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4164716



More information about the jboss-dev-forums mailing list