KickJava   Java API By Example, From Geeks To Geeks.

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


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.Advisor;
25 import org.jboss.aop.AspectManager;
26 import org.jboss.aop.ClassAdvisor;
27 import org.jboss.aop.pointcut.ast.ASTCall;
28 import org.jboss.aop.pointcut.ast.ASTConstructor;
29 import org.jboss.aop.pointcut.ast.ASTField;
30 import org.jboss.aop.pointcut.ast.ASTHas;
31 import org.jboss.aop.pointcut.ast.ASTHasField;
32 import org.jboss.aop.pointcut.ast.ASTMethod;
33 import org.jboss.aop.pointcut.ast.ASTStart;
34 import org.jboss.aop.pointcut.ast.ASTWithin;
35 import org.jboss.aop.pointcut.ast.ASTWithincode;
36 import org.jboss.aop.pointcut.ast.Node;
37
38 import java.lang.reflect.AccessibleObject JavaDoc;
39 import java.lang.reflect.Constructor JavaDoc;
40
41 /**
42  * Comment
43  *
44  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
45  * @version $Revision: 43990 $
46  */

47 public class ConstructorCallMatcher extends MatcherHelper
48 {
49    Advisor advisor;
50    AccessibleObject JavaDoc within;
51    Class JavaDoc calledClass;
52    Constructor calledConstructor;
53
54    public ConstructorCallMatcher(Advisor advisor, AccessibleObject JavaDoc within, Class JavaDoc calledClass, Constructor calledCon, ASTStart start)
55    {
56       super(start, advisor.getManager());
57       this.advisor = advisor;
58       this.within = within;
59       this.calledClass = calledClass;
60       this.calledConstructor = calledCon;
61    }
62
63    public Object JavaDoc visit(ASTCall node, Object JavaDoc data)
64    {
65       try
66       {
67          if (!(node.getBehavior() instanceof ASTConstructor)) return Boolean.FALSE;
68          ASTConstructor astCon = (ASTConstructor) node.getBehavior();
69          Advisor calledAdvisor = AspectManager.instance().getTempClassAdvisorIfNotExist(calledClass);
70          ConstructorMatcher constructorMatcher = new ConstructorMatcher(calledAdvisor, calledConstructor, null);
71          return constructorMatcher.matches(astCon);
72       }
73       catch (Exception JavaDoc e)
74       {
75          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
76
}
77    }
78
79    public Object JavaDoc visit(ASTHas node, Object JavaDoc data)
80    {
81       Node n = node.jjtGetChild(0);
82       if (n instanceof ASTMethod)
83       {
84          return new Boolean JavaDoc(Util.has(calledClass, (ASTMethod) n, advisor));
85       }
86       else
87       {
88          return new Boolean JavaDoc(Util.has(calledClass, (ASTConstructor) n, advisor));
89       }
90    }
91
92    public Object JavaDoc visit(ASTHasField node, Object JavaDoc data)
93    {
94       ASTField f = (ASTField) node.jjtGetChild(0);
95       return new Boolean JavaDoc(Util.has(calledClass, f, advisor));
96    }
97
98    public Object JavaDoc visit(ASTWithin node, Object JavaDoc data)
99    {
100       WithinMatcher visitor = new WithinMatcher(advisor, within, null);
101       return node.jjtAccept(visitor, null);
102    }
103
104    public Object JavaDoc visit(ASTWithincode node, Object JavaDoc data)
105    {
106       WithinMatcher visitor = new WithinMatcher(advisor, within, null);
107       return node.jjtAccept(visitor, null);
108    }
109
110    protected Boolean JavaDoc resolvePointcut(Pointcut p)
111    {
112       return new Boolean JavaDoc(p.matchesCall(advisor, within, calledClass, calledConstructor));
113    }
114
115 }
116
Popular Tags