KickJava   Java API By Example, From Geeks To Geeks.

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


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: 37406 $
69  */

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

289
290    public Object JavaDoc visit(SimpleNode node, Object JavaDoc data)
291    {
292       return Boolean.FALSE;
293    }
294
295    public Object JavaDoc visit(ASTCFlowBoolean node, Object JavaDoc data)
296    {
297       return Boolean.FALSE;
298    }
299
300    public Object JavaDoc visit(ASTNotCFlow node, Object JavaDoc data)
301    {
302       return Boolean.FALSE;
303    }
304
305    public Object JavaDoc visit(ASTCompositeCFlow node, Object JavaDoc data)
306    {
307       return Boolean.FALSE;
308    }
309
310    public Object JavaDoc visit(ASTSubCFlow node, Object JavaDoc data)
311    {
312       return Boolean.FALSE;
313    }
314
315    public Object JavaDoc visit(ASTAndCFlow node, Object JavaDoc data)
316    {
317       return Boolean.FALSE;
318    }
319
320    public Object JavaDoc visit(ASTOrCFlow node, Object JavaDoc data)
321    {
322       return Boolean.FALSE;
323    }
324
325    public Object JavaDoc visit(ASTCFlow node, Object JavaDoc data)
326    {
327       return Boolean.FALSE;
328    }
329
330    public Object JavaDoc visit(ASTMethod node, Object JavaDoc data)
331    {
332       return Boolean.FALSE;
333    }
334
335    public Object JavaDoc visit(ASTAttribute node, Object JavaDoc data)
336    {
337       return Boolean.FALSE;
338    }
339
340    public Object JavaDoc visit(ASTConstructor node, Object JavaDoc data)
341    {
342       return Boolean.FALSE;
343    }
344
345    public Object JavaDoc visit(ASTParameter node, Object JavaDoc data)
346    {
347       return Boolean.FALSE;
348    }
349
350    public Object JavaDoc visit(ASTAllParameter node, Object JavaDoc data)
351    {
352       return Boolean.FALSE;
353    }
354
355    public Object JavaDoc visit(ASTField node, Object JavaDoc data)
356    {
357       return Boolean.FALSE;
358    }
359
360    public Object JavaDoc visit(ASTException node, Object JavaDoc data)
361    {
362       return Boolean.FALSE;
363    }
364
365    public Object JavaDoc visit(ASTHas node, Object JavaDoc data)
366    {
367       return Boolean.FALSE;
368    }
369
370    public Object JavaDoc visit(ASTHasField node, Object JavaDoc data)
371    {
372       return Boolean.FALSE;
373    }
374
375
376 }
377
Popular Tags