KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > filter > ExecutionsInSubclassFilter


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: ExecutionsInSubclassFilter.java,v 1.1.1.1 2003/07/02 15:30:52 apopovic Exp $
22
// =====================================================================
23
//
24
// (history at end)
25
//
26

27 package ch.ethz.prose.filter;
28
29 // used packages
30
import java.util.*;
31 import java.io.*;
32 import ch.ethz.jvmai.JoinPoint;
33 import ch.ethz.jvmai.ClassSpecific;
34 import ch.ethz.jvmai.CodeJoinPoint;
35 import ch.ethz.jvmai.JoinPointKinds;
36 import ch.ethz.prose.engine.JoinPointRequest;
37
38 /**
39  * Class ExecutionsInSubclassFilter XXX
40  *
41  * @version $Revision: 1.1.1.1 $
42  * @author Andrei Popovici
43  */

44 public
45 class ExecutionsInSubclassFilter extends PointCutter implements JoinPointKinds {
46
47   final public static int SUBCLASS_INHERITANCE = 1;
48   final public static int SUPERCLASS_INHERITANCE = 2;
49   final public static int NO_INHERITANCE =3;
50   
51   private int inheritanceType;
52   private Class JavaDoc subOrSuperClass;
53
54   public ExecutionsInSubclassFilter(Class JavaDoc cls, int inhType)
55     {
56       if (cls == null)
57     throw new IllegalArgumentException JavaDoc("null argument illegal");
58
59       subOrSuperClass = cls;
60       acceptMask = MASK_ALL_JP;
61       mayFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP;
62       canFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP;
63       this.inheritanceType = inhType;
64     }
65
66    /** This method is executed if and only if the 'mayFilterStatically'
67     * and the current request match. That is, JUST for
68     * method entries and exits.
69     *
70     */

71   protected boolean doIsSpecialRequest(JoinPointRequest jpr)
72     {
73       try
74     {
75       Class JavaDoc classDeclaringTheMentryExit = ((ClassSpecific)jpr).getTargetClass();
76       if (inheritanceType == SUBCLASS_INHERITANCE)
77         // (cls)X : = (executionClass)Y; Y class is a subclass of X
78
return subOrSuperClass.isAssignableFrom(classDeclaringTheMentryExit);
79       
80       if (inheritanceType == SUPERCLASS_INHERITANCE)
81         // (executionClass)X := (cls)Y; X is a superclass of the passed parameter
82
return classDeclaringTheMentryExit.isAssignableFrom(subOrSuperClass);
83         
84         if (inheritanceType == NO_INHERITANCE)
85              return classDeclaringTheMentryExit.equals(subOrSuperClass);
86              else
87              throw new Error JavaDoc("_doIsSpecialReques was supplied with an illegal state");
88     }
89       catch (ClassCastException JavaDoc jprWasNotClassSpecific)
90     {
91       throw new Error JavaDoc("request was allowed in spite of mayFilterStaticallyMask");
92     }
93     }
94
95   /** The abstract crosscut mechanism ensures that this method
96    * is called only for NON-METHOD-ENTRY and NON-METHOD-EXIT events.
97    *
98    */

99   protected boolean doIsSpecialEvent(CodeJoinPoint jp)
100     {
101       Class JavaDoc classDeclaringExecutedCode = jp.getMethod().getDeclaringClass();
102       if (inheritanceType == SUBCLASS_INHERITANCE)
103     // (cls)X : = (executionClass)Y; Y class is a subclass of X
104
return subOrSuperClass.isAssignableFrom(classDeclaringExecutedCode);
105       else
106     // (executionClass)X := (cls)Y; X is a superclass of the passed parameter
107
return classDeclaringExecutedCode.isAssignableFrom(subOrSuperClass);
108     }
109
110 }
111
112
113 //======================================================================
114
//
115
// $Log: ExecutionsInSubclassFilter.java,v $
116
// Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
117
// Imported from ETH Zurich
118
//
119
// Revision 1.2 2003/05/06 15:51:38 popovici
120
// Mozilla-ification
121
//
122
// Revision 1.1 2003/05/05 13:58:01 popovici
123
// renaming from runes to prose
124
//
125
// Revision 1.4 2003/04/27 13:08:47 popovici
126
// Specializers renamed to PointCutter
127
//
128
// Revision 1.3 2003/04/25 15:41:57 popovici
129
// Added the 'equalsTo' type filter in within
130
//
131
// Revision 1.2 2003/04/17 12:49:32 popovici
132
// Refactoring of the crosscut package
133
// ExceptionCut renamed to ThrowCut
134
// McutSignature is now SignaturePattern
135
//
136
// Revision 1.1 2003/04/17 08:47:43 popovici
137
// Important functionality additions
138
// - Cflow specializers
139
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
140
// - Transactional capabilities
141
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
142
// between static and dynamic specializers.
143
// - Functionality pulled up in abstract classes
144
// - Uniformization of advice methods patterns and names
145
//
146
Popular Tags