KickJava   Java API By Example, From Geeks To Geeks.

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


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.CtBehavior;
25 import javassist.CtConstructor;
26 import javassist.CtMethod;
27 import javassist.NotFoundException;
28 import org.jboss.aop.Advisor;
29 import org.jboss.aop.pointcut.ast.ASTConstructor;
30 import org.jboss.aop.pointcut.ast.ASTMethod;
31 import org.jboss.aop.pointcut.ast.ASTStart;
32 import org.jboss.aop.pointcut.ast.ASTWithin;
33 import org.jboss.aop.pointcut.ast.ASTWithincode;
34
35 import java.lang.reflect.AccessibleObject JavaDoc;
36 import java.lang.reflect.Constructor JavaDoc;
37 import java.lang.reflect.Method JavaDoc;
38
39 /**
40  * Comment
41  *
42  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
43  * @version $Revision: 37406 $
44  */

45 public class WithinMatcher extends MatcherHelper
46 {
47    CtBehavior behavior;
48    Advisor advisor;
49    AccessibleObject JavaDoc accessible;
50
51    public WithinMatcher(Advisor advisor, CtBehavior behavior, ASTStart start) throws NotFoundException
52    {
53       super(start, advisor.getManager());
54       this.advisor = advisor;
55       this.behavior = behavior;
56    }
57
58    public WithinMatcher(Advisor advisor, AccessibleObject JavaDoc behavior, ASTStart start)
59    {
60       super(start, advisor.getManager());
61       this.advisor = advisor;
62       this.accessible = behavior;
63    }
64
65    protected Boolean JavaDoc resolvePointcut(Pointcut p)
66    {
67       throw new RuntimeException JavaDoc("NOT REACHABLE");
68    }
69
70    public Class JavaDoc getDeclaringClass()
71    {
72       if (accessible instanceof Constructor)
73          return ((Constructor) accessible).getDeclaringClass();
74       else if (accessible instanceof Method) return ((Method) accessible).getDeclaringClass();
75       return null;
76    }
77
78    public Object JavaDoc visit(ASTWithin node, Object JavaDoc data)
79    {
80       if (behavior != null)
81       {
82          if (!Util.matchesClassExpr(node.getClazz(), behavior.getDeclaringClass(), advisor)) return Boolean.FALSE;
83       }
84       else
85       {
86          if (!Util.matchesClassExpr(node.getClazz(), getDeclaringClass(), advisor)) return Boolean.FALSE;
87       }
88       return Boolean.TRUE;
89    }
90
91    public Object JavaDoc visit(ASTWithincode node, Object JavaDoc data)
92    {
93       return node.jjtGetChild(0).jjtAccept(this, null);
94    }
95
96    public Object JavaDoc visit(ASTMethod node, Object JavaDoc data)
97    {
98       if (behavior != null)
99       {
100          if (behavior instanceof CtConstructor) return Boolean.FALSE;
101          MethodMatcher matcher = new MethodMatcher(advisor, (CtMethod) behavior, null);
102          return matcher.matches(node);
103       }
104       if (accessible instanceof Constructor) return Boolean.FALSE;
105       MethodMatcher matcher = new MethodMatcher(advisor, (Method) accessible, null);
106       return matcher.matches(node);
107
108    }
109
110    public Object JavaDoc visit(ASTConstructor node, Object JavaDoc data)
111    {
112       if (behavior != null)
113       {
114          try
115          {
116             if (behavior instanceof CtMethod) return Boolean.FALSE;
117             ConstructorMatcher matcher = new ConstructorMatcher(advisor, (CtConstructor) behavior, null);
118             return matcher.matches(node);
119          }
120          catch (NotFoundException e)
121          {
122             throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
123
}
124       }
125       if (accessible instanceof Method) return Boolean.FALSE;
126       ConstructorMatcher matcher = new ConstructorMatcher(advisor, (Constructor) accessible, null);
127       return matcher.matches(node);
128
129    }
130
131 }
132
Popular Tags