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

java.lang.Object
  extended by org.objectweb.asm.MethodVisitor
      extended by org.objectweb.asm.commons.LocalVariablesSorter
          extended by org.objectweb.asm.commons.GeneratorAdapter
              extended by org.apache.aries.proxy.impl.common.AbstractWovenProxyMethodAdapter
Direct Known Subclasses:
WovenProxyAbstractMethodAdapter, WovenProxyConcreteMethodAdapter

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 WovenProxyConcreteMethodAdapter is used for weaving instance methods WovenProxyAbstractMethodAdapter 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.MethodVisitor
api, 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, org.objectweb.asm.Type methodDeclaringType, boolean isMethodDeclaringTypeInterface)
          Construct a new method adapter
 
Method Summary
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, 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.MethodVisitor
visitAnnotation, visitAnnotationDefault, visitAttribute, visitEnd, visitFieldInsn, visitInsn, visitIntInsn, visitInvokeDynamicInsn, 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,
                                       org.objectweb.asm.Type methodDeclaringType,
                                       boolean isMethodDeclaringTypeInterface)
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()
Overrides:
visitCode in class org.objectweb.asm.MethodVisitor

visitMaxs

public abstract void visitMaxs(int stack,
                               int locals)
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.


unwrapEqualsArgument

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



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