jef.dna.constantPoolTable
Interface ConstantPoolTable

All Superinterfaces:
java.lang.Cloneable
All Known Implementing Classes:
CPTable

public interface ConstantPoolTable
extends java.lang.Cloneable

This interface defines the methods every ConstantPoolTable implementation has to provide. Instances of ConstantPoolTable will be contained within Dna instances.

Author:
Francesco Russo frusso@cs.unibo.it

Method Summary
 void addAll(ConstantPoolTable cpt)
          Appends the given ConstantPoolTable to the current one.
 void addElement(ConstantInfo entry)
          Adds the specified ConstantInfo at the end of the constant pool table.
 void addElementAt(ConstantInfo entry, int index, boolean overwrite)
          Adds the specified ConstantInfo at the provided position, shifting of one index any subsequente entry (if exists) iff the overwrite parameter is set to false, otherwise the current entry at index index will be overwritten.
 java.lang.Object clone()
          Clone the current ConstantPoolTable instance.
 void fromStream(java.io.DataInputStream dis, Dna dna, int cptSize)
          Reads the constant pool table from the given stream.
 ConstantInfo get(int index)
          Get a reference to the entry stored at the provided index.
 Dna getDna()
          Get the Dna container
 java.lang.String getEntryType(int index)
          This method returns a human readable definition of the type of the entry references by the given index.
 int getIndexOf(ConstantInfo entry)
          Return the index of the provided entry, if exists.
 Range getValidRange()
          This method returns the admitted range for accessing the ConstantPoolTable.
 boolean isConstantClass(int index)
          This method states whether the given index refers to a CONSTANT_Class_info or not.
 boolean isConstantDouble(int index)
          This method states whether the given index refers to a CONSTANT_Double_info or not.
 boolean isConstantFieldRef(int index)
          This method states whether the given index refers to a CONSTANT_Field_info or not.
 boolean isConstantFloat(int index)
          This method states whether the given index refers to a CONSTANT_Float_info or not.
 boolean isConstantInteger(int index)
          This method states whether the given index refers to a CONSTANT_Integer_info or not.
 boolean isConstantInterfaceMethodRef(int index)
          This method states whether the given index refers to a CONSTANT_InterfaceMethodref_info or not.
 boolean isConstantLong(int index)
          This method states whether the given index refers to a CONSTANT_Long_info or not.
 boolean isConstantMethodRef(int index)
          This method states whether the given index refers to a CONSTANT_Method_info or not.
 boolean isConstantNameAndType(int index)
          This method states whether the given index refers to a CONSTANT_NameAndType_info or not.
 boolean isConstantString(int index)
          This method states whether the given index refers to a CONSTANT_String_info or not.
 boolean isConstantUTF8(int index)
          This method states whether the given index refers to a CONSTANT_Utf8_info or not.
 boolean isIndexValid(int index)
          This methods states whether the specified index index is valid within the constant pool table according to the class file specification.
 int remove(ConstantInfo entry, boolean compact)
          Removes the specified entry, if exists, resizing the constant pool table if compact is true, otherwise the removed entry has to be replaced by null
 ConstantInfo remove(int index, boolean compact)
          Removes the entry at the specified index, if exists, resizing the constant pool table if compact is true, otherwise the removed entry has to be replaced by null
 void setDna(Dna dna)
          Set the Dna container
 int size()
          Returns the number of entries stored by the constant pool table
 void toStream(java.io.DataOutputStream dos)
          Writes the constant pool table to the given output stream.
 void validate()
          This method validates the current Constant Pool Table along with its entries.
 

Method Detail

addElement

void addElement(ConstantInfo entry)
Adds the specified ConstantInfo at the end of the constant pool table.

Parameters:
entry - The entry to be added

addElementAt

void addElementAt(ConstantInfo entry,
                  int index,
                  boolean overwrite)
                  throws java.lang.IndexOutOfBoundsException,
                         java.lang.UnsupportedOperationException
Adds the specified ConstantInfo at the provided position, shifting of one index any subsequente entry (if exists) iff the overwrite parameter is set to false, otherwise the current entry at index index will be overwritten.

Parameters:
entry - The entry to be added
index - The position at which the entry should be placed
overwrite - Should any existing entry be overwritten?
Throws:
java.lang.IndexOutOfBoundsException - Trying to access to an invalid index
java.lang.UnsupportedOperationException - The method is not supported by the current implementation

get

ConstantInfo get(int index)
                 throws java.lang.IndexOutOfBoundsException
Get a reference to the entry stored at the provided index.

Parameters:
index - The index to access to
Returns:
ConstantInfo The entry located at the provided index, if any
Throws:
java.lang.IndexOutOfBoundsException - Tying to acces to an invalid index

getIndexOf

int getIndexOf(ConstantInfo entry)
               throws ConstantInfoNotFoundException,
                      java.lang.UnsupportedOperationException
Return the index of the provided entry, if exists.

Parameters:
entry - The entry whose index has to be returned
Returns:
int The index of the provided entry
Throws:
ConstantInfoNotFoundException - The provided entry is not stored within the current constant pool table
java.lang.UnsupportedOperationException - The method is not supported by the current implementation

remove

ConstantInfo remove(int index,
                    boolean compact)
                    throws java.lang.IndexOutOfBoundsException,
                           java.lang.UnsupportedOperationException
Removes the entry at the specified index, if exists, resizing the constant pool table if compact is true, otherwise the removed entry has to be replaced by null

Parameters:
index - The index of the entry we want to remove
compact - Has the constant pool table to be resized?
Returns:
ConstantInfo The removed entry
Throws:
java.lang.IndexOutOfBoundsException - Tying to acces to an invalid index
java.lang.UnsupportedOperationException - The method is not supported by the current implementation

remove

int remove(ConstantInfo entry,
           boolean compact)
           throws ConstantInfoNotFoundException,
                  java.lang.UnsupportedOperationException
Removes the specified entry, if exists, resizing the constant pool table if compact is true, otherwise the removed entry has to be replaced by null

Parameters:
entry - The entry we want to remove
compact - Has the constant pool table to be resized?
Returns:
int The index of the removed entry
Throws:
ConstantInfoNotFoundException - The provided entry is not stored within the current constant pool table
java.lang.UnsupportedOperationException - The method is not supported by the current implementation

size

int size()
Returns the number of entries stored by the constant pool table

Returns:
int The number of constant pool table entries

addAll

void addAll(ConstantPoolTable cpt)
Appends the given ConstantPoolTable to the current one.

Parameters:
cpt - The ConstantPoolTable to be appended

clone

java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone the current ConstantPoolTable instance.

Returns:
Object The clone
Throws:
java.lang.CloneNotSupportedException

fromStream

void fromStream(java.io.DataInputStream dis,
                Dna dna,
                int cptSize)
                throws MissingDnaContainerException,
                       DnaDeserializationException
Reads the constant pool table from the given stream.

Parameters:
dis - The stream for reading the constant pool table from
dna - The Dna container instance
cptSize - The number of expected constant pool table entries
Throws:
MissingDnaContainerException - This exception is thrown iff no valid Dna instance has been set
DnaDeserializationException

toStream

void toStream(java.io.DataOutputStream dos)
              throws MissingDnaContainerException,
                     DnaSerializationException
Writes the constant pool table to the given output stream.

Parameters:
dos - The stream for writing the Dna instance to
Throws:
MissingDnaContainerException - This exception is thrown iff no valid Dna instance has been set
DnaSerializationException - Something went wrong either accessing or reading from the input stream

setDna

void setDna(Dna dna)
Set the Dna container

Parameters:
dna - The Dna container

getDna

Dna getDna()
Get the Dna container

Returns:
Dna The Dna container

isIndexValid

boolean isIndexValid(int index)
This methods states whether the specified index index is valid within the constant pool table according to the class file specification.

Parameters:
index - The index whose validity has to be checked
Returns:
boolean true iff the index is valid, false otherwise

isConstantUTF8

boolean isConstantUTF8(int index)
                       throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_Utf8_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantClass

boolean isConstantClass(int index)
                        throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_Class_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantFieldRef

boolean isConstantFieldRef(int index)
                           throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_Field_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantMethodRef

boolean isConstantMethodRef(int index)
                            throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_Method_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantInterfaceMethodRef

boolean isConstantInterfaceMethodRef(int index)
                                     throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_InterfaceMethodref_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantString

boolean isConstantString(int index)
                         throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_String_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantInteger

boolean isConstantInteger(int index)
                          throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_Integer_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantFloat

boolean isConstantFloat(int index)
                        throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_Float_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantLong

boolean isConstantLong(int index)
                       throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_Long_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantDouble

boolean isConstantDouble(int index)
                         throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_Double_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

isConstantNameAndType

boolean isConstantNameAndType(int index)
                              throws IndexOutOfRangeException
This method states whether the given index refers to a CONSTANT_NameAndType_info or not.

Parameters:
index - The index whose entry has to be inspected
Returns:
boolean True or False according to the test result
Throws:
IndexOutOfRangeException - The specified index is out of the valid range

getEntryType

java.lang.String getEntryType(int index)
This method returns a human readable definition of the type of the entry references by the given index.

Parameters:
index - The index whose entry type we are interested in
Returns:
String The entry type or null if the index is out of the admitted range

getValidRange

Range getValidRange()
This method returns the admitted range for accessing the ConstantPoolTable.

Returns:
Range The valid range for accessing entries in the ConstantPoolTable or null should the ConstantPoolTable be empty.

validate

void validate()
              throws ConstantInfoValidationException,
                     ConstantInfoAttributeOutOfRangeException,
                     MissingDnaContainerException,
                     MissingCPTableException
This method validates the current Constant Pool Table along with its entries.

Throws:
ConstantInfoValidationException - Something failed with the validation process; further information are stored within the raised exception
ConstantInfoAttributeOutOfRangeException - This exception is thrown whenever a constant pool table element refers to an invalid constant pool table entry
MissingDnaContainerException - The validation process cannot be accomplished since any of the examined entities is missing its own Dna container
MissingCPTableException - The validation process cannot be accomplished since there is no reference to the ConstantPoolTable in the current Dna instance