Package org.jibx.binding.def
Class BindingDefinition
- java.lang.Object
-
- org.jibx.binding.def.BindingDefinition
-
- All Implemented Interfaces:
IContainer
public class BindingDefinition extends Object implements IContainer
Binding definition. This is the root of the object graph for a binding.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description static intBASE_USER_NAMESPACEFirst namespace index available for user definitions.static StringCURRENT_VERSION_NAMECurrent distribution file name.protected intm_accessLevelAccess level for default mappings.protected intm_autoLinkAuto-link style for default mappings.protected IContainerm_containerContaining binding component.protected intm_nameStyleStyle used for generating element or attribute names.protected Stringm_stripPrefixPrefix text to be stripped from names.protected Stringm_stripSuffixSuffix text to be stripped from names.protected intm_styleDefaultDefault style for value expression.
-
Constructor Summary
Constructors Constructor Description 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)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddClassList(ClassFile[] adds, ClassFile[] keeps)Add the list of classes used by the binding compiler to the binding factory.voidaddMappingName(String name)Add mapping name to binding.int[]addPrecompiledBinding(org.jibx.runtime.IBindingFactory factory, int major, int minor)Add a precompiled binding reference to this binding.voidgenerateCode(boolean verbose)Generate code.voidgenerateCode(boolean verbose1, boolean verbose2)Generate code.static BindingDefinitiongetBinding(int index)Get indexed binding.BindingDefinitiongetBindingRoot()Get root of binding definition.BoundClassgetBoundClass()Get class linked to binding element.StringgetDefaultPackage()Get default package used for code generation.FilegetDefaultRoot()Get root directory for default code generation package.DefinitionContextgetDefinitionContext()Get definition context for binding element.StringgetFactoryName()Get the fully-qualified name of the binding factory class for this binding.intgetIdClassIndex(String name)Get index for ID'ed class from binding.intgetIndex()Get index number of binding.StringgetMarshallerUnmarshallerName(String clas)Get marshaller/unmarshaller name in binding.intgetNamespaceUriIndex(String uri, String prefix)Get index for namespace URI in binding.StringgetPrefix()Get prefix for method or class generation.StringgetPrefix(String uri)Get the prefix assigned for a namespace.intgetStyleDefault()Get default style for value expression.booleanhasNamespaces()static voidindent(int depth)booleanisAddConstructors()Check if default constructor generation is enabled.booleanisContentOrdered()Check if content children are ordered.booleanisForwards()Check if forward ids are supported by unmarshalling binding.booleanisIdGlobal()Check if global ids are used by binding.booleanisInput()Check if binding is defined for unmarshalling.booleanisOutput()Check if binding is defined for marshalling.booleanisTrackSource()Check if source tracking is supported by unmarshalling binding.voidprint()static voidreset()Discard cached information and reset in preparation for a new binding run.voidsetFactoryLocation(String tpack, File root)Set location for binding factory class generation.booleansetIdChild(IComponent child)Set ID property.voidsetMarshallerUnmarshallerClasses(String name, String mclas, String uclas)Set marshaller and unmarshaller class names.voidsetSchemaInstanceUsed()Set flag for schema instance namespace used in binding.voidunmarshal(org.jibx.runtime.impl.UnmarshallingContext ctx)Unmarshal common container attributes.
-
-
-
Field Detail
-
BASE_USER_NAMESPACE
public static final int BASE_USER_NAMESPACE
First namespace index available for user definitions.- See Also:
- Constant Field Values
-
CURRENT_VERSION_NAME
public static final String CURRENT_VERSION_NAME
Current distribution file name. This is filled in by the Ant build process to match the current distribution.- See Also:
- Constant Field Values
-
m_container
protected IContainer m_container
Containing binding component.
-
m_styleDefault
protected int m_styleDefault
Default style for value expression.
-
m_autoLink
protected int m_autoLink
Auto-link style for default mappings.
-
m_accessLevel
protected int m_accessLevel
Access level for default mappings.
-
m_stripPrefix
protected String m_stripPrefix
Prefix text to be stripped from names.
-
m_stripSuffix
protected String m_stripSuffix
Suffix text to be stripped from names.
-
m_nameStyle
protected int m_nameStyle
Style used for generating element or attribute names.
-
-
Constructor Detail
-
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 org.jibx.runtime.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:
org.jibx.runtime.JiBXException- if error in transformation
-
-
Method Detail
-
getBoundClass
public BoundClass getBoundClass()
Get class linked to binding element. Implementation ofIContainerinterface, just returnsnullin this case.- Returns:
- information for class linked by binding
-
getStyleDefault
public int getStyleDefault()
Get default style for value expression. Implementation ofIContainerinterface.- Specified by:
getStyleDefaultin interfaceIContainer- Returns:
- default style type for values
-
setIdChild
public boolean setIdChild(IComponent child)
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
public String getDefaultPackage()
Get default package used for code generation.- Returns:
- default code generation package
-
getDefaultRoot
public File getDefaultRoot()
Get root directory for default code generation package.- Returns:
- root for default code generation
-
setFactoryLocation
public void setFactoryLocation(String tpack, File root)
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:
trueif defined,falseif not
-
isOutput
public boolean isOutput()
Check if binding is defined for marshalling.- Returns:
trueif defined,falseif not
-
isIdGlobal
public boolean isIdGlobal()
Check if global ids are used by binding.- Returns:
trueif defined,falseif not
-
isForwards
public boolean isForwards()
Check if forward ids are supported by unmarshalling binding.- Returns:
trueif supported,falseif not
-
isTrackSource
public boolean isTrackSource()
Check if source tracking is supported by unmarshalling binding.- Returns:
trueif defined,falseif not
-
isAddConstructors
public boolean isAddConstructors()
Check if default constructor generation is enabled.- Returns:
trueif default constructor generation enabled,falseif not
-
getPrefix
public String getPrefix()
Get prefix for method or class generation.- Returns:
- prefix for names created by this binding
-
addMappingName
public void addMappingName(String name)
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
public String getMarshallerUnmarshallerName(String clas)
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
public void setMarshallerUnmarshallerClasses(String name, String mclas, String uclas)
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
public int getIdClassIndex(String name)
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
public int getNamespaceUriIndex(String uri, String prefix)
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
public int[] addPrecompiledBinding(org.jibx.runtime.IBindingFactory factory, int major, int minor)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 (
nullif none)
-
getPrefix
public String getPrefix(String uri)
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
-
getFactoryName
public String getFactoryName()
Get the fully-qualified name of the binding factory class for this binding.- Returns:
- class name
-
generateCode
public void generateCode(boolean verbose1, boolean verbose2) throws org.jibx.runtime.JiBXExceptionGenerate 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:
org.jibx.runtime.JiBXException- if error in code generation
-
generateCode
public void generateCode(boolean verbose) throws org.jibx.runtime.JiBXExceptionGenerate code. This version preserves compatibility with the older form of the call, always passingfalsefor the second-pass verbose flag. SeegenerateCode(boolean, boolean)for details of processing.- Parameters:
verbose- flag for verbose output from first pass- Throws:
org.jibx.runtime.JiBXException- if error in code generation
-
addClassList
public void addClassList(ClassFile[] adds, ClassFile[] keeps)
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
-
getBinding
public static BindingDefinition getBinding(int index)
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:IContainerCheck if content children are ordered.- Specified by:
isContentOrderedin interfaceIContainer- Returns:
trueif ordered,falseif not
-
hasNamespaces
public boolean hasNamespaces()
-
getBindingRoot
public BindingDefinition getBindingRoot()
Description copied from interface:IContainerGet root of binding definition.- Specified by:
getBindingRootin interfaceIContainer- Returns:
- binding definition root
-
getDefinitionContext
public DefinitionContext getDefinitionContext()
Description copied from interface:IContainerGet definition context for binding element.- Specified by:
getDefinitionContextin interfaceIContainer- Returns:
- binding definition context
-
indent
public static void indent(int depth)
-
print
public void print()
-
unmarshal
public void unmarshal(org.jibx.runtime.impl.UnmarshallingContext ctx) throws org.jibx.runtime.JiBXExceptionUnmarshal common container attributes.- Parameters:
ctx- unmarshalling context information- Throws:
org.jibx.runtime.JiBXException- if error in unmarshalling
-
-