01: //
02: // This file is part of the prose package.
03: //
04: // The contents of this file are subject to the Mozilla Public License
05: // Version 1.1 (the "License"); you may not use this file except in
06: // compliance with the License. You may obtain a copy of the License at
07: // http://www.mozilla.org/MPL/
08: //
09: // 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: package ch.ethz.prose.crosscut;
22:
23: import java.lang.IllegalAccessException;
24: import ch.ethz.jvmai.JoinPoint;
25: import java.lang.Object;
26: import java.lang.reflect.InvocationTargetException;
27:
28: /** An advice execution for an advice action of the form
29: * <code>XXX(ANY thisObj,String a, int b, <em>other non-wildcards..</em>)</code>
30: * <p>
31: * This method redefines the <code>allocStackArgs</code> because it
32: * knows that the number of arguments on the stack is exactly
33: * equal to the number of arguments of the advice method.
34: */
35: class WildcardConcreteMcutAdvice extends McutAdvice {
36: private static final long serialVersionUID = 3545516222696600882L;
37: private final MethodCut methodCut;
38:
39: protected void allocStackArgs(int expectedLength) {
40: stackArgsLength = advice.getLength();
41: stackArgs = new Object[stackArgsLength];
42: }
43:
44: WildcardConcreteMcutAdvice(MethodCut methodCut, JoinPoint m,
45: MethodCutSignaturePattern a) {
46: super (methodCut, m, a);
47: this .methodCut = methodCut;
48: }
49:
50: /** Invoke (reflection) the method of the advice object.
51: * Because of the special signature of the advice, one can
52: * pass the stack arguments to
53: * <code>Method.invoke</code>. the only modification of
54: * the actual stack arguments is to wrap the target into
55: * an <code>ANY</code> object.
56: *
57: */
58: protected void execute() throws IllegalAccessException,
59: InvocationTargetException {
60: ANY adviceThis = new ANY();
61: adviceThis.setObject(stackArgs[0]);
62: stackArgs[0] = adviceThis;
63: advice.methodObj.invoke(methodCut, stackArgs);
64: }
65: }
|