1 22 package org.jboss.aop; 23 24 import java.lang.ref.WeakReference ; 25 import java.lang.reflect.Field ; 26 import java.security.AccessController ; 27 import java.security.PrivilegedAction ; 28 import java.security.ProtectionDomain ; 29 import java.util.ArrayList ; 30 import java.util.Collection ; 31 import java.util.HashMap ; 32 import java.util.HashSet ; 33 import java.util.Hashtable ; 34 import java.util.Iterator ; 35 import java.util.LinkedHashMap ; 36 import java.util.Map ; 37 import java.util.Set ; 38 import java.util.StringTokenizer ; 39 import java.util.WeakHashMap ; 40 import java.util.List ; 41 42 import org.jboss.aop.advice.AdviceBinding; 43 import org.jboss.aop.advice.AdviceStack; 44 import org.jboss.aop.advice.AspectDefinition; 45 import org.jboss.aop.advice.AspectFactory; 46 import org.jboss.aop.advice.AspectFactoryWithClassLoader; 47 import org.jboss.aop.advice.DynamicCFlowDefinition; 48 import org.jboss.aop.advice.InterceptorFactory; 49 import org.jboss.aop.advice.PrecedenceDef; 50 import org.jboss.aop.advice.PrecedenceDefEntry; 51 import org.jboss.aop.advice.PrecedenceSorter; 52 import org.jboss.aop.advice.Scope; 53 import org.jboss.aop.classpool.AOPClassPoolRepository; 54 import org.jboss.aop.classpool.AOPScopedClassLoaderHelper; 55 import org.jboss.aop.instrument.GeneratedAdvisorInstrumentor; 56 import org.jboss.aop.instrument.Instrumentor; 57 import org.jboss.aop.instrument.InstrumentorFactory; 58 import org.jboss.aop.instrument.TransformerCommon; 59 import org.jboss.aop.introduction.AnnotationIntroduction; 60 import org.jboss.aop.introduction.InterfaceIntroduction; 61 import org.jboss.aop.metadata.ClassMetaDataBinding; 62 import org.jboss.aop.metadata.ClassMetaDataLoader; 63 import org.jboss.aop.metadata.SimpleClassMetaDataLoader; 64 import org.jboss.aop.pointcut.CFlowStack; 65 import org.jboss.aop.pointcut.DeclareDef; 66 import org.jboss.aop.pointcut.DynamicCFlow; 67 import org.jboss.aop.pointcut.Pointcut; 68 import org.jboss.aop.pointcut.PointcutExpression; 69 import org.jboss.aop.pointcut.PointcutInfo; 70 import org.jboss.aop.pointcut.PointcutStats; 71 import org.jboss.aop.pointcut.Typedef; 72 import org.jboss.aop.pointcut.ast.ClassExpression; 73 import org.jboss.util.loading.Translatable; 74 import org.jboss.util.loading.Translator; 75 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 76 import javassist.ClassPool; 77 import javassist.CtClass; 78 import javassist.scopedpool.ScopedClassPool; 79 import javassist.scopedpool.ScopedClassPoolFactory; 80 81 95 public class AspectManager 96 implements Translator 97 { 98 99 protected final WeakHashMap advisors = new WeakHashMap (); 101 102 protected final WeakHashMap scopedClassLoaderDomains = new WeakHashMap (); 103 104 105 protected final WeakHashMap subDomainsPerClass = new WeakHashMap (); 106 107 108 protected final WeakHashMap subscribedSubDomains = new WeakHashMap (); 109 110 111 protected final WeakHashMap subscribedSubDomainsQueue = new WeakHashMap (); 112 protected int subscribedDomainQueueRef; 113 114 protected final LinkedHashMap interfaceIntroductions = new LinkedHashMap (); 115 protected final LinkedHashMap annotationIntroductions = new LinkedHashMap (); 116 protected final LinkedHashMap annotationOverrides = new LinkedHashMap (); 117 protected final LinkedHashMap bindings = new LinkedHashMap (); 118 protected final LinkedHashMap typedefs = new LinkedHashMap (); 119 protected final HashMap interceptorFactories = new HashMap (); 120 protected final Hashtable classMetaDataLoaders = new Hashtable (); 121 protected final HashMap interceptorStacks = new HashMap (); 122 protected final HashMap declares = new HashMap (); 123 protected final ConcurrentReaderHashMap cflowStacks = new ConcurrentReaderHashMap(); 124 protected final ConcurrentReaderHashMap dynamicCFlows = new ConcurrentReaderHashMap(); 125 protected final ConcurrentReaderHashMap aspectDefinitions = new ConcurrentReaderHashMap(); 126 protected final ConcurrentReaderHashMap perVMAspects = new ConcurrentReaderHashMap(); 127 128 129 protected final ArrayList exclude = new ArrayList (); 130 131 132 protected final ArrayList include = new ArrayList (); 133 134 135 protected final ArrayList ignore = new ArrayList (); 136 137 138 protected ClassExpression[] ignoreExpressions = new ClassExpression[0]; 139 140 protected final LinkedHashMap pointcuts = new LinkedHashMap (); 141 protected final LinkedHashMap pointcutInfos = new LinkedHashMap (); 143 protected boolean execution = false; 146 protected boolean construction = false; 147 protected boolean call = false; 148 protected boolean within = false; 149 protected boolean get = false; 150 protected boolean set = false; 151 protected boolean withincode = false; 152 public static boolean classicOrder = false; 153 154 protected final LinkedHashMap classMetaData = new LinkedHashMap (); 155 protected final HashMap containers = new HashMap (); 156 protected final LinkedHashMap precedenceDefs = new LinkedHashMap (); 157 protected PrecedenceDefEntry[] sortedPrecedenceDefEntries; 158 protected WeavingStrategy weavingStrategy; 159 160 protected final ConcurrentReaderHashMap convertableReference = new ConcurrentReaderHashMap(); 161 protected final ConcurrentReaderHashMap hasFieldInterception = new ConcurrentReaderHashMap(); 162 protected final ConcurrentReaderHashMap hasConstructorInterception = new ConcurrentReaderHashMap(); 163 164 protected final ConcurrentReaderHashMap skipConvertableReference = new ConcurrentReaderHashMap(); 165 protected final ConcurrentReaderHashMap skipFieldInterception = new ConcurrentReaderHashMap(); 166 protected final ConcurrentReaderHashMap skipConstructorInterception = new ConcurrentReaderHashMap(); 167 168 protected DynamicAOPStrategy dynamicStrategy = new LoadInterceptedClassesStrategy(); 169 protected boolean transformationStarted = false; 171 172 public static AOPScopedClassLoaderHelper scopedCLHelper; 174 175 public void addConstructionInterceptionMarker(String classname) 176 { 177 skipConstructorInterception.remove(classname); 178 skipConvertableReference.remove(classname); 179 hasConstructorInterception.put(classname, classname); 180 convertableReference.put(classname, classname); 181 } 182 183 public void addFieldInterceptionMarker(String classname) 184 { 185 skipFieldInterception.remove(classname); 186 skipConvertableReference.remove(classname); 187 hasFieldInterception.put(classname, classname); 188 convertableReference.put(classname, classname); 189 } 190 191 public void skipReference(String classname) 192 { 193 skipConvertableReference.put(classname, classname); 194 } 195 196 public boolean shouldSkipConstruction(String classname) 197 { 198 return !(hasConstructorInterception.containsKey(classname) || !skipConstructorInterception.containsKey(classname)); 199 } 201 202 public boolean shouldSkipFieldAccess(String classname) 203 { 204 return !(hasFieldInterception.containsKey(classname) || !skipFieldInterception.containsKey(classname)); 205 } 207 208 public void skipConstruction(String classname) 209 { 210 skipConstructorInterception.put(classname, classname); 211 } 212 213 public void skipFieldAccess(String classname) 214 { 215 skipFieldInterception.put(classname, classname); 216 } 217 218 public boolean convertReference(String classname) 219 { 220 return !skipConvertableReference.containsKey(classname) || convertableReference.containsKey(classname); 221 } 223 224 226 protected static AspectManager manager; 227 public static boolean optimize = true; 228 public static boolean debugClasses; public static ClassLoaderValidation classLoaderValidator; 230 231 234 public static boolean verbose = false; 235 236 public static synchronized AspectManager getTopLevelAspectManager() 237 { 238 if (scopedCLHelper != null) 239 { 240 return instance(); 242 } 243 ClassLoader topUcl = scopedCLHelper.getTopLevelJBossClassLoader(); 244 return instance(topUcl); 245 246 } 247 248 public static synchronized AspectManager instance() 249 { 250 return instance(Thread.currentThread().getContextClassLoader()); 251 } 252 253 public static synchronized AspectManager instance(ClassLoader loadingClassLoader) 254 { 255 if (manager == null) 256 { 257 AccessController.doPrivileged(new PrivilegedAction () 258 { 259 public Object run() 260 { 261 String optimized = System.getProperty("jboss.aop.optimized", null); 262 if (optimized != null) 263 { 264 optimize = (new Boolean (optimized)).booleanValue(); 265 } 266 String pruneit = System.getProperty("jboss.aop.prune", null); 267 if (pruneit != null) 268 { 269 AOPClassPoolRepository.getInstance().setPrune((new Boolean (pruneit)).booleanValue()); 270 } 271 manager = new AspectManager(); 272 AOPClassPoolRepository.getInstance().setAspectManager(manager); 273 274 if (!verbose) 275 { 276 verbose = (new Boolean (System.getProperty("jboss.aop.verbose", "false"))).booleanValue(); 277 } 278 String exclude = System.getProperty("jboss.aop.exclude", null); 279 if (exclude != null) 280 { 281 ArrayList list = new ArrayList (); 282 StringTokenizer tokenizer = new StringTokenizer (exclude, ","); 283 while (tokenizer.hasMoreTokens()) 284 { 285 list.add(tokenizer.nextToken().trim()); 286 } 287 manager.setExclude(list); 288 } 289 String include = System.getProperty("jboss.aop.include", null); 290 if (include != null) 291 { 292 ArrayList list = new ArrayList (); 293 StringTokenizer tokenizer = new StringTokenizer (include, ","); 294 while (tokenizer.hasMoreTokens()) 295 { 296 list.add(tokenizer.nextToken().trim()); 297 } 298 manager.setInclude(list); 299 } 300 String ignore = System.getProperty("jboss.aop.ignore", null); 301 if (ignore != null) 302 { 303 ArrayList list = new ArrayList (); 304 StringTokenizer tokenizer = new StringTokenizer (ignore, ","); 305 while (tokenizer.hasMoreTokens()) 306 { 307 list.add(tokenizer.nextToken().trim()); 308 } 309 manager.setIgnore(list); 310 } 311 312 String instrument = System.getProperty("jboss.aop.instrumentor", null); 313 InstrumentorFactory.initialise(instrument); 314 315 String advisorName = System.getProperty("jboss.aop.advisor", null); 316 AdvisorFactory.initialise(advisorName); 317 318 String debugClass = System.getProperty("jboss.aop.debug.classes", null); 319 if (debugClass != null) 320 { 321 debugClasses = (new Boolean (debugClass)).booleanValue(); 322 } 323 324 String classic = System.getProperty("jboss.aop.classicorder", null); 325 if (classic != null) 326 { 327 classicOrder = (new Boolean (classic)).booleanValue(); 328 } 329 330 331 Deployment.deploy(); 332 return null; 333 } 334 }); 335 } 336 337 if (scopedCLHelper != null) 338 { 339 ClassLoader scopedClassLoader = scopedCLHelper.ifScopedDeploymentGetScopedParentUclForCL(loadingClassLoader); 340 if (scopedClassLoader != null) 341 { 342 Domain scopedManager = null; 343 synchronized (AOPClassPoolRepository.getInstance().getRegisteredCLs()) 344 { 345 scopedManager = (Domain)manager.scopedClassLoaderDomains.get(scopedClassLoader); 346 if (scopedManager == null) 347 { 348 scopedManager = scopedCLHelper.getScopedClassLoaderDomain(scopedClassLoader, manager); 349 if (verbose) 350 { 351 System.out.println("Created domain " + scopedManager + " for scoped deployment on: " + 352 loadingClassLoader + "; identifying scoped ucl: " + scopedClassLoader); 353 } 354 scopedManager.setInheritsBindings(true); 355 scopedManager.setInheritsDeclarations(true); 356 manager.scopedClassLoaderDomains.put(scopedClassLoader, scopedManager); 357 } 358 } 359 return scopedManager; 360 } 361 } 362 return manager; 363 } 364 365 366 public LinkedHashMap getPointcuts() 367 { 368 return pointcuts; 369 } 370 371 public LinkedHashMap getPointcutInfos() 372 { 373 return pointcutInfos; 374 } 375 376 public CFlowStack getCFlowStack(String name) 377 { 378 return (CFlowStack) cflowStacks.get(name); 379 } 380 381 public void addCFlowStack(CFlowStack stack) 382 { 383 cflowStacks.put(stack.getName(), stack); 384 } 385 386 public void removeCFlowStack(String name) 387 { 388 cflowStacks.remove(name); 389 } 390 391 public DynamicCFlow getDynamicCFlow(String name) 392 { 393 DynamicCFlowDefinition def = (DynamicCFlowDefinition) dynamicCFlows.get(name); 394 395 if (def != null) 396 { 397 return def.create(); 398 } 399 return null; 400 } 401 402 403 406 public void addDynamicCFlow(String name, DynamicCFlowDefinition cflow) 407 { 408 dynamicCFlows.put(name, cflow); 409 } 410 411 public void removeDynamicCFlow(String name) 412 { 413 dynamicCFlows.remove(name); 414 } 415 416 421 public static AspectNotificationHandler notificationHandler = null; 422 423 public static boolean suppressTransformationErrors = false; 424 425 426 431 public static boolean suppressReferenceErrors = true; 432 433 435 438 public AspectManager() 439 { 440 441 } 442 449 public ClassMetaDataLoader findClassMetaDataLoader(String group) 450 { 451 ClassMetaDataLoader loader = (ClassMetaDataLoader) classMetaDataLoaders.get(group); 452 if (loader == null) loader = SimpleClassMetaDataLoader.singleton; 453 return loader; 454 } 455 456 463 public void addClassMetaDataLoader(String group, ClassMetaDataLoader loader) 464 { 465 classMetaDataLoaders.put(group, loader); 466 } 467 468 471 public void removeClassMetaDataLoader(String group) 472 { 473 classMetaDataLoaders.remove(group); 474 } 475 476 public Map getAdvisors() 477 { 478 return advisors; 479 } 480 481 public Advisor getAdvisor(String name) 482 { 483 489 throw new RuntimeException ("OPERATION NOT SUPPORTED ANYMORE"); 490 } 491 492 public LinkedHashMap getBindings() 493 { 494 return bindings; 495 } 496 497 protected Map getSubDomainsPerClass() 498 { 499 return subDomainsPerClass; 500 } 501 502 public Advisor findAdvisor(Class clazz) 503 { 504 if (getSubDomainsPerClass().size() > 0) 505 { 506 Domain subDomain = null; 509 synchronized (getSubDomainsPerClass()) 510 { 511 WeakReference ref = (WeakReference )getSubDomainsPerClass().get(clazz); 512 if (ref != null) 513 { 514 subDomain = (Domain)ref.get(); 515 } 516 } 517 518 if (subDomain != null && subDomain != this) 519 { 520 Advisor advisor = subDomain.findAdvisor(clazz); 521 if (advisor != null) 522 { 523 return advisor; 524 } 525 } 526 } 527 528 synchronized (advisors) 529 { 530 WeakReference ref = (WeakReference ) advisors.get(clazz); 531 if (ref == null) return null; 532 return (Advisor) ref.get(); 533 } 534 } 535 536 public ClassAdvisor getAdvisorIfAdvised(Class clazz) 537 { 538 return (ClassAdvisor)getAnyAdvisorIfAdvised(clazz); 539 } 540 541 544 public Advisor getAnyAdvisorIfAdvised(Class clazz) 545 { 546 try 547 { 548 Advisor advisor; 549 advisor = findAdvisor(clazz); 550 if (advisor == null) 551 { 552 return null; 553 } 554 if (advisor.getClazz() == null && advisor instanceof ClassAdvisor) 555 { 556 ((ClassAdvisor)advisor).attachClass(clazz); 557 if (notificationHandler != null) 558 { 559 notificationHandler.attachClass(clazz.getName()); 560 } 561 } 562 return advisor; 563 } 564 catch (RuntimeException ex) 565 { 566 ex.printStackTrace(); 567 throw ex; 568 } 569 } 570 571 578 public ClassAdvisor getAdvisor(Class clazz) 579 { 580 ClassAdvisor advisor = null; 581 advisor = (ClassAdvisor)findAdvisor(clazz); 583 if (advisor == null) 585 { 586 advisor = AdvisorFactory.getClassAdvisor(clazz, this); 587 initialiseClassAdvisor(clazz, advisor); 588 } 589 return advisor; 590 } 591 592 public void initialiseClassAdvisor(Class clazz, ClassAdvisor advisor) 593 { 594 synchronized (advisors) 595 { 596 advisors.put(clazz, new WeakReference (advisor)); 597 } 598 599 registerClass(clazz); 600 advisor.attachClass(clazz); 601 InterceptorChainObserver observer = dynamicStrategy.getInterceptorChainObserver(clazz); 602 advisor.setInterceptorChainObserver(observer); 603 if (notificationHandler != null) 604 { 605 notificationHandler.attachClass(clazz.getName()); 606 } 607 } 608 609 611 public static Map getRegisteredCLs() 612 { 613 return AOPClassPoolRepository.getInstance().getRegisteredCLs(); 614 } 615 616 619 public static void clearUnregisteredClassLoaders() 620 { 621 AOPClassPoolRepository.getInstance().clearUnregisteredClassLoaders(); 622 } 623 624 630 public boolean isAdvisorRegistered(Advisor advisor) 631 { 632 synchronized (getRegisteredCLs()) 633 { 634 if (!advisors.containsKey(advisor.getClazz())) return false; 635 ScopedClassPool pool = (ScopedClassPool) getRegisteredClassPool(advisor.getClazz().getClassLoader()); 636 if (pool == null) return false; 637 if (pool.isUnloadedClassLoader()) 638 { 639 unregisterClassLoader(advisor.getClazz().getClassLoader()); 640 return false; 641 } 642 else 643 { 644 return true; 645 } 646 } 647 } 648 649 public ClassPool findClassPool(ClassLoader cl) 650 { 651 if (!(cl instanceof Translatable)) 652 { 653 return registerClassLoader(Thread.currentThread().getContextClassLoader()); 655 } 656 return registerClassLoader(cl); 657 } 658 659 protected ClassPool getRegisteredClassPool(ClassLoader cl) 660 { 661 return (ClassPool)getRegisteredCLs().get(cl); 662 } 663 664 public ClassPool registerClassLoader(ClassLoader ucl) 665 { 666 return AOPClassPoolRepository.getInstance().registerClassLoader(ucl); 667 } 668 669 protected void registerClass(Class clazz) 670 { 671 AOPClassPoolRepository.getInstance().registerClass(clazz); 672 } 673 674 protected Map getScopedClassLoaderDomains() 675 { 676 return scopedClassLoaderDomains; 677 } 678 679 public void unregisterClassLoader(ClassLoader cl) 680 { 681 AOPClassPoolRepository.getInstance().unregisterClassLoader(cl); 682 getScopedClassLoaderDomains().remove(cl); 684 } 685 686 public ArrayList getExclude() 687 { 688 return exclude; 689 } 690 691 public void setExclude(ArrayList exclude) 692 { 693 this.exclude.clear(); 694 this.exclude.addAll(exclude); 695 } 696 697 public ArrayList getInclude() 698 { 699 return include; 700 } 701 702 public void setInclude(ArrayList include) 703 { 704 this.include.clear(); 705 this.include.addAll(include); 706 } 707 708 public ArrayList getIgnore() 709 { 710 return ignore; 711 } 712 713 public ClassExpression[] getIgnoreExpressions() 714 { 715 return ignoreExpressions; 716 } 717 718 public void setIgnore(ArrayList ignore) 719 { 720 this.ignore.clear(); 721 this.ignore.addAll(ignore); 722 ignoreExpressions = new ClassExpression[ignore.size()]; 723 for (int i = 0 ; i < ignore.size() ; i++) 724 { 725 String ex = (String )ignore.get(i); 726 ignoreExpressions[i] = new ClassExpression(ex); 727 } 728 } 729 730 public boolean ignoreClass(String classname) 731 { 732 ArrayList ignore = getIgnore(); 733 if (ignore == null) return false; 734 for (int i = 0; i < ignoreExpressions.length; i++) 735 { 736 if(ignoreExpressions[i].matches(classname)) return true; 737 } 738 return false; 739 } 740 741 public boolean includeClass(String classname) 742 { 743 ArrayList include = getInclude(); 744 if (include == null) return false; 745 for (int i = 0; i < include.size(); i++) 746 { 747 String str = (String ) include.get(i); 748 if (classname.startsWith(str)) return true; 749 } 750 return false; 751 } 752 753 public boolean excludeClass(String classname) 754 { 755 ArrayList exclude = getExclude(); 756 if (exclude == null) return false; 757 for (int i = 0; i < exclude.size(); i++) 758 { 759 String str = (String ) exclude.get(i); 760 if (classname.startsWith(str)) return true; 761 } 762 return false; 763 } 764 765 public static boolean getPrune() 766 { 767 return AOPClassPoolRepository.getInstance().isPrune(); 768 } 769 770 public static void setPrune(boolean prune) 771 { 772 AOPClassPoolRepository.getInstance().setPrune(prune); 773 } 774 775 public static void setClassPoolFactory(ScopedClassPoolFactory factory) 776 { 777 AOPClassPoolRepository.getInstance().setClassPoolFactory(factory); 778 } 779 780 public static ScopedClassPoolFactory getClassPoolFactory() 781 { 782 return AOPClassPoolRepository.getInstance().getClassPoolFactory(); 783 } 784 785 public boolean isNonAdvisableClassName(String classname) 786 { 787 if (ignoreClass(classname)) return true; 788 if (includeClass(classname)) return false; 789 if (excludeClass(classname)) return true; 790 return (classname.startsWith("org.jboss.aop") || 791 classname.endsWith("$aop") || 792 classname.startsWith("javassist") || 793 classname.startsWith("org.jboss.util.") || 794 classname.startsWith("gnu.trove.") || 795 classname.startsWith("EDU.oswego.cs.dl.util.concurrent.") || 796 classname.startsWith("org.apache.tools.ant") || 798 classname.startsWith("org.apache.crimson") || 799 classname.startsWith("org.apache.xalan") || 800 classname.startsWith("org.apache.xml") || 801 classname.startsWith("org.apache.xpath") || 802 classname.startsWith("org.ietf.") || 803 classname.startsWith("org.omg.") || 804 classname.startsWith("org.w3c.") || 805 classname.startsWith("org.xml.sax.") || 806 classname.startsWith("sunw.") || 807 classname.startsWith("sun.") || 808 classname.startsWith("java.") || 809 classname.startsWith("javax.") || 810 classname.startsWith("com.sun.") || 811 classname.startsWith("junit") || 812 classname.startsWith("jrockit.") || 813 classname.startsWith("com.bea.vm.") 814 ); 815 } 816 817 823 public byte[] transform(ClassLoader loader, 824 String className, 825 Class classBeingRedefined, 826 ProtectionDomain protectionDomain, 827 byte[] classfileBuffer) 828 throws Exception 829 { 830 byte[] b = translate(className, loader, classfileBuffer); 831 return b; 832 } 833 834 835 843 public byte[] translate(String className, ClassLoader loader) throws Exception 844 { 845 return translate(className, loader, null); 846 } 847 848 856 public byte[] translate(String className, ClassLoader loader, byte[] classfileBuffer) throws Exception 857 { 858 try 859 { 860 if (isNonAdvisableClassName(className)) 861 { 862 return null; 863 } 864 if (weavingStrategy == null) 865 { 866 synchronized (this) 867 { 868 if (TransformerCommon.isCompileTime() || classicOrder) 869 { 870 weavingStrategy = new ClassicWeavingStrategy(); 871 } 872 else if(InstrumentorFactory.getInstrumentor(this,dynamicStrategy.getJoinpointClassifier()) 873 instanceof GeneratedAdvisorInstrumentor) 874 { 875 weavingStrategy = new SuperClassesFirstWeavingStrategy(); 876 } 877 else 878 { 879 weavingStrategy = new ClassicWeavingStrategy(); 880 } 881 } 882 } 883 884 return weavingStrategy.translate(this, className, loader, classfileBuffer); 885 } 886 catch (Exception e) 887 { 888 throw new RuntimeException (e); 890 } 891 } 892 893 896 public void addInterceptorFactory(String name, InterceptorFactory factory) 897 { 898 synchronized (interceptorFactories) 899 { 900 interceptorFactories.put(name, factory); 901 } 902 } 903 904 907 public void removeInterceptorFactory(String name) 908 { 909 synchronized (interceptorFactories) 910 { 911 interceptorFactories.remove(name); 912 } 913 } 914 915 public Map getInterceptorFactories() 916 { 917 return interceptorFactories; 918 } 919 920 923 public InterceptorFactory getInterceptorFactory(String name) 924 { 925 synchronized (interceptorFactories) 926 { 927 return (InterceptorFactory) interceptorFactories.get(name); 928 } 929 } 930 931 932 public void addPrecedence(PrecedenceDef precedenceDef) 933 { 934 synchronized (precedenceDefs) 935 { 936 precedenceDefs.put(precedenceDef.getName(), precedenceDef); 937 } 938 forceResortPrecedenceDefs(); 939 } 940 941 942 public void removePrecedence(String name) 943 { 944 synchronized (precedenceDefs) 945 { 946 precedenceDefs.remove(name); 947 } 948 949 forceResortPrecedenceDefs(); 950 } 951 952 protected void forceResortPrecedenceDefs() 953 { 954 synchronized (precedenceDefs) 955 { 956 sortedPrecedenceDefEntries = null; 957 } 958 synchronized (subscribedSubDomains) 959 { 960 copySubDomainsFromQueue(true); 961 boolean newSubscribers = true; 962 while (newSubscribers) 963 { 964 for (Iterator it = subscribedSubDomains.keySet().iterator() ; it.hasNext() ; ) 965 { 966 Domain domain = (Domain)it.next(); 967 domain.forceResortPrecedenceDefs(); 968 } 969 newSubscribers = copySubDomainsFromQueue(false); 970 } 971 } 972 } 973 974 public LinkedHashMap getPrecedenceDefs() 975 { 976 return precedenceDefs; 977 } 978 979 public PrecedenceDefEntry[] getSortedPrecedenceDefEntries() 980 { 981 if (sortedPrecedenceDefEntries == null) 982 { 983 synchronized (precedenceDefs) 984 { 985 if (sortedPrecedenceDefEntries == null) 986 { 987 sortedPrecedenceDefEntries = PrecedenceSorter.createOverallPrecedence(this); 988 } 989 } 990 } 991 return sortedPrecedenceDefEntries; 992 } 993 994 997 public void addAdviceStack(AdviceStack stack) 998 { 999 synchronized (interceptorStacks) 1000 { 1001 interceptorStacks.put(stack.getName(), stack); 1002 } 1003 } 1004 1005 1008 public void removeInterceptorStack(String name) 1009 { 1010 synchronized (interceptorStacks) 1011 { 1012 interceptorStacks.remove(name); 1013 } 1014 } 1015 1016 1019 public AdviceStack getAdviceStack(String name) 1020 { 1021 synchronized (interceptorStacks) 1022 { 1023 return (AdviceStack) interceptorStacks.get(name); 1024 } 1025 } 1026 1027 1028 protected boolean attachMetaData(ClassAdvisor advisor, CtClass clazz, boolean addAdvisor) throws Exception 1029 { 1030 boolean attached = false; 1031 synchronized (classMetaData) 1032 { 1033 Iterator it = classMetaData.values().iterator(); 1034 while (it.hasNext()) 1035 { 1036 ClassMetaDataBinding data = (ClassMetaDataBinding) it.next(); 1037 if (data.matches(advisor, clazz)) 1038 { 1039 attached = true; 1040 if (addAdvisor) data.addAdvisor(advisor); 1041 ClassMetaDataLoader loader = data.getLoader(); 1042 loader.bind(advisor, data, clazz.getDeclaredMethods(), clazz.getDeclaredFields(), clazz.getDeclaredConstructors()); 1043 } 1044 } 1045 } 1046 return attached; 1047 } 1048 1049 protected void attachMetaData(ClassAdvisor advisor, Class clazz) 1050 { 1051 synchronized (classMetaData) 1052 { 1053 Iterator it = classMetaData.values().iterator(); 1054 while (it.hasNext()) 1055 { 1056 ClassMetaDataBinding data = (ClassMetaDataBinding) it.next(); 1057 addAdvisorToClassMetaDataBinding(data, clazz, advisor, clazz); 1058 } 1059 } 1060 } 1061 1062 public ClassAdvisor getTempClassAdvisor(CtClass clazz) throws Exception 1063 { 1064 String classname = clazz.getName(); 1065 ClassAdvisor advisor = AdvisorFactory.getClassAdvisor(clazz, this); 1066 attachMetaData(advisor, clazz, false); 1067 applyInterfaceIntroductions(advisor, clazz); 1068 return advisor; 1069 } 1070 1071 public Advisor getTempClassAdvisorIfNotExist(Class clazz) 1072 { 1073 Advisor advisor = findAdvisor(clazz); 1074 if (advisor != null) return advisor; 1075 if (Advised.class.isAssignableFrom(clazz)) 1076 { 1077 1078 Class superClass = clazz; 1079 try 1080 { 1081 while (superClass != null) 1082 { 1083 try 1084 { 1085 Field field = superClass.getDeclaredField(Instrumentor.HELPER_FIELD_NAME); 1086 SecurityActions.setAccessible(field); 1087 return (ClassAdvisor) field.get(null); 1088 } 1089 catch (NoSuchFieldException e) 1090 { 1091 superClass = clazz.getSuperclass(); 1092 } 1093 } 1094 } 1095 catch (IllegalAccessException e) 1096 { 1097 throw new RuntimeException (e); 1098 } 1099 } 1100 1101 advisor = AdvisorFactory.getClassAdvisor(clazz, this); 1102 advisor.setClazz(clazz); 1103 return advisor; 1104 } 1105 1106 1107 public DomainDefinition getContainer(String name) 1108 { 1109 return (DomainDefinition) containers.get(name); 1110 } 1111 1112 public void addContainer(DomainDefinition def) 1113 { 1114 containers.put(def.getName(), def); 1115 } 1116 1117 public void removeContainer(String name) 1118 { 1119 containers.remove(name); 1120 } 1121 1122 1125 public Pointcut getPointcut(String name) 1126 { 1127 synchronized (pointcuts) 1128 { 1129 return (Pointcut) pointcuts.get(name); 1130 } 1131 } 1132 1133 1136 public void removePointcut(String name) 1137 { 1138 synchronized (pointcuts) 1139 { 1140 pointcuts.remove(name); 1141 pointcutInfos.remove(name); 1142 } 1143 } 1144 1145 1148 public synchronized void addPointcut(Pointcut pointcut) 1149 { 1150 removePointcut(pointcut.getName()); 1151 synchronized (pointcuts) 1152 { 1153 pointcuts.put(pointcut.getName(), pointcut); 1154 pointcutInfos.put(pointcut.getName(), new PointcutInfo(pointcut, this.transformationStarted)); 1155 } 1156 updatePointcutStats(pointcut); 1157 } 1158 1159 1164 protected void updatePointcutStats(Pointcut pointcut) 1165 { 1166 if (pointcut instanceof PointcutExpression) 1168 { 1169 PointcutExpression expr = (PointcutExpression) pointcut; 1170 expr.setManager(this); 1171 PointcutStats stats = expr.getStats(); 1172 updateStats(stats); 1173 } 1174 else 1175 { 1176 execution = true; 1178 construction = true; 1179 call = true; 1180 within = true; 1181 get = true; 1182 set = true; 1183 withincode = true; 1184 } 1185 } 1186 1187 protected void updateStats(PointcutStats stats) 1188 { 1189 if (stats != null) 1190 { 1191 construction |= stats.isConstruction(); 1192 execution |= stats.isExecution(); 1193 call |= stats.isCall(); 1194 within |= stats.isWithin(); 1195 get |= stats.isGet(); 1196 set |= stats.isSet(); 1197 withincode |= stats.isWithincode(); 1198 } 1199 else 1200 { 1201 if (verbose) System.out.println("[debug] Setting all pointcut stats to true"); 1202 execution = true; 1204 construction = true; 1205 call = true; 1206 within = true; 1207 get = true; 1208 set = true; 1209 withincode = true; 1210 } 1211 } 1212 1213 public boolean isExecution() 1214 { 1215 return execution; 1216 } 1217 1218 public boolean isConstruction() 1219 { 1220 return construction; 1221 } 1222 1223 public boolean isCall() 1224 { 1225 return call; 1226 } 1227 1228 public boolean isWithin() 1229 { 1230 return within; 1231 } 1232 1233 public boolean isWithincode() 1234 { 1235 return withincode; 1236 } 1237 1238 public boolean isGet() 1239 { 1240 return get; 1241 } 1242 1243 public boolean isSet() 1244 { 1245 return set; 1246 } 1247 1248 1251 public void removeBinding(String name) 1252 { 1253 AdviceBinding binding = internalRemoveBinding(name); 1254 if (binding != null) 1255 { 1256 binding.clearAdvisors(); 1257 dynamicStrategy.interceptorChainsUpdated(); 1258 } 1259 } 1260 1261 public void removeBindings(ArrayList binds) 1262 { 1263 clearUnregisteredClassLoaders(); 1264 1265 HashSet bindingAdvisors = new HashSet (); 1266 ArrayList removedBindings = new ArrayList (); 1267 synchronized (bindings) 1268 { 1269 int bindSize = binds.size(); 1270 1271 for (int i = 0; i < bindSize; i++) 1272 { 1273 1274 AdviceBinding binding = (AdviceBinding) bindings.get(binds.get(i)); 1275 if (binding == null) 1276 { 1277 System.out.println("[warn] AspectManager.removeBindings() no binding found with name " + binds.get(i)); 1278 continue; 1279 } 1280 ArrayList ads = binding.getAdvisors(); 1281 bindingAdvisors.addAll(ads); 1282 bindings.remove(binding.getName()); 1283 Pointcut pointcut = binding.getPointcut(); 1284 this.removePointcut(pointcut.getName()); 1285 removedBindings.add(binding); 1286 } 1287 } 1288 Iterator it = bindingAdvisors.iterator(); 1289 while (it.hasNext()) 1290 { 1291 Advisor advisor = (Advisor) it.next(); 1292 if (!isAdvisorRegistered(advisor)) 1293 { 1294 1296 WeakReference ref = (WeakReference )getSubDomainsPerClass().get(advisor.getClazz()); 1297 Domain domain = null; 1298 if (ref != null) domain = (Domain)ref.get(); 1299 if (domain != null) 1300 { 1301 if (subscribedSubDomains.containsKey(domain)) 1302 { 1303 if (!domain.isAdvisorRegistered(advisor))continue; 1304 } 1305 } 1306 } 1307 advisor.removeAdviceBindings(removedBindings); 1308 } 1309 dynamicStrategy.interceptorChainsUpdated(); 1310 } 1311 1312 1315 public synchronized void addBinding(AdviceBinding binding) 1316 { 1317 AdviceBinding removedBinding = internalRemoveBinding(binding.getName()); 1318 Set affectedAdvisors = removedBinding == null? new HashSet (): new HashSet (removedBinding.getAdvisors()); 1319 synchronized (bindings) 1320 { 1321 bindings.put(binding.getName(), binding); 1322 } 1323 synchronized (pointcuts) 1324 { 1325 Pointcut pointcut = binding.getPointcut(); 1326 pointcuts.put(pointcut.getName(), pointcut); 1327 pointcutInfos.put(pointcut.getName(), new PointcutInfo(pointcut, binding, this.transformationStarted)); 1328 updatePointcutStats(pointcut); 1329 } 1330 1331 synchronized (advisors) 1332 { 1333 updateAdvisorsForAddedBinding(binding); 1334 1335 for (Iterator i = affectedAdvisors.iterator(); i.hasNext(); ) 1336 { 1337 Advisor advisor = (Advisor) i.next(); 1338 if (isAdvisorRegistered(advisor)) 1339 advisor.removeAdviceBinding(removedBinding); 1340 } 1341 } 1342 this.dynamicStrategy.interceptorChainsUpdated(); 1343 } 1344 1345 1346 public void updateAdvisorsForAddedBinding(AdviceBinding binding) 1347 { 1348 synchronized (advisors) 1349 { 1350 Collection keys = advisors.keySet(); 1352 if (keys.size() > 0) 1353 { 1354 Iterator it = keys.iterator(); 1355 while (it.hasNext()) 1356 { 1357 Advisor advisor = getAdvisorFromAdvisorsKeySetIterator(it); 1358 if (advisor == null) continue; 1359 1360 if (binding.getPointcut().softMatch(advisor)) 1361 { 1362 if (AspectManager.verbose) 1363 System.out.println("[debug] softmatch succeeded for : " + advisor.getName() + " " + binding + " " + binding.getPointcut().getExpr()); 1364 advisor.newBindingAdded(); 1365 } 1367 else 1368 { 1369 if (AspectManager.verbose) 1370 System.out.println("[debug] softmatch failed for : " + advisor.getName() + " " + binding + " " + binding.getPointcut().getExpr()); 1371 } 1372 } 1373 } 1374 } 1375 synchronized (subscribedSubDomains) 1376 { 1377 copySubDomainsFromQueue(true); 1378 boolean newSubscribers = true; 1379 while (newSubscribers) 1380 { 1381 Collection keys = subscribedSubDomains.keySet(); 1382 if (keys.size() > 0) 1383 { 1384 for (Iterator it = keys.iterator() ; it.hasNext() ; ) 1386 { 1387 Domain domain = (Domain)it.next(); 1388 domain.updateAdvisorsForAddedBinding(binding); 1389 } 1390 } 1391 newSubscribers = copySubDomainsFromQueue(false); 1392 } 1393 } 1394 } 1395 1396 public void removeClassMetaData(String name) 1397 { 1398 synchronized (classMetaData) 1399 { 1400 ClassMetaDataBinding meta = (ClassMetaDataBinding) classMetaData.remove(name); 1401 if (meta == null) return; 1402 meta.clearAdvisors(); 1403 } 1404 } 1405 1406 public void addClassMetaData(ClassMetaDataBinding meta) 1407 { 1408 removeClassMetaData(meta.getName()); 1409 1410 updateAdvisorsForAddedClassMetaData(meta); 1411 1412 synchronized (classMetaData) 1413 { 1414 classMetaData.put(meta.getName(), meta); 1415 } 1416 } 1417 1418 protected void updateAdvisorsForAddedClassMetaData(ClassMetaDataBinding meta) 1419 { 1420 synchronized (advisors) 1421 { 1422 Iterator it = advisors.keySet().iterator(); 1423 1424 while (it.hasNext()) 1425 { 1426 Advisor advisor = getAdvisorFromAdvisorsKeySetIterator(it); 1427 if (advisor == null) continue; 1428 1429 Class clazz = advisor.getClazz(); 1430 addAdvisorToClassMetaDataBinding(meta, clazz, advisor, clazz); 1431 } 1432 } 1433 1434 synchronized (subscribedSubDomains) 1435 { 1436 copySubDomainsFromQueue(true); 1437 boolean newSubscribers = true; 1438 while (newSubscribers) 1439 { 1440 for (Iterator it = subscribedSubDomains.keySet().iterator() ; it.hasNext() ; ) 1441 { 1442 Domain domain = (Domain)it.next(); 1443 domain.updateAdvisorsForAddedClassMetaData(meta); 1444 } 1445 newSubscribers = copySubDomainsFromQueue(false); 1446 } 1447 } 1448 } 1449 1450 protected void addAdvisorToClassMetaDataBinding(ClassMetaDataBinding meta, Class clazz, Advisor advisor, Class advisedClass) 1451 { 1452 if (meta.matches(advisor, clazz)) 1453 { 1454 meta.addAdvisor(advisor); 1455 } 1456 else if (advisor.chainOverridingForInheritedMethods()) 1457 { 1458 Class superClass = clazz.getSuperclass(); 1461 if (superClass != null && superClass != Object .class) 1462 { 1463 addAdvisorToClassMetaDataBinding(meta, superClass, advisor, advisedClass); 1464 } 1465 } 1466 } 1467 1468 1470 1473 public InterfaceIntroduction getInterfaceIntroduction(String name) 1474 { 1475 synchronized (interfaceIntroductions) 1476 { 1477 return (InterfaceIntroduction) interfaceIntroductions.get(name); 1478 } 1479 } 1480 1481 1484 public synchronized void addInterfaceIntroduction(InterfaceIntroduction pointcut) 1485 { 1486 removeInterfaceIntroduction(pointcut.getName()); 1487 synchronized (interfaceIntroductions) 1488 { 1489 interfaceIntroductions.put(pointcut.getName(), pointcut); 1490 } 1491 } 1492 1493 1496 public void removeInterfaceIntroduction(String name) 1497 { 1498 synchronized (interfaceIntroductions) 1499 { 1500 InterfaceIntroduction pointcut = (InterfaceIntroduction) interfaceIntroductions.remove(name); 1501 if (pointcut == null) return; 1502 pointcut.clearAdvisors(); 1503 } 1504 } 1505 1506 1509 public synchronized void addAnnotationIntroduction(AnnotationIntroduction pointcut) 1510 { 1511 String name = pointcut.getOriginalAnnotationExpr() + pointcut.getOriginalExpression(); 1512 removeAnnotationIntroduction(pointcut); 1513 synchronized (annotationIntroductions) 1514 { 1515 annotationIntroductions.put(name, pointcut); 1516 } 1517 } 1518 1519 1522 public void removeAnnotationIntroduction(AnnotationIntroduction pointcut) 1523 { 1524 String name = pointcut.getOriginalAnnotationExpr() + pointcut.getOriginalExpression(); 1525 synchronized (annotationIntroductions) 1526 { 1527 annotationIntroductions.remove(name); 1528 } 1529 } 1530 1531 public List getAnnotationIntroductions() 1532 { 1533 synchronized (annotationIntroductions) 1534 { 1535 return new ArrayList (annotationIntroductions.values()); 1536 } 1537 } 1538 1539 public synchronized void addDeclare(DeclareDef declare) 1540 { 1541 removeDeclare(declare.getName()); 1542 synchronized (declares) 1543 { 1544 declares.put(declare.getName(), declare); 1545 } 1546 if (declare.isPointcut()) 1547 { 1548 PointcutStats stats; 1549 stats = new PointcutStats(declare.getAst(), manager); 1550 stats.matches(); 1551 updateStats(stats); 1552 } 1553 } 1554 1555 public void removeDeclare(String name) 1556 { 1557 synchronized (declares) 1558 { 1559 declares.remove(name); 1560 } 1561 } 1562 1563 public Iterator getDeclares() 1564 { 1565 return declares.values().iterator(); 1566 } 1567 1568 protected void applyInterfaceIntroductions(Advisor advisor, Class clazz) 1569 { 1570 Map interfaceIntroductions = getInterfaceIntroductions(); 1571 if (interfaceIntroductions != null && interfaceIntroductions.size() > 0) 1572 { 1573 Iterator it = interfaceIntroductions.values().iterator(); 1574 while (it.hasNext()) 1575 { 1576 InterfaceIntroduction pointcut = (InterfaceIntroduction) it.next(); 1577 if (pointcut.matches(advisor, clazz)) 1578 { 1579 pointcut.addAdvisor(advisor); 1580 } 1581 } 1582 } 1583 } 1584 1585 protected void applyInterfaceIntroductions(ClassAdvisor advisor, CtClass clazz) throws Exception 1586 { 1587 Map interfaceIntroductions = getInterfaceIntroductions(); 1588 if (interfaceIntroductions != null && interfaceIntroductions.size() > 0) 1589 { 1590 Iterator it = interfaceIntroductions.values().iterator(); 1591 while (it.hasNext()) 1592 { 1593 InterfaceIntroduction pointcut = (InterfaceIntroduction) it.next(); 1594 if (pointcut.matches(advisor, clazz)) 1595 { 1596 pointcut.addAdvisor(advisor); 1597 } 1598 } 1599 } 1600 } 1601 1602 1603 1606 public synchronized void addAnnotationOverride(AnnotationIntroduction pointcut) 1607 { 1608 String name = pointcut.getOriginalAnnotationExpr() + pointcut.getOriginalExpression(); 1609 synchronized (annotationOverrides) 1610 { 1611 annotationOverrides.put(name, pointcut); 1612 } 1613 updateAdvisorsForAddedAnnotationOverride(pointcut); 1614 } 1615 1616 public void updateAdvisorsForAddedAnnotationOverride(AnnotationIntroduction introduction) 1617 { 1618 synchronized (advisors) 1619 { 1620 Iterator it = advisors.keySet().iterator(); 1622 while (it.hasNext()) 1623 { 1624 Advisor advisor = getAdvisorFromAdvisorsKeySetIterator(it); 1625 if (advisor == null) continue; 1626 1627 advisor.deployAnnotationOverride(introduction); 1628 } 1629 } 1630 synchronized (subscribedSubDomains) 1631 { 1632 copySubDomainsFromQueue(true); 1633 boolean newSubscribers = true; 1634 while (newSubscribers) 1635 { 1636 for (Iterator it = subscribedSubDomains.keySet().iterator() ; it.hasNext() ; ) 1637 { 1638 Domain domain = (Domain)it.next(); 1639 domain.updateAdvisorsForAddedAnnotationOverride(introduction); 1640 } 1641 newSubscribers = copySubDomainsFromQueue(false); 1642 } 1643 } 1644 } 1645 1646 1647 1650 public void removeAnnotationOverride(AnnotationIntroduction pointcut) 1651 { 1652 String name = pointcut.getOriginalAnnotationExpr() + pointcut.getOriginalExpression(); 1653 synchronized (annotationOverrides) 1654 { 1655 annotationOverrides.remove(name); 1656 } 1657 } 1658 1659 public List getAnnotationOverrides() 1660 { 1661 synchronized (annotationOverrides) 1662 { 1663 return new ArrayList (annotationOverrides.values()); 1664 } 1665 } 1666 1667 public Object getPerVMAspect(AspectDefinition def) 1668 { 1669 return getPerVMAspect(def.getName()); 1670 } 1671 1672 public Object getPerVMAspect(String def) 1673 { 1674 Object aspect = perVMAspects.get(def); 1675 if (aspect instanceof AspectDefinition) 1676 { 1677 synchronized (aspect) 1678 { 1679 return createPerVmAspect(def, (AspectDefinition)aspect, null); 1680 } 1681 } 1682 return aspect; 1683 } 1684 1685 protected Object createPerVmAspect(String def, AspectDefinition adef, ClassLoader scopedClassLoader) 1686 { 1687 Object instance = null; 1688 synchronized (adef) 1689 { 1690 try 1691 { 1692 if (scopedClassLoader != null && adef.getFactory() instanceof AspectFactoryWithClassLoader) 1693 { 1694 ((AspectFactoryWithClassLoader)adef.getFactory()).pushScopedClassLoader(scopedClassLoader); 1696 } 1697 instance = adef.getFactory().createPerVM(); 1698 perVMAspects.put(def, instance); 1699 } 1700 finally 1701 { 1702 if (scopedClassLoader != null && adef.getFactory() instanceof AspectFactoryWithClassLoader) 1703 { 1704 ((AspectFactoryWithClassLoader)adef.getFactory()).popScopedClassLoader(); 1705 } 1706 } 1707 } 1708 return instance; 1709 } 1710 1711 public void addAspectDefinition(AspectDefinition def) 1712 { 1713 removeAspectDefinition(def.getName()); 1714 if (def.getScope() == Scope.PER_VM) 1715 { 1716 perVMAspects.put(def.getName(), def); 1717 } 1718 aspectDefinitions.put(def.getName(), def); 1719 } 1720 1721 public void removeAspectDefinition(String name) 1722 { 1723 AspectDefinition def = (AspectDefinition) aspectDefinitions.remove(name); 1724 if (def != null) 1725 { 1726 def.undeploy(); 1727 if (def.getScope() == Scope.PER_VM) perVMAspects.remove(def.getName()); 1728 } 1729 } 1730 1731 public Map getAspectDefinitions() 1732 { 1733 return aspectDefinitions; 1734 } 1735 1736 public AspectDefinition getAspectDefinition(String name) 1737 { 1738 return (AspectDefinition) aspectDefinitions.get(name); 1739 } 1740 1741 public synchronized void addTypedef(Typedef def) throws Exception 1742 { 1743 removeTypedef(def.getName()); 1744 synchronized (typedefs) 1745 { 1746 typedefs.put(def.getName(), def); 1747 } 1748 } 1749 1750 public void removeTypedef(String name) 1751 { 1752 synchronized (typedefs) 1753 { 1754 typedefs.remove(name); 1755 } 1756 } 1757 1758 public Typedef getTypedef(String name) 1759 { 1760 synchronized (typedefs) 1761 { 1762 return (Typedef) typedefs.get(name); 1763 } 1764 } 1765 1766 public Map getInterfaceIntroductions() 1767 { 1768 return interfaceIntroductions; 1769 } 1770 1771 public Map getTypedefs() 1772 { 1773 return typedefs; 1774 } 1775 1776 public Map getInterceptorStacks() 1777 { 1778 return interceptorStacks; 1779 } 1780 1781 public Map getClassMetaDataLoaders() 1782 { 1783 return classMetaDataLoaders; 1784 } 1785 1786 public Map getCflowStacks() 1787 { 1788 return cflowStacks; 1789 } 1790 1791 public Map getDynamicCFlows() 1792 { 1793 return dynamicCFlows; 1794 } 1795 1796 public Map getPerVMAspects() 1797 { 1798 return perVMAspects; 1799 } 1800 1801 public Map getClassMetaData() 1802 { 1803 return classMetaData; 1804 } 1805 1806 1809 public DynamicAOPStrategy getDynamicAOPStrategy() 1810 { 1811 return this.dynamicStrategy; 1812 } 1813 1814 1819 public void setDynamicAOPStrategy(DynamicAOPStrategy strategy) 1820 { 1821 if (this.transformationStarted) 1823 { 1824 throw new RuntimeException ("Dynamic AOP Strategy Update not allowed in run time"); 1825 } 1826 this.dynamicStrategy = strategy; 1827 } 1828 1829 1833 private AdviceBinding internalRemoveBinding(String name) 1834 { 1835 synchronized (bindings) 1836 { 1837 AdviceBinding binding = (AdviceBinding) bindings.remove(name); 1838 if (binding == null) 1839 { 1840 return null; 1841 } 1842 Pointcut pointcut = binding.getPointcut(); 1843 this.removePointcut(pointcut.getName()); 1844 return binding; 1845 } 1846 } 1847 1848 public void setBindings(LinkedHashMap bindings) 1849 { 1850 this.bindings.clear(); 1851 this.bindings.putAll(bindings); 1852 } 1853 1854 public void addSubDomainPerClass(Class clazz, Domain domain) 1855 { 1856 synchronized (getSubDomainsPerClass()) 1857 { 1858 getSubDomainsPerClass().put(clazz, new WeakReference (domain)); 1859 } 1860 } 1861 1862 1866 public void subscribeSubDomain(Domain domain) 1867 { 1868 synchronized (subscribedSubDomains) 1869 { 1870 subscribedSubDomainsQueue.put(domain, "Contents do not matter"); 1871 } 1872 } 1873 1874 public void unsubscribeSubDomain(Domain domain) 1875 { 1876 synchronized (subscribedSubDomains) 1877 { 1878 subscribedSubDomains.remove(domain); 1879 } 1880 } 1881 1882 private Advisor getAdvisorFromAdvisorsKeySetIterator(Iterator it) 1883 { 1884 Class clazz = (Class ) it.next(); 1885 if (classLoaderValidator != null && !classLoaderValidator.isValidClassLoader(clazz.getClassLoader())) 1886 { 1887 it.remove(); 1888 return null; 1889 } 1890 WeakReference ref = (WeakReference ) advisors.get(clazz); 1891 if (ref == null) return null; 1892 Advisor advisor = (Advisor) ref.get(); 1893 if (advisor == null) 1894 { 1895 it.remove(); 1896 return null; 1897 } 1898 return advisor; 1899 } 1900 1901 1906 private boolean copySubDomainsFromQueue(boolean increment) 1907 { 1908 boolean copied = false; 1909 synchronized (subscribedSubDomains) 1910 { 1911 if (!increment && subscribedDomainQueueRef > 0) subscribedDomainQueueRef--; 1912 1913 if (subscribedDomainQueueRef == 0 && subscribedSubDomainsQueue.size() > 0){ 1914 subscribedSubDomains.putAll(subscribedSubDomainsQueue); 1915 subscribedSubDomainsQueue.clear(); 1916 copied = true; 1917 } 1918 1919 if (increment) subscribedDomainQueueRef++; 1920 } 1921 return copied; 1922 } 1923 1924 1968} 1969 | Popular Tags |