001: //
002: // This file is part of the prose package.
003: //
004: // The contents of this file are subject to the Mozilla Public License
005: // Version 1.1 (the "License"); you may not use this file except in
006: // compliance with the License. You may obtain a copy of the License at
007: // http://www.mozilla.org/MPL/
008: //
009: // Software distributed under the License is distributed on an "AS IS" basis,
010: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: // for the specific language governing rights and limitations under the
012: // License.
013: //
014: // The Original Code is prose.
015: //
016: // The Initial Developer of the Original Code is Andrei Popovici. Portions
017: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: // $Id: MethodCutSpecializer.java,v 1.1.1.1 2003/07/02 15:30:51 apopovic Exp $
022: // =====================================================================
023: //
024: // (history at end)
025: //
026:
027: package ch.ethz.prose.crosscut;
028:
029: // used packages
030: import java.lang.reflect.Modifier;
031: import java.lang.reflect.Method;
032: import ch.ethz.prose.engine.JoinPointRequest;
033: import ch.ethz.prose.engine.MethodExitRequest;
034: import ch.ethz.prose.engine.MethodEntryRequest;
035: import ch.ethz.prose.filter.PointCutter;
036: import ch.ethz.jvmai.JoinPointKinds;
037: import ch.ethz.jvmai.CodeJoinPoint;
038:
039: /**
040: * Class MethodCutSpecializer XXX
041: *
042: * @version $Revision: 1.1.1.1 $
043: * @author Andrei Popovici
044: */
045: public class MethodCutSpecializer extends PointCutter implements
046: JoinPointKinds {
047:
048: private static final long serialVersionUID = 3256728394065654069L;
049: MethodCutSignaturePattern adviceSignature;
050:
051: public MethodCutSpecializer(
052: MethodCutSignaturePattern adviceSignature) {
053: this .adviceSignature = adviceSignature;
054: acceptMask = MASK_ALL_JP;
055: mayFilterStaticallyMask = MASK_METHOD_ENTRY_JP
056: | MASK_METHOD_EXIT_JP;
057: canFilterStaticallyMask = MASK_METHOD_ENTRY_JP
058: | MASK_METHOD_EXIT_JP;
059: }
060:
061: protected boolean doIsSpecialRequest(JoinPointRequest jpr) {
062: Class targetClass = null;
063: Method methodToExecute = null;
064: int methodModifiers = 0;
065: if (jpr instanceof MethodEntryRequest) {
066: targetClass = ((MethodEntryRequest) jpr).getTargetClass();
067: methodToExecute = ((MethodEntryRequest) jpr).getMethod();
068: }
069: if (jpr instanceof MethodExitRequest) {
070: targetClass = ((MethodExitRequest) jpr).getTargetClass();
071: methodToExecute = ((MethodExitRequest) jpr).getMethod();
072: }
073:
074: methodModifiers = methodToExecute.getModifiers();
075:
076: return ((methodModifiers & Modifier.ABSTRACT) != Modifier.ABSTRACT)
077: && ((methodModifiers & Modifier.NATIVE) != Modifier.NATIVE)
078: && adviceSignature.matchesTarget(targetClass)
079: && adviceSignature.matchesParameters(methodToExecute);
080: }
081:
082: protected boolean doIsSpecialEvent(CodeJoinPoint jpe) {
083: Object target = jpe.getTarget();
084: if (target != null)
085: return adviceSignature.matchesTarget(target.getClass())
086: && adviceSignature.matchesParameters(jpe
087: .getMethod());
088: else
089: return adviceSignature.matchesTarget(jpe.getMethod()
090: .getDeclaringClass())
091: && adviceSignature.matchesParameters(jpe
092: .getMethod());
093: }
094:
095: //
096: }
097:
098: //======================================================================
099: //
100: // $Log: MethodCutSpecializer.java,v $
101: // Revision 1.1.1.1 2003/07/02 15:30:51 apopovic
102: // Imported from ETH Zurich
103: //
104: // Revision 1.2 2003/05/06 15:51:30 popovici
105: // Mozilla-ification
106: //
107: // Revision 1.1 2003/05/05 13:58:17 popovici
108: // renaming from runes to prose
109: //
110: // Revision 1.3 2003/04/27 13:08:57 popovici
111: // Specializers renamed to PointCutter
112: //
113: // Revision 1.2 2003/04/17 12:49:22 popovici
114: // Refactoring of the crosscut package
115: // ExceptionCut renamed to ThrowCut
116: // McutSignature is now SignaturePattern
117: //
118: // Revision 1.1 2003/04/17 08:47:21 popovici
119: // Important functionality additions
120: // - Cflow specializers
121: // - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
122: // - Transactional capabilities
123: // - Total refactoring of Specializer evaluation, which permits fine-grained distinction
124: // between static and dynamic specializers.
125: // - Functionality pulled up in abstract classes
126: // - Uniformization of advice methods patterns and names
127: //
|