KickJava   Java API By Example, From Geeks To Geeks.

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


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.CtClass;
25 import org.jboss.aop.Advisor;
26 import org.jboss.aop.pointcut.ast.ASTAllParameter;
27 import org.jboss.aop.pointcut.ast.ASTAnd;
28 import org.jboss.aop.pointcut.ast.ASTAttribute;
29 import org.jboss.aop.pointcut.ast.ASTBoolean;
30 import org.jboss.aop.pointcut.ast.ASTClass;
31 import org.jboss.aop.pointcut.ast.ASTComposite;
32 import org.jboss.aop.pointcut.ast.ASTConstructor;
33 import org.jboss.aop.pointcut.ast.ASTException;
34 import org.jboss.aop.pointcut.ast.ASTField;
35 import org.jboss.aop.pointcut.ast.ASTHas;
36 import org.jboss.aop.pointcut.ast.ASTHasField;
37 import org.jboss.aop.pointcut.ast.ASTMethod;
38 import org.jboss.aop.pointcut.ast.ASTNot;
39 import org.jboss.aop.pointcut.ast.ASTOr;
40 import org.jboss.aop.pointcut.ast.ASTParameter;
41 import org.jboss.aop.pointcut.ast.ASTStart;
42 import org.jboss.aop.pointcut.ast.ASTSub;
43 import org.jboss.aop.pointcut.ast.Node;
44 import org.jboss.aop.pointcut.ast.SimpleNode;
45 import org.jboss.aop.pointcut.ast.TypeExpressionParserVisitor;
46
47 /**
48  * Comment
49  *
50  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
51  * @version $Revision: 37406 $
52  */

53 public class TypeMatcher implements TypeExpressionParserVisitor
54 {
55    protected Advisor advisor;
56    protected CtClass ctClass;
57    protected Class JavaDoc clazz;
58
59    public TypeMatcher(Advisor advisor, Class JavaDoc clazz)
60    {
61       this.advisor = advisor;
62       this.clazz = clazz;
63    }
64
65    public TypeMatcher(Advisor advisor, CtClass ctClass)
66    {
67       this.advisor = advisor;
68       this.ctClass = ctClass;
69    }
70
71    public Object JavaDoc visit(ASTStart node, Object JavaDoc data)
72    {
73       return node.jjtGetChild(0).jjtAccept(this, data);
74    }
75
76    public Object JavaDoc visit(ASTBoolean node, Object JavaDoc data)
77    {
78       return node.jjtGetChild(0).jjtAccept(this, data);
79    }
80
81    public Object JavaDoc visit(ASTComposite node, Object JavaDoc data)
82    {
83       return node.jjtGetChild(0).jjtAccept(this, data);
84    }
85
86    public Object JavaDoc visit(ASTNot node, Object JavaDoc data)
87    {
88
89       Boolean JavaDoc bool = (Boolean JavaDoc) node.jjtGetChild(0).jjtAccept(this, data);
90       boolean val = bool.booleanValue();
91       return val ? Boolean.FALSE : Boolean.TRUE;
92    }
93
94    public Object JavaDoc visit(ASTSub node, Object JavaDoc data)
95    {
96       for (int i = 0; i < node.jjtGetNumChildren(); i++)
97       {
98          data = node.jjtGetChild(i).jjtAccept(this, data);
99       }
100       return data;
101    }
102
103    public Object JavaDoc visit(ASTAnd node, Object JavaDoc left)
104    {
105       Node andChild = node.jjtGetChild(0); // should only have one child
106
boolean val = ((Boolean JavaDoc) left).booleanValue();
107       return new Boolean JavaDoc(val && ((Boolean JavaDoc) andChild.jjtAccept(this, Boolean.FALSE)).booleanValue());
108    }
109
110    public Object JavaDoc visit(ASTOr node, Object JavaDoc left)
111    {
112       Node orChild = node.jjtGetChild(0); // should only have one child
113
boolean val = ((Boolean JavaDoc) left).booleanValue();
114       return new Boolean JavaDoc(val || ((Boolean JavaDoc) orChild.jjtAccept(this, Boolean.FALSE)).booleanValue());
115    }
116
117
118    public Object JavaDoc visit(SimpleNode node, Object JavaDoc data)
119    {
120       return null;
121    }
122
123
124    public Object JavaDoc visit(ASTHas node, Object JavaDoc data)
125    {
126       Node n = node.jjtGetChild(0);
127       if (n instanceof ASTMethod)
128       {
129          if (clazz != null) return new Boolean JavaDoc(Util.has(clazz, (ASTMethod) n, advisor));
130          if (ctClass != null) return new Boolean JavaDoc(Util.has(ctClass, (ASTMethod) n, advisor));
131       }
132       else
133       {
134          if (clazz != null) return new Boolean JavaDoc(Util.has(clazz, (ASTConstructor) n, advisor));
135          if (ctClass != null) return new Boolean JavaDoc(Util.has(ctClass, (ASTConstructor) n, advisor));
136       }
137       return Boolean.FALSE;
138    }
139
140    public Object JavaDoc visit(ASTHasField node, Object JavaDoc data)
141    {
142       ASTField f = (ASTField) node.jjtGetChild(0);
143       if (clazz != null)
144          return new Boolean JavaDoc(Util.has(clazz, f, advisor));
145       else
146          return new Boolean JavaDoc(Util.has(ctClass, f, advisor));
147    }
148
149    public Object JavaDoc visit(ASTClass node, Object JavaDoc data)
150    {
151       if (clazz != null)
152       {
153          return new Boolean JavaDoc(Util.matchesClassExpr(node.getClazz(), clazz, advisor));
154       }
155       else
156       {
157          return new Boolean JavaDoc(Util.matchesClassExpr(node.getClazz(), ctClass, advisor));
158       }
159    }
160
161    public Object JavaDoc visit(ASTMethod node, Object JavaDoc data)
162    {
163       return Boolean.FALSE;
164    }
165
166    public Object JavaDoc visit(ASTAttribute node, Object JavaDoc data)
167    {
168       return Boolean.FALSE;
169    }
170
171    public Object JavaDoc visit(ASTConstructor node, Object JavaDoc data)
172    {
173       return Boolean.FALSE;
174    }
175
176    public Object JavaDoc visit(ASTParameter node, Object JavaDoc data)
177    {
178       return Boolean.FALSE;
179    }
180
181    public Object JavaDoc visit(ASTAllParameter node, Object JavaDoc data)
182    {
183       return Boolean.FALSE;
184    }
185
186    public Object JavaDoc visit(ASTField node, Object JavaDoc data)
187    {
188       return Boolean.FALSE;
189    }
190
191    public Object JavaDoc visit(ASTException node, Object JavaDoc data)
192    {
193       return Boolean.FALSE;
194    }
195
196    
197 }
198
Popular Tags