Package org.jibx.binding
Class BindingGenerator
- java.lang.Object
-
- org.jibx.binding.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.
-
-
-
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 resultsmixed
- use camel case in element namesuri
- 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 informationcontain
- 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 informationprops
- list of properties specified for classinternal
- allow private get/set methods flagcontain
- 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 informationcontain
- 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 informationfname
- 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 informationabstr
- 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
, andjava.lang.Object
. Exception classes thrown by the methods are also optionally accumulated.- Parameters:
cname
- target class namemnames
- method names to be checkeddataset
- set for accumulation of data classes (optional, data classes not recorded ifnull
)exceptset
- set for accumulation of exception classes (optional, data classes not recorded ifnull
)- 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 bindingabstracts
- set of classes to be handled with abstract mappings in bindingcustoms
- map of customized class names to marshaller/unmarshaller class namesbeans
- map of class names to supplied lists of propertiesenums
- map of typesafe enumeration classes to deserializer methodsignores
- 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
-
-