jef.dna
Class Dna

java.lang.Object
  extended by jef.dna.Dna

public class Dna
extends java.lang.Object

The Dna class is the object oriented representation of a Java class file's content. Each item can be accessed through getter and setter methods. A Dna instance is returned by the DnaReader class, and can thereon be written to a file leveraging on the DnaWriter class.

Author:
Francesco Russo (frusso@cs.unibo.it)

Field Summary
 int ACC_ABSTRACT
          Bit mask for the ABSTRACT access modifier
 int ACC_FINAL
          Bit mask for the FINAL access modifier
 int ACC_INTERFACE
          Bit mask for the INTERFACE access modifier
 int ACC_PUBLIC
          Bit mask for the PUBLIC access modifier
 int ACC_SUPER
          Bit mask for the SUPER access modifier
 
Constructor Summary
Dna()
          Constructor.
Dna(int magicNumber)
          Parameterized constructor.
 
Method Summary
 void fromStream(java.io.DataInputStream dis)
          Reads a Java class file from the specified stream, and fills in the current Dna instance.
 int getAccessFlags()
          Return the current class access modifier.
 AttribFactory getAttribFactory()
          Returns the AttribFactory configured in the Dna configuration file, needed for instantiating Attributes instances.
 int getAttributeCount()
          Returns the number of attributes of the Java class represented by the current Dna instance or -1 if any attribute has been set.
 AttributesTable getAttributes()
          Returns the AttributesTable representing the attributes exposed by the Java class represented by the current Dna instance.
 AttributesTableFactory getAttributesTableFactory()
          Returns the AttributesTableFactory configured in the Dna configuration file, needed for instantiating Attribute instances.
 int getConstantPoolCount()
          Returns the number of entries in the Constant Pool Table.
 ConstantPoolTable getConstantPoolTable()
          Returns the Constant Pool Table.
 ConstantPoolTableFactory getConstantPoolTableFactory()
          Returns the ConstantPoolTableFactory configured in the Dna configuration file, needed for instantiating ConstantPoolTable instances.
 ConstInfoFactory getConstInfoFactory()
          Returns the ConstantInfoFactory configured in the Dna configuration file, needed for instantiating ConstantInfo instances.
 FieldsTable getFields()
          Returns the fields of the Java class represented by the current Dna instance, as a FieldsTable instance.
 int getFieldsCount()
          This method returns the number of field declared by the Java class represented by this Dna instance, or -1 if the fields property has not already been set.
 FieldsTableFactory getFieldsTableFactory()
          Returns the FieldsTableFactory configured in the Dna configuration file, needed for instantiating FieldInfoStructure instances.
 java.lang.String getFqnAsString(int index)
          This method returns the FQN of the class associated with the given Dna instance.
 int getFqnReference()
          This method returns the index of the constant pool table's entry containig the constant UTF8 info storing the current Dna instance's FQN.
 InfoStructuresFactory getInfoStructuresFactory()
          Returns the factory class used for instantiating InfoStructure components.
 MethodInfoStructure getInitMethod()
           
 InstructionFactory getInstructionFactory()
          Returns the InstructionFactory configured in the Dna configuration file, needed for instantiating Instruction instances.
 int getInterfaceCount()
          Returns the number of implemented interfaces or -1 if the interfaces property has not been set.
 java.util.List<java.lang.Integer> getInterfaces()
          Returns the set of references to the constant pool table.
 int getMagicNumber()
          Returns the class' file magic number.
 int getMajorNumber()
          Returns the Dna instance magic number.
 int getMethodCount()
          Returns the number of methods declared by the Java class represented by the current Dna instance or -1 if the methods property has not been set.
 MethodsTable getMethods()
          Returns the MethodsTable instance containing all the methods declared by the Java class represented by the current Dna instance.
 MethodsTableFactory getMethodsTableFactory()
          Returns the MethodsTableFactory configured in the Dna configuration file, needed for instantiating MethodInfoStructure instances.
 int getMinorNumber()
          Returns the class' file minor number.
 int getSuperClass()
          Returns the index of the Constant Class Info representing the direct superclass of the current class, into the constant pool table.
 int getThisClass()
          Returns the reference to the constant pool table entry of type Constant Class Info representing the current class.
 void setAccessFlags(int flags)
          This method sets the current class access modifier.
 void setAttributes(AttributesTable attributes)
          Sets the attributes exposed by the Java class represented by the current Dna instance.
 void setConstantPoolTable(ConstantPoolTable table)
          Sets the Constant Pool Table in the current Dna instance.
 void setFields(FieldsTable fields)
          Sets the fields declared by the Java class represented by this Dna instance.
 void setInitMethod(MethodInfoStructure initMethod)
           
 void setInterfaces(java.util.List<java.lang.Integer> interfaces)
          Set the array of references to the constant pool table entries of type Constant Class Info associated with this class' implemented interfaces.
 void setMajorNumber(int major)
          Sets the major number in the Dna instance.
 void setMethods(MethodsTable methods)
          Sets the MethodsTable instance containing all the methods defined by the Java class represented by the current Dna instance.
 void setMinorNumber(int minor)
          Sets the class' file minor number in the Dna instance.
 void setSuperClass(int superClass)
          Set the reference to the constant pool table entry representing the direct superclass of the class associated with the current Dna instance
 void setThisClass(int thisClass)
          Sets the reference to the constant pool table entry of type Constant Class Info representing the current class.
 void toStream(java.io.DataOutputStream dos)
          This method writes the Dna instance's content to the specified DataOutputStream
 void validate()
          This method launches the validation process over the current Dna instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACC_PUBLIC

public final int ACC_PUBLIC
Bit mask for the PUBLIC access modifier

See Also:
Constant Field Values

ACC_FINAL

public final int ACC_FINAL
Bit mask for the FINAL access modifier

See Also:
Constant Field Values

ACC_SUPER

public final int ACC_SUPER
Bit mask for the SUPER access modifier

See Also:
Constant Field Values

ACC_INTERFACE

public final int ACC_INTERFACE
Bit mask for the INTERFACE access modifier

See Also:
Constant Field Values

ACC_ABSTRACT

public final int ACC_ABSTRACT
Bit mask for the ABSTRACT access modifier

See Also:
Constant Field Values
Constructor Detail

Dna

public Dna()
    throws InstantiatorException
Constructor. Sets the default magic number automatically.

Throws:
InstantiatorException - The jef.config.Instantiator was unable to perform one the required instantiations

Dna

public Dna(int magicNumber)
Parameterized constructor. It takes as input the class file magic number. If you don't know it's value, please use the default constructor instead.

Parameters:
magicNumber - The java class file magic number
Method Detail

getMagicNumber

public int getMagicNumber()
Returns the class' file magic number.

Returns:
The major number.

setMinorNumber

public void setMinorNumber(int minor)
Sets the class' file minor number in the Dna instance.

Parameters:
minor - The minor number.

getMinorNumber

public int getMinorNumber()
Returns the class' file minor number.

Returns:
The minor number

setMajorNumber

public void setMajorNumber(int major)
Sets the major number in the Dna instance.

Parameters:
major - The major number.

getMajorNumber

public int getMajorNumber()
Returns the Dna instance magic number.

Returns:
The major number.

getConstantPoolCount

public int getConstantPoolCount()
Returns the number of entries in the Constant Pool Table. Since the constantPoolCount property depends on the presence of the constantPoolTabl property, this method might return -1 should the constantPoolTable be null.

Returns:
The ConstantPoolCount or -1 if the ConstantPoolTable is not already set.

setConstantPoolTable

public void setConstantPoolTable(ConstantPoolTable table)
Sets the Constant Pool Table in the current Dna instance. This method has also impact over the constantPoolCount property: its value is set to equal the constantPoolTable's size plus one.

Parameters:
table - The ConstantPoolTable instance containing all the constant pool table entries.

getConstantPoolTable

public ConstantPoolTable getConstantPoolTable()
Returns the Constant Pool Table.

Returns:
The ConstantPoolTable representing the Constant Pool Table.

setAccessFlags

public void setAccessFlags(int flags)
This method sets the current class access modifier.

Parameters:
flags - The valid mask of flags

getAccessFlags

public int getAccessFlags()
Return the current class access modifier.

Returns:
int accessFlag

setThisClass

public void setThisClass(int thisClass)
Sets the reference to the constant pool table entry of type Constant Class Info representing the current class.

Parameters:
thisClass - The reference to the constant pool table entry representing the class defined by this Dna instance

getThisClass

public int getThisClass()
Returns the reference to the constant pool table entry of type Constant Class Info representing the current class.

Returns:
int thisClass

setSuperClass

public void setSuperClass(int superClass)
Set the reference to the constant pool table entry representing the direct superclass of the class associated with the current Dna instance

Parameters:
superClass - superClass

getSuperClass

public int getSuperClass()
Returns the index of the Constant Class Info representing the direct superclass of the current class, into the constant pool table.

Returns:
int superClass

getInterfaceCount

public int getInterfaceCount()
Returns the number of implemented interfaces or -1 if the interfaces property has not been set.

Returns:
int interfaceCount or -1

setInterfaces

public void setInterfaces(java.util.List<java.lang.Integer> interfaces)
Set the array of references to the constant pool table entries of type Constant Class Info associated with this class' implemented interfaces.

Parameters:
interfaces - interfaces interfaces Each entry of interfaces has to be of type Integer

getInterfaces

public java.util.List<java.lang.Integer> getInterfaces()
Returns the set of references to the constant pool table. Each entry of the returned List is an Integer referring to a constant pool table's entry of type Constant Class Info

Returns:
List interfaces

getFieldsCount

public int getFieldsCount()
This method returns the number of field declared by the Java class represented by this Dna instance, or -1 if the fields property has not already been set.

Returns:
The numeber of the declared fields or -1

setFields

public void setFields(FieldsTable fields)
Sets the fields declared by the Java class represented by this Dna instance. The fields are represented by a FieldsTable instance.

Parameters:
fields - The FieldsTable instance representing the current Java class' fields

getFields

public FieldsTable getFields()
Returns the fields of the Java class represented by the current Dna instance, as a FieldsTable instance.

Returns:
The Java class' fields

getMethodCount

public int getMethodCount()
Returns the number of methods declared by the Java class represented by the current Dna instance or -1 if the methods property has not been set.

Returns:
The numeber of declared methods or -1

setMethods

public void setMethods(MethodsTable methods)
Sets the MethodsTable instance containing all the methods defined by the Java class represented by the current Dna instance. The length of the above MethodsTable has to be equal to the number of methods specified via the setMethodCount method.

Parameters:
methods - The MethodsTable containing the definitions of all the methods declared by the current Java class

getMethods

public MethodsTable getMethods()
Returns the MethodsTable instance containing all the methods declared by the Java class represented by the current Dna instance.

Returns:
The MethodsTable which stores the current Java class' methods

getAttributeCount

public int getAttributeCount()
Returns the number of attributes of the Java class represented by the current Dna instance or -1 if any attribute has been set.

Returns:
The number of attributes of the current Java class or -1

setAttributes

public void setAttributes(AttributesTable attributes)
Sets the attributes exposed by the Java class represented by the current Dna instance. These attributes are stored within an AttributesTable instance.

Parameters:
attributes - The AttributesTable representing the current class' attributes

getAttributes

public AttributesTable getAttributes()
Returns the AttributesTable representing the attributes exposed by the Java class represented by the current Dna instance.

Returns:
The current represented class' attributes, stored within an AttributesTable

toStream

public void toStream(java.io.DataOutputStream dos)
              throws DnaSerializationException,
                     MissingDnaContainerException
This method writes the Dna instance's content to the specified DataOutputStream

Parameters:
dos - DataOutputStream used for writing the Dna content to
Throws:
DnaSerializationException - Thrown should an error occour while writing to the output stream
MissingDnaContainerException - This exception can only be thrown by inner components should they be missing a reference to their Dna-container.

fromStream

public void fromStream(java.io.DataInputStream dis)
                throws DnaDeserializationException,
                       MissingDnaContainerException
Reads a Java class file from the specified stream, and fills in the current Dna instance.

Parameters:
dis - The DataInputStream the Java class should be read from
Throws:
MissingDnaContainerException - One of the inner components is missing a reference to the current Dna container
DnaDeserializationException - An error occourred during the Dna deserialization process

validate

public void validate()
              throws DnaValidationException
This method launches the validation process over the current Dna instance.

Throws:
DnaValidationException - The validation process failed.

getFqnReference

public int getFqnReference()
                    throws WrongReferenceInConstantPoolTableException
This method returns the index of the constant pool table's entry containig the constant UTF8 info storing the current Dna instance's FQN. In order to get the associated String representation, please use the public String getFqnAsString(int index) method.

Returns:
int The index of the constant UTF8 entry storing the FQN of this Dna instance
Throws:
WrongReferenceInConstantPoolTableException - One of the inner Dna components has a wrong reference to one of the ConstantPoolTable's entry

getFqnAsString

public java.lang.String getFqnAsString(int index)
                                throws WrongReferenceInConstantPoolTableException
This method returns the FQN of the class associated with the given Dna instance. The required int index argument can be obtained through the public int getFqnReference() method.

Parameters:
index - The index of the ConstantPoolTable entry storing the fully qualified name of the Java class represented by the current Dna instance
Returns:
The java class FQN
Throws:
WrongReferenceInConstantPoolTableException
WrongReferenceInConstantPoolTableException - Trying to access a ConstantPoolTable entry of a type not matching with the expected one

getInfoStructuresFactory

public InfoStructuresFactory getInfoStructuresFactory()
Returns the factory class used for instantiating InfoStructure components.

Returns:
The required InfoStructuresFactory

getConstantPoolTableFactory

public ConstantPoolTableFactory getConstantPoolTableFactory()
Returns the ConstantPoolTableFactory configured in the Dna configuration file, needed for instantiating ConstantPoolTable instances.

Returns:
The configured ConstantPoolTableFactory implementation

getConstInfoFactory

public ConstInfoFactory getConstInfoFactory()
Returns the ConstantInfoFactory configured in the Dna configuration file, needed for instantiating ConstantInfo instances.

Returns:
The configured ConstantInfoFactory implementation

getAttribFactory

public AttribFactory getAttribFactory()
Returns the AttribFactory configured in the Dna configuration file, needed for instantiating Attributes instances.

Returns:
The configured AttribFactory implementation

getFieldsTableFactory

public FieldsTableFactory getFieldsTableFactory()
Returns the FieldsTableFactory configured in the Dna configuration file, needed for instantiating FieldInfoStructure instances.

Returns:
The configured FieldsTableFactory implementation

getMethodsTableFactory

public MethodsTableFactory getMethodsTableFactory()
Returns the MethodsTableFactory configured in the Dna configuration file, needed for instantiating MethodInfoStructure instances.

Returns:
The configured MethodsTableFactory implementation

getAttributesTableFactory

public AttributesTableFactory getAttributesTableFactory()
Returns the AttributesTableFactory configured in the Dna configuration file, needed for instantiating Attribute instances.

Returns:
The configured AttributesTableFactory implementation

getInstructionFactory

public InstructionFactory getInstructionFactory()
Returns the InstructionFactory configured in the Dna configuration file, needed for instantiating Instruction instances.

Returns:
The configured InstructionFactory implementation

getInitMethod

public MethodInfoStructure getInitMethod()

setInitMethod

public void setInitMethod(MethodInfoStructure initMethod)