KickJava   Java API By Example, From Geeks To Geeks.

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


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.CtConstructor;
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.Constructor JavaDoc;
37
38 /**
39  * Comment
40  *
41  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
42  * @version $Revision: 37406 $
43  */

44 public class ExecutionConstructorMatcher extends ConstructorMatcher
45 {
46    public ExecutionConstructorMatcher(Advisor advisor, CtConstructor con, ASTStart start) throws NotFoundException
47    {
48       super(advisor, con, start);
49    }
50
51    public ExecutionConstructorMatcher(Advisor advisor, Constructor con, ASTStart start)
52    {
53       super(advisor, con, 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    public Object JavaDoc visit(ASTHas node, Object JavaDoc data)
62    {
63       Node n = node.jjtGetChild(0);
64       if (n instanceof ASTMethod)
65       {
66          if (ctCon != null)
67          {
68             return new Boolean JavaDoc(Util.has(ctCon.getDeclaringClass(), (ASTMethod) n, advisor));
69          }
70          else
71          {
72             return new Boolean JavaDoc(Util.has(refCon.getDeclaringClass(), (ASTMethod) n, advisor));
73
74          }
75       }
76       else
77       {
78          if (ctCon != null)
79          {
80             return new Boolean JavaDoc(Util.has(ctCon.getDeclaringClass(), (ASTConstructor) n, advisor));
81          }
82          else
83          {
84             return new Boolean JavaDoc(Util.has(refCon.getDeclaringClass(), (ASTConstructor) n, advisor));
85
86          }
87       }
88    }
89
90    public Object JavaDoc visit(ASTHasField node, Object JavaDoc data)
91    {
92       ASTField f = (ASTField) node.jjtGetChild(0);
93       if (ctCon != null)
94       {
95          return new Boolean JavaDoc(Util.has(ctCon.getDeclaringClass(), f, advisor));
96       }
97       else
98       {
99          return new Boolean JavaDoc(Util.has(refCon.getDeclaringClass(), f, advisor));
100       }
101
102    }
103
104    protected Boolean JavaDoc resolvePointcut(Pointcut p)
105    {
106       try
107       {
108          if (refCon != null) return new Boolean JavaDoc(p.matchesExecution(advisor, refCon));
109          return new Boolean JavaDoc(p.matchesExecution(advisor, ctCon));
110       }
111       catch (NotFoundException e)
112       {
113          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
114
}
115    }
116 }
117
Popular Tags