KickJava   Java API By Example, From Geeks To Geeks.

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


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.AspectManager;
25 import org.jboss.aop.pointcut.ast.ASTAll;
26 import org.jboss.aop.pointcut.ast.ASTAllParameter;
27 import org.jboss.aop.pointcut.ast.ASTAnd;
28 import org.jboss.aop.pointcut.ast.ASTAndCFlow;
29 import org.jboss.aop.pointcut.ast.ASTAttribute;
30 import org.jboss.aop.pointcut.ast.ASTBoolean;
31 import org.jboss.aop.pointcut.ast.ASTCFlow;
32 import org.jboss.aop.pointcut.ast.ASTCFlowBoolean;
33 import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
34 import org.jboss.aop.pointcut.ast.ASTCall;
35 import org.jboss.aop.pointcut.ast.ASTComposite;
36 import org.jboss.aop.pointcut.ast.ASTCompositeCFlow;
37 import org.jboss.aop.pointcut.ast.ASTConstructor;
38 import org.jboss.aop.pointcut.ast.ASTException;
39 import org.jboss.aop.pointcut.ast.ASTExecution;
40 import org.jboss.aop.pointcut.ast.ASTExecutionOnly;
41 import org.jboss.aop.pointcut.ast.ASTField;
42 import org.jboss.aop.pointcut.ast.ASTFieldExecution;
43 import org.jboss.aop.pointcut.ast.ASTGet;
44 import org.jboss.aop.pointcut.ast.ASTHas;
45 import org.jboss.aop.pointcut.ast.ASTHasField;
46 import org.jboss.aop.pointcut.ast.ASTMethod;
47 import org.jboss.aop.pointcut.ast.ASTNot;
48 import org.jboss.aop.pointcut.ast.ASTNotCFlow;
49 import org.jboss.aop.pointcut.ast.ASTOr;
50 import org.jboss.aop.pointcut.ast.ASTOrCFlow;
51 import org.jboss.aop.pointcut.ast.ASTParameter;
52 import org.jboss.aop.pointcut.ast.ASTPointcut;
53 import org.jboss.aop.pointcut.ast.ASTSet;
54 import org.jboss.aop.pointcut.ast.ASTStart;
55 import org.jboss.aop.pointcut.ast.ASTSub;
56 import org.jboss.aop.pointcut.ast.ASTSubCFlow;
57 import org.jboss.aop.pointcut.ast.ASTWithin;
58 import org.jboss.aop.pointcut.ast.ASTWithincode;
59 import org.jboss.aop.pointcut.ast.Node;
60 import org.jboss.aop.pointcut.ast.PointcutExpressionParserVisitor;
61 import org.jboss.aop.pointcut.ast.SimpleNode;
62 import org.jboss.aop.pointcut.ast.ASTConstruction;
63
64 /**
65  * Comment
66  *
67  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
68  * @version $Revision: 44925 $
69  */

70 public abstract class MatcherHelper implements PointcutExpressionParserVisitor
71 {
72    protected ASTStart start;
73    protected AspectManager manager;
74
75    protected MatcherHelper(ASTStart start, AspectManager manager)
76    {
77       this.start = start;
78       this.manager = manager;
79    }
80
81    public boolean matches()
82    {
83       boolean matches = ((Boolean JavaDoc) visit(start, null)).booleanValue();
84       return matches;
85    }
86
87    public Object JavaDoc visit(ASTStart node, Object JavaDoc data)
88    {
89       return node.jjtGetChild(0).jjtAccept(this, data);
90    }
91
92    public Object JavaDoc visit(ASTExecutionOnly node, Object JavaDoc data)
93    {
94       throw new RuntimeException JavaDoc("SHOULD NEVER BE CALLED!");
95    }
96
97    public Object JavaDoc visit(ASTBoolean node, Object JavaDoc data)
98    {
99       return node.jjtGetChild(0).jjtAccept(this, data);
100    }
101
102    public Object JavaDoc visit(ASTComposite node, Object JavaDoc data)
103    {
104       return node.jjtGetChild(0).jjtAccept(this, data);
105    }
106
107    public Object JavaDoc visit(ASTNot node, Object JavaDoc data)
108    {
109
110       Boolean JavaDoc bool = (Boolean JavaDoc) node.jjtGetChild(0).jjtAccept(this, data);
111       boolean val = bool.booleanValue();
112       return val ? Boolean.FALSE : Boolean.TRUE;
113    }
114
115    public Object JavaDoc visit(ASTSub node, Object JavaDoc data)
116    {
117       for (int i = 0; i < node.jjtGetNumChildren(); i++)
118       {
119          data = node.jjtGetChild(i).jjtAccept(this, data);
120       }
121       return data;
122    }
123
124    public Object JavaDoc visit(ASTAnd node, Object JavaDoc left)
125    {
126       Node andChild = node.jjtGetChild(0); // should only have one child
127
boolean val = ((Boolean JavaDoc) left).booleanValue();
128       return new Boolean JavaDoc(val && ((Boolean JavaDoc) andChild.jjtAccept(this, Boolean.FALSE)).booleanValue());
129    }
130
131    public Object JavaDoc visit(ASTOr node, Object JavaDoc left)
132    {
133       Node orChild = node.jjtGetChild(0); // should only have one child
134
boolean val = ((Boolean JavaDoc) left).booleanValue();
135       return new Boolean JavaDoc(val || ((Boolean JavaDoc) orChild.jjtAccept(this, Boolean.FALSE)).booleanValue());
136    }
137
138    protected abstract Boolean JavaDoc resolvePointcut(Pointcut p);
139
140    public Object JavaDoc visit(ASTPointcut node, Object JavaDoc data)
141    {
142       Pointcut p = manager.getPointcut(node.getPointcutName());
143       if (p == null) throw new RuntimeException JavaDoc("Unable to resolve pointcut reference: " + node.getPointcutName());
144       return resolvePointcut(p);
145    }
146
147    //--- return false by default
148
public Object JavaDoc visit(SimpleNode node, Object JavaDoc data)
149    {
150       return Boolean.FALSE;
151    }
152
153    public Object JavaDoc visit(ASTAll node, Object JavaDoc data)
154    {
155       return Boolean.FALSE;
156    }
157
158    public Object JavaDoc visit(ASTCFlowExpression node, Object JavaDoc data)
159    {
160       return Boolean.FALSE;
161    }
162
163    public Object JavaDoc visit(ASTCFlowBoolean node, Object JavaDoc data)
164    {
165       return Boolean.FALSE;
166    }
167
168    public Object JavaDoc visit(ASTNotCFlow node, Object JavaDoc data)
169    {
170       return Boolean.FALSE;
171    }
172
173    public Object JavaDoc visit(ASTCompositeCFlow node, Object JavaDoc data)
174    {
175       return Boolean.FALSE;
176    }
177
178    public Object JavaDoc visit(ASTSubCFlow node, Object JavaDoc data)
179    {
180       return Boolean.FALSE;
181    }
182
183    public Object JavaDoc visit(ASTAndCFlow node, Object JavaDoc data)
184    {
185       return Boolean.FALSE;
186    }
187
188    public Object JavaDoc visit(ASTOrCFlow node, Object JavaDoc data)
189    {
190       return Boolean.FALSE;
191    }
192
193    public Object JavaDoc visit(ASTCFlow node, Object JavaDoc data)
194    {
195       return Boolean.FALSE;
196    }
197
198    public Object JavaDoc visit(ASTCall node, Object JavaDoc data)
199    {
200       return Boolean.FALSE;
201    }
202
203    public Object JavaDoc visit(ASTWithin node, Object JavaDoc data)
204    {
205       return Boolean.FALSE;
206    }
207
208    public Object JavaDoc visit(ASTWithincode node, Object JavaDoc data)
209    {
210       return Boolean.FALSE;
211    }
212
213    public Object JavaDoc visit(ASTExecution node, Object JavaDoc data)
214    {
215       return Boolean.FALSE;
216    }
217
218    public Object JavaDoc visit(ASTConstruction node, Object JavaDoc data)
219    {
220       return Boolean.FALSE;
221    }
222
223    public Object JavaDoc visit(ASTGet node, Object JavaDoc data)
224    {
225       return Boolean.FALSE;
226    }
227
228    public Object JavaDoc visit(ASTSet node, Object JavaDoc data)
229    {
230       return Boolean.FALSE;
231    }
232
233    public Object JavaDoc visit(ASTMethod node, Object JavaDoc data)
234    {
235       return Boolean.FALSE;
236    }
237
238    public Object JavaDoc visit(ASTAttribute node, Object JavaDoc data)
239    {
240       return Boolean.FALSE;
241    }
242
243    public Object JavaDoc visit(ASTConstructor node, Object JavaDoc data)
244    {
245       return Boolean.FALSE;
246    }
247
248    public Object JavaDoc visit(ASTParameter node, Object JavaDoc data)
249    {
250       return Boolean.FALSE;
251    }
252
253    public Object JavaDoc visit(ASTAllParameter node, Object JavaDoc data)
254    {
255       return Boolean.FALSE;
256    }
257
258    public Object JavaDoc visit(ASTField node, Object JavaDoc data)
259    {
260       return Boolean.FALSE;
261    }
262
263    public Object JavaDoc visit(ASTException node, Object JavaDoc data)
264    {
265       return Boolean.FALSE;
266    }
267
268    public Object JavaDoc visit(ASTFieldExecution node, Object JavaDoc data)
269    {
270       return Boolean.FALSE;
271    }
272
273    public Object JavaDoc visit(ASTHas node, Object JavaDoc data)
274    {
275       return Boolean.FALSE;
276    }
277
278    public Object JavaDoc visit(ASTHasField node, Object JavaDoc data)
279    {
280       return Boolean.FALSE;
281    }
282
283
284 }
285
Popular Tags