Class BindingGenerator

java.lang.Object
org.jibx.binding.BindingGenerator

public class BindingGenerator extends Object
Binding generator. This loads the specified input classes and processes them to generate a default binding definition.
Author:
Dennis M. Sosnoski
  • Field Details

    • CURRENT_VERSION

      private static String CURRENT_VERSION
      Generator version.
    • s_objectPrimitiveSet

      private static HashSet s_objectPrimitiveSet
      Set of objects treated as primitives.
    • m_verbose

      private boolean m_verbose
      Show verbose output flag.
    • m_mixedCase

      private boolean m_mixedCase
      Use camel case for XML names flag.
    • m_namespaceUri

      private String m_namespaceUri
      Namespace URI for elements.
    • m_mappedNames

      private HashMap m_mappedNames
      Class names to mapped element names map.
    • m_beanNames

      private HashMap m_beanNames
      Class names to properties list map.
    • m_enumerationNames

      private HashMap m_enumerationNames
      Class names to deserializers map for typesafe enumerations.
    • m_structureStack

      private ObjectStack m_structureStack
      Stack of structure definitions in progress (used to detect cycles).
    • m_structureNames

      private HashSet m_structureNames
      Class names bound as nested structures.
    • m_ignoreNames

      private HashSet m_ignoreNames
      Class names to be treated like interfaces (not mapped directly).
  • Constructor Details

    • BindingGenerator

      public BindingGenerator()
      Default constructor. This just initializes all options disabled.
    • BindingGenerator

      public BindingGenerator(boolean verbose, boolean mixed, String uri)
      Constructor with settings specified.
      Parameters:
      verbose - report binding details and results
      mixed - use camel case in element names
      uri - namespace URI for element bindings
  • Method Details

    • setVerbose

      public void setVerbose(boolean verbose)
      Set control flag for verbose processing reports.
      Parameters:
      verbose - report verbose information in processing bindings flag
    • setCamelCase

      public void setCamelCase(boolean camel)
      Set control flag for camel case element naming.
      Parameters:
      camel - use camel case element naming flag
    • nestingIndent

      private void nestingIndent(PrintStream pw)
      Indent to proper depth for current item.
      Parameters:
      pw - output print stream to be indented
    • convertName

      private String convertName(String base)
      Convert class or unprefixed field name to element or attribute name.
      Parameters:
      base - class or simple field name to be converted
      Returns:
      element or attribute name
    • elementName

      public String elementName(String cname)
      Generate structure element name from class name using set conversions.
      Parameters:
      cname - class name to be converted
      Returns:
      element name for instances of class
    • valueName

      private String valueName(String fname)
      Generate structure element name from class name using set conversions.
      Parameters:
      fname - field name to be converted
      Returns:
      element name for instances of class
    • defineFields

      private void defineFields(ClassFile cf, ContainerElementBase contain) throws JiBXException
      Construct the list of child binding components that define the binding structure for fields of a particular class. This binds all non-final/non-static/non-transient fields of the class, if necessary creating nested structure elements for unmapped classes referenced by the fields.
      Parameters:
      cf - class information
      contain - binding structure container element
      Throws:
      JiBXException - on error in binding generation
    • defineProperties

      private void defineProperties(ClassFile cf, ArrayList props, boolean internal, ContainerElementBase contain) throws JiBXException
      Construct the list of child binding components that define the binding structure corresponding to properties of a particular class. This binds the specified properties of the class, using get/set methods, if necessary creating nested structure elements for unmapped classes referenced by the properties.
      Parameters:
      cf - class information
      props - list of properties specified for class
      internal - allow private get/set methods flag
      contain - binding structure container element
      Throws:
      JiBXException - on error in binding generation
    • defineStructure

      private void defineStructure(ClassFile cf, ContainerElementBase contain) throws JiBXException
      Construct the list of child binding components that define the binding structure corresponding to a particular class. This binds all non-final/non-static/non-transient fields of the class, if necessary creating nested structure elements for unmapped classes referenced by the fields.
      Parameters:
      cf - class information
      contain - binding structure container element
      Throws:
      JiBXException - on error in binding generation
    • createStructure

      private StructureElement createStructure(ClassFile cf, String fname) throws JiBXException
      Create the structure element for a particular class. This maps all non-final/non-static/non-transient fields of the class, if necessary creating nested structures.
      Parameters:
      cf - class information
      fname - name of field supplying reference
      Throws:
      JiBXException - on error in binding generation
    • createMapping

      private MappingElementBase createMapping(ClassFile cf, boolean abstr) throws JiBXException
      Create the mapping element for a particular class. This maps all non-final/non-static/non-transient fields of the class, if necessary creating nested structures.
      Parameters:
      cf - class information
      abstr - force abstract mapping flag
      Throws:
      JiBXException - on error in binding generation
    • isMappable

      private static boolean isMappable(String cname)
    • findClassesUsed

      public static void findClassesUsed(String cname, ArrayList mnames, HashSet dataset, HashSet exceptset) throws JiBXException
      Get the set of data classes passed to or returned by a list of methods within a class. The classes returned exclude primitive types, wrappers, java.lang.String, and java.lang.Object. Exception classes thrown by the methods are also optionally accumulated.
      Parameters:
      cname - target class name
      mnames - method names to be checked
      dataset - set for accumulation of data classes (optional, data classes not recorded if null)
      exceptset - set for accumulation of exception classes (optional, data classes not recorded if null)
      Throws:
      JiBXException - on error in loading class information
    • generate

      public BindingElement generate(ArrayList names, HashSet abstracts, HashMap customs, HashMap beans, HashMap enums, ArrayList ignores) throws JiBXException
      Generate a set of bindings using supplied classpaths and class names.
      Parameters:
      names - list of class names to be included in binding
      abstracts - set of classes to be handled with abstract mappings in binding
      customs - map of customized class names to marshaller/unmarshaller class names
      beans - map of class names to supplied lists of properties
      enums - map of typesafe enumeration classes to deserializer methods
      ignores - list of non-interface classes to be treated as interfaces (no mapping, but mapped subclasses are used at runtime)
      Throws:
      JiBXException - if error in generating the binding definition
    • main

      public static void main(String[] args)
      Main method for running compiler as application.
      Parameters:
      args - command line arguments