jef.dna.constantPoolTable.impl
Class CPTable

java.lang.Object
  extended by jef.dna.constantPoolTable.impl.CPTable
All Implemented Interfaces:
java.lang.Cloneable, ConstantPoolTable

public class CPTable
extends java.lang.Object
implements ConstantPoolTable

Default implementation for the ConstantPoolTable interface

Author:
Francesco Russo frusso@cs.unibo.it

Field Summary
protected static Logger logger
           
 
Constructor Summary
CPTable()
          Creates a new instance of CPTable
 
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 const_pool_count)
          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 contained
 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.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static Logger logger
Constructor Detail

CPTable

public CPTable()
Creates a new instance of CPTable

Method Detail

addElement

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

Specified by:
addElement in interface ConstantPoolTable
Parameters:
entry - The entry to be added

addElementAt

public 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.

Specified by:
addElementAt in interface ConstantPoolTable
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

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

Specified by:
get in interface ConstantPoolTable
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

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

Specified by:
getIndexOf in interface ConstantPoolTable
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

public 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

Specified by:
remove in interface ConstantPoolTable
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

remove

public 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

Specified by:
remove in interface ConstantPoolTable
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

size

public int size()
Returns the number of entries contained

Specified by:
size in interface ConstantPoolTable
Returns:
int The number of constant pool table entries

addAll

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

Specified by:
addAll in interface ConstantPoolTable
Parameters:
cpt - The ConstantPoolTable to be appended

fromStream

public void fromStream(java.io.DataInputStream dis,
                       Dna dna,
                       int const_pool_count)
                throws MissingDnaContainerException,
                       DnaDeserializationException
Description copied from interface: ConstantPoolTable
Reads the constant pool table from the given stream.

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

toStream

public void toStream(java.io.DataOutputStream dos)
              throws MissingDnaContainerException,
                     DnaSerializationException
Description copied from interface: ConstantPoolTable
Writes the constant pool table to the given output stream.

Specified by:
toStream in interface ConstantPoolTable
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

getDna

public Dna getDna()
Description copied from interface: ConstantPoolTable
Get the Dna container

Specified by:
getDna in interface ConstantPoolTable
Returns:
Dna The Dna container

setDna

public void setDna(Dna dna)
Set the Dna container

Specified by:
setDna in interface ConstantPoolTable
Parameters:
dna - The Dna container

validate

public void validate()
              throws ConstantInfoValidationException,
                     ConstantInfoAttributeOutOfRangeException,
                     MissingDnaContainerException,
                     MissingCPTableException
Description copied from interface: ConstantPoolTable
This method validates the current Constant Pool Table along with its entries.

Specified by:
validate in interface ConstantPoolTable
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

isIndexValid

public 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.

Specified by:
isIndexValid in interface ConstantPoolTable
Parameters:
index - The index whose validity has to be checked
Returns:
boolean true iff the index is valid, false otherwise

isConstantUTF8

public boolean isConstantUTF8(int index)
                       throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_Utf8_info or not.

Specified by:
isConstantUTF8 in interface ConstantPoolTable
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

public boolean isConstantFieldRef(int index)
                           throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_Field_info or not.

Specified by:
isConstantFieldRef in interface ConstantPoolTable
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

public boolean isConstantMethodRef(int index)
                            throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_Method_info or not.

Specified by:
isConstantMethodRef in interface ConstantPoolTable
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

public boolean isConstantInterfaceMethodRef(int index)
                                     throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_InterfaceMethodref_info or not.

Specified by:
isConstantInterfaceMethodRef in interface ConstantPoolTable
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

public boolean isConstantString(int index)
                         throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_String_info or not.

Specified by:
isConstantString in interface ConstantPoolTable
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

public boolean isConstantInteger(int index)
                          throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_Integer_info or not.

Specified by:
isConstantInteger in interface ConstantPoolTable
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

public boolean isConstantFloat(int index)
                        throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_Float_info or not.

Specified by:
isConstantFloat in interface ConstantPoolTable
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

public boolean isConstantLong(int index)
                       throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_Long_info or not.

Specified by:
isConstantLong in interface ConstantPoolTable
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

public boolean isConstantDouble(int index)
                         throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_Double_info or not.

Specified by:
isConstantDouble in interface ConstantPoolTable
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

public boolean isConstantNameAndType(int index)
                              throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_NameAndType_info or not.

Specified by:
isConstantNameAndType in interface ConstantPoolTable
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

public boolean isConstantClass(int index)
                        throws IndexOutOfRangeException
Description copied from interface: ConstantPoolTable
This method states whether the given index refers to a CONSTANT_Class_info or not.

Specified by:
isConstantClass in interface ConstantPoolTable
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

public java.lang.String getEntryType(int index)
Description copied from interface: ConstantPoolTable
This method returns a human readable definition of the type of the entry references by the given index.

Specified by:
getEntryType in interface ConstantPoolTable
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

public Range getValidRange()
Description copied from interface: ConstantPoolTable
This method returns the admitted range for accessing the ConstantPoolTable.

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

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone the current ConstantPoolTable instance. This method will not modify the reference to the containing Dna instance.

Specified by:
clone in interface ConstantPoolTable
Overrides:
clone in class java.lang.Object
Returns:
Object The clone
Throws:
java.lang.CloneNotSupportedException