Package org.jibx.binding
Class BindingGenerator
java.lang.Object
org.jibx.binding.BindingGenerator
Binding generator. This loads the specified input classes and processes them
to generate a default binding definition.
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static String
Generator version.private HashMap
Class names to properties list map.private HashMap
Class names to deserializers map for typesafe enumerations.private HashSet
Class names to be treated like interfaces (not mapped directly).private HashMap
Class names to mapped element names map.private boolean
Use camel case for XML names flag.private String
Namespace URI for elements.private HashSet
Class names bound as nested structures.private ObjectStack
Stack of structure definitions in progress (used to detect cycles).private boolean
Show verbose output flag.private static HashSet
Set of objects treated as primitives. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.BindingGenerator
(boolean verbose, boolean mixed, String uri) Constructor with settings specified. -
Method Summary
Modifier and TypeMethodDescriptionprivate String
convertName
(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, 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, 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.elementName
(String cname) Generate structure element name from class name using set conversions.static void
findClassesUsed
(String cname, ArrayList mnames, HashSet dataset, HashSet exceptset) Get the set of data classes passed to or returned by a list of methods within a class.generate
(ArrayList names, HashSet abstracts, HashMap customs, HashMap beans, HashMap enums, ArrayList ignores) Generate a set of bindings using supplied classpaths and class names.private static boolean
isMappable
(String cname) static void
Main method for running compiler as application.private void
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 String
Generate structure element name from class name using set conversions.
-
Field Details
-
CURRENT_VERSION
Generator version. -
s_objectPrimitiveSet
Set of objects treated as primitives. -
m_verbose
private boolean m_verboseShow verbose output flag. -
m_mixedCase
private boolean m_mixedCaseUse camel case for XML names flag. -
m_namespaceUri
Namespace URI for elements. -
m_mappedNames
Class names to mapped element names map. -
m_beanNames
Class names to properties list map. -
m_enumerationNames
Class names to deserializers map for typesafe enumerations. -
m_structureStack
Stack of structure definitions in progress (used to detect cycles). -
m_structureNames
Class names bound as nested structures. -
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
Constructor with settings specified.- Parameters:
verbose
- report binding details and resultsmixed
- use camel case in element namesuri
- 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
Indent to proper depth for current item.- Parameters:
pw
- output print stream to be indented
-
convertName
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
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
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
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, 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
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
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
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
-
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
, 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(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 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
Main method for running compiler as application.- Parameters:
args
- command line arguments
-