KickJava   Java API By Example, From Geeks To Geeks.

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


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: ExecutionsAclFilter.java,v 1.2 2004/05/12 09:41:55 anicoara 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 java.lang.reflect.Modifier JavaDoc;
33
34 import ch.ethz.jvmai.JoinPointKinds;
35 import ch.ethz.jvmai.JoinPoint;
36 import ch.ethz.jvmai.CodeJoinPoint;
37 import ch.ethz.prose.engine.JoinPointRequest;
38 import ch.ethz.prose.engine.MethodEntryRequest;
39 import ch.ethz.prose.engine.MethodExitRequest;
40 import ch.ethz.prose.engine.MethodRedefineRequest;
41
42 /**
43  * Class ExecutionsAclFilter XXX
44  *
45  * @version $Revision: 1.2 $
46  * @author Andrei Popovici
47  */

48 public
49 class ExecutionsAclFilter extends PointCutter implements JoinPointKinds
50 {
51   private boolean opMode;
52   private int theModifier;
53   public static boolean FILTER_METHOD_MODIFIERS = true;
54   public static boolean FILTER_CLASS_MODIFIERS = false;
55
56   public ExecutionsAclFilter(int modifier, boolean opMode)
57   {
58     this.theModifier = modifier;
59     this.opMode = opMode;
60     acceptMask = MASK_ALL_JP;
61     mayFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP | MASK_METHOD_REDEFINE_JP;
62     canFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP | MASK_METHOD_REDEFINE_JP;
63
64   }
65
66   protected boolean doIsSpecialRequest(JoinPointRequest jpr)
67   {
68       int modifiers = 0;
69       switch(jpr.getMask() & (MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP))
70       {
71         case MASK_METHOD_ENTRY_JP:
72           if (opMode == FILTER_METHOD_MODIFIERS)
73             modifiers = ((MethodEntryRequest)jpr).getMethod().getModifiers();
74           else
75             modifiers = ((MethodEntryRequest)jpr).getTargetClass().getModifiers();
76           break;
77         case MASK_METHOD_EXIT_JP:
78           if (opMode == FILTER_METHOD_MODIFIERS)
79             modifiers = ((MethodExitRequest)jpr).getMethod().getModifiers();
80           else
81             modifiers = ((MethodExitRequest)jpr).getTargetClass().getModifiers();
82           break;
83             case MASK_METHOD_REDEFINE_JP:
84               if (opMode == FILTER_METHOD_MODIFIERS)
85                 modifiers = ((MethodRedefineRequest)jpr).getMethod().getModifiers();
86               else
87                 modifiers = ((MethodRedefineRequest)jpr).getTargetClass().getModifiers();
88               break;
89         default:
90           throw new Error JavaDoc("Illegal join point request allowed by the PointCutter");
91       }
92
93       return (modifiers & theModifier) == theModifier;
94     }
95
96   protected boolean doIsSpecialEvent(CodeJoinPoint jp)
97   {
98      int modifiers;
99      if (opMode == FILTER_METHOD_MODIFIERS)
100        modifiers = jp.getMethod().getModifiers();
101      else
102        modifiers = jp.getMethod().getDeclaringClass().getModifiers();
103
104      return (modifiers & theModifier) == theModifier;
105   }
106
107   public String JavaDoc toString()
108   {
109      String JavaDoc result = "";
110      if (opMode = FILTER_METHOD_MODIFIERS)
111        result += "Within.methods(";
112      else
113        result += "Within.type(";
114     
115      switch (theModifier)
116      {
117          case Modifier.FINAL: result+= "final"; break;
118          case Modifier.PRIVATE: result+= "private";break;
119          case Modifier.PROTECTED: result+= "protected"; break;
120          case Modifier.PUBLIC: result+= "public"; break;
121          case Modifier.STATIC: result+= "static"; break;
122          case Modifier.SYNCHRONIZED: result+= "synchronized"; break;
123          case Modifier.TRANSIENT: result+= "transient"; break;
124      }
125      result += ")";
126      return result;
127   }
128 }
129
130
131 //======================================================================
132
//
133
// $Log: ExecutionsAclFilter.java,v $
134
// Revision 1.2 2004/05/12 09:41:55 anicoara
135
// Remove the README.RVM file
136
//
137
// Revision 1.1.1.1 2003/07/02 15:30:52 apopovic
138
// Imported from ETH Zurich
139
//
140
// Revision 1.3 2003/05/25 11:46:47 popovici
141
// Improved 'toString' presentation of aspects
142
//
143
// Revision 1.2 2003/05/06 15:51:36 popovici
144
// Mozilla-ification
145
//
146
// Revision 1.1 2003/05/05 13:58:06 popovici
147
// renaming from runes to prose
148
//
149
// Revision 1.3 2003/04/27 13:08:42 popovici
150
// Specializers renamed to PointCutter
151
//
152
// Revision 1.2 2003/04/17 12:49:33 popovici
153
// Refactoring of the crosscut package
154
// ExceptionCut renamed to ThrowCut
155
// McutSignature is now SignaturePattern
156
//
157
// Revision 1.1 2003/04/17 08:47:41 popovici
158
// Important functionality additions
159
// - Cflow specializers
160
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
161
// - Transactional capabilities
162
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
163
// between static and dynamic specializers.
164
// - Functionality pulled up in abstract classes
165
// - Uniformization of advice methods patterns and names
166
//
167
Popular Tags