Class ClassHolder

java.lang.Object
org.apache.derby.iapi.services.classfile.ClassHolder
Direct Known Subclasses:
ClassInvestigator

public class ClassHolder extends Object
Based upon "THE class FILE FORMAT" chapter of "The Java Virtual Machine Specification" corresponding to version 1.0.2 of the Java Virtual Machine and 1.0.2 of the Java Language Specification. ISBN 0-201-63452-X, September 1996.
  • Field Details

    • minor_version

      protected int minor_version
      Minor class format number defaults to VMDescriptor.JAVA_CLASS_FORMAT_MINOR_VERSION which currently corresponds to a really old (JDK 1.0.2) setting. The default major and minor value is used by the generated code for Derby's SQL statements. Currently there is no need to bump the version number as the generated code does not take advantage of any of the new elements in the class file format. If such a need exists then this can be bumped. One issue is that the change in format numbers is not well documented.
    • major_version

      protected int major_version
      Minor class format number defaults to VMDescriptor.JAVA_CLASS_FORMAT_MAJOR_VERSION
    • access_flags

      protected int access_flags
    • this_class

      protected int this_class
    • super_class

      protected int super_class
    • interfaces

      protected int[] interfaces
    • field_info

      protected MemberTable field_info
    • method_info

      protected MemberTable method_info
    • attribute_info

      protected Attributes attribute_info
    • cptHashTable

      protected Hashtable<Object,ConstantPoolEntry> cptHashTable
    • cptEntries

      protected Vector<ConstantPoolEntry> cptEntries
    • cptEstimatedSize

      private int cptEstimatedSize
    • searchIndex

      private final CONSTANT_Index_info searchIndex
      Used to search for index entries to avoid object allocation in the case a referecne already exists.
  • Constructor Details

    • ClassHolder

      protected ClassHolder(int estimatedConstantPoolCount)
    • ClassHolder

      public ClassHolder(String fullyQualifiedName, String superClassName, int modifiers)
      This will not define a constructor -- it is up to the caller to add at least one.
  • Method Details

    • put

      private void put(ClassFormatOutput out) throws IOException
      Throws:
      IOException
    • getFileFormat

      public ByteArray getFileFormat() throws IOException
      Convert the object representation of the class into its class file format.
      Throws:
      IOException - error writing the class
    • getModifier

      public int getModifier()
      See Also:
    • getName

      public String getName()
      See Also:
    • addMember

      public ClassMember addMember(String simpleName, String descriptor, int modifier)
      See Also:
    • addFieldReference

      public int addFieldReference(String className, String simpleName, String descriptor)
      See Also:
    • addFieldReference

      public int addFieldReference(ClassMember field)
    • addMethodReference

      public int addMethodReference(String className, String simpleName, String descriptor, boolean isInterface)
      See Also:
    • addReference

      private int addReference(int tag, String className, String simpleName, String descriptor)
    • addReference

      private int addReference(int tag, ClassMember member)
    • addConstant

      public int addConstant(String value)
      See Also:
    • addUtf8

      public int addUtf8(String value)
      See Also:
    • addConstant

      public int addConstant(int value)
      See Also:
    • addConstant

      public int addConstant(float value)
      See Also:
    • addConstant

      public int addConstant(long value)
      See Also:
    • addConstant

      public int addConstant(double value)
      See Also:
    • getConstantPoolIndex

      public int getConstantPoolIndex()
      See Also:
    • addAttribute

      public void addAttribute(String attributeName, ClassFormatOutput info)
    • getSuperClassName

      public String getSuperClassName()
    • addEntry

      protected int addEntry(Object key, ConstantPoolEntry item)
      Generic add entry to constant pool. Includes the logic for an entry to occupy more than one slot (e.g. long).
      Returns:
      The number of slots occupied by the entry. .
    • addDirectEntry

      private int addDirectEntry(ConstantPoolEntry item)
      Add an entry, but only if it doesn't exist.
      Returns:
      the constant pool index of the added or existing item.
    • addIndexReference

      private int addIndexReference(int tag, int i1, int i2)
      Add an index reference.
    • addClassReference

      public int addClassReference(String fullyQualifiedName)
      Add a class entry to the pool.
    • addNameAndType

      private int addNameAndType(String name, String descriptor)
      Add a name and type entry
    • addUtf8Entry

      private CONSTANT_Utf8_info addUtf8Entry(String value)
      Add a UTF8 into the pool and return the index to it.
    • addExtraUtf8

      private CONSTANT_Utf8_info addExtraUtf8(String value)
      Add an extra UTF8 into the pool
    • addString

      private int addString(String value)
      Add a string entry
    • cptPut

      protected void cptPut(ClassFormatOutput out) throws IOException
      Throws:
      IOException
    • getEntry

      public ConstantPoolEntry getEntry(int index)
    • className

      protected String className(int classIndex)
      Return the class name for an index to a CONSTANT_Class_info.
    • findUtf8

      int findUtf8(String value)
      Return the index of a UTF entry or -1 if it doesn't exist.
    • findClass

      public int findClass(String fullyQualifiedName)
      Find a class descriptor (section 4.4.1) and return its index, returns -1 if not found.
    • findNameAndType

      public int findNameAndType(String name, String descriptor)
      Find a name and type descriptor (section 4.4.6) and return it's index.

      returns -1 if not found.

    • findIndexEntry

      protected CONSTANT_Index_info findIndexEntry(int tag, int i1, int i2)
    • findIndexIndex

      protected int findIndexIndex(int tag, int i1, int i2)
    • findMatchingEntry

      protected ConstantPoolEntry findMatchingEntry(Object key)
    • nameIndexToString

      String nameIndexToString(int index)
      get a string (UTF) given a name_index into the constant pool
    • getClassName

      protected String getClassName(int index)
      get the class name of a Class given the index of its CONSTANT_Class_info entry in the Constant Pool.
    • isExternalClassName

      public static boolean isExternalClassName(String className)
    • convertToInternalClassName

      public static String convertToInternalClassName(String externalName)
    • convertToInternalDescriptor

      public static String convertToInternalDescriptor(String externalName)
    • convertToInternal

      private static String convertToInternal(String externalName, boolean descriptor)
    • makeDesc

      private static String makeDesc(char builtin, int arity)
      A helper to build a type description based on a built-in type and an array arity.
    • makeDesc

      private static String makeDesc(String className, int arity, boolean descriptor)
      A helper to build a type description based on a Java class and an array arity. If descriptor is true create a descriptor according to section 4.3.2 of the vm spec. If false create a class name according to sections 4.3.2 and 4.4.1 of the vm spec.