1 22 package org.jboss.aop.deployment; 23 24 import java.lang.ref.WeakReference ; 25 26 import org.jboss.aop.AspectManager; 27 import org.jboss.aop.Domain; 28 import org.jboss.aop.InterceptionMarkers; 29 import org.jboss.aop.advice.AspectDefinition; 30 import org.jboss.mx.loading.HeirarchicalLoaderRepository3; 31 import org.jboss.mx.loading.LoaderRepository; 32 import org.jboss.mx.loading.RepositoryClassLoader; 33 34 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 35 36 42 public class ScopedClassLoaderDomain extends Domain 43 { 44 45 WeakReference loader; 46 boolean parentDelegation; 47 ConcurrentReaderHashMap myPerVMAspects = new ConcurrentReaderHashMap(); 48 ConcurrentReaderHashMap notMyPerVMAspects = new ConcurrentReaderHashMap(); 49 InterceptionMarkers interceptionMarkers = new InterceptionMarkers(); 50 51 public ScopedClassLoaderDomain(ClassLoader loader, String name, boolean parentDelegation, AspectManager manager, boolean parentFirst) 52 { 53 super(manager, name, parentFirst); 54 this.loader = new WeakReference (loader); 55 this.parentDelegation = parentDelegation; 56 } 57 58 protected ClassLoader getClassLoader() 59 { 60 ClassLoader cl = (ClassLoader )loader.get(); 61 if (cl != null) 62 { 63 return cl; 64 } 65 return null; 66 } 67 68 public Object getPerVMAspect(AspectDefinition def) 69 { 70 return getPerVMAspect(def.getName()); 71 } 72 73 @Override 74 public InterceptionMarkers getInterceptionMarkers() 75 { 76 return interceptionMarkers; 77 } 78 79 public Object getPerVMAspect(String def) 80 { 81 if (parentDelegation == true) 82 { 83 Object aspect = super.getPerVMAspect(def); 85 return aspect; 86 } 87 else 88 { 89 return getPerVmAspectWithNoParentDelegation(def); 90 } 91 } 92 93 private Object getPerVmAspectWithNoParentDelegation(String def) 94 { 95 Object aspect = myPerVMAspects.get(def); 96 if (aspect != null) 97 { 98 return aspect; 99 } 100 101 aspect = super.getPerVMAspect(def); 102 if (aspect != null) 103 { 104 LoaderRepository loadingRepository = getAspectRepository(aspect); 105 LoaderRepository myRepository = getScopedRepository(); 106 if (loadingRepository == myRepository) 107 { 108 myPerVMAspects.put(def, aspect); 110 } 111 else 112 { 113 try 115 { 116 Class clazz = myRepository.loadClass(aspect.getClass().getName()); 117 if (clazz == aspect.getClass()) 118 { 119 notMyPerVMAspects.put(def, Boolean.TRUE); 120 } 121 else 122 { 123 AspectDefinition aspectDefinition = getAspectDefinition(def); 125 aspect = createPerVmAspect(def, aspectDefinition, getClassLoader()); 127 myPerVMAspects.put(def, aspect); 128 } 129 } 130 catch (ClassNotFoundException e) 131 { 132 throw new RuntimeException (e); 133 } 134 } 135 } 136 137 return aspect; 138 } 139 140 private LoaderRepository getAspectRepository(Object aspect) 141 { 142 ClassLoader cl = aspect.getClass().getClassLoader(); 143 ClassLoader parent = cl; 144 while (parent != null) 145 { 146 if (parent instanceof RepositoryClassLoader) 147 { 148 return ((RepositoryClassLoader)parent).getLoaderRepository(); 149 } 150 parent = parent.getParent(); 151 } 152 return null; 153 } 154 155 private HeirarchicalLoaderRepository3 getScopedRepository() 156 { 157 HeirarchicalLoaderRepository3 myRepository = (HeirarchicalLoaderRepository3)((RepositoryClassLoader)getClassLoader()).getLoaderRepository(); 158 return myRepository; 159 } 160 } 161 | Popular Tags |