KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
24 import ch.ethz.jvmai.JoinPoint;
25 import java.lang.Object JavaDoc;
26 import java.lang.reflect.InvocationTargetException JavaDoc;
27 ///////////////////////////////////////////////////////////////////////////////////////////
28
/// ADVICE EXECUTION
29
///////////////////////////////////////////////////////////////////////////////////////////
30

31     /** The <code>McutAdvice</code> encapsulates the transformation of the join-point
32      * data (e.g., target, stack parameters) to the types required to execute
33      * the <code>UserDefinedMCSignature</code> of this crosscut. The <code>execute</code>
34      * method does this job.
35      * <p>
36      * An <code>McutAdvice</code> object contains all the data needed
37      * for the advice method <em>invocation</em>:
38      * <ol>
39      * <li> An array of objects containing the arguments of the method
40      * being currently invoked (<code>stackArgs</code>). The <code>this</code>
41      * object (if existent, that is, if the invoked method is not static)
42      * is the first argument.
43      * <li> the number of valid arguments
44      * <li> the <code>UserDefinedMCSignature</code> object describing the static
45      * information about the advice action to be invoked.
46      * <ol>
47      * <p>
48      * Because of performance reasons, thi class expose a part of the
49      * inner structure of this class. In addition to the protected
50      * <code>stackArgs</code>,<code>stackArgsLength</code>, and <code>advice</code>,
51      * for which no setters/getters are provided, the construtor invokes
52      * the <code>allocStackArgs</code> template method to allocate
53      * the space for the <code>stackArgs</code> array. This way,
54      * subclasses have the chance to override this method and create
55      * an array in which the number of arguments (<code>stackArgsLength</code>)
56      * is equal to the actual length of the argument array. Having an
57      * array with no trailing nulls will make <code>execute</code>'s task
58      * more efficient (because execute will avoid array copying).
59      */

60   abstract class McutAdvice implements Serializable JavaDoc
61   {
62     private final MethodCut methodCut;
63     private static final int UNKNOWN = -1;
64
65     transient protected Object JavaDoc[] stackArgs = null;
66     transient protected int stackArgsLength = UNKNOWN;
67     transient protected MethodCutSignaturePattern advice;
68
69     protected McutAdvice(MethodCut methodCut, JoinPoint joinPoint, MethodCutSignaturePattern advice)
70       {
71     this.advice = advice;
72     Object JavaDoc[] args = joinPoint.getArgs();
73     allocStackArgs(args.length + 1);
74
75     stackArgs[0] = joinPoint.getThis();
76     for (int i=0; i<args.length; i++)
77         stackArgs[i+1]=args[i];
78     this.methodCut = methodCut;
79
80       }
81
82     // 2. Alllocate local params array
83
protected void allocStackArgs(int expectedLength)
84      {
85        stackArgsLength = expectedLength;
86        stackArgs= new Object JavaDoc[stackArgsLength];
87      }
88
89     abstract protected void execute() throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc;
90   }
91
Popular Tags