Package org.jibx.binding.def
Class BindingDefinition
java.lang.Object
org.jibx.binding.def.BindingBuilder.ContainerBase
org.jibx.binding.def.BindingDefinition
- All Implemented Interfaces:
IContainer
Binding definition. This is the root of the object graph for a binding.
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
First namespace index available for user definitions.private static final String
private static final String
static final String
Current distribution file name.(package private) static final String
Default prefix for automatic ID generation.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 DefinitionContext
Inner definition context constructed for binding.private GrowableStringArray
Factory class names for precompiled base bindings (same order as binding names).private GrowableStringArray
Precompiled base binding names used by this binding.private ArrayList
Hashes for base binding factories (same order as binding names).private ArrayList
Namespace index mapping tables for base bindings (same order as binding names).private GrowableStringArray
Factory classes for base bindings of base bindings.private ArrayList
Namespace index mapping tables for base bindings of base bindings (same order as factories).private ArrayMap
Classes handled by in-line marshaller/unmarshaller references.private GrowableStringArray
Marshaller classes used in-line.private GrowableStringArray
Unmarshaller classes used in-line.private ClassFile
Generated binding factory class.private String
Fully-qualified name of binding factory.private int
High mark in prefixes from from precompiled base bindings.private final int
Index number of this binding.private boolean
Add default constructors where needed flag.private final boolean
Generate marshaller/unmarshaller classes for top-level non-base abstract mappings flag.private final boolean
Support forward references to IDs flag.private final boolean
Use global ID values flag.private final boolean
Input binding flag.private boolean
Flag for done assigning indexes to mapped classes.private final boolean
Output binding flag.private boolean
Flag for schema instance namespace used in binding.private final boolean
Generate souce tracking interface flag.private final int
Major version of binding.private final int
Minor version of binding.private int
Next index number for marshaller/unmarshaller slots used in-line.private final String
Binding name.private GrowableStringArray
Original prefixes for namespaces.private ArrayMap
Namespaces URIs included in binding.private DefinitionContext
Outer definition context with default definitions.private String
Package for generated context factory.private File
File root for generated context factory.private ArrayMap
Classes using unique (per class) identifiers.private static final int
(package private) static final QName
Name of object default conversion.private static final int
private static final int
private static final StringConversion
private static ArrayList
Table of defined bindings.private static byte[]
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static ArrayMap
Classes included in any binding.private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
private static final StringConversion
(package private) static final StringConversion
private static final StringConversion
private static final StringConversion
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
Minimum size to use map for index from type name.private static final String
Fields inherited from class org.jibx.binding.def.BindingBuilder.ContainerBase
m_accessLevel, m_autoLink, m_container, m_nameStyle, m_stripPrefix, m_stripSuffix, m_styleDefault
-
Constructor Summary
ConstructorsConstructorDescriptionBindingDefinition
(String name, boolean ibind, boolean obind, String tpack, boolean glob, boolean forward, boolean source, boolean force, boolean add, boolean trim, int major, int minor) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addClassList
(ClassFile[] adds, ClassFile[] keeps) Add the list of classes used by the binding compiler to the binding factory.void
addMappingName
(String name) Add mapping name to binding.int[]
addPrecompiledBinding
(IBindingFactory factory, int major, int minor) Add a precompiled binding reference to this binding.private static String
buildClassNamesBlob
(String[] names) Build a class or method name blob from an array of fully-qualified class and/or method names.private static String
buildClassNamesBlob
(List names) Build a class or method name blob from a list of fully-qualified class and/or method names.private static String
buildIntsBlob
(int[] ints) Convert an array of int values into a string blob.private static String
buildIntsBlob
(List values) Convert a list ofInteger
values into a string blob.private static String
buildNamesBlob
(String[] names) Build a name blob from an array of names.private static String
buildNamespaceIndexBlob
(String[] uris, String[] nss) Build a namespace index blob from an array of namespace URIs.private static void
codegenString
(String string, MethodBuilder mb) Generate code to load a string value, which may be longer than the maximum string length.private void
Fix the prefixes for namespaces imported from precompiled base bindings.void
generateCode
(boolean verbose) Generate code.void
generateCode
(boolean verbose1, boolean verbose2) Generate code.static BindingDefinition
getBinding
(int index) Get indexed binding.Get root of binding definition.Get class linked to binding element.Get default package used for code generation.Get root directory for default code generation package.Get definition context for binding element.Get the fully-qualified name of the binding factory class for this binding.int
getIdClassIndex
(String name) Get index for ID'ed class from binding.int
getIndex()
Get index number of binding.Get marshaller/unmarshaller name in binding.int
getNamespaceUriIndex
(String uri, String prefix) Get index for namespace URI in binding.Get prefix for method or class generation.Get the prefix assigned for a namespace.int
Get default style for value expression.boolean
static void
indent
(int depth) boolean
Check if default constructor generation is enabled.boolean
Check if content children are ordered.boolean
Check if forward ids are supported by unmarshalling binding.boolean
Check if global ids are used by binding.boolean
isInput()
Check if binding is defined for unmarshalling.boolean
isOutput()
Check if binding is defined for marshalling.boolean
Check if source tracking is supported by unmarshalling binding.private static String
methodNameOrNull
(ClassItem item) Convenience method to get an name, if the item is defined.void
print()
static void
reset()
Discard cached information and reset in preparation for a new binding run.void
setFactoryLocation
(String tpack, File root) Set location for binding factory class generation.boolean
setIdChild
(IComponent child) Set ID property.void
setMarshallerUnmarshallerClasses
(String name, String mclas, String uclas) Set marshaller and unmarshaller class names.void
Set flag for schema instance namespace used in binding.Methods inherited from class org.jibx.binding.def.BindingBuilder.ContainerBase
unmarshal
-
Field Details
-
OBJECT_DEFAULT_NAME
Name of object default conversion. -
BASE_USER_NAMESPACE
public static final int BASE_USER_NAMESPACEFirst namespace index available for user definitions.- See Also:
-
CURRENT_VERSION_NAME
Current distribution file name. This is filled in by the Ant build process to match the current distribution.- See Also:
-
DEFAULT_AUTOPREFIX
Default prefix for automatic ID generation.- See Also:
-
TYPEMAP_MINIMUM_SIZE
private static final int TYPEMAP_MINIMUM_SIZEMinimum size to use map for index from type name.- See Also:
-
s_bindings
Table of defined bindings. -
s_mappedClasses
Classes included in any binding. -
s_byteConversion
-
s_charConversion
-
s_doubleConversion
-
s_floatConversion
-
s_intConversion
-
s_longConversion
-
s_shortConversion
-
s_booleanConversion
-
s_dateConversion
-
s_sqlDateConversion
-
s_sqlTimeConversion
-
s_timestampConversion
-
s_jodaLocalDateConversion
-
s_jodaZonedDateMidnightConversion
-
s_jodaLocalUnzonedDateMidnightConversion
-
s_jodaUTCDateMidnightConversion
-
s_jodaUnzonedLocalTimeConversion
-
s_jodaUnzonedUTCLocalTimeConversion
-
s_jodaZonedDateTimeConversion
-
s_jodaUTCDateTimeConversion
-
s_jodaLocalDateTimeConversion
-
s_jodaStrictLocalDateTimeConversion
-
s_jodaStrictUTCDateTimeConversion
-
s_java5DecimalConversion
-
s_base64Conversion
-
s_wrappedBooleanConversion
-
s_qnameConversion
-
s_stringConversion
-
s_objectConversion
-
FACTORY_SUFFIX
- See Also:
-
FACTORY_INTERFACE
- See Also:
-
FACTORY_BASE
- See Also:
-
FACTORY_INTERFACES
-
FACTORY_INSTNAME
- See Also:
-
PRIVATESTATIC_ACCESS
private static final int PRIVATESTATIC_ACCESS -
PRIVATESTATICFINAL_ACCESS
private static final int PRIVATESTATICFINAL_ACCESS -
TYPEMAP_NAME
- See Also:
-
GETINST_METHODNAME
- See Also:
-
GETVERSION_METHODNAME
- See Also:
-
GETDISTRIB_METHODNAME
- See Also:
-
GETTYPEINDEX_METHODNAME
- See Also:
-
STRINGINT_MAPTYPE
- See Also:
-
STRINGINTINIT_SIGNATURE
- See Also:
-
STRINGINTADD_METHOD
- See Also:
-
STRINGINTADD_SIGNATURE
- See Also:
-
STRINGINTGET_METHOD
- See Also:
-
STRINGINTGET_SIGNATURE
- See Also:
-
MAX_STRING_LENGTH
private static final int MAX_STRING_LENGTH- See Also:
-
CLASSLIST_METHOD_NAME
- See Also:
-
CLASSLIST_METHOD_SIGNATURE
- See Also:
-
m_name
Binding name. -
m_index
private final int m_indexIndex number of this binding. -
m_isInput
private final boolean m_isInputInput binding flag. -
m_isOutput
private final boolean m_isOutputOutput binding flag. -
m_isIdGlobal
private final boolean m_isIdGlobalUse global ID values flag. -
m_isForwards
private final boolean m_isForwardsSupport forward references to IDs flag. -
m_isTrackSource
private final boolean m_isTrackSourceGenerate souce tracking interface flag. -
m_isForceClasses
private final boolean m_isForceClassesGenerate marshaller/unmarshaller classes for top-level non-base abstract mappings flag. -
m_majorVersion
private final int m_majorVersionMajor version of binding. -
m_minorVersion
private final int m_minorVersionMinor version of binding. -
m_isAddConstructors
private boolean m_isAddConstructorsAdd default constructors where needed flag. -
m_targetPackage
Package for generated context factory. -
m_targetRoot
File root for generated context factory. -
m_factoryName
Fully-qualified name of binding factory. -
m_uniqueIds
Classes using unique (per class) identifiers. This isnull
and unused when using global ID values. -
m_namespaceUris
Namespaces URIs included in binding. -
m_namespacePrefixes
Original prefixes for namespaces. -
m_highBasePrefix
private int m_highBasePrefixHigh mark in prefixes from from precompiled base bindings. -
m_outerContext
Outer definition context with default definitions. -
m_activeContext
Inner definition context constructed for binding. -
m_isMappedDone
private boolean m_isMappedDoneFlag for done assigning indexes to mapped classes. -
m_isSchemaInstanceUsed
private boolean m_isSchemaInstanceUsedFlag for schema instance namespace used in binding. -
m_mumIndex
private int m_mumIndexNext index number for marshaller/unmarshaller slots used in-line. -
m_extraClasses
Classes handled by in-line marshaller/unmarshaller references. -
m_extraMarshallers
Marshaller classes used in-line. -
m_extraUnmarshallers
Unmarshaller classes used in-line. -
m_baseBindings
Precompiled base binding names used by this binding. -
m_baseBindingFactories
Factory class names for precompiled base bindings (same order as binding names). -
m_baseHashes
Hashes for base binding factories (same order as binding names). -
m_baseNamespaceTables
Namespace index mapping tables for base bindings (same order as binding names). -
m_closureFactories
Factory classes for base bindings of base bindings. -
m_closureNamespaceTables
Namespace index mapping tables for base bindings of base bindings (same order as factories). -
m_factoryClass
Generated binding factory class. -
s_blanks
private static byte[] s_blanks
-
-
Constructor Details
-
BindingDefinition
public BindingDefinition(String name, boolean ibind, boolean obind, String tpack, boolean glob, boolean forward, boolean source, boolean force, boolean add, boolean trim, int major, int minor) throws JiBXException Constructor. Sets all defaults, including the default name provided, and initializes the definition context for the outermost level of the binding.- Parameters:
name
- binding nameibind
- input binding flagobind
- output binding flagtpack
- target packageglob
- global IDs flagforward
- support forward referenced IDs flagsource
- add source tracking for unmarshalled objects flagforce
- create marshaller/unmarshaller classes for top-level non-base mappingsadd
- add default constructors where necessary flagtrim
- trim whitespace from simple values before conversion flagmajor
- major version numberminor
- minor version number- Throws:
JiBXException
- if error in transformation
-
-
Method Details
-
getBoundClass
Get class linked to binding element. Implementation ofIContainer
interface, just returnsnull
in this case.- Returns:
- information for class linked by binding
-
getStyleDefault
public int getStyleDefault()Get default style for value expression. Implementation ofIContainer
interface.- Specified by:
getStyleDefault
in interfaceIContainer
- Overrides:
getStyleDefault
in classBindingBuilder.ContainerBase
- Returns:
- default style type for values
-
setIdChild
Set ID property. This parent binding component interface method should never be called for the binding definition, and will throw a runtime exception if it is called.- Parameters:
child
- child defining the ID property- Returns:
false
-
getDefaultPackage
Get default package used for code generation.- Returns:
- default code generation package
-
getDefaultRoot
Get root directory for default code generation package.- Returns:
- root for default code generation
-
setFactoryLocation
Set location for binding factory class generation.- Parameters:
tpack
- target package for generated context factoryroot
- target root for generated context factory
-
getIndex
public int getIndex()Get index number of binding.- Returns:
- index number for this binding definition
-
isInput
public boolean isInput()Check if binding is defined for unmarshalling.- Returns:
true
if defined,false
if not
-
isOutput
public boolean isOutput()Check if binding is defined for marshalling.- Returns:
true
if defined,false
if not
-
isIdGlobal
public boolean isIdGlobal()Check if global ids are used by binding.- Returns:
true
if defined,false
if not
-
isForwards
public boolean isForwards()Check if forward ids are supported by unmarshalling binding.- Returns:
true
if supported,false
if not
-
isTrackSource
public boolean isTrackSource()Check if source tracking is supported by unmarshalling binding.- Returns:
true
if defined,false
if not
-
isAddConstructors
public boolean isAddConstructors()Check if default constructor generation is enabled.- Returns:
true
if default constructor generation enabled,false
if not
-
getPrefix
Get prefix for method or class generation.- Returns:
- prefix for names created by this binding
-
addMappingName
Add mapping name to binding. If the name is not already included in any binding it is first added to the list of mapping names. This method is intended for use with <mapping> definitions. It is an error to call this method after calling thegetMarshallerUnmarshallerName(java.lang.String)
method.- Parameters:
name
- mapping name (type name if given, otherwise the fully qualified mapped class name)
-
getMarshallerUnmarshallerName
Get marshaller/unmarshaller name in binding. The same class may have more than one marshaller/unmarshaller pair defined, so this uses the supplied class name as a base and appends a numeric suffix as necessary to generate a unique name. After the name has been assigned by this method, thesetMarshallerUnmarshallerClasses(java.lang.String, java.lang.String, java.lang.String)
method must be used to set the actual class names.- Parameters:
clas
- fully qualified name of class handled by marshaller/unmarshaller- Returns:
- unique name for marshaller/unmarshaller pair
-
setMarshallerUnmarshallerClasses
Set marshaller and unmarshaller class names.- Parameters:
name
- assigned marshaller/unmarshaller namemclas
- fully qualified name of marshaller classuclas
- fully qualified name of unmarshaller class
-
getIdClassIndex
Get index for ID'ed class from binding. If the class is not already included it is first added to the binding. If globally unique IDs are used this always returns0
.- Parameters:
name
- fully qualified name of ID'ed class- Returns:
- index number of class
-
getNamespaceUriIndex
Get index for namespace URI in binding. If the URI is not already included it is first added to the binding. The empty namespace URI is always given index number0
.- Parameters:
uri
- namespace URI to be included in bindingprefix
- prefix used with namespace- Returns:
- index number of namespace
-
setSchemaInstanceUsed
public void setSchemaInstanceUsed()Set flag for schema instance namespace used in binding. -
addPrecompiledBinding
Add a precompiled binding reference to this binding. This records the reference and makes sure that all the namespaces used in the precompiled binding are defined in this binding, also generating a namespace index mapping table if this binding supports output and the indexes differ.- Parameters:
factory
- actual binding factory for precompiled bindingmajor
- required major version numberminor
- required minor version number- Returns:
- namespace index translation table (
null
if none)
-
fixPrefixes
private void fixPrefixes()Fix the prefixes for namespaces imported from precompiled base bindings. If there are no namespaces from precompiled base bindings, or these namespaces use prefixes which are unique from each other and from those used in this binding, nothing is done. If there are conflicts or namespaces used without prefixes this sets unique prefixes for each namespace. -
getPrefix
Get the prefix assigned for a namespace. This is intended mainly for use with precompiled bindings, where thefixPrefixes()
method may change the initial prefixes (if any) in order to avoid conflicts.- Parameters:
uri
- namespace URI- Returns:
- prefix for namespace
-
buildClassNamesBlob
Build a class or method name blob from an array of fully-qualified class and/or method names. The returned string consists of compacted fully-qualified names separated by '|' delimiter characters. If some number of package (and potentially class) name levels are the same as the last name, these components are replaced with simple '.' characters (and '$' characters, in the case of class name components) in the compacted name.null
values are represented as empty names.- Parameters:
names
- fully-qualified class and/or method names list- Returns:
- compacted name blob
-
buildClassNamesBlob
Build a class or method name blob from a list of fully-qualified class and/or method names. This just converts the list to an array and delegates tobuildClassNamesBlob(String[])
.- Parameters:
names
- fully-qualified class and/or method names list- Returns:
- compacted name blob
-
buildNamespaceIndexBlob
Build a namespace index blob from an array of namespace URIs. The returned string consists of one character per namespace, giving the index of the namespace URI within the array of definitions, biased by +2 to avoid use of null characters (with +1 used fornull
values).- Parameters:
uris
- table of namespaces defined in bindingnss
- namespaces for index blob- Returns:
- index blob
-
buildNamesBlob
Build a name blob from an array of names. The returned string consists of names separated by '|' delimiter characters.null
values are represented as empty names.- Parameters:
names
- names for blob- Returns:
- name blob
-
buildIntsBlob
Convert an array of int values into a string blob.- Parameters:
ints
-- Returns:
- string with int values as characters
-
buildIntsBlob
Convert a list ofInteger
values into a string blob. This is just a convenience wrapper forbuildIntsBlob(int[])
.- Parameters:
values
-- Returns:
- string with int values as characters
-
codegenString
Generate code to load a string value, which may be longer than the maximum string length. This either loads the string directly (if within the limit) or recreates it by concatenating two or more shorter strings.- Parameters:
string
-mb
-
-
getFactoryName
Get the fully-qualified name of the binding factory class for this binding.- Returns:
- class name
-
generateCode
Generate code. First sets linkages and executes code generation for each top-level mapping defined in this binding, which in turn propagates the code generation all the way down. Then generates the actual binding factory for this binding.- Parameters:
verbose1
- flag for verbose output from first passverbose2
- flag for verbose output from second pass- Throws:
JiBXException
- if error in code generation
-
generateCode
Generate code. This version preserves compatibility with the older form of the call, always passingfalse
for the second-pass verbose flag. SeegenerateCode(boolean, boolean)
for details of processing.- Parameters:
verbose
- flag for verbose output from first pass- Throws:
JiBXException
- if error in code generation
-
addClassList
Add the list of classes used by the binding compiler to the binding factory. This needs to be done as a separate step after the normal binding process has completed in order to make sure that the full set of classes is available. Ugly, but necessary because the class handling doesn't finalize newly-generated class names until they're actually written (too much sophistication, in retrospect).- Parameters:
adds
- classes added by bindingkeeps
- classes used but kept unchanged by binding
-
methodNameOrNull
Convenience method to get an name, if the item is defined.- Parameters:
item
- information, ornull
if none- Returns:
- item name, or
null
if no item
-
getBinding
Get indexed binding.- Parameters:
index
- number of binding to be returned- Returns:
- binding at the specified index
-
reset
public static void reset()Discard cached information and reset in preparation for a new binding run. -
isContentOrdered
public boolean isContentOrdered()Description copied from interface:IContainer
Check if content children are ordered.- Specified by:
isContentOrdered
in interfaceIContainer
- Returns:
true
if ordered,false
if not
-
hasNamespaces
public boolean hasNamespaces() -
getBindingRoot
Description copied from interface:IContainer
Get root of binding definition.- Specified by:
getBindingRoot
in interfaceIContainer
- Returns:
- binding definition root
-
getDefinitionContext
Description copied from interface:IContainer
Get definition context for binding element.- Specified by:
getDefinitionContext
in interfaceIContainer
- Returns:
- binding definition context
-
indent
public static void indent(int depth) -
print
public void print()
-