KickJava   Java API By Example, From Geeks To Geeks.

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


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
package ch.ethz.prose.crosscut;
22 import java.lang.IllegalAccessException JavaDoc;
23 import ch.ethz.jvmai.JoinPoint;
24 import java.lang.Object JavaDoc;
25 import java.lang.reflect.InvocationTargetException JavaDoc;
26 /** An advice execution for an advice action of the form
27     * <code>XXX(ANY thisObj,String a, int b, <em>other non-wildcards..</em>)</code>
28     * <p>
29     * This method redefines the <code>allocStackArgs</code> because it
30     * knows that the number of arguments on the stack is exactly
31     * equal to the number of arguments of the advice method.
32     */

33   class WildcardConcreteMcutAdvice extends McutAdvice
34   {
35     private final MethodCut methodCut;
36     protected void allocStackArgs(int expectedLength)
37       {
38     stackArgsLength = advice.getLength();
39     stackArgs= new Object JavaDoc[stackArgsLength];
40       }
41
42
43     WildcardConcreteMcutAdvice(MethodCut methodCut, JoinPoint m, MethodCutSignaturePattern a)
44       {
45     super(methodCut, m,a);
46     this.methodCut = methodCut;
47       }
48
49     /** Invoke (reflection) the method of the advice object.
50      * Because of the special signature of the advice, one can
51      * pass the stack arguments to
52      * <code>Method.invoke</code>. the only modification of
53      * the actual stack arguments is to wrap the target into
54      * an <code>ANY</code> object.
55      *
56      */

57     protected void execute() throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc
58       {
59     ANY adviceThis = new ANY();
60     adviceThis.setObject(stackArgs[0]);
61     stackArgs[0]=adviceThis;
62     advice.methodObj.invoke(methodCut,stackArgs);
63       }
64   }
65
Popular Tags