jef.mixers.impl.simpleMixer
Class DnaSimpleMixer

java.lang.Object
  extended by jef.mixers.impl.simpleMixer.DnaSimpleMixer
All Implemented Interfaces:
DnaMixer

public class DnaSimpleMixer
extends java.lang.Object
implements DnaMixer

This class is in charge of performing a simple mix of two given Dna instances. This task is accomplished by generating a new Dna instance consisiting of the methods exposed by both the supplied Dnas. This simple Dna Mixer only appends methods exposed by the second parameter to the ones exposed by the first one.

Author:
Francesco Russo

Field Summary
protected  Dna dnaX
           
protected  Dna dnaY
           
 
Constructor Summary
DnaSimpleMixer()
          The default constructor.
 
Method Summary
protected  int findThisClassType(Dna dna, int thisIndex)
          This method returns the index of the constant pool table entry containing the ConstantUTF8 structure representing the type of the class associated with the Dna parameter.
protected  int findThisReference(ConstantPoolTable cpt)
           
 Dna mix()
          This method mixes the two Dna instances passed to the contructor and returns a new one exposing a set of methods equals to the union of the ones exposed by both the Dna instances above.
protected  ConstantPoolTable reorganizeIndexes(ConstantPoolTable cpt, int offset)
          This method reorganizes all the references within a constant pool table in a way that all of them get shifted by the given offset.
protected  void setAccessFlags(Dna dna, Dna dnaX, Dna dnaY)
          This methodo sets the right access flags to the new generated class file.
protected  void setConstantPoolTable(Dna newDna, ConstantPoolTable xCPT, ConstantPoolTable yCPT)
          newDna's constant pool table will be the union of xDna's and yDna's constant pool tables.
 void setDnas(Dna dnaX, Dna dnaY)
          This method sets the two Dna instances that will be used for generating the new one.
protected  void setFields(Dna dna, Dna xDna, Dna yDna, int thisEntry, int fqnEntry)
          The new dna instance will have, as fields, the union of xDna's and yDna's fields.
protected  void setMethods(Dna dna, Dna dnaX, Dna dnaY, int thisEntry, int fqnEntry)
          The new dna instance will have, as methods, the union of xDna's and yDna's methods.
protected  void setMinorMajorNumber(Dna dna, Dna dnaA, Dna dnaB)
          This method sets the values of the major and minor number for the new Dna instance.
protected  void setSuperClass(Dna dna, Dna dnaX)
           
protected  void setThis(Dna dna, Dna dnaX)
           
protected  void updateConstantClassInfoRefs(ConstantPoolTable cpt, java.lang.String fqClassName, int newFqnIndx)
          This method reorganizes the given constant pool table in a way that all the Constant Class Info structures pointing to a Constant UTF8 entry having a value equal to , will point to the constant pool table entry specified by the third input parameter newFqnIndx.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dnaX

protected Dna dnaX

dnaY

protected Dna dnaY
Constructor Detail

DnaSimpleMixer

public DnaSimpleMixer()
               throws InstantiatorException
The default constructor.

Throws:
InstantiatorException
Method Detail

setDnas

public void setDnas(Dna dnaX,
                    Dna dnaY)
This method sets the two Dna instances that will be used for generating the new one.

Specified by:
setDnas in interface DnaMixer
Parameters:
dnaX - The first Dna instance.
dnaY - The second Dna instance

mix

public Dna mix()
        throws InstantiatorException,
               MixerException
This method mixes the two Dna instances passed to the contructor and returns a new one exposing a set of methods equals to the union of the ones exposed by both the Dna instances above.

Specified by:
mix in interface DnaMixer
Returns:
The new Dna instance exposing all the methods of the two Dna instances passed to the constructor.
Throws:
InstantiatorException
MixerException

setMinorMajorNumber

protected void setMinorMajorNumber(Dna dna,
                                   Dna dnaA,
                                   Dna dnaB)
This method sets the values of the major and minor number for the new Dna instance. Should xDna's maj. number be greater then yDna's maj. number, new maj. and minor number will correspond to the xDna's ones.


setConstantPoolTable

protected void setConstantPoolTable(Dna newDna,
                                    ConstantPoolTable xCPT,
                                    ConstantPoolTable yCPT)
                             throws java.lang.CloneNotSupportedException
newDna's constant pool table will be the union of xDna's and yDna's constant pool tables. This method sets the constant pool count as well.

Throws:
java.lang.CloneNotSupportedException

updateConstantClassInfoRefs

protected void updateConstantClassInfoRefs(ConstantPoolTable cpt,
                                           java.lang.String fqClassName,
                                           int newFqnIndx)
                                    throws WrongReferenceInConstantPoolTableException
This method reorganizes the given constant pool table in a way that all the Constant Class Info structures pointing to a Constant UTF8 entry having a value equal to , will point to the constant pool table entry specified by the third input parameter newFqnIndx.

Parameters:
cpt - The constant pool table to work with
fqClassName - The old fully qualified name we want to look for and replace
newFqnIndx - The index of the new ConstantUTF8 entry in the given cpt, containing the new FQN we want to point to
Throws:
WrongReferenceInConstantPoolTableException

findThisReference

protected int findThisReference(ConstantPoolTable cpt)

findThisClassType

protected int findThisClassType(Dna dna,
                                int thisIndex)
                         throws WrongReferenceInConstantPoolTableException
This method returns the index of the constant pool table entry containing the ConstantUTF8 structure representing the type of the class associated with the Dna parameter.

Throws:
WrongReferenceInConstantPoolTableException

reorganizeIndexes

protected ConstantPoolTable reorganizeIndexes(ConstantPoolTable cpt,
                                              int offset)
This method reorganizes all the references within a constant pool table in a way that all of them get shifted by the given offset.


setAccessFlags

protected void setAccessFlags(Dna dna,
                              Dna dnaX,
                              Dna dnaY)
This methodo sets the right access flags to the new generated class file.


setThis

protected void setThis(Dna dna,
                       Dna dnaX)

setSuperClass

protected void setSuperClass(Dna dna,
                             Dna dnaX)

setFields

protected void setFields(Dna dna,
                         Dna xDna,
                         Dna yDna,
                         int thisEntry,
                         int fqnEntry)
                  throws java.lang.CloneNotSupportedException
The new dna instance will have, as fields, the union of xDna's and yDna's fields. This method sets the fields count entry too.

Throws:
java.lang.CloneNotSupportedException

setMethods

protected void setMethods(Dna dna,
                          Dna dnaX,
                          Dna dnaY,
                          int thisEntry,
                          int fqnEntry)
                   throws java.lang.CloneNotSupportedException
The new dna instance will have, as methods, the union of xDna's and yDna's methods. This method sets the methods count entry too.

Throws:
java.lang.CloneNotSupportedException