1 22 package org.jboss.aop; 23 24 import java.util.ArrayList ; 25 26 import org.jboss.aop.advice.AdviceBinding; 27 import org.jboss.aop.joinpoint.MethodJoinpoint; 28 import org.jboss.aop.pointcut.PointcutMethodMatch; 29 30 35 class MethodMatchInfo 36 { 37 Advisor advisor; 38 MethodInfo info; 39 ArrayList bindings; 40 ArrayList pointcutMethodMatches; 41 42 MethodMatchInfo(Advisor advisor, MethodInfo info) 43 { 44 this.advisor = advisor; 45 this.info = info; 46 } 47 48 public void addMatchedBinding(AdviceBinding binding, PointcutMethodMatch pointcutMethodMatch) 49 { 50 if (bindings == null) 51 { 52 bindings = new ArrayList (); 53 } 54 if (pointcutMethodMatches == null) 55 { 56 pointcutMethodMatches = new ArrayList (); 57 } 58 bindings.add(binding); 59 pointcutMethodMatches.add(pointcutMethodMatch); 60 } 61 62 public MethodInfo getInfo() 63 { 64 return info; 65 } 66 67 public void setInfo(MethodInfo info) 68 { 69 this.info = info; 70 } 71 72 public ArrayList populateBindings() 73 { 74 if (bindings != null) 75 { 76 ArrayList applicableBindings = new ArrayList (); 77 if (advisor.chainOverridingForInheritedMethods()) 78 { 79 overridePopulateBindings(applicableBindings); 80 } 81 else 82 { 83 simplePopulateBindings(applicableBindings); 84 } 85 86 if (applicableBindings.size() > 0) 87 { 88 return applicableBindings; 89 } 90 } 91 return null; 92 } 93 94 private void simplePopulateBindings(ArrayList applicableBindings) 95 { 96 int size = bindings.size(); 97 for (int i = 0 ; i < size ; i++) 98 { 99 AdviceBinding binding = (AdviceBinding)bindings.get(i); 100 applyBinding(applicableBindings, binding); 101 } 102 } 103 104 private void overridePopulateBindings(ArrayList applicableBindings) 105 { 106 if (AspectManager.verbose) System.out.println("[debug] populate bindings for " + info.getAdvisedMethod() + " all bindings"); 107 int size = bindings.size(); 108 int minMatchLevel = 1000000; 109 for (int i = 0 ; i < size ; i++) 110 { 111 AdviceBinding binding = (AdviceBinding)bindings.get(i); 112 PointcutMethodMatch match = (PointcutMethodMatch)pointcutMethodMatches.get(i); 113 if (AspectManager.verbose) System.out.println("[debug] " + match.getMatchLevel() + " " + match.getMatchedClass().getName() + " " + binding.getPointcut().getExpr() + " : " + binding.getInterceptorFactories().length); 114 115 if (minMatchLevel > match.getMatchLevel() && !match.isInstanceOf()) 116 { 117 minMatchLevel = match.getMatchLevel(); 118 } 119 } 120 121 if (AspectManager.verbose) System.out.println("[debug] populate bindings for " + info.getAdvisedMethod() + " actual bindings"); 122 for (int i = 0 ; i < size ; i++) 123 { 124 AdviceBinding binding = (AdviceBinding)bindings.get(i); 125 PointcutMethodMatch match = (PointcutMethodMatch)pointcutMethodMatches.get(i); 126 127 if (match.isInstanceOf() || match.getMatchLevel() == minMatchLevel) 128 { 129 if (AspectManager.verbose) System.out.println("[debug] " + match.getMatchLevel() + " " + match.getMatchedClass().getName() + " " + binding.getPointcut().getExpr() + " : " + binding.getInterceptorFactories().length); 130 applyBinding(applicableBindings, binding); 131 } 132 } 133 } 134 135 private void applyBinding(ArrayList applicableBindings, AdviceBinding binding) 136 { 137 applicableBindings.add(binding); 138 binding.addAdvisor(advisor); 139 advisor.pointcutResolved(info, binding, new MethodJoinpoint(info.getAdvisedMethod())); 140 } 141 142 public void clear() 143 { 144 bindings = null; 145 pointcutMethodMatches = null; 146 info.clear(); 147 } 148 } 149 | Popular Tags |