Class MungedClass

java.lang.Object
org.jibx.binding.classes.MungedClass

public class MungedClass extends Object
Modifiable class handler. Each instance controls changes to a particular class modified by one or more binding definitions. As methods are generated they're checked for uniqueness. If an already-generated method is found with the same characteristics (including byte code) as the one being generated, the already-generated is used instead.
Author:
Dennis M. Sosnoski
  • Field Details

    • EMPTY_CLASSFILE_ARRAY

      private static final ClassFile[] EMPTY_CLASSFILE_ARRAY
      Empty class file array.
    • EXTRA_METHODS_MATCHES

      private static final String[] EXTRA_METHODS_MATCHES
      Name and signature for generated methods without standard prefix.
    • s_classes

      private static ArrayList s_classes
      Munged class information.
    • s_classNameSet

      private static HashSet s_classNameSet
      Set of class names in list (used to assure uniqueness).
    • s_classMap

      private static HashMap s_classMap
      Map from generated class to binding information.
    • s_directories

      private static HashMap s_directories
      Map of directories already checked for JiBX classes.
    • s_nameMap

      private static HashMap s_nameMap
      Map from class name to binding information.
    • s_pendingClasses

      private static ArrayList s_pendingClasses
      Munged classes to be unique-added at end of binding.
    • m_classFile

      private ClassFile m_classFile
      Munged class file information.
    • m_methodMap

      private HashMap m_methodMap
      Map from method byte code and signature to method item.
    • m_existingMethods

      private ExistingMethod[] m_existingMethods
      Existing binding methods in class.
    • m_factoryList

      private String m_factoryList
      List of factory names for this class.
  • Constructor Details

    • MungedClass

      private MungedClass(ClassFile cf)
      Constructor. This sets up for modifying a class with added methods.
      Parameters:
      cf - owning class file information
  • Method Details

    • getClassFile

      ClassFile getClassFile()
      Get munged class file information.
      Returns:
      class file information for bound class
    • purgeUnusedMethods

      private void purgeUnusedMethods()
      Delete pre-existing binding methods that are no longer needed.
    • getUniqueMethod

      BindingMethod getUniqueMethod(MethodBuilder builder, boolean suffix)
      Get unique method. If a method matching the byte code of the supplied method has already been defined the existing method is returned. Otherwise the method is added to the definitions. If necessary, a number suffix is appended to the method name to prevent conflicts with existing names.
      Parameters:
      builder - method to be defined
      suffix - append name suffix to assure uniqueness flag
      Returns:
      defined method item
    • getUniqueSupportClass

      public static ClassFile getUniqueSupportClass(ClassFile cf)
      Get unique generated support class. Allows tracking of all generated classes for common handling with the bound classes. Each generated support class is associated with a particular bound class.
      Parameters:
      cf - generated class file
      Returns:
      unique class file information
    • checkDirectory

      static void checkDirectory(File root, String pack) throws JiBXException
      Check directory for JiBX generated files. Scans through all class files in the target directory and loads any that start with the JiBX identifier string which have not been added to the preserve list.
      Parameters:
      root - class path root for directory (non-null)
      pack - package relative to root directory
      Throws:
      JiBXException - on configuration error
    • addFactory

      void addFactory(String fact)
      Add binding factory to class. The binding factories are accumulated as a delimited string during generation, then dumped to a static field in the class at the end.
      Parameters:
      fact - binding factory name
    • setFactoryList

      void setFactoryList()
      Generate factory list. Adds or replaces the existing static array of factories in the class.
    • getInstance

      static MungedClass getInstance(ClassFile cf) throws JiBXException
      Get modification tracking information for class.
      Parameters:
      cf - information for class to be modified (must be writable)
      Returns:
      binding information for class
      Throws:
      JiBXException - on configuration error
    • delayedAddUnique

      public static void delayedAddUnique(ClassFile cf)
      Add unique support class at end of binding process. This allows a class to be constructed in steps during handling of one or more bindings, with the class finished and checked for uniqueness only after all bindings have been handled. The actual add of the class is done during the fixDispositions() handling.
      Parameters:
      cf - class file to be added as unique support class at end of binding
    • addModifiedClass

      public static void addModifiedClass(ClassFile cf)
      Add class file to set modified. This uses the class name as a identifier to prevent duplicate entries in the list, so that classes which are still under construction can be handled.
      Parameters:
      cf -
    • fixDispositions

      public static ClassFile[][] fixDispositions()
      Finalize class name assignments and dispositions.
      Returns:
      three-way array of class files, for modified, unchanged, and deleted
    • writeChanges

      public static void writeChanges() throws JiBXException
      Write all modified class files, and delete all obsolete class files from previous runs of the binding compiler.
      Throws:
      JiBXException - on write error
    • reset

      public static void reset()
      Discard cached information and reset in preparation for a new binding run.