KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > MethodMatchInfo


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.aop;
23
24 import java.util.ArrayList JavaDoc;
25
26 import org.jboss.aop.advice.AdviceBinding;
27 import org.jboss.aop.joinpoint.MethodJoinpoint;
28 import org.jboss.aop.pointcut.PointcutMethodMatch;
29
30 /**
31  *
32  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
33  * @version $Revision: 46033 $
34  */

35 class MethodMatchInfo
36 {
37    Advisor advisor;
38    MethodInfo info;
39    ArrayList JavaDoc bindings;
40    ArrayList JavaDoc 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 JavaDoc();
53       }
54       if (pointcutMethodMatches == null)
55       {
56          pointcutMethodMatches = new ArrayList JavaDoc();
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 JavaDoc populateBindings()
73    {
74       if (bindings != null)
75       {
76          ArrayList JavaDoc applicableBindings = new ArrayList JavaDoc();
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 JavaDoc 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 JavaDoc 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 JavaDoc 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