KickJava   Java API By Example, From Geeks To Geeks.

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


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

46 public class CallMatcher extends MatcherHelper
47 {
48    Advisor advisor;
49    AccessibleObject JavaDoc within;
50    Class JavaDoc calledClass;
51    Method calledMethod;
52
53    public CallMatcher(Advisor advisor, AccessibleObject JavaDoc within, Class JavaDoc calledClass, Method calledMethod, ASTStart start)
54    {
55       super(start, advisor.getManager());
56       this.advisor = advisor;
57       this.within = within;
58       this.calledClass = calledClass;
59       this.calledMethod = calledMethod;
60    }
61
62    public Object JavaDoc visit(ASTCall node, Object JavaDoc data)
63    {
64       try
65       {
66          if (!(node.getBehavior() instanceof ASTMethod)) return Boolean.FALSE;
67          ASTMethod astMethod = (ASTMethod) node.getBehavior();
68          Advisor calledAdvisor = AspectManager.instance().getTempClassAdvisorIfNotExist(calledClass);
69          MethodMatcher methodMatcher = new MethodMatcher(calledAdvisor, calledMethod, null);
70          if (!(methodMatcher.matches(astMethod)).booleanValue()) return Boolean.FALSE;
71          return Boolean.TRUE;
72       }
73       catch (Exception JavaDoc e)
74       {
75          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
76
}
77    }
78
79    public Object JavaDoc visit(ASTHas node, Object JavaDoc data)
80    {
81       Node n = node.jjtGetChild(0);
82       if (n instanceof ASTMethod)
83       {
84          return new Boolean JavaDoc(Util.has(calledClass, (ASTMethod) n, advisor));
85       }
86       else
87       {
88          return new Boolean JavaDoc(Util.has(calledClass, (ASTConstructor) n, advisor));
89       }
90    }
91
92    public Object JavaDoc visit(ASTHasField node, Object JavaDoc data)
93    {
94       ASTField f = (ASTField) node.jjtGetChild(0);
95       return new Boolean JavaDoc(Util.has(calledClass, f, advisor));
96    }
97
98    public Object JavaDoc visit(ASTWithin node, Object JavaDoc data)
99    {
100       WithinMatcher visitor = new WithinMatcher(advisor, this.within, null);
101       return node.jjtAccept(visitor, null);
102    }
103
104    public Object JavaDoc visit(ASTWithincode node, Object JavaDoc data)
105    {
106       WithinMatcher visitor = new WithinMatcher(advisor, this.within, null);
107       return node.jjtAccept(visitor, null);
108    }
109
110    protected Boolean JavaDoc resolvePointcut(Pointcut p)
111    {
112       return new Boolean JavaDoc(p.matchesCall(advisor, within, calledClass, calledMethod));
113    }
114
115 }
116
Popular Tags