KickJava   Java API By Example, From Geeks To Geeks.

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


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.AspectManager;
32 import org.jboss.aop.pointcut.Pointcut;
33
34 /**
35  * This joinpoint classifier is anaware of differences between <code>
36  * PREPARED</code> and <code>WRAPPED</code> classifications.
37  * It classifies a joinpoint either as something that must be instrumented
38  * or something that mustn't, without caring about preparation.
39  * Whenever a joinpoint must be instrumented, it is classified as <code>
40  * WRAPPED</code>; by the other hand, whenever
41  * it is should not be instrumented, it is classified as <code>NOT_INSTRUMENTED
42  * </code>
43  * @see JoinpointClassifier
44  * @see JoinpointClassification
45  * @author Flavia Rainone
46  */

47 public class JoinpointSimpleClassifier extends JoinpointClassifier
48 {
49
50    /**
51     * Classifies the execution of a joinpoint. The joinpoint being classified
52     * is identified by <code>matcher</code>.
53     * If the joinpoint is matched by one or more pointcuts, then
54     * it is classified as <code>JoinpointClassification.WRAPPED</code>. Otherwise,
55     * it is classified as <code>JoinpointClassification.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       Collection JavaDoc pointcuts = advisor.getManager().getPointcuts().values();
61       for (Iterator JavaDoc it = pointcuts.iterator(); it.hasNext(); )
62       {
63          Pointcut pointcut = (Pointcut) it.next();
64
65          if (joinpointMatcher.matches(pointcut, advisor, member))
66          {
67             if (AspectManager.verbose)
68             {
69                System.out.println("[debug] " + member + " matches pointcut: " + pointcut.getExpr());
70             }
71             return JoinpointClassification.WRAPPED;
72          }
73       }
74       if (AspectManager.verbose)
75       {
76          System.out.println("[debug] " + member + " matches no pointcuts");
77       }
78       return JoinpointClassification.NOT_INSTRUMENTED;
79    }
80 }
Popular Tags