KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > crosscut > MethodCutSpecializer


1 //
2
// This file is part of the prose package.
3
//
4
// The contents of this file are subject to the Mozilla Public License
5
// Version 1.1 (the "License"); you may not use this file except in
6
// compliance with the License. You may obtain a copy of the License at
7
// http://www.mozilla.org/MPL/
8
//
9
// Software distributed under the License is distributed on an "AS IS" basis,
10
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
// for the specific language governing rights and limitations under the
12
// License.
13
//
14
// The Original Code is prose.
15
//
16
// The Initial Developer of the Original Code is Andrei Popovici. Portions
17
// created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18
// All Rights Reserved.
19
//
20
// Contributor(s):
21
// $Id: MethodCutSpecializer.java,v 1.1.1.1 2003/07/02 15:30:51 apopovic Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.prose.crosscut;
28
29 // used packages
30
import java.lang.reflect.Modifier JavaDoc;
31 import java.lang.reflect.Method JavaDoc;
32 import ch.ethz.prose.engine.JoinPointRequest;
33 import ch.ethz.prose.engine.MethodExitRequest;
34 import ch.ethz.prose.engine.MethodEntryRequest;
35 import ch.ethz.prose.filter.PointCutter;
36 import ch.ethz.jvmai.JoinPointKinds;
37 import ch.ethz.jvmai.CodeJoinPoint;
38
39 /**
40  * Class MethodCutSpecializer XXX
41  *
42  * @version $Revision: 1.1.1.1 $
43  * @author Andrei Popovici
44  */

45 public
46 class MethodCutSpecializer extends PointCutter implements JoinPointKinds {
47
48     MethodCutSignaturePattern adviceSignature;
49   public MethodCutSpecializer(MethodCutSignaturePattern adviceSignature)
50     {
51     this.adviceSignature=adviceSignature;
52     acceptMask = MASK_ALL_JP;
53     mayFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP;
54     canFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP;
55     }
56
57     protected boolean doIsSpecialRequest(JoinPointRequest jpr)
58     {
59     Class JavaDoc targetClass =null;
60     Method JavaDoc methodToExecute = null;
61     int methodModifiers = 0;
62     if (jpr instanceof MethodEntryRequest)
63         {
64         targetClass = ((MethodEntryRequest)jpr).getTargetClass();
65         methodToExecute=((MethodEntryRequest)jpr).getMethod();
66         }
67     if (jpr instanceof MethodExitRequest)
68         {
69         targetClass = ((MethodExitRequest)jpr).getTargetClass();
70         methodToExecute = ((MethodExitRequest)jpr).getMethod();
71         }
72
73     methodModifiers = methodToExecute.getModifiers();
74
75       return
76       ((methodModifiers & Modifier.ABSTRACT) != Modifier.ABSTRACT) &&
77       ((methodModifiers & Modifier.NATIVE ) != Modifier.NATIVE ) &&
78       adviceSignature.matchesTarget(targetClass) &&
79       adviceSignature.matchesParameters(methodToExecute);
80     }
81
82
83     protected boolean doIsSpecialEvent(CodeJoinPoint jpe)
84     {
85     Object JavaDoc target = jpe.getTarget();
86     if (target != null)
87         return adviceSignature.matchesTarget(target.getClass()) &&
88         adviceSignature.matchesParameters(jpe.getMethod());
89     else
90         return adviceSignature.matchesTarget(jpe.getMethod().getDeclaringClass()) &&
91         adviceSignature.matchesParameters(jpe.getMethod());
92     }
93
94
95     //
96
}
97
98
99 //======================================================================
100
//
101
// $Log: MethodCutSpecializer.java,v $
102
// Revision 1.1.1.1 2003/07/02 15:30:51 apopovic
103
// Imported from ETH Zurich
104
//
105
// Revision 1.2 2003/05/06 15:51:30 popovici
106
// Mozilla-ification
107
//
108
// Revision 1.1 2003/05/05 13:58:17 popovici
109
// renaming from runes to prose
110
//
111
// Revision 1.3 2003/04/27 13:08:57 popovici
112
// Specializers renamed to PointCutter
113
//
114
// Revision 1.2 2003/04/17 12:49:22 popovici
115
// Refactoring of the crosscut package
116
// ExceptionCut renamed to ThrowCut
117
// McutSignature is now SignaturePattern
118
//
119
// Revision 1.1 2003/04/17 08:47:21 popovici
120
// Important functionality additions
121
// - Cflow specializers
122
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
123
// - Transactional capabilities
124
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
125
// between static and dynamic specializers.
126
// - Functionality pulled up in abstract classes
127
// - Uniformization of advice methods patterns and names
128
//
129
Popular Tags