KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > instrument > JoinpointFullClassifier


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.instrument;
23
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import javassist.CtMember;
28 import javassist.NotFoundException;
29
30 import org.jboss.aop.Advisor;
31 import org.jboss.aop.pointcut.Pointcut;
32 import org.jboss.aop.pointcut.PointcutInfo;
33
34 /**
35  * This class fully classifies joinpoints as <code>JoinpointClassification.PREPARED</code>
36  * as <code>JoinpointClasification.WRAPPED</code> and as <code>
37  * JoinpointClassification.DYNAMICALY_WRAPPED</code> according
38  * to the pointcuts registered in <code>AspectManager</code>.
39  * @see JoinpointClassifier
40  * @see JoinpointClassification
41  * @author Flavia Rainone
42  */

43 public class JoinpointFullClassifier extends JoinpointClassifier
44 {
45    /**
46     * Classifies the execution of a joinpoint. The joinpoint being classified
47     * is identified by <code>matcher</code>.
48     * If the joinpoint is matched only with pointcuts not associated with bindings, then
49     * the joinpoint is classified as <code>JoinpointClassification.PREPARED</code>. If it
50     * is matched with one or more binding associated pointcuts, then it is classified
51     * as <code>JoinpointClassification.WRAPPED</code>. If it is matched by only dynamicaly
52     * added binding pointcuts, it is classified as <code>
53     * JoinpointClassification.DYNAMICALY_WRAPPED</code>. On the other
54     * hand, if it is not matched by any pointcut at all, the joinpoint is classified as
55     * <code>NOT_INSTRUMENTED</code>.
56     * @see org.jboss.aop.instrument.JoinpointClassifier#classifyJoinpoint(javassist.CtMember, org.jboss.aop.Advisor, org.jboss.aop.instrument.JoinpointClassifier.Matcher)
57     */

58    protected JoinpointClassification classifyJoinpoint(CtMember member, Advisor advisor, Matcher joinpointMatcher) throws NotFoundException
59    {
60       JoinpointClassification classification = JoinpointClassification.NOT_INSTRUMENTED;
61       Collection JavaDoc pointcuts = advisor.getManager().getPointcutInfos().values();
62       boolean dynamicAop = true;
63       for (Iterator JavaDoc it = pointcuts.iterator(); it.hasNext(); )
64       {
65          PointcutInfo pointcutInfo = (PointcutInfo) it.next();
66          // won't check matching of preparation pointcuts unnecessarily
67
if (classification == JoinpointClassification.PREPARED && pointcutInfo.getBinding() == null)
68          {
69             continue;
70          }
71          Pointcut pointcut = pointcutInfo.getPointcut();
72          if (joinpointMatcher.matches(pointcut, advisor, member)) {
73             // only prepare if pointcut isn't associated with a binding
74
if (pointcutInfo.getBinding() == null)
75             {
76                classification = JoinpointClassification.PREPARED;
77             }
78             else if (pointcutInfo.isDynamicAop())
79             {
80                classification = JoinpointClassification.DYNAMICALY_WRAPPED;
81             }
82             else
83             {
84                classification = JoinpointClassification.WRAPPED;
85                // break. We can't get any better than this classification
86
break;
87             }
88          }
89       }
90       return classification;
91    }
92 }
Popular Tags