KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > pointcut > ExecutionMethodMatcher


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.pointcut;
23
24 import javassist.CtMethod;
25 import javassist.NotFoundException;
26 import org.jboss.aop.Advisor;
27 import org.jboss.aop.pointcut.ast.ASTConstructor;
28 import org.jboss.aop.pointcut.ast.ASTExecution;
29 import org.jboss.aop.pointcut.ast.ASTField;
30 import org.jboss.aop.pointcut.ast.ASTHas;
31 import org.jboss.aop.pointcut.ast.ASTHasField;
32 import org.jboss.aop.pointcut.ast.ASTMethod;
33 import org.jboss.aop.pointcut.ast.ASTStart;
34 import org.jboss.aop.pointcut.ast.Node;
35
36 import java.lang.reflect.Method JavaDoc;
37
38 /**
39  * Comment
40  *
41  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
42  * @version $Revision: 46033 $
43  */

44 public class ExecutionMethodMatcher extends MethodMatcher
45 {
46    public ExecutionMethodMatcher(Advisor advisor, CtMethod method, ASTStart start) throws NotFoundException
47    {
48       super(advisor, method, start);
49    }
50
51    public ExecutionMethodMatcher(Advisor advisor, Method method, ASTStart start)
52    {
53       super(advisor, method, start);
54    }
55
56    public Object JavaDoc visit(ASTExecution node, Object JavaDoc data)
57    {
58       return node.jjtGetChild(0).jjtAccept(this, data);
59    }
60
61    protected Boolean JavaDoc resolvePointcut(Pointcut p)
62    {
63       try
64       {
65          if (refMethod != null)
66          {
67             PointcutMethodMatch pmatch = p.matchesExecution(advisor, refMethod);
68             if (pmatch != null && pmatch.isMatch())
69             {
70                this.matchedClass = pmatch.getMatchedClass();
71                this.matchLevel = pmatch.getMatchLevel();
72                this.isInstanceof = pmatch.isInstanceOf();
73                return Boolean.TRUE;
74             }
75             return Boolean.FALSE;
76          }
77          return new Boolean JavaDoc(p.matchesExecution(advisor, ctMethod));
78       }
79       catch (NotFoundException e)
80       {
81          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
82
}
83    }
84
85    public Object JavaDoc visit(ASTHas node, Object JavaDoc data)
86    {
87       Node n = node.jjtGetChild(0);
88       if (n instanceof ASTMethod)
89       {
90          if (ctMethod != null)
91          {
92             return new Boolean JavaDoc(Util.has(ctMethod.getDeclaringClass(), (ASTMethod) n, advisor));
93          }
94          else
95          {
96             return new Boolean JavaDoc(Util.has(refMethod.getDeclaringClass(), (ASTMethod) n, advisor));
97
98          }
99       }
100       else
101       {
102          if (ctMethod != null)
103          {
104             return new Boolean JavaDoc(Util.has(ctMethod.getDeclaringClass(), (ASTConstructor) n, advisor));
105          }
106          else
107          {
108             return new Boolean JavaDoc(Util.has(refMethod.getDeclaringClass(), (ASTConstructor) n, advisor));
109
110          }
111       }
112    }
113
114    public Object JavaDoc visit(ASTHasField node, Object JavaDoc data)
115    {
116       ASTField f = (ASTField) node.jjtGetChild(0);
117       if (ctMethod != null)
118       {
119          return new Boolean JavaDoc(Util.has(ctMethod.getDeclaringClass(), f, advisor));
120       }
121       else
122       {
123          return new Boolean JavaDoc(Util.has(refMethod.getDeclaringClass(), f, advisor));
124       }
125
126    }
127
128
129 }
130
Popular Tags