Class BindingGenerator


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

      Fields 
      Modifier and Type Field Description
      private static java.lang.String CURRENT_VERSION
      Generator version.
      private java.util.HashMap m_beanNames
      Class names to properties list map.
      private java.util.HashMap m_enumerationNames
      Class names to deserializers map for typesafe enumerations.
      private java.util.HashSet m_ignoreNames
      Class names to be treated like interfaces (not mapped directly).
      private java.util.HashMap m_mappedNames
      Class names to mapped element names map.
      private boolean m_mixedCase
      Use camel case for XML names flag.
      private java.lang.String m_namespaceUri
      Namespace URI for elements.
      private java.util.HashSet m_structureNames
      Class names bound as nested structures.
      private ObjectStack m_structureStack
      Stack of structure definitions in progress (used to detect cycles).
      private boolean m_verbose
      Show verbose output flag.
      private static java.util.HashSet s_objectPrimitiveSet
      Set of objects treated as primitives.
    • Constructor Summary

      Constructors 
      Constructor Description
      BindingGenerator()
      Default constructor.
      BindingGenerator​(boolean verbose, boolean mixed, java.lang.String uri)
      Constructor with settings specified.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String convertName​(java.lang.String base)
      Convert class or unprefixed field name to element or attribute name.
      private MappingElementBase createMapping​(ClassFile cf, boolean abstr)
      Create the mapping element for a particular class.
      private StructureElement createStructure​(ClassFile cf, java.lang.String fname)
      Create the structure element for a particular class.
      private void defineFields​(ClassFile cf, ContainerElementBase contain)
      Construct the list of child binding components that define the binding structure for fields of a particular class.
      private void defineProperties​(ClassFile cf, java.util.ArrayList props, boolean internal, ContainerElementBase contain)
      Construct the list of child binding components that define the binding structure corresponding to properties of a particular class.
      private void defineStructure​(ClassFile cf, ContainerElementBase contain)
      Construct the list of child binding components that define the binding structure corresponding to a particular class.
      java.lang.String elementName​(java.lang.String cname)
      Generate structure element name from class name using set conversions.
      static void findClassesUsed​(java.lang.String cname, java.util.ArrayList mnames, java.util.HashSet dataset, java.util.HashSet exceptset)
      Get the set of data classes passed to or returned by a list of methods within a class.
      BindingElement generate​(java.util.ArrayList names, java.util.HashSet abstracts, java.util.HashMap customs, java.util.HashMap beans, java.util.HashMap enums, java.util.ArrayList ignores)
      Generate a set of bindings using supplied classpaths and class names.
      private static boolean isMappable​(java.lang.String cname)  
      static void main​(java.lang.String[] args)
      Main method for running compiler as application.
      private void nestingIndent​(java.io.PrintStream pw)
      Indent to proper depth for current item.
      void setCamelCase​(boolean camel)
      Set control flag for camel case element naming.
      void setVerbose​(boolean verbose)
      Set control flag for verbose processing reports.
      private java.lang.String valueName​(java.lang.String fname)
      Generate structure element name from class name using set conversions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CURRENT_VERSION

        private static java.lang.String CURRENT_VERSION
        Generator version.
      • s_objectPrimitiveSet

        private static java.util.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 java.lang.String m_namespaceUri
        Namespace URI for elements.
      • m_mappedNames

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

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

        private java.util.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 java.util.HashSet m_structureNames
        Class names bound as nested structures.
      • m_ignoreNames

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

      • BindingGenerator

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

        public BindingGenerator​(boolean verbose,
                                boolean mixed,
                                java.lang.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 Detail

      • 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​(java.io.PrintStream pw)
        Indent to proper depth for current item.
        Parameters:
        pw - output print stream to be indented
      • convertName

        private java.lang.String convertName​(java.lang.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 java.lang.String elementName​(java.lang.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 java.lang.String valueName​(java.lang.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,
                                      java.util.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,
                                                 java.lang.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​(java.lang.String cname)
      • findClassesUsed

        public static void findClassesUsed​(java.lang.String cname,
                                           java.util.ArrayList mnames,
                                           java.util.HashSet dataset,
                                           java.util.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​(java.util.ArrayList names,
                                       java.util.HashSet abstracts,
                                       java.util.HashMap customs,
                                       java.util.HashMap beans,
                                       java.util.HashMap enums,
                                       java.util.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​(java.lang.String[] args)
        Main method for running compiler as application.
        Parameters:
        args - command line arguments