jef.disconnection.impl
Class DefaultMethodDisconnector

java.lang.Object
  extended by jef.disconnection.impl.DefaultMethodDisconnector
All Implemented Interfaces:
Disconnector, MethodDisconnector

public class DefaultMethodDisconnector
extends java.lang.Object
implements MethodDisconnector

Default implementation of the MethodDisconnector interface.

Author:
frusso@dev.java.net

Constructor Summary
DefaultMethodDisconnector()
          Creates a new instance of DefaultMethodDisconnector
 
Method Summary
 void extract(MethodInfoStructure methodInfo, Dna srcDna, DisconnectedMethod disconnectedMethod)
          This method copies into the disconnectedMethod instance provided as parameter the given methodInfo object.
protected  CodeAttribute handleAttributes(MethodInfoStructure clonedMethodInfo, boolean isInit)
           
protected  void handleBytecode(CodeAttribute codeAttribute, DisconnectedMethod disconnectedMethod, ConstantPoolTable srcCpt, Dna srcDna)
           
protected  CodeAttribute handleCodeAttribute(Attribute attr, boolean isInit)
           
protected  void handleDeprecatedAttribute(DeprecatedAttribute attr)
           
protected  void handleExceptionAttribute(ExceptionsAttribute attr)
           
protected  void handleFieldOrMethodRef(DisconnectedMethod dm, Dna srcDna, ConstantPoolTable srcCpt, int oldRef, int newRef, Instruction instruction)
           
protected  void handleFirstLevelRefs(MethodInfoStructure clonedMethodInfo, boolean isInit, DisconnectedMethod dm, Dna srcDna)
           
protected  void handleInnerClassRef(ConstClass cInfo, DisconnectedMethod dm, Dna srcDna)
           
protected  void handleLineNumberTableAttribute(LineNumberTableAttribute attr, boolean isInit)
           
protected  void handleLocalVariableTableAttribute(LocalVariableTableAttribute attr, boolean isInit)
           
protected  void handleSyntheticAttribute(SyntheticAttribute attr)
           
protected  void innerExtract(MethodInfoStructure methodInfo, Dna srcDna, DisconnectedMethod disconnectedMethod)
          Protected extraction method.
protected  void innerExtractInit(MethodInfoStructure methodInfo, Dna srcDna, DisconnectedMethod disconnectedMethod)
           
protected  FieldInfoStructure searchField(Dna dna, int nameIndex, int descIndex)
          This method searches over the provided Dna instance for a field having the given nameIndex and descriptorIndex.
protected  MethodInfoStructure searchMethod(Dna dna, int nameIndex, int descIndex)
          This method searches over the provided Dna instance for a method having the given nameIndex and descriptorIndex.
protected  void spawnNewInnerClass(DisconnectedMethod dm, java.lang.String fqicn)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultMethodDisconnector

public DefaultMethodDisconnector()
Creates a new instance of DefaultMethodDisconnector

Method Detail

extract

public void extract(MethodInfoStructure methodInfo,
                    Dna srcDna,
                    DisconnectedMethod disconnectedMethod)
             throws DisconnectionFailedException
This method copies into the disconnectedMethod instance provided as parameter the given methodInfo object. Actually this is a real copy, that is the source methodInfo gets cloned and all its references to cp_infos entries are correctly updated.
What this means is that the copy of a method from a source Dna to a target DisconnectedMethod data structure entails that a deep copy of all the referenced cp_infos will be launched. This is a required step to bring into the target DisconnectedMethod all the other information on which the method definition is based.

Note: if using a stateful deep copier it is fundamental to perform all the deep copy invocations by means of the same DeepCopier instance.

Specified by:
extract in interface MethodDisconnector
Parameters:
methodInfo - The reference to the method to be copied into the target disconnectMethod
srcDna - The Dna instance the methodInfo belongs to
disconnectedMethod - The target DisconnectedMethod instance in which the disconnected method will be stored for a subsequent injection
Throws:
DisconnectionFailedException

innerExtract

protected void innerExtract(MethodInfoStructure methodInfo,
                            Dna srcDna,
                            DisconnectedMethod disconnectedMethod)
                     throws DisconnectionFailedException
Protected extraction method. This is the method that actually implements the logic necessary for "extracting a method" from a Java class definition.

Parameters:
methodInfo - The reference to the method to be copied into the target disconnectMethod
srcDna - The Dna instance the methodInfo belongs to
disconnectMethod - The target DisconnectedMethod instance in which the disconnected method will be stored for a subsequent injection
dstDna - The target Dna instance the disconnected method will be attached to
Throws:
DisconnectionFailedException

handleFirstLevelRefs

protected void handleFirstLevelRefs(MethodInfoStructure clonedMethodInfo,
                                    boolean isInit,
                                    DisconnectedMethod dm,
                                    Dna srcDna)
                             throws DeepCopyException,
                                    java.lang.CloneNotSupportedException,
                                    DisconnectionFailedException
Throws:
DeepCopyException
java.lang.CloneNotSupportedException
DisconnectionFailedException

handleAttributes

protected CodeAttribute handleAttributes(MethodInfoStructure clonedMethodInfo,
                                         boolean isInit)
                                  throws DeepCopyException,
                                         java.lang.CloneNotSupportedException
Throws:
DeepCopyException
java.lang.CloneNotSupportedException

handleCodeAttribute

protected CodeAttribute handleCodeAttribute(Attribute attr,
                                            boolean isInit)
                                     throws DeepCopyException,
                                            java.lang.CloneNotSupportedException
Throws:
DeepCopyException
java.lang.CloneNotSupportedException

handleLineNumberTableAttribute

protected void handleLineNumberTableAttribute(LineNumberTableAttribute attr,
                                              boolean isInit)
                                       throws DeepCopyException,
                                              java.lang.CloneNotSupportedException
Throws:
DeepCopyException
java.lang.CloneNotSupportedException

handleLocalVariableTableAttribute

protected void handleLocalVariableTableAttribute(LocalVariableTableAttribute attr,
                                                 boolean isInit)
                                          throws DeepCopyException,
                                                 java.lang.CloneNotSupportedException
Throws:
DeepCopyException
java.lang.CloneNotSupportedException

handleExceptionAttribute

protected void handleExceptionAttribute(ExceptionsAttribute attr)
                                 throws DeepCopyException,
                                        java.lang.CloneNotSupportedException
Throws:
DeepCopyException
java.lang.CloneNotSupportedException

handleSyntheticAttribute

protected void handleSyntheticAttribute(SyntheticAttribute attr)
                                 throws DeepCopyException,
                                        java.lang.CloneNotSupportedException
Throws:
DeepCopyException
java.lang.CloneNotSupportedException

handleDeprecatedAttribute

protected void handleDeprecatedAttribute(DeprecatedAttribute attr)
                                  throws DeepCopyException,
                                         java.lang.CloneNotSupportedException
Throws:
DeepCopyException
java.lang.CloneNotSupportedException

handleBytecode

protected void handleBytecode(CodeAttribute codeAttribute,
                              DisconnectedMethod disconnectedMethod,
                              ConstantPoolTable srcCpt,
                              Dna srcDna)
                       throws DisconnectionFailedException,
                              DeepCopyException,
                              java.lang.CloneNotSupportedException,
                              InstantiatorException
Throws:
DisconnectionFailedException
DeepCopyException
java.lang.CloneNotSupportedException
InstantiatorException

handleFieldOrMethodRef

protected void handleFieldOrMethodRef(DisconnectedMethod dm,
                                      Dna srcDna,
                                      ConstantPoolTable srcCpt,
                                      int oldRef,
                                      int newRef,
                                      Instruction instruction)
                               throws DisconnectionFailedException
Throws:
DisconnectionFailedException

handleInnerClassRef

protected void handleInnerClassRef(ConstClass cInfo,
                                   DisconnectedMethod dm,
                                   Dna srcDna)
                            throws java.lang.CloneNotSupportedException,
                                   InstantiatorException,
                                   DeepCopyException
Throws:
java.lang.CloneNotSupportedException
InstantiatorException
DeepCopyException

spawnNewInnerClass

protected void spawnNewInnerClass(DisconnectedMethod dm,
                                  java.lang.String fqicn)

innerExtractInit

protected void innerExtractInit(MethodInfoStructure methodInfo,
                                Dna srcDna,
                                DisconnectedMethod disconnectedMethod)
                         throws DisconnectionFailedException
Throws:
DisconnectionFailedException

searchField

protected FieldInfoStructure searchField(Dna dna,
                                         int nameIndex,
                                         int descIndex)
This method searches over the provided Dna instance for a field having the given nameIndex and descriptorIndex. If found, the first matching field is returned, otherwise null will be the expected return value.

Parameters:
dna - The Dna instance to be inspected
nameIndex - The nameIndex of the field
descIndex - The descIndex of the field
Returns:
FieldInfoStructure The field (if it exists) or null otherwise

searchMethod

protected MethodInfoStructure searchMethod(Dna dna,
                                           int nameIndex,
                                           int descIndex)
This method searches over the provided Dna instance for a method having the given nameIndex and descriptorIndex. If found, the first matching method is returned, otherwise null will be the expected return value.

Parameters:
dna - The Dna instance to be inspected
nameIndex - The nameIndex of the field
descIndex - The descIndex of the field
Returns:
MethodInfoStructure The method (if it exists) or null otherwise