Package org.jibx.binding.def
Class BindingBuilder
java.lang.Object
org.jibx.binding.def.BindingBuilder
Binding definition builder. This processes the binding definition file to
generate the code generation structure.
- Author:
- Dennis M. Sosnoski
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Base class for containers. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
private static final String[]
private static final int[]
private static final String[]
private static final int[]
private static final String
private static final String
private static final String
Definitions for "binding" element use "BINDING" prefix.private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String[]
private static final int[]
private static final String
private static final String
Definitions for "collection" element use "COLLECTION" prefix.private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String[]
private static final String[]
private static final String[]
private static final int[]
private static final String
private static final String
private static final int
private static final int
private static final int
private static final String
Definitions for "format" element use "FORMAT" prefix.private static final String
private static final String
private static final String[]
private static final int[]
private static final String
Definitions for "include" element use "INCLUDE" prefix.private static final String
private static final String
(package private) static final int
(package private) static final int
(package private) static final int
private static final String
private static final String
private static final String
Definitions for "mapping" element use "MAPPING" prefix.private static final String
private static final String
private static final String
private static final String
private static final String[]
private static final int[]
(package private) static final int
(package private) static final int
private static final String
private static final String
Definitions for "namespace" element use "NAMESPACE" prefix.private static final String
private static final String
private static final String[]
private static final int[]
private static final String
Definitions for "structure" element use "STRUCTURE" prefix.private static final String
private static final String
private static final String
private static final String
Attribute namespace used for binding definition file.private static final String
Element namespace used for binding definition file.private static final String
private static final String
private static final String
private static final String
Definitions for "value" element use "VALUE" prefix.private static final String
private static final String
private static final String
private static final String[]
private static final int[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
buildEnumDeserializeMethod
(String type, String typesig, String evfull, ExceptionMethodBuilder dmeth) Fill in the body of an enum deserialization method.private static void
buildEnumSerializeMethod
(String evfull, ExceptionMethodBuilder smeth) Fill in the body of an enum serialization method.private static void
buildEnumValueMethods
(boolean exists, String type, String evmeth) Add (or verify) serializer and deserializer methods to enum class with special value method.private static boolean
Check if attributes define a direct object reference.private static boolean
Check if attributes define a mapping reference.private static boolean
Check if attributes supply a name definition.private static boolean
Check for component object present.private static boolean
Check for optional property.private static boolean
Check for property definition present.private static void
preserveMethodClass
(String name) Force the class containing a method to be preserved from modification.static BindingDefinition
unmarshalBindingDefinition
(UnmarshallingContext ctx, String name, URL root) Unmarshal binding definition.private static DirectObject
unmarshalDirectObj
(UnmarshallingContext ctx, String type, IContainer parent, DefinitionContext defc, String mapname, NameDefinition name) Unmarshal direct object component.private static void
unmarshalFormats
(UnmarshallingContext ctx, boolean exists, DefinitionContext defc) Unmarshal format definitions.static void
unmarshalInclude
(UnmarshallingContext ctx, boolean precomp, BindingDefinition bdef, URL root, ArrayList nslist, HashSet paths, IBindingFactory factory, int[] nsxlate) Unmarshal included binding.static IMapping
unmarshalMapping
(UnmarshallingContext ctx, IContainer parent, ArrayList nss, boolean uord) Unmarshal mapping definition.private static IComponent
unmarshalMappingRef
(UnmarshallingContext ctx, IContainer parent, IContextObj objc, PropertyDefinition prop, NameDefinition name) Unmarshal mapping reference component.private static void
unmarshalMappings
(UnmarshallingContext ctx, IContainer parent, ArrayList nss, boolean uord) Unmarshal mapping definitions.private static NameDefinition
unmarshalName
(UnmarshallingContext ctx, boolean attr) Unmarshal name definition.private static NamespaceDefinition
Unmarshal namespace definition.private static void
Unmarshal namespace definitions.private static ObjectBinding
unmarshalObjectBinding
(UnmarshallingContext ctx, IContextObj objc, IContainer parent, String type) Unmarshal object binding component.private static void
unmarshalPrecompiledMappings
(UnmarshallingContext ctx, IBindingFactory factory, IContainer parent, int[] nsxlate) Unmarshal precompiled mapping definitions.private static PropertyDefinition
unmarshalProperty
(UnmarshallingContext ctx, IContainer parent, IContextObj cobj, boolean opt) Unmarshal property definition.private static StringConversion
unmarshalStringConversion
(UnmarshallingContext ctx, boolean exists, StringConversion base, String type) Unmarshal string conversion.static IComponent
unmarshalStructure
(UnmarshallingContext ctx, IContainer contain, IContextObj cobj, boolean coll, boolean uord, boolean implic) Unmarshal subclass instance for structure definition.private static void
unmarshalStructureChildren
(UnmarshallingContext ctx, NestedBase nest, IContextObj objc, boolean impl, String itype) Unmarshal child bindings for a nested structure definition.private static IComponent
unmarshalStructureRef
(UnmarshallingContext ctx, IContainer contain, NameDefinition name, PropertyDefinition prop, IContextObj cobj) Unmarshal structure reference component.private static ValueChild
unmarshalValue
(UnmarshallingContext ctx, IContainer parent, IContextObj cobj, boolean uord, boolean impl, String itype) Unmarshal value definition.
-
Field Details
-
URI_ELEMENTS
Element namespace used for binding definition file. -
URI_ATTRIBUTES
Attribute namespace used for binding definition file. -
COMMON_STYLE
- See Also:
-
COMMON_AUTOLINK
- See Also:
-
COMMON_ACCESSLEVEL
- See Also:
-
COMMON_STRIPPREFIX
- See Also:
-
COMMON_STRIPSUFFIX
- See Also:
-
COMMON_NAMESTYLE
- See Also:
-
COMMON_NAME
- See Also:
-
COMMON_NAMESPACE
- See Also:
-
COMMON_FACTORY
- See Also:
-
COMMON_PRESET
- See Also:
-
COMMON_POSTSET
- See Also:
-
COMMON_PREGET
- See Also:
-
COMMON_MARSHALLER
- See Also:
-
COMMON_UNMARSHALLER
- See Also:
-
COMMON_CREATETYPE
- See Also:
-
COMMON_FIELD
- See Also:
-
COMMON_TYPE
- See Also:
-
COMMON_USAGE
- See Also:
-
COMMON_TESTMETHOD
- See Also:
-
COMMON_GETMETHOD
- See Also:
-
COMMON_SETMETHOD
- See Also:
-
COMMON_FLAGMETHOD
- See Also:
-
COMMON_DEFAULT
- See Also:
-
COMMON_SERIALIZER
- See Also:
-
COMMON_WHITESPACE
- See Also:
-
COMMON_DESERIALIZER
- See Also:
-
COMMON_ENUMVALUEMETHOD
- See Also:
-
COMMON_LABEL
- See Also:
-
COMMON_USING
- See Also:
-
COMMON_ORDERED
- See Also:
-
COMMON_CHOICE
- See Also:
-
COMMON_FLEXIBLE
- See Also:
-
COMMON_DUPLICATES
- See Also:
-
COMMON_NILLABLE
- See Also:
-
BINDING_ELEMENT
Definitions for "binding" element use "BINDING" prefix.- See Also:
-
BINDING_NAME
- See Also:
-
BINDING_DIRECTION
- See Also:
-
BINDING_GLOBALID
- See Also:
-
BINDING_FORWARDS
- See Also:
-
BINDING_PACKAGE
- See Also:
-
BINDING_TRACKING
- See Also:
-
BINDING_FORCE
- See Also:
-
BINDING_ADD
- See Also:
-
BINDING_TRIM
- See Also:
-
BINDING_MAJORVER
- See Also:
-
BINDING_MINORVER
- See Also:
-
NAMESPACE_ELEMENT
Definitions for "namespace" element use "NAMESPACE" prefix.- See Also:
-
NAMESPACE_URI
- See Also:
-
NAMESPACE_PREFIX
- See Also:
-
NAMESPACE_DEFAULT
- See Also:
-
FORMAT_ELEMENT
Definitions for "format" element use "FORMAT" prefix.- See Also:
-
FORMAT_NAME
- See Also:
-
FORMAT_TYPE
- See Also:
-
MAPPING_ELEMENT
Definitions for "mapping" element use "MAPPING" prefix.- See Also:
-
MAPPING_CLASS
- See Also:
-
MAPPING_ABSTRACT
- See Also:
-
MAPPING_EXTENDS
- See Also:
-
MAPPING_TYPENAME
- See Also:
-
VALUE_ELEMENT
Definitions for "value" element use "VALUE" prefix.- See Also:
-
VALUE_STYLE
- See Also:
-
VALUE_FORMAT
- See Also:
-
VALUE_CONSTANT
- See Also:
-
VALUE_IDENT
- See Also:
-
STRUCTURE_ELEMENT
Definitions for "structure" element use "STRUCTURE" prefix.- See Also:
-
STRUCTURE_MAPAS
- See Also:
-
COLLECTION_ELEMENT
Definitions for "collection" element use "COLLECTION" prefix.- See Also:
-
COLLECTION_LOADMETHOD
- See Also:
-
COLLECTION_SIZEMETHOD
- See Also:
-
COLLECTION_STOREMETHOD
- See Also:
-
COLLECTION_ADDMETHOD
- See Also:
-
COLLECTION_ITERMETHOD
- See Also:
-
COLLECTION_ITEMTYPE
- See Also:
-
INCLUDE_ELEMENT
Definitions for "include" element use "INCLUDE" prefix.- See Also:
-
INCLUDE_PATH
- See Also:
-
INCLUDE_PRECOMPILED
- See Also:
-
VALUE_STYLE_NAMES
-
VALUE_STYLE_NUMS
private static final int[] VALUE_STYLE_NUMS -
CONTAINING_STYLE_NAMES
-
CONTAINING_STYLE_NUMS
private static final int[] CONTAINING_STYLE_NUMS -
LINK_NONE
static final int LINK_NONE- See Also:
-
LINK_FIELDS
static final int LINK_FIELDS- See Also:
-
LINK_METHODS
static final int LINK_METHODS- See Also:
-
AUTO_LINK_NAMES
-
AUTO_LINK_NUMS
private static final int[] AUTO_LINK_NUMS -
ACC_PRIVATE
static final int ACC_PRIVATE- See Also:
-
ACC_PACKAGE
static final int ACC_PACKAGE- See Also:
-
ACC_PROTECTED
static final int ACC_PROTECTED- See Also:
-
ACC_PUBLIC
static final int ACC_PUBLIC- See Also:
-
ACCESS_LEVEL_NAMES
-
ACCESS_LEVEL_NUMS
private static final int[] ACCESS_LEVEL_NUMS -
NAME_HYPHENS
static final int NAME_HYPHENS- See Also:
-
NAME_MIXED
static final int NAME_MIXED- See Also:
-
NAME_GENERATE_NAMES
-
NAME_GENERATE_NUMS
private static final int[] NAME_GENERATE_NUMS -
COMPONENT_OBJECT_NAMESPACES
-
COMPONENT_OBJECT_NAMES
-
NAMESPACEACCESS_NAMES
-
NAMESPACEACCESS_NUMS
private static final int[] NAMESPACEACCESS_NUMS -
IDENTTYPE_NAMES
-
IDENTTYPE_NUMS
private static final int[] IDENTTYPE_NUMS -
DIRECTION_INPUT
private static final int DIRECTION_INPUT- See Also:
-
DIRECTION_OUTPUT
private static final int DIRECTION_OUTPUT- See Also:
-
DIRECTION_BOTH
private static final int DIRECTION_BOTH- See Also:
-
BINDINGDIR_NAMES
-
BINDINGDIR_NUMS
private static final int[] BINDINGDIR_NUMS -
USAGE_OPTIONAL
- See Also:
-
USAGE_REQUIRED
- See Also:
-
UNMARSHALLER_INTERFACE
- See Also:
-
MARSHALLER_INTERFACE
- See Also:
-
UNMARSHALLER_INTERFACETYPE
- See Also:
-
MARSHALLER_INTERFACETYPE
- See Also:
-
CUSTOM_ENUM_SERIALIZER_NAME
- See Also:
-
CUSTOM_ENUM_DESERIALIZER_NAME
- See Also:
-
-
Constructor Details
-
BindingBuilder
public BindingBuilder()
-
-
Method Details
-
isNamePresent
Check if attributes supply a name definition.- Parameters:
ctx
- unmarshalling context information- Returns:
true
if attributes define a name,false
if not
-
isPropertyPresent
Check for property definition present. Just checks the attributes of the current element.- Parameters:
ctx
- unmarshalling context information
-
isDirectObject
Check if attributes define a direct object reference. Just checks the attributes of the current element.- Parameters:
ctx
- unmarshalling context information
-
isMappingRef
Check if attributes define a mapping reference.- Parameters:
ctx
- unmarshalling context information- Returns:
true
if attributes define a mapping reference,false
if not- Throws:
JiBXException
- if error in unmarshalling
-
isObjectBinding
Check for component object present. Just checks the attributes of the current element, so this is not definitive - there may still be child binding definitions even without attributes.- Parameters:
ctx
- unmarshalling context information- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalName
private static NameDefinition unmarshalName(UnmarshallingContext ctx, boolean attr) throws JiBXException Unmarshal name definition. This unmarshals directly from attributes of the current element.- Parameters:
ctx
- unmarshalling context informationattr
- flag for attribute name definition- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalNamespace
private static NamespaceDefinition unmarshalNamespace(UnmarshallingContext ctx) throws JiBXException Unmarshal namespace definition.- Parameters:
ctx
- unmarshalling context information- Throws:
JiBXException
- if error in unmarshalling
-
buildEnumValueMethods
private static void buildEnumValueMethods(boolean exists, String type, String evmeth) throws JiBXException Add (or verify) serializer and deserializer methods to enum class with special value method. This allows enums to be used even when the values present in XML are not valid Java names.- Parameters:
exists
- only verify existing methods flagtype
-evmeth
-- Throws:
JiBXException
-
buildEnumSerializeMethod
Fill in the body of an enum serialization method.- Parameters:
evfull
-smeth
-
-
buildEnumDeserializeMethod
private static void buildEnumDeserializeMethod(String type, String typesig, String evfull, ExceptionMethodBuilder dmeth) Fill in the body of an enum deserialization method.- Parameters:
type
-typesig
-evfull
-dmeth
-
-
unmarshalStringConversion
private static StringConversion unmarshalStringConversion(UnmarshallingContext ctx, boolean exists, StringConversion base, String type) throws JiBXException Unmarshal string conversion. Unmarshals conversion information directly from the attributes of the current start tag.- Parameters:
ctx
- unmarshalling context informationexists
- only verify existing methods flagbase
- conversion used as base for this conversiontype
- fully qualified class name of type handled by conversion- Throws:
JiBXException
- if error in unmarshalling
-
isOptionalProperty
Check for optional property. Just checks for the attribute and makes sure it has a valid value if present, returning either the default or the defined value.- Parameters:
ctx
- unmarshalling context information- Returns:
true
if attribute present with value "true",false
otherwise- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalProperty
private static PropertyDefinition unmarshalProperty(UnmarshallingContext ctx, IContainer parent, IContextObj cobj, boolean opt) throws JiBXException Unmarshal property definition. This unmarshals directly from attributes of the current element.- Parameters:
ctx
- unmarshalling context informationparent
- containing binding definition structurecobj
- context object informationopt
- force optional value flag- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalValue
private static ValueChild unmarshalValue(UnmarshallingContext ctx, IContainer parent, IContextObj cobj, boolean uord, boolean impl, String itype) throws JiBXException Unmarshal value definition. This handles the complete element supplying the value binding.- Parameters:
ctx
- unmarshalling context informationparent
- containing binding definition structurecobj
- context object informationuord
- unordered collection member flagimpl
- implicit value from collection flagitype
- base type for value- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalDirectObj
private static DirectObject unmarshalDirectObj(UnmarshallingContext ctx, String type, IContainer parent, DefinitionContext defc, String mapname, NameDefinition name) throws JiBXException Unmarshal direct object component. Just constructs the component to be returned along with the supporting objects, and verifies that no disallowed properties are present.- Parameters:
ctx
- unmarshalling context informationtype
- fully qualified class name of object type handledparent
- containing binding definition structuredefc
- definition context to be used (if separate from parent, otherwisenull
)mapname
- marshaller/unmarshaller namename
- element name information (null
if no element name)- Returns:
- constructed direct object component
- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalMappingRef
private static IComponent unmarshalMappingRef(UnmarshallingContext ctx, IContainer parent, IContextObj objc, PropertyDefinition prop, NameDefinition name) throws JiBXException Unmarshal mapping reference component. Just constructs the component to be returned along with the supporting objects, and verifies that no disallowed properties are present.- Parameters:
ctx
- unmarshalling context informationparent
- containing binding definition structureobjc
- current object contextprop
- property definitionname
- reference name definition (only allowed with abstract mappings)- Returns:
- constructed mapping reference component
- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalStructureRef
private static IComponent unmarshalStructureRef(UnmarshallingContext ctx, IContainer contain, NameDefinition name, PropertyDefinition prop, IContextObj cobj) throws JiBXException Unmarshal structure reference component. Just constructs the component to be returned along with the supporting objects, and verifies that no disallowed properties are present.- Parameters:
ctx
- unmarshalling context informationcontain
- containing binding componentname
- element name information (null
if no element name)prop
- property definition (null
if no separate property)cobj
- context object- Returns:
- constructed structure reference component
- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalStructureChildren
private static void unmarshalStructureChildren(UnmarshallingContext ctx, NestedBase nest, IContextObj objc, boolean impl, String itype) throws JiBXException Unmarshal child bindings for a nested structure definition.- Parameters:
ctx
- unmarshalling context informationnest
- nested structure definitionobjc
- context object definitionimpl
- property value implicit flagitype
- item type for child components- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalObjectBinding
private static ObjectBinding unmarshalObjectBinding(UnmarshallingContext ctx, IContextObj objc, IContainer parent, String type) throws JiBXException Unmarshal object binding component. Just constructs the component to be returned along with the supporting objects. This handles both the unmarshalling of attributes, and of nested binding components.- Parameters:
ctx
- unmarshalling context informationobjc
- current object contextparent
- containing binding definition structuretype
- fully qualified name of object class- Returns:
- constructed structure reference component
- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalNamespaces
private static void unmarshalNamespaces(UnmarshallingContext ctx, DefinitionContext defc) throws JiBXException Unmarshal namespace definitions. Any namespace definitions present are unmarshalled and added to the supplied definition context.- Parameters:
ctx
- unmarshalling context informationdefc
- definition context for defined namespaces- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalFormats
private static void unmarshalFormats(UnmarshallingContext ctx, boolean exists, DefinitionContext defc) throws JiBXException Unmarshal format definitions. Any format definitions present are unmarshalled and added to the supplied definition context.- Parameters:
ctx
- unmarshalling context informationexists
- only verify existing methods flagdefc
- definition context for defined formats- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalMappings
private static void unmarshalMappings(UnmarshallingContext ctx, IContainer parent, ArrayList nss, boolean uord) throws JiBXException Unmarshal mapping definitions. Any mapping definitions present are unmarshalled and added to the supplied definition context.- Parameters:
ctx
- unmarshalling context informationparent
- containing binding definition structurenss
- extra namespaces to be included in this mapping definition (may benull
)uord
- container is unordered structure flag- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalStructure
public static IComponent unmarshalStructure(UnmarshallingContext ctx, IContainer contain, IContextObj cobj, boolean coll, boolean uord, boolean implic) throws JiBXException Unmarshal subclass instance for structure definition. This handles all combinations of attributes on the start tag, generating the appropriate structure of nested components and other classes to represent the binding information within the current element. This must be called with the parse positioned at the start tag of the element to be unmarshalled. TODO: At least split this up, or organize a better way to build binding- Parameters:
ctx
- unmarshalling context informationcontain
- containing binding definition structurecobj
- context object informationcoll
- collection structure flaguord
- container is unordered structure flagimplic
- property value implicit flag- Returns:
- root of component tree constructed from binding
- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalMapping
public static IMapping unmarshalMapping(UnmarshallingContext ctx, IContainer parent, ArrayList nss, boolean uord) throws JiBXException Unmarshal mapping definition. This handles all combinations of attributes on the start tag, generating the appropriate structure of nested components and other classes to represent the binding information within the current element. This must be called with the parse positioned at the start tag of the element to be unmarshalled.- Parameters:
ctx
- unmarshalling context informationparent
- containing binding definition structurenss
- extra namespaces to be included in this mapping definition (may benull
)uord
- container is unordered structure flag- Returns:
- mapping definition constructed from binding
- Throws:
JiBXException
- if error in unmarshalling
-
preserveMethodClass
Force the class containing a method to be preserved from modification.- Parameters:
name
-
-
unmarshalPrecompiledMappings
private static void unmarshalPrecompiledMappings(UnmarshallingContext ctx, IBindingFactory factory, IContainer parent, int[] nsxlate) throws JiBXException Unmarshal precompiled mapping definitions. Any mapping definitions present are unmarshalled and added to the supplied definition context.- Parameters:
ctx
- unmarshalling context informationfactory
- binding factory for mapping informationparent
- containing binding definition structurensxlate
- namespace index translation table (null
if none)- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalInclude
public static void unmarshalInclude(UnmarshallingContext ctx, boolean precomp, BindingDefinition bdef, URL root, ArrayList nslist, HashSet paths, IBindingFactory factory, int[] nsxlate) throws JiBXException Unmarshal included binding. This handles the actual include element along with the actual included binding. The current implementation allows for nested includes, but requires that all the included bindings use compatible settings for the attributes of the root element, and only allows mapping elements as children of the included bindings (no namespace or format elements).- Parameters:
ctx
- unmarshalling context informationprecomp
- in precompiled bindings flagbdef
- binding definition at root of includesroot
- base URL for binding, ornull
if unknownnslist
- list of namespaces definedpaths
- set of binding paths processedfactory
- precompiled binding factory (null
if not in precompiled binding)nsxlate
- namespace translation table for precompiled binding (null
if not in precompiled binding)- Throws:
JiBXException
- if error in unmarshalling
-
unmarshalBindingDefinition
public static BindingDefinition unmarshalBindingDefinition(UnmarshallingContext ctx, String name, URL root) throws JiBXException Unmarshal binding definition. This handles the entire binding definition document.- Parameters:
ctx
- unmarshalling context informationname
- default name for bindingroot
- base URL for binding, ornull
if unknown- Returns:
- binding definition
- Throws:
JiBXException
- if error in unmarshalling
-