com.deltax.util
Class CPoolReader

java.lang.Object
  extended bycom.deltax.util.CPoolReader

public class CPoolReader
extends java.lang.Object

This class reads directly a class file as specified in the Java Language specification.
Unfortunately java.lang.ClassLoader does not provide services for accessing class bytecode, so a ClassFileFinder object is used to locate and load the bytecode for a class.
Generally this scheme must be identical to the currently used ClassLoader scheme.
A JDK 1.2 ClassFileFinder - which emulates standard JDK 1.2 behaviour is used by default, but a different ClassFileFinder can be specified at construction time.

Version:
1.0
Author:
Cristiano Sadun
See Also:
JDK12ClassFileFinder

Nested Class Summary
 class CPoolReader.attribute_info
           
 class CPoolReader.C_Class
           
 class CPoolReader.C_Double
           
 class CPoolReader.C_Fieldref
           
 class CPoolReader.C_Float
           
 class CPoolReader.C_FMIRefBase
          Base for CONSTANT_Fieldref, CONSTANT_Methodref, CONSTANT_InterfaceMethodref entries
 class CPoolReader.C_IFBase
           
 class CPoolReader.C_Integer
           
 class CPoolReader.C_InterfaceMethodref
           
 class CPoolReader.C_LDBase
           
 class CPoolReader.C_Long
           
 class CPoolReader.C_Methodref
           
 class CPoolReader.C_NameAndType
           
 class CPoolReader.C_String
           
 class CPoolReader.C_Utf8
           
 class CPoolReader.classfile
          This class mirrors exactly the class file structure, providing basic translation and filtering services.
 class CPoolReader.cp_info
          The basic cp_info class.
 class CPoolReader.field_info
           
 class CPoolReader.method_info
           
 class CPoolReader.MF_info
           
 class CPoolReader.unknown_cp_info
          An helper class used for internal debugging only
 
Field Summary
static short ACC_ABSTRACT
           
static java.lang.String ACC_ABSTRACT_s
           
static short ACC_FINAL
           
static java.lang.String ACC_FINAL_s
           
static short ACC_INTERFACE
           
static java.lang.String ACC_INTERFACE_s
           
static short ACC_NATIVE
           
static java.lang.String ACC_NATIVE_s
           
static short ACC_PRIVATE
           
static java.lang.String ACC_PRIVATE_s
           
static short ACC_PROTECTED
           
static java.lang.String ACC_PROTECTED_s
           
static short ACC_PUBLIC
           
static java.lang.String ACC_PUBLIC_s
           
static short ACC_STATIC
           
static java.lang.String ACC_STATIC_s
           
static short ACC_SYNCHRONIZED
           
static java.lang.String ACC_SYNCHRONIZED_s
           
static short ACC_TRANSIENT
           
static java.lang.String ACC_TRANSIENT_s
           
static short ACC_VOLATILE
           
static java.lang.String ACC_VOLATILE_s
           
protected  ClassFileFinder cff
          The ClassFileFinder object used to locate bytecode By default, a plain JDK12ClassFileFinder.
static byte CONSTANT_Class
           
static java.lang.String CONSTANT_Class_s
           
static byte CONSTANT_Double
           
static java.lang.String CONSTANT_Double_s
           
static byte CONSTANT_Fieldref
           
static java.lang.String CONSTANT_Fieldref_s
           
static byte CONSTANT_Float
           
static java.lang.String CONSTANT_Float_s
           
static byte CONSTANT_Integer
           
static java.lang.String CONSTANT_Integer_s
           
static byte CONSTANT_InterfaceMethodref
           
static java.lang.String CONSTANT_InterfaceMethodref_s
           
static byte CONSTANT_Long
           
static java.lang.String CONSTANT_Long_s
           
static byte CONSTANT_Methodref
           
static java.lang.String CONSTANT_Methodref_s
           
static byte CONSTANT_NameAndType
           
static java.lang.String CONSTANT_NamedType_s
           
static byte CONSTANT_String
           
static java.lang.String CONSTANT_String_s
           
static byte CONSTANT_Unknown
           
static java.lang.String CONSTANT_Unknown_s
           
static byte CONSTANT_Utf8
           
static java.lang.String CONSTANT_Utf8_s
           
 
Constructor Summary
CPoolReader()
          Buids a CPoolReader which uses a JDK12ClassFileFinder
CPoolReader(ClassFileFinder cff)
          Buids a CPoolReader which uses the specifies ClassFileFinder
CPoolReader(java.lang.String classPath)
          Buids a CPoolReader which uses a JDK12 with the given application class path
 
Method Summary
 boolean forNameCalled(java.lang.String name)
          This method detects the presence of "Class.forName()" call in this classfile.
static java.lang.String getAcc_s(short access_flag)
           
static java.lang.String getConstTag_s(short tag)
           
 java.lang.String[] getUsedClasses(java.lang.String name)
          Retrieve the classes known to this .class file Note: The classes are returned in external form Refer to class description for finding/loading scheme discussion
static void main(java.lang.String[] args)
           
 CPoolReader.classfile readClass(java.lang.String className)
          This returns an interpreted class file.
 CPoolReader.classfile readClassData(byte[] data)
           
 CPoolReader.classfile readClassData(java.io.InputStream is)
           
 CPoolReader.classfile readClassData(java.lang.String className, java.io.InputStream is)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSTANT_Class

public static final byte CONSTANT_Class
See Also:
Constant Field Values

CONSTANT_Fieldref

public static final byte CONSTANT_Fieldref
See Also:
Constant Field Values

CONSTANT_Methodref

public static final byte CONSTANT_Methodref
See Also:
Constant Field Values

CONSTANT_InterfaceMethodref

public static final byte CONSTANT_InterfaceMethodref
See Also:
Constant Field Values

CONSTANT_String

public static final byte CONSTANT_String
See Also:
Constant Field Values

CONSTANT_Integer

public static final byte CONSTANT_Integer
See Also:
Constant Field Values

CONSTANT_Float

public static final byte CONSTANT_Float
See Also:
Constant Field Values

CONSTANT_Long

public static final byte CONSTANT_Long
See Also:
Constant Field Values

CONSTANT_Double

public static final byte CONSTANT_Double
See Also:
Constant Field Values

CONSTANT_NameAndType

public static final byte CONSTANT_NameAndType
See Also:
Constant Field Values

CONSTANT_Utf8

public static final byte CONSTANT_Utf8
See Also:
Constant Field Values

CONSTANT_Unknown

public static final byte CONSTANT_Unknown
See Also:
Constant Field Values

CONSTANT_Class_s

public static final java.lang.String CONSTANT_Class_s
See Also:
Constant Field Values

CONSTANT_Fieldref_s

public static final java.lang.String CONSTANT_Fieldref_s
See Also:
Constant Field Values

CONSTANT_Methodref_s

public static final java.lang.String CONSTANT_Methodref_s
See Also:
Constant Field Values

CONSTANT_InterfaceMethodref_s

public static final java.lang.String CONSTANT_InterfaceMethodref_s
See Also:
Constant Field Values

CONSTANT_String_s

public static final java.lang.String CONSTANT_String_s
See Also:
Constant Field Values

CONSTANT_Integer_s

public static final java.lang.String CONSTANT_Integer_s
See Also:
Constant Field Values

CONSTANT_Float_s

public static final java.lang.String CONSTANT_Float_s
See Also:
Constant Field Values

CONSTANT_Long_s

public static final java.lang.String CONSTANT_Long_s
See Also:
Constant Field Values

CONSTANT_Double_s

public static final java.lang.String CONSTANT_Double_s
See Also:
Constant Field Values

CONSTANT_NamedType_s

public static final java.lang.String CONSTANT_NamedType_s
See Also:
Constant Field Values

CONSTANT_Utf8_s

public static final java.lang.String CONSTANT_Utf8_s
See Also:
Constant Field Values

CONSTANT_Unknown_s

public static final java.lang.String CONSTANT_Unknown_s
See Also:
Constant Field Values

ACC_PUBLIC

public static final short ACC_PUBLIC
See Also:
Constant Field Values

ACC_PRIVATE

public static final short ACC_PRIVATE
See Also:
Constant Field Values

ACC_PROTECTED

public static final short ACC_PROTECTED
See Also:
Constant Field Values

ACC_STATIC

public static final short ACC_STATIC
See Also:
Constant Field Values

ACC_FINAL

public static final short ACC_FINAL
See Also:
Constant Field Values

ACC_VOLATILE

public static final short ACC_VOLATILE
See Also:
Constant Field Values

ACC_TRANSIENT

public static final short ACC_TRANSIENT
See Also:
Constant Field Values

ACC_SYNCHRONIZED

public static final short ACC_SYNCHRONIZED
See Also:
Constant Field Values

ACC_NATIVE

public static final short ACC_NATIVE
See Also:
Constant Field Values

ACC_ABSTRACT

public static final short ACC_ABSTRACT
See Also:
Constant Field Values

ACC_INTERFACE

public static final short ACC_INTERFACE
See Also:
Constant Field Values

ACC_PUBLIC_s

public static final java.lang.String ACC_PUBLIC_s
See Also:
Constant Field Values

ACC_PRIVATE_s

public static final java.lang.String ACC_PRIVATE_s
See Also:
Constant Field Values

ACC_PROTECTED_s

public static final java.lang.String ACC_PROTECTED_s
See Also:
Constant Field Values

ACC_STATIC_s

public static final java.lang.String ACC_STATIC_s
See Also:
Constant Field Values

ACC_FINAL_s

public static final java.lang.String ACC_FINAL_s
See Also:
Constant Field Values

ACC_VOLATILE_s

public static final java.lang.String ACC_VOLATILE_s
See Also:
Constant Field Values

ACC_TRANSIENT_s

public static final java.lang.String ACC_TRANSIENT_s
See Also:
Constant Field Values

ACC_SYNCHRONIZED_s

public static final java.lang.String ACC_SYNCHRONIZED_s
See Also:
Constant Field Values

ACC_NATIVE_s

public static final java.lang.String ACC_NATIVE_s
See Also:
Constant Field Values

ACC_ABSTRACT_s

public static final java.lang.String ACC_ABSTRACT_s
See Also:
Constant Field Values

ACC_INTERFACE_s

public static final java.lang.String ACC_INTERFACE_s
See Also:
Constant Field Values

cff

protected ClassFileFinder cff
The ClassFileFinder object used to locate bytecode By default, a plain JDK12ClassFileFinder.

Constructor Detail

CPoolReader

public CPoolReader()
Buids a CPoolReader which uses a JDK12ClassFileFinder


CPoolReader

public CPoolReader(java.lang.String classPath)
Buids a CPoolReader which uses a JDK12 with the given application class path

Parameters:
classPath - the application class path to use

CPoolReader

public CPoolReader(ClassFileFinder cff)
Buids a CPoolReader which uses the specifies ClassFileFinder

Parameters:
cff - the ClassFileFinder to use for locating class bytecode
Method Detail

getConstTag_s

public static java.lang.String getConstTag_s(short tag)

getAcc_s

public static java.lang.String getAcc_s(short access_flag)

readClass

public CPoolReader.classfile readClass(java.lang.String className)
                                throws java.io.IOException,
                                       java.lang.ClassNotFoundException
This returns an interpreted class file. The object returned can be a cached instance.

Returns:
a classfile instance with the information about the class
Throws:
java.io.IOException - if an I/O Exception occurs reading the class file
java.lang.ClassNotFoundException - if the class is not found

readClassData

public CPoolReader.classfile readClassData(java.lang.String className,
                                           java.io.InputStream is)
                                    throws java.io.IOException
Throws:
java.io.IOException

readClassData

public CPoolReader.classfile readClassData(java.io.InputStream is)
                                    throws java.io.IOException
Throws:
java.io.IOException

readClassData

public CPoolReader.classfile readClassData(byte[] data)
                                    throws java.io.IOException
Throws:
java.io.IOException

getUsedClasses

public java.lang.String[] getUsedClasses(java.lang.String name)
                                  throws java.io.IOException,
                                         java.lang.ClassNotFoundException
Retrieve the classes known to this .class file Note: The classes are returned in external form

Refer to class description for finding/loading scheme discussion

Returns:
an array containing the external-form fully qualified names of the classes used by the class object
Throws:
java.io.IOException
java.lang.ClassNotFoundException

forNameCalled

public boolean forNameCalled(java.lang.String name)
                      throws java.io.IOException,
                             java.lang.ClassNotFoundException
This method detects the presence of "Class.forName()" call in this classfile.

Returns:
true if the class refers to "Class.forName()" methods
Throws:
java.io.IOException
java.lang.ClassNotFoundException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception