org.apache.aries.proxy.impl.common
Class AbstractWovenProxyMethodAdapter

java.lang.Object
  extended by org.objectweb.asm.MethodAdapter
      extended by org.objectweb.asm.commons.LocalVariablesSorter
          extended by org.objectweb.asm.commons.GeneratorAdapter
              extended by org.apache.aries.proxy.impl.common.AbstractWovenProxyMethodAdapter
All Implemented Interfaces:
org.objectweb.asm.MethodVisitor

public abstract class AbstractWovenProxyMethodAdapter
extends org.objectweb.asm.commons.GeneratorAdapter

This class weaves dispatch and listener code into a method, there are two known subclasses WovenProxyMethodAdapter is used for weaving instance methods InterfaceUsingWovenProxyMethodAdapter is used to provide a delegating implementation of an interface method. Roughly (but not exactly because it's easier to write working bytecode if you don't have to exactly recreate the Java!) this is trying to do the following: if(dispatcher != null) { int returnValue; Object token = null; boolean inInvoke = false; try { Object toInvoke = dispatcher.call(); if(listener != null) token = listener.preInvoke(toInvoke, method, args); inInvoke = true; returnValue = ((Template) toInvoke).doStuff(args); inInvoke = false; if(listener != null) listener.postInvoke(token, toInvoke, method, args); } catch (Throwable e){ // whether the the exception is an error is an application decision // if we catch an exception we decide carefully which one to // throw onwards Throwable exceptionToRethrow = null; // if the exception came from a precall or postcall // we will rethrow it if (!inInvoke) { exceptionToRethrow = e; } // if the exception didn't come from precall or postcall then it // came from invoke // we will rethrow this exception if it is not a runtime // exception, but we must unwrap InvocationTargetExceptions else { if (!(e instanceof RuntimeException)) { exceptionToRethrow = e; } } try { if(listener != null) listener.postInvokeExceptionalReturn(token, method, null, e); } catch (Throwable f) { // we caught an exception from // postInvokeExceptionalReturn // if we haven't already chosen an exception to rethrow then // we will throw this exception if (exceptionToRethrow == null) { exceptionToRethrow = f; } } // if we made it this far without choosing an exception we // should throw e if (exceptionToRethrow == null) { exceptionToRethrow = e; } throw exceptionToRethrow; } } //...original method body


Field Summary
protected  org.objectweb.asm.commons.Method currentTransformMethod
          The current method
protected  org.objectweb.asm.Type typeBeingWoven
          The type of this
 
Fields inherited from class org.objectweb.asm.commons.GeneratorAdapter
ADD, AND, DIV, EQ, GE, GT, LE, LT, MUL, NE, NEG, OR, REM, SHL, SHR, SUB, USHR, XOR
 
Fields inherited from class org.objectweb.asm.commons.LocalVariablesSorter
firstLocal, nextLocal
 
Fields inherited from class org.objectweb.asm.MethodAdapter
mv
 
Constructor Summary
AbstractWovenProxyMethodAdapter(org.objectweb.asm.MethodVisitor mv, int access, String name, String desc, String methodStaticFieldName, org.objectweb.asm.commons.Method currentTransformMethod, org.objectweb.asm.Type typeBeingWoven)
          Construct a new method adapter
 
Method Summary
protected abstract  org.objectweb.asm.Type getTypeToCastTo()
          Get the type to which the class should be cast for delegation
protected abstract  boolean isTypeToCastToInterface()
           
protected  void unwrapEqualsArgument()
          This method unwraps woven proxy instances for use in the right-hand side of equals methods
abstract  void visitCode()
           
abstract  void visitMaxs(int stack, int locals)
           
protected  void writeDispatcher()
          Write out the bytecode instructions necessary to do the dispatch.
 
Methods inherited from class org.objectweb.asm.commons.GeneratorAdapter
arrayLength, arrayLoad, arrayStore, box, cast, catchException, checkCast, dup, dup2, dup2X1, dup2X2, dupX1, dupX2, endMethod, getField, getLocalType, getStatic, goTo, ifCmp, ifICmp, ifNonNull, ifNull, ifZCmp, iinc, instanceOf, invokeConstructor, invokeDynamic, invokeInterface, invokeStatic, invokeVirtual, loadArg, loadArgArray, loadArgs, loadArgs, loadLocal, loadLocal, loadThis, mark, mark, math, monitorEnter, monitorExit, newArray, newInstance, newLabel, not, pop, pop2, push, push, push, push, push, push, push, putField, putStatic, ret, returnValue, setLocalType, storeArg, storeLocal, storeLocal, swap, swap, tableSwitch, tableSwitch, throwException, throwException, unbox, valueOf
 
Methods inherited from class org.objectweb.asm.commons.LocalVariablesSorter
newLocal, newLocalMapping, visitFrame, visitIincInsn, visitLocalVariable, visitVarInsn
 
Methods inherited from class org.objectweb.asm.MethodAdapter
visitAnnotation, visitAnnotationDefault, visitAttribute, visitEnd, visitFieldInsn, visitInsn, visitIntInsn, visitJumpInsn, visitLabel, visitLdcInsn, visitLineNumber, visitLookupSwitchInsn, visitMethodInsn, visitMultiANewArrayInsn, visitParameterAnnotation, visitTableSwitchInsn, visitTryCatchBlock, visitTypeInsn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentTransformMethod

protected final org.objectweb.asm.commons.Method currentTransformMethod
The current method


typeBeingWoven

protected final org.objectweb.asm.Type typeBeingWoven
The type of this

Constructor Detail

AbstractWovenProxyMethodAdapter

public AbstractWovenProxyMethodAdapter(org.objectweb.asm.MethodVisitor mv,
                                       int access,
                                       String name,
                                       String desc,
                                       String methodStaticFieldName,
                                       org.objectweb.asm.commons.Method currentTransformMethod,
                                       org.objectweb.asm.Type typeBeingWoven)
Construct a new method adapter

Parameters:
mv - - the method visitor to write to
access - - the access modifiers on this method
name - - the name of this method
desc - - the descriptor of this method
methodStaticFieldName - - the name of the static field that will hold the Method representing this method.
currentTransformMethod - - the ASM representation of this method
proxyType - - the type being woven that contains this method
Method Detail

visitCode

public abstract void visitCode()
Specified by:
visitCode in interface org.objectweb.asm.MethodVisitor
Overrides:
visitCode in class org.objectweb.asm.MethodAdapter

visitMaxs

public abstract void visitMaxs(int stack,
                               int locals)
Specified by:
visitMaxs in interface org.objectweb.asm.MethodVisitor
Overrides:
visitMaxs in class org.objectweb.asm.commons.LocalVariablesSorter

writeDispatcher

protected final void writeDispatcher()
Write out the bytecode instructions necessary to do the dispatch. We know the dispatcher is non-null, and we need a try/catch around the invocation and listener calls.


getTypeToCastTo

protected abstract org.objectweb.asm.Type getTypeToCastTo()
Get the type to which the class should be cast for delegation

Returns:

isTypeToCastToInterface

protected abstract boolean isTypeToCastToInterface()

unwrapEqualsArgument

protected final void unwrapEqualsArgument()
This method unwraps woven proxy instances for use in the right-hand side of equals methods



Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.