org.jibx.binding.def
Class BindingDefinition

java.lang.Object
  extended by 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
static int BASE_USER_NAMESPACE
          First namespace index available for user definitions.
static String CURRENT_VERSION_NAME
          Current distribution file name.
protected  int m_accessLevel
          Access level for default mappings.
protected  int m_autoLink
          Auto-link style for default mappings.
protected  IContainer m_container
          Containing binding component.
protected  int m_nameStyle
          Style used for generating element or attribute names.
protected  String m_stripPrefix
          Prefix text to be stripped from names.
protected  String m_stripSuffix
          Suffix text to be stripped from names.
protected  int m_styleDefault
          Default style for value expression.
 
Constructor Summary
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
 void 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.
 void generateCode(boolean verbose)
          Generate code.
 void generateCode(boolean verbose1, boolean verbose2)
          Generate code.
static BindingDefinition getBinding(int index)
          Get indexed binding.
 BindingDefinition getBindingRoot()
          Get root of binding definition.
 BoundClass getBoundClass()
          Get class linked to binding element.
 String getDefaultPackage()
          Get default package used for code generation.
 File getDefaultRoot()
          Get root directory for default code generation package.
 DefinitionContext getDefinitionContext()
          Get definition context for binding element.
 String getFactoryName()
          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.
 String getMarshallerUnmarshallerName(String clas)
          Get marshaller/unmarshaller name in binding.
 int getNamespaceUriIndex(String uri, String prefix)
          Get index for namespace URI in binding.
 String getPrefix()
          Get prefix for method or class generation.
 String getPrefix(String uri)
          Get the prefix assigned for a namespace.
 int getStyleDefault()
          Get default style for value expression.
 boolean hasNamespaces()
           
static void indent(int depth)
           
 boolean isAddConstructors()
          Check if default constructor generation is enabled.
 boolean isContentOrdered()
          Check if content children are ordered.
 boolean isForwards()
          Check if forward ids are supported by unmarshalling binding.
 boolean isIdGlobal()
          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 isTrackSource()
          Check if source tracking is supported by unmarshalling binding.
 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 setSchemaInstanceUsed()
          Set flag for schema instance namespace used in binding.
 void unmarshal(UnmarshallingContext ctx)
          Unmarshal common container attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 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 name
ibind - input binding flag
obind - output binding flag
tpack - target package
glob - global IDs flag
forward - support forward referenced IDs flag
source - add source tracking for unmarshalled objects flag
force - create marshaller/unmarshaller classes for top-level non-base mappings
add - add default constructors where necessary flag
trim - trim whitespace from simple values before conversion flag
major - major version number
minor - minor version number
Throws:
JiBXException - if error in transformation
Method Detail

getBoundClass

public BoundClass getBoundClass()
Get class linked to binding element. Implementation of IContainer interface, just returns null in this case.

Returns:
information for class linked by binding

getStyleDefault

public int getStyleDefault()
Get default style for value expression. Implementation of IContainer interface.

Specified by:
getStyleDefault in interface IContainer
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 factory
root - 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

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 the getMarshallerUnmarshallerName(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, the setMarshallerUnmarshallerClasses(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 name
mclas - fully qualified name of marshaller class
uclas - 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 returns 0.

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 number 0.

Parameters:
uri - namespace URI to be included in binding
prefix - 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(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 binding
major - required major version number
minor - required minor version number
Returns:
namespace index translation table (null if none)

getPrefix

public String getPrefix(String uri)
Get the prefix assigned for a namespace. This is intended mainly for use with precompiled bindings, where the fixPrefixes() 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 JiBXException
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 pass
verbose2 - flag for verbose output from second pass
Throws:
JiBXException - if error in code generation

generateCode

public void generateCode(boolean verbose)
                  throws JiBXException
Generate code. This version preserves compatibility with the older form of the call, always passing false for the second-pass verbose flag. See generateCode(boolean, boolean) for details of processing.

Parameters:
verbose - flag for verbose output from first pass
Throws:
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 binding
keeps - 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: IContainer
Check if content children are ordered.

Specified by:
isContentOrdered in interface IContainer
Returns:
true if ordered, false if not

hasNamespaces

public boolean hasNamespaces()

getBindingRoot

public BindingDefinition getBindingRoot()
Description copied from interface: IContainer
Get root of binding definition.

Specified by:
getBindingRoot in interface IContainer
Returns:
binding definition root

getDefinitionContext

public DefinitionContext getDefinitionContext()
Description copied from interface: IContainer
Get definition context for binding element.

Specified by:
getDefinitionContext in interface IContainer
Returns:
binding definition context

indent

public static void indent(int depth)

print

public void print()

unmarshal

public void unmarshal(UnmarshallingContext ctx)
               throws JiBXException
Unmarshal common container attributes.

Parameters:
ctx - unmarshalling context information
Throws:
JiBXException - if error in unmarshalling


Copyright © 2005-2011 jibx.org. All Rights Reserved.