org.jibx.binding.generator
Class BindGen

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

public class BindGen
extends java.lang.Object

Binding generator implementation.

Author:
Dennis M. Sosnoski

Field Summary
private  BindingOrganizer m_directory
          Directory for bindings being built.
private  java.util.Set m_directSet
          Set of class names to be handled directly.
private  java.util.Map m_elementNamesMap
          Map from namespace URI to UniqueNameSet for element names.
private  java.util.Set m_formatSet
          Set of class names possibly requiring format definitions.
private  GlobalCustom m_global
          Binding generation customizations.
private  java.util.Set m_ignoreSet
          Set of class names to be ignored.
private  java.util.Set m_includeSet
          Set of class names to be included.
private  java.util.Map m_mappingDetailsMap
          Map from fully-qualified class name to mapping details.
private  java.util.Set m_superSet
          Set of class names subclassed by other classes in binding.
private  java.lang.String m_targetPackage
          Target package for binding code generation.
private  java.util.Map m_typeNamesMap
          Map from namespace URI to UniqueNameSet for type names.
 
Constructor Summary
BindGen(GlobalCustom glob)
          Create a generator based on a particular set of customizations.
 
Method Summary
private  void addMapping(java.lang.String type, BindingMappingDetail detail)
          Add the <mapping> definition for a class to a binding.
private  BindingMappingDetail addMappingDetails(java.lang.Boolean abstr, QName ename, java.lang.String type)
          Add the details for mapping a class.
private  void addMemberBindings(ClassCustom cust, java.util.Map exmethmap, java.util.Map inmethmap, NestingElementBase parent, BindingHolder hold)
          Add binding details for the actual members of a class, excluding any members which have been handled separately.
private  void addReferencedMappings(ReferenceCountMap refmap)
          Add mapping details for classes referenced more than once, or classes with mapping forced.
 boolean checkInclude(java.lang.String type)
          Check if a class needs to be included in the binding.
private  MappingElement createMapping(java.lang.String type, ClassCustom cust)
          Create and initialize a <mapping> element.
 void defineCollection(java.lang.String itype, java.lang.String iname, CollectionElement coll, BindingHolder hold)
          Define the details of a collection binding.
 void expandReferences(java.lang.String type, ReferenceCountMap refmap)
          Expand all references from a class.
private  void fillStructure(ClassCustom cust, ValueCustom memb, java.util.Map inmethmap, StructureElement struct, BindingHolder hold)
          Add binding details for the full representation of a class.
 BindingHolder findBinding(java.lang.String uri)
          Find the binding to be used for a particular namespace.
private  void findReferences(java.util.List classes, ReferenceCountMap refmap)
          Find closure of references from a supplied list of classes.
 BindingHolder finish(java.lang.String name, java.lang.String[] adduris)
          Complete the generated bindings.
private  void fixBaseClasses()
          Fix the base classes that are to be used as extension types.
private  QName fixElementName(QName qname)
          Fix element local name to be unique within the appropriate namespace.
private  QName fixQName(QName qname, java.util.Map map)
          Fix local name to be unique within the appropriate namespace for a category of names.
private  QName fixTypeName(QName qname)
          Fix type local name to be unique within the appropriate namespace.
private  void flagMultipleReferences(ReferenceCountMap refmap)
          Flag classes referenced more than once to be handled with <mapping> definitions.
 void generate(java.lang.Boolean abstr, java.util.List classes)
          Generate binding(s) for a list of classes.
private  void generateFormats()
          Generate any required format definitions.
private  void generateMappings(java.util.List classes)
          Generate mappings for a list of classes.
private  void generateReferencedMappings(ReferenceCountMap refmap)
          Generate the mapping definitions for classes referenced more than once.
 void generateSpecified(java.util.ArrayList qnames, java.util.List concrs, java.util.List abstrs)
          Generate binding(s) for lists of classes.
 BindingHolder getBinding(java.lang.String uri)
          Get the binding definition for a namespace.
 BindingMappingDetail getMappingDetail(java.lang.String type)
          Get the mapping details for a class.
 java.util.ArrayList getNamespaces()
          Get the list of binding namespace URIs.
private  boolean isQNameUsed(QName qname, java.util.Map map)
          Check if a qualified name is already defined within a category of names.
 boolean isValueClass(java.lang.String type)
          Check if a class represents a simple value.
static void main(java.lang.String[] args)
          Run the binding generation using command line parameters.
private  void setTypes(ValueCustom memb, StructureElementBase struct)
          Set creation information for structure binding component.
 java.util.List validateFiles(java.io.File dir, IClassLocator loc, BindingHolder root)
          Write and validate the generated binding definition files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_global

private final GlobalCustom m_global
Binding generation customizations.


m_includeSet

private final java.util.Set m_includeSet
Set of class names to be included.


m_ignoreSet

private final java.util.Set m_ignoreSet
Set of class names to be ignored.


m_directSet

private final java.util.Set m_directSet
Set of class names to be handled directly.


m_superSet

private final java.util.Set m_superSet
Set of class names subclassed by other classes in binding.


m_formatSet

private final java.util.Set m_formatSet
Set of class names possibly requiring format definitions.


m_mappingDetailsMap

private final java.util.Map m_mappingDetailsMap
Map from fully-qualified class name to mapping details.


m_typeNamesMap

private final java.util.Map m_typeNamesMap
Map from namespace URI to UniqueNameSet for type names.


m_elementNamesMap

private final java.util.Map m_elementNamesMap
Map from namespace URI to UniqueNameSet for element names.


m_targetPackage

private java.lang.String m_targetPackage
Target package for binding code generation.


m_directory

private BindingOrganizer m_directory
Directory for bindings being built.

Constructor Detail

BindGen

public BindGen(GlobalCustom glob)
Create a generator based on a particular set of customizations.

Parameters:
glob -
Method Detail

isValueClass

public boolean isValueClass(java.lang.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(java.lang.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(java.lang.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(java.lang.String itype,
                             java.lang.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,
                               java.util.Map exmethmap,
                               java.util.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,
                           java.util.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(java.lang.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(java.lang.String type,
                                     ClassCustom cust)
Create and initialize a <mapping> element.

Parameters:
type -
cust -
Returns:
mapping

addMappingDetails

private BindingMappingDetail addMappingDetails(java.lang.Boolean abstr,
                                               QName ename,
                                               java.lang.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,
                            java.util.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,
                       java.util.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(java.util.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(java.util.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(java.lang.Boolean abstr,
                     java.util.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(java.util.ArrayList qnames,
                              java.util.List concrs,
                              java.util.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(java.lang.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

findBinding

public BindingHolder findBinding(java.lang.String uri)
Find the binding to be used for a particular namespace. If this is the first time a particular namespace was requested, a new binding will be created for that namespace and returned. This method just delegates to the BindingOrganizer implementation.

Parameters:
uri - namespace URI (null if no namespace)
Returns:
binding holder

getBinding

public BindingHolder getBinding(java.lang.String uri)
Get the binding definition for a namespace. 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, or null if none

getNamespaces

public java.util.ArrayList getNamespaces()
Get the list of binding namespace URIs.

Returns:
namespaces

finish

public BindingHolder finish(java.lang.String name,
                            java.lang.String[] adduris)
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
adduris - list of namespaces to be added to bindings, if not already defined
Returns:
holder for root binding definition

validateFiles

public java.util.List validateFiles(java.io.File dir,
                                    IClassLocator loc,
                                    BindingHolder root)
                             throws java.io.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:
java.io.IOException
JiBXException

main

public static void main(java.lang.String[] args)
                 throws JiBXException,
                        java.io.IOException
Run the binding generation using command line parameters.

Parameters:
args -
Throws:
JiBXException
java.io.IOException


Project Web Site