KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.Constructor JavaDoc;
25 import org.jboss.aop.Advisor;
26 import org.jboss.aop.pointcut.ast.ASTConstruction;
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.Node;
34 import javassist.CtConstructor;
35 import javassist.NotFoundException;
36
37 /**
38  * Comment
39  *
40  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
41  * @version $Revision: 37406 $
42  */

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