org.jibx.binding.def
Class DefinitionContext

java.lang.Object
  extended by org.jibx.binding.def.DefinitionContext

public class DefinitionContext
extends java.lang.Object

Nesting level for definitions in binding. This tracks namespace and mapping definitions that apply to all enclosed items.

Version:
1.0
Author:
Dennis M. Sosnoski

Field Summary
private  NamespaceDefinition m_attributeDefault
          Namespace used by default at this level for attributes.
private  org.jibx.binding.util.ArrayMap m_classMap
          Mapping from fully qualified class name to mapping index (lazy create).
private  IContainer m_container
          Containing binding definition component.
private  DefinitionContext m_context
          Containing definition context.
private  java.util.HashMap m_convertMap
          Map from signatures to String conversions.
private  NamespaceDefinition m_elementDefault
          Namespace used by default at this level for elements.
private  java.util.HashMap m_formatMap
          Map from format qnames to String conversions.
private  java.util.ArrayList m_mappings
          Class mappings defined at level (lazy create).
private  java.util.HashMap m_namedStructureMap
          Named binding components (only for root context of a binding).
private  java.util.ArrayList m_namespaces
          Namespaces defined at level (lazy create).
private  java.util.HashMap m_prefixMap
          Mapping from prefix to namespace definition (lazy create).
private  java.util.HashMap m_uriMap
          Mapping from URI to namespace definition (lazy create).
 
Constructor Summary
DefinitionContext(IContainer contain)
          Constructor.
 
Method Summary
 void addConversion(QName name, StringConversion conv)
          Add named conversion.
 void addImpliedNamespace(NamespaceDefinition def)
          Add namespace declaration to set defined at this level.
 void addMapping(IMapping def)
          Add class mapping to set defined at this level.
 void addNamedStructure(java.lang.String name, IComponent comp)
          Add named structure component to set defined at this level.
 void addNamespace(NamespaceDefinition def)
          Add namespace to set defined at this level.
private  boolean checkDuplicateNamespace(NamespaceDefinition def)
          Check for duplicate or conflicting namespace.
 void generateCode(boolean verbose, boolean force)
          Generate code.
private  void genFillNamespaceIndexes(java.util.ArrayList nss, MethodBuilder mb)
          Internal method to generate code to fill array with namespace indexes.
private  void genFillNamespacePrefixes(java.util.ArrayList nss, MethodBuilder mb)
          Internal method to generate code to fill array with namespace prefixes.
 void genLoadNamespaces(MethodBuilder mb)
          Generate code for loading namespace index and URI arrays.
 IMapping getClassMapping(java.lang.String name)
          Get mapping definition for class.
 StringConversion getConversion(ClassFile clas)
          Get conversion definition for class.
 int getDefaultIndex(boolean attr)
          Get the default namespace index for a contained name.
private  NamespaceDefinition getDefaultNamespace(boolean attr)
          Get the default namespace for a contained name.
 java.lang.String getDefaultURI(boolean attr)
          Get the default namespace URI for a contained name.
 IMapping getMappingAtLevel(java.lang.String name)
          Get mapping definition for class if defined at this level.
 java.util.ArrayList getMappings()
          Get mapping definitions at level.
 StringConversion getNamedConversion(QName name)
          Get named conversion definition.
 IComponent getNamedStructure(java.lang.String name)
          Get nested structure by name.
 int getNamespaceIndex(java.lang.String uri, boolean attr)
          Get namespace index for a given URI.
 java.util.ArrayList getNamespaces()
          Get the namespaces defined in this context
 StringConversion getSpecificConversion(java.lang.String name)
          Get specific conversion definition for type.
 boolean hasNamespace()
          Check if one or more namespaces are defined in this context.
private  void internalAddNamespace(NamespaceDefinition def)
          Add namespace to internal tables.
 void linkMappings()
          Links extension mappings to their base mappings.
 void print(int depth)
           
 void setConversion(StringConversion conv)
          Set specific conversion definition for type.
 void setDefaultConversion(QName name, StringConversion conv)
          Sets a conversion definition by both type and name.
 void setLinkages()
          Set linkages between binding components.
 void setNamedConversion(QName name, StringConversion conv)
          Sets a named conversion definition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_container

private final IContainer m_container
Containing binding definition component.


m_context

private final DefinitionContext m_context
Containing definition context.


m_attributeDefault

private NamespaceDefinition m_attributeDefault
Namespace used by default at this level for attributes.


m_elementDefault

private NamespaceDefinition m_elementDefault
Namespace used by default at this level for elements.


m_namespaces

private java.util.ArrayList m_namespaces
Namespaces defined at level (lazy create).


m_prefixMap

private java.util.HashMap m_prefixMap
Mapping from prefix to namespace definition (lazy create).


m_uriMap

private java.util.HashMap m_uriMap
Mapping from URI to namespace definition (lazy create).


m_classMap

private org.jibx.binding.util.ArrayMap m_classMap
Mapping from fully qualified class name to mapping index (lazy create).


m_mappings

private java.util.ArrayList m_mappings
Class mappings defined at level (lazy create).


m_convertMap

private java.util.HashMap m_convertMap
Map from signatures to String conversions.


m_formatMap

private java.util.HashMap m_formatMap
Map from format qnames to String conversions.


m_namedStructureMap

private java.util.HashMap m_namedStructureMap
Named binding components (only for root context of a binding).

Constructor Detail

DefinitionContext

public DefinitionContext(IContainer contain)
Constructor. Uses the containing context to establish the hierarchy for resolving namespaces and class mappings.

Parameters:
contain - containing binding definition component
Method Detail

checkDuplicateNamespace

private boolean checkDuplicateNamespace(NamespaceDefinition def)
                                 throws JiBXException
Check for duplicate or conflicting namespace. This also intializes the namespace structures for this context the first time the method is called.

Parameters:
def -
Returns:
duplicate flag (either complete duplicate, or prior definition of same URI with prefix is present)
Throws:
JiBXException - on conflicting prefix

internalAddNamespace

private void internalAddNamespace(NamespaceDefinition def)
Add namespace to internal tables.

Parameters:
def -

addNamespace

public void addNamespace(NamespaceDefinition def)
                  throws JiBXException
Add namespace to set defined at this level. If the new namespace conflicts with an existing namespace at this level (in terms of default usage or prefix) this throws an exception.

Parameters:
def - namespace definition to be added (duplicates ignored)
Throws:
JiBXException - on namespace definition conflict

addImpliedNamespace

public void addImpliedNamespace(NamespaceDefinition def)
                         throws JiBXException
Add namespace declaration to set defined at this level. This method treats all namespaces as though they were declared with default="none". If the new namespace prefix conflicts with an existing namespace this throws an exception.

Parameters:
def - namespace definition to be added (duplicates ignored)
Throws:
JiBXException - on namespace definition conflict

addMapping

public void addMapping(IMapping def)
                throws JiBXException
Add class mapping to set defined at this level. If the new mapping conflicts with an existing one at this level it throws an exception.

Parameters:
def - mapping definition to be added
Throws:
JiBXException - on mapping definition conflict

addNamedStructure

public void addNamedStructure(java.lang.String name,
                              IComponent comp)
                       throws JiBXException
Add named structure component to set defined at this level. If the name conflicts with an existing one at this level it throws an exception.

Parameters:
name - component name to be set
comp - named component
Throws:
JiBXException - on mapping definition conflict

getDefaultNamespace

private NamespaceDefinition getDefaultNamespace(boolean attr)
Get the default namespace for a contained name. Elements and attributes are treated separately, since namespace handling differs between the two.

Parameters:
attr - flag for attribute name
Returns:
default namespace URI, or null if none

getDefaultURI

public java.lang.String getDefaultURI(boolean attr)
Get the default namespace URI for a contained name. Elements and attributes are treated separately, since namespace handling differs between the two.

Parameters:
attr - flag for attribute name
Returns:
default namespace URI, or null if none

getDefaultIndex

public int getDefaultIndex(boolean attr)
Get the default namespace index for a contained name. Elements and attributes are treated separately, since namespace handling differs between the two.

Parameters:
attr - flag for attribute name
Returns:
default namespace index

getNamespaceIndex

public int getNamespaceIndex(java.lang.String uri,
                             boolean attr)
                      throws JiBXException
Get namespace index for a given URI. Finds the prefix for a URI in a name contained by this level, throwing an exception if the URI is not found or does not have a prefix.

Parameters:
uri - namespace URI to be found
attr - flag for attribute name
Returns:
namespace index for URI
Throws:
JiBXException - if URI not defined or not usable

getMappingAtLevel

public IMapping getMappingAtLevel(java.lang.String name)
Get mapping definition for class if defined at this level.

Parameters:
name - fully qualified class name
Returns:
mapping definition for class, or null if not defined

getClassMapping

public IMapping getClassMapping(java.lang.String name)
Get mapping definition for class. Finds the mapping for a fully qualified class name, throwing an exception if no mapping is defined. This can only be used during the linkage phase.

Parameters:
name - fully qualified class name
Returns:
mapping definition for class, or null if not defined

getNamedStructure

public IComponent getNamedStructure(java.lang.String name)
                             throws JiBXException
Get nested structure by name. Finds the nested structure with the given name, throwing an exception if no component with that name is defined.

Parameters:
name - component name to be found
Returns:
component with given name
Throws:
JiBXException - if name not defined

getMappings

public java.util.ArrayList getMappings()
Get mapping definitions at level.

Returns:
mapping definitions, null if none defined at level

getSpecificConversion

public StringConversion getSpecificConversion(java.lang.String name)
Get specific conversion definition for type. Finds with an exact match on the class name, checking the containing definitions if a conversion is not found at this level.

Parameters:
name - fully qualified class name to be converted
Returns:
conversion definition for class, or null if not found

getConversion

public StringConversion getConversion(ClassFile clas)
Get conversion definition for class. Finds the conversion based on a fully qualified class name. If a specific conversion for the actual class is not found (either in this or a containing level) this returns the generic object conversion.

Parameters:
clas - information for target conversion class
Returns:
conversion definition for class

getNamedConversion

public StringConversion getNamedConversion(QName name)
Get named conversion definition. Finds the conversion with the supplied name, checking the containing definitions if the conversion is not found at this level.

Parameters:
name - conversion name to be found
Returns:
conversion definition for class

addConversion

public void addConversion(QName name,
                          StringConversion conv)
                   throws JiBXException
Add named conversion. Checks for duplicate conversions defined within a level with the same name.

Parameters:
name - format name for this conversion
conv - conversion definition for class
Throws:
JiBXException - if duplicate conversion definition

setConversion

public void setConversion(StringConversion conv)
                   throws JiBXException
Set specific conversion definition for type. Sets the conversion based on a type signature, checking for duplicate conversions defined within a level.

Parameters:
conv - conversion definition for class
Throws:
JiBXException - if duplicate conversion definition

setNamedConversion

public void setNamedConversion(QName name,
                               StringConversion conv)
                        throws JiBXException
Sets a named conversion definition.

Parameters:
name - format name for this conversion
conv - conversion definition for class
Throws:
JiBXException - if duplicate conversion definition

setDefaultConversion

public void setDefaultConversion(QName name,
                                 StringConversion conv)
                          throws JiBXException
Sets a conversion definition by both type and name. Both the type and name are checked for duplicate conversions defined within a level.

Parameters:
name - format name for this conversion
conv - conversion definition for class
Throws:
JiBXException - if duplicate conversion definition

hasNamespace

public boolean hasNamespace()
Check if one or more namespaces are defined in this context.

Returns:
true if namespaces are defined, false if not

getNamespaces

public java.util.ArrayList getNamespaces()
Get the namespaces defined in this context

Returns:
namespace definitions (may be null if none)

genFillNamespaceIndexes

private void genFillNamespaceIndexes(java.util.ArrayList nss,
                                     MethodBuilder mb)
Internal method to generate code to fill array with namespace indexes. The code generated to this point must have the array reference on the stack.

Parameters:
nss - namespaces to be handled
mb - method builder for generated code

genFillNamespacePrefixes

private void genFillNamespacePrefixes(java.util.ArrayList nss,
                                      MethodBuilder mb)
Internal method to generate code to fill array with namespace prefixes. The code generated to this point must have the array reference on the stack.

Parameters:
nss - namespaces to be handled
mb - method builder for generated code

genLoadNamespaces

public void genLoadNamespaces(MethodBuilder mb)
Generate code for loading namespace index and URI arrays. The code creates the arrays and leaves the references on the stack.

Parameters:
mb - method builder for generated code

generateCode

public void generateCode(boolean verbose,
                         boolean force)
                  throws JiBXException
Generate code. Executes code generation for each top-level mapping defined in this binding, which in turn propagates the code generation all the way down.

Parameters:
verbose - flag for verbose output
force - create marshaller/unmarshaller even for abstract non-base mappings flag
Throws:
JiBXException - if error in transformation

linkMappings

public void linkMappings()
                  throws JiBXException
Links extension mappings to their base mappings. This must be done before the more general linking step in order to determine which abstract mappings are standalone and which are extended by other mappings

Throws:
JiBXException - if error in linking

setLinkages

public void setLinkages()
                 throws JiBXException
Set linkages between binding components. This is called after all the basic information has been set up. All linkage to higher level components should be done by this method, in order to prevent problems due to the order of definitions between components. For the definition context this calls the same method on all mappings defined in this context.

Throws:
JiBXException - if error in configuration

print

public void print(int depth)


Project Web Site