[jboss-dev-forums] [Design the new POJO MicroContainer] - AbstractDeploymentClassLoaderPolicyModule is mossing reset

alesj do-not-reply at jboss.com
Fri Nov 28 15:33:16 EST 2008


Deployers's AbstractDeploymentClassLoaderPolicyModule is not removing alias if one was added at AbstractDeploymentClassLoaderPolicyModule construction.

I've added the following code:

  |  public abstract class AbstractDeploymentClassLoaderPolicyModule extends ClassLoaderPolicyModule
  | @@ -64,12 +66,14 @@
  |      * Determine the classloading metadata for the deployment unit
  |      *
  |      * @param unit the deployment unit
  | +    * @param addAlias should we add alias or remove
  |      * @return the classloading metadata
  |      */
  | -   private static String determineContextName(DeploymentUnit unit)
  | +   private static String determineContextName(DeploymentUnit unit, boolean addAlias)
  |     {
  |        if (unit == null)
  |           throw new IllegalArgumentException("Null unit");
  | +
  |        ControllerContext context = unit.getTopLevel().getAttachment(ControllerContext.class);
  |        if (context == null)
  |           throw new IllegalStateException("Deployment has no controller context");
  | @@ -83,13 +87,21 @@
  |           Set<Object> aliases = context.getAliases();
  |           if (aliases != null && aliases.contains(contextName) == false)
  |           {
  | -            try
  | +            Controller controller = context.getController();
  | +            if (addAlias)
  |              {
  | -               context.getController().addAlias(contextName, context.getName());
  | +               try
  | +               {
  | +                  controller.addAlias(contextName, context.getName());
  | +               }
  | +               catch (Throwable t)
  | +               {
  | +                  throw new RuntimeException("Error adding deployment alias " + contextName + " to " + context, t);
  | +               }
  |              }
  | -            catch (Throwable t)
  | +            else
  |              {
  | -               throw new RuntimeException("Error adding deployment alias " + contextName + " to " + context, t);
  | +               controller.removeAlias(contextName);
  |              }
  |           }
  |        }
  | @@ -105,7 +117,7 @@
  |      */
  |     public AbstractDeploymentClassLoaderPolicyModule(DeploymentUnit unit)
  |     {
  | -      super(determineClassLoadingMetaData(unit), determineContextName(unit));
  | +      super(determineClassLoadingMetaData(unit), determineContextName(unit, true));
  |        this.unit = unit;
  |        ControllerContext context = unit.getTopLevel().getAttachment(ControllerContext.class);
  |        setControllerContext(context);
  | @@ -126,4 +138,11 @@
  |     {
  |        return CLASSLOADER_STATE;
  |     }
  | +
  | +   @Override
  | +   public void reset()
  | +   {
  | +      super.reset();
  | +      determineContextName(unit, false);
  | +   }
  |  }
  | 

Should this be part of new release for JBoss5 GA?
I still need to write some tests, checking if it was successfully removed from Controller (in case it was added).

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

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



More information about the jboss-dev-forums mailing list