FileDocCategorySizeDatePackage
ScopedClassLoaderDomain.javaAPI DocJBoss 4.2.15412Fri Jul 13 21:02:24 BST 2007org.jboss.aop.deployment

ScopedClassLoaderDomain

public class ScopedClassLoaderDomain extends org.jboss.aop.Domain
A domain that is used for scoped classloaders
author
Kabir Khan
version
$Revision: 1.1 $

Fields Summary
WeakReference
loader
boolean
parentDelegation
EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap
myPerVMAspects
EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap
notMyPerVMAspects
Constructors Summary
public ScopedClassLoaderDomain(ClassLoader loader, String name, boolean parentDelegation, org.jboss.aop.AspectManager manager, boolean parentFirst)

   
             
   
      // FIXME ScopedClassLoaderDomain constructor
      super(manager, name, parentFirst);
      this.loader = new WeakReference(loader);
      this.parentDelegation = parentDelegation;
   
Methods Summary
private org.jboss.mx.loading.LoaderRepositorygetAspectRepository(java.lang.Object aspect)

      ClassLoader cl = aspect.getClass().getClassLoader();
      ClassLoader parent = cl;
      while (parent != null)
      {
         if (parent instanceof RepositoryClassLoader)
         {
            return ((RepositoryClassLoader)parent).getLoaderRepository();
         }
         parent = parent.getParent();
      }
      return null;
   
protected java.lang.ClassLoadergetClassLoader()

      ClassLoader cl = (ClassLoader)loader.get();
      if (cl != null)
      {
         return cl;
      }
      return null;
   
public java.lang.ObjectgetPerVMAspect(org.jboss.aop.advice.AspectDefinition def)

      return getPerVMAspect(def.getName());
   
public java.lang.ObjectgetPerVMAspect(java.lang.String def)

      if (parentDelegation == true)
      {
         //We will alway be loading up the correct class
         Object aspect = super.getPerVMAspect(def);
         return aspect;
      }
      else
      {
         return getPerVmAspectWithNoParentDelegation(def);
      }
   
private java.lang.ObjectgetPerVmAspectWithNoParentDelegation(java.lang.String def)

      Object aspect = myPerVMAspects.get(def);
      if (aspect != null)
      {
         return aspect;
      }

      aspect = super.getPerVMAspect(def);
      if (aspect != null)
      {
         LoaderRepository loadingRepository = getAspectRepository(aspect);
         LoaderRepository myRepository = getScopedRepository();
         if (loadingRepository == myRepository)
         {
            //The parent does not load this class
            myPerVMAspects.put(def, aspect);
         }
         else
         {
            //The class has been loaded by a parent classloader, find out if we also have a copy
            try
            {
               Class clazz = myRepository.loadClass(aspect.getClass().getName());
               if (clazz == aspect.getClass())
               {
                  notMyPerVMAspects.put(def, Boolean.TRUE);
               }
               else
               {
                  //We have a different version of the class deployed
                  AspectDefinition aspectDefinition = getAspectDefinition(def);
                  //Override the classloader to create the aspect instance
                  aspect = createPerVmAspect(def, aspectDefinition, getClassLoader());
                  myPerVMAspects.put(def, aspect);
               }
            }
            catch (ClassNotFoundException e)
            {
               throw new RuntimeException(e);
            }
         }
      }
      
      return aspect;
   
private org.jboss.mx.loading.HeirarchicalLoaderRepository3getScopedRepository()

      HeirarchicalLoaderRepository3 myRepository = (HeirarchicalLoaderRepository3)((RepositoryClassLoader)getClassLoader()).getLoaderRepository();
      return myRepository;
   
public voidremoveAspectDefinition(java.lang.String name)

      AspectDefinition def = super.internalRemoveAspectDefintion(name);
      if (def != null)
      {
         Object o = myPerVMAspects.remove(name);
      }