Class BindGen

java.lang.Object
org.jibx.binding.generator.BindGen

public class BindGen extends Object
Binding generator implementation. Although many of the methods in this class use public access, they are intended for use only by the JiBX developers and may change from one release to the next. To make use of this class from your own code, call the main(String[]) method with an appropriate argument list.
Author:
Dennis M. Sosnoski
  • Field Details

    • m_global

      private final GlobalCustom m_global
      Binding generation customizations.
    • m_includeSet

      private final Set m_includeSet
      Set of class names to be included.
    • m_ignoreSet

      private final Set m_ignoreSet
      Set of class names to be ignored.
    • m_directSet

      private final Set m_directSet
      Set of class names to be handled directly.
    • m_superSet

      private final Set m_superSet
      Set of class names subclassed by other classes in binding.
    • m_formatSet

      private final Set m_formatSet
      Set of class names possibly requiring format definitions.
    • m_mappingDetailsMap

      private final Map m_mappingDetailsMap
      Map from fully-qualified class name to mapping details.
    • m_typeNamesMap

      private final Map m_typeNamesMap
      Map from namespace URI to UniqueNameSet for type names.
    • m_elementNamesMap

      private final Map m_elementNamesMap
      Map from namespace URI to UniqueNameSet for element names.
    • m_targetPackage

      private String m_targetPackage
      Target package for binding code generation.
    • m_directory

      private BindingOrganizer m_directory
      Directory for bindings being built.
  • Constructor Details

    • BindGen

      public BindGen(GlobalCustom glob)
      Create a generator based on a particular set of customizations.
      Parameters:
      glob -
  • Method Details

    • isValueClass

      public boolean isValueClass(String type)
      Check if a class represents a simple value. TODO: implement ClassCustom hooks for this purpose
      Parameters:
      type - fully qualified class name
      Returns:
      true if simple value, false if not
    • checkInclude

      public boolean checkInclude(String type)
      Check if a class needs to be included in the binding. This checks all members of the class and if necessary superclasses, returning true if any member is ultimately found with a simple value.
      Parameters:
      type - fully qualified class name
      Returns:
      true if class to be included in binding, false if it should be skipped
    • expandReferences

      public void expandReferences(String type, ReferenceCountMap refmap)
      Expand all references from a class. This checks the types of all members of the class, counting references and calling itself recursively for any types which are not primitives and not java.* or javax.* classes. It also expands the superclass, if specified by the class customizations.
      Parameters:
      type - fully qualified class name
      refmap - reference count map
    • setTypes

      private void setTypes(ValueCustom memb, StructureElementBase struct)
      Set creation information for structure binding component. This includes the declared type, as well as the create type and factory method.
      Parameters:
      memb -
      struct -
    • defineCollection

      public void defineCollection(String itype, String iname, CollectionElement coll, BindingHolder hold)
      Define the details of a collection binding. Collection bindings may be empty (in the case where the item type is directly mapped), have a <value> child element, or have either a mapping reference or direct definition <structure> child element. This determines the appropriate form based on the item type.
      Parameters:
      itype - item type
      iname - item name
      coll -
      hold -
    • addMemberBindings

      private void addMemberBindings(ClassCustom cust, Map exmethmap, Map inmethmap, NestingElementBase parent, BindingHolder hold)
      Add binding details for the actual members of a class, excluding any members which have been handled separately.
      Parameters:
      cust - class customization information
      exmethmap - map from property method names to be excluded to the corresponding property customizations
      inmethmap - map from property method names included in binding to the corresponding property customizations (populated by this method, null if not needed)
      parent - containing binding component
      hold - binding holder
    • fillStructure

      private void fillStructure(ClassCustom cust, ValueCustom memb, Map inmethmap, StructureElement struct, BindingHolder hold)
      Add binding details for the full representation of a class. This includes superclasses, if configured, and makes use of any appropriate <mapping> definitions as part of the binding.
      Parameters:
      cust - class customization information
      memb - member customization information (null if implicit reference, rather than member)
      inmethmap - map from property method names included in binding to the corresponding property customizations, (needed in case of interface or overridden methods; populated by this method, null if not needed)
      struct - structure element referencing the class
      hold - binding holder
    • addMapping

      private void addMapping(String type, BindingMappingDetail detail)
      Add the <mapping> definition for a class to a binding. This creates either an abstract mapping with a type name, or a concrete mapping with an element name, as determined by the passed-in mapping information. If the class is a concrete mapping that extends or implements another class with an anonymous abstract mapping, the created <mapping> will extend that base mapping. TODO: type substitution requires extending the binding definition
      Parameters:
      type - fully qualified class name
      detail - mapping details
    • createMapping

      private MappingElement createMapping(String type, ClassCustom cust)
      Create and initialize a <mapping> element.
      Parameters:
      type -
      cust -
      Returns:
      mapping
    • addMappingDetails

      private BindingMappingDetail addMappingDetails(Boolean abstr, QName ename, String type)
      Add the details for mapping a class. TODO: should add checks for unique particle attribution rule - need to check for duplicate element names without a required element in between, and if found alter the names after the first; note that duplicates may be from the base type, or from a group; also need to make sure attribute names are unique
      Parameters:
      abstr - force abstract mapping flag
      ename - element name for concrete mapping (null if unspecified)
      type - fully-qualified class name
      Returns:
      mapping details
    • isQNameUsed

      private boolean isQNameUsed(QName qname, Map map)
      Check if a qualified name is already defined within a category of names.
      Parameters:
      qname - requested qualified name (null allowed, always returns false)
      map - namespace URI to UniqueNameSet map for category
      Returns:
      true if used, false if not
    • fixQName

      private QName fixQName(QName qname, Map map)
      Fix local name to be unique within the appropriate namespace for a category of names.
      Parameters:
      qname - requested qualified name (null allowed, always returns null)
      map - namespace URI to UniqueNameSet map for category
      Returns:
      unique version of qualified name
    • fixElementName

      private QName fixElementName(QName qname)
      Fix element local name to be unique within the appropriate namespace.
      Parameters:
      qname - requested qualified name (null allowed, always returns null)
      Returns:
      unique version of qualified name
    • fixTypeName

      private QName fixTypeName(QName qname)
      Fix type local name to be unique within the appropriate namespace.
      Parameters:
      qname - requested qualified name (null allowed, always returns null)
      Returns:
      unique version of qualified name
    • findReferences

      private void findReferences(List classes, ReferenceCountMap refmap)
      Find closure of references from a supplied list of classes. References counted, and direct references are accumulated for handling. The supplied list may include generic classes with type parameters.
      Parameters:
      classes -
      refmap -
    • flagMultipleReferences

      private void flagMultipleReferences(ReferenceCountMap refmap)
      Flag classes referenced more than once to be handled with <mapping> definitions.
      Parameters:
      refmap -
    • addReferencedMappings

      private void addReferencedMappings(ReferenceCountMap refmap)
      Add mapping details for classes referenced more than once, or classes with mapping forced.
      Parameters:
      refmap -
    • generateReferencedMappings

      private void generateReferencedMappings(ReferenceCountMap refmap)
      Generate the mapping definitions for classes referenced more than once.
      Parameters:
      refmap -
    • generateMappings

      private void generateMappings(List classes)
      Generate mappings for a list of classes. The mapping details must have been configured before this method is called.
      Parameters:
      classes -
    • fixBaseClasses

      private void fixBaseClasses()
      Fix the base classes that are to be used as extension types. This step is needed to generate the substitution group structures for classes which are both referenced directly and extended by other classes. The method must be called after all mapping details have been constucted but before the actual binding generation.
    • generateFormats

      private void generateFormats()
      Generate any required format definitions. Format definitions are used for all classes defining serializer or deserializer methods.
    • generate

      public void generate(Boolean abstr, List classes)
      Generate binding(s) for a list of classes. This creates a <mapping> definition for each class in the list, and either embeds <structure> definitions or creates separate <mapping>s for other classes referenced by these classes. If all the classes use the same namespace only the binding for that namespace will be created; otherwise, a separate binding will be created for each namespace.
      Parameters:
      abstr - force abstract mapping flag (use both abstract and concrete if null)
      classes - class list
    • generateSpecified

      public void generateSpecified(ArrayList qnames, List concrs, List abstrs)
      Generate binding(s) for lists of classes. This creates a <mapping> definition for each class in the lists, and either embeds <structure> definitions or creates separate <mapping>s for other classes referenced by these classes. If all the classes use the same namespace only the binding for that namespace will be created; otherwise, a separate binding will be created for each namespace.
      Parameters:
      qnames - list of names for concrete mappings
      concrs - list of classes to be given concrete mappings
      abstrs - list of classes to be given abstract mappings
    • getMappingDetail

      public BindingMappingDetail getMappingDetail(String type)
      Get the mapping details for a class. This method should only be used after the generate(Boolean, List) method has been called.
      Parameters:
      type - fully-qualified class name
      Returns:
      mapping details, or null if none
    • getBinding

      public BindingHolder getBinding(String uri)
      Get the binding definition for a namespace, which must already have been created. This method should only be used after the generate(Boolean, List) method has been called. It delegates to the BindingOrganizer implementation.
      Parameters:
      uri -
      Returns:
      binding holder
    • addRootUris

      public void addRootUris(Collection uris)
      Adds a collection of namespace URIs to be referenced at root binding level.
      Parameters:
      uris -
    • addBinding

      public BindingHolder addBinding(String uri, boolean dflt)
      Get the binding definition for a namespace, creating a new one if not previously defined. This method should only be used after the generate(Boolean, List) method has been called. It delegates to the BindingOrganizer implementation.
      Parameters:
      uri -
      dflt - namespace is default for elements in binding flag
      Returns:
      binding holder
    • finish

      public BindingHolder finish(String name)
      Complete the generated bindings. This prepares the generated bindings for writing to the file system, if desired.
      Parameters:
      name - file name for root or singleton binding definition
      Returns:
      holder for root binding definition
    • validateFiles

      public List validateFiles(File dir, IClassLocator loc, BindingHolder root) throws IOException, JiBXException
      Write and validate the generated binding definition files.
      Parameters:
      dir - target directory (bindings not written if null)
      loc - class locator for binding validation (ignored if no target directory supplied)
      root - holder for root binding definition
      Returns:
      binding definitions, or null if validation error
      Throws:
      IOException
      JiBXException
    • main

      public static void main(String[] args) throws JiBXException, IOException
      Run the binding generation using command line parameters.
      Parameters:
      args -
      Throws:
      JiBXException
      IOException