Package org.jibx.binding.def
Class DefinitionContext
- java.lang.Object
-
- org.jibx.binding.def.DefinitionContext
-
public class DefinitionContext extends java.lang.ObjectNesting level for definitions in binding. This tracks namespace and mapping definitions that apply to all enclosed items.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description private NamespaceDefinitionm_attributeDefaultNamespace used by default at this level for attributes.private ArrayMapm_classMapMapping from fully qualified class name to mapping index (lazy create).private IContainerm_containerContaining binding definition component.private DefinitionContextm_contextContaining definition context.private java.util.Mapm_convertMapMap from signatures toStringconversions.private NamespaceDefinitionm_elementDefaultNamespace used by default at this level for elements.private java.util.Mapm_formatMapMap from format qnames toStringconversions.private java.util.ArrayListm_mappingsClass mappings defined at level (lazy create).private java.util.Mapm_namedStructureMapNamed binding components (only for root context of a binding).private java.util.ArrayListm_namespacesNamespaces defined at level (lazy create).private java.util.Mapm_overrideMapMapping from override namespace definition to original (lazy create).private java.util.Mapm_uriMapMapping from URI to namespace definition (lazy create).
-
Constructor Summary
Constructors Constructor Description DefinitionContext(IContainer contain)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConversion(QName name, StringConversion conv)Add named conversion.voidaddImpliedNamespace(NamespaceDefinition def)Add namespace declaration to set defined at this level.voidaddMapping(IMapping def)Add class mapping to set defined at this level.voidaddNamedStructure(java.lang.String name, IComponent comp)Add named structure component to set defined at this level.voidaddNamespace(NamespaceDefinition def)Add namespace to set defined at this level.private booleancheckDuplicateNamespace(NamespaceDefinition def)Check for duplicate namespace definition.voidgenerateCode(boolean verbose, boolean force)Generate code.private voidgenFillNamespaceIndexes(java.util.ArrayList nss, MethodBuilder mb)Internal method to generate code to fill array with namespace indexes.private voidgenFillNamespacePrefixes(java.util.ArrayList nss, MethodBuilder mb)Internal method to generate code to fill array with namespace prefixes.voidgenLoadNamespaces(MethodBuilder mb)Generate code for loading namespace index and URI arrays.IMappinggetClassMapping(java.lang.String name)Get mapping definition for class.StringConversiongetConversion(ClassFile clas)Get conversion definition for class.intgetDefaultIndex(boolean attr)Get the default namespace index for a contained name.private NamespaceDefinitiongetDefaultNamespace(boolean attr)Get the default namespace for a contained name.java.lang.StringgetDefaultURI(boolean attr)Get the default namespace URI for a contained name.IMappinggetMappingAtLevel(java.lang.String name)Get mapping definition for class if defined at this level.java.util.ArrayListgetMappings()Get mapping definitions at level.StringConversiongetNamedConversion(QName name)Get named conversion definition.IComponentgetNamedStructure(java.lang.String name)Get nested structure by name.intgetNamespaceIndex(java.lang.String uri, boolean attr)Get namespace index for a given URI.java.util.ArrayListgetNamespaces()Get the namespaces defined in this contextStringConversiongetSpecificConversion(java.lang.String name)Get specific conversion definition for type.booleanhasNamespace()Check if one or more namespaces are defined in this context.private voidinternalAddNamespace(NamespaceDefinition def)Add namespace to internal tables.voidlinkMappings()Links extension mappings to their base mappings.voidprint(int depth)voidsetConversion(StringConversion conv)Set specific conversion definition for type.voidsetDefaultConversion(QName name, StringConversion conv)Sets a conversion definition by both type and name.voidsetLinkages()Set linkages between binding components.voidsetNamedConversion(QName name, StringConversion conv)Sets a named conversion definition.
-
-
-
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_uriMap
private java.util.Map m_uriMap
Mapping from URI to namespace definition (lazy create).
-
m_overrideMap
private java.util.Map m_overrideMap
Mapping from override namespace definition to original (lazy create).
-
m_classMap
private 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.Map m_convertMap
Map from signatures toStringconversions.
-
m_formatMap
private java.util.Map m_formatMap
Map from format qnames toStringconversions.
-
m_namedStructureMap
private java.util.Map 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)
Check for duplicate namespace definition. This also initializes 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)
-
internalAddNamespace
private void internalAddNamespace(NamespaceDefinition def)
Add namespace to internal tables.- Parameters:
def-
-
addNamespace
public void addNamespace(NamespaceDefinition def)
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)
-
addImpliedNamespace
public void addImpliedNamespace(NamespaceDefinition def)
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)
-
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 JiBXExceptionAdd 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 setcomp- 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
nullif 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
nullif 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 JiBXExceptionGet 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 foundattr- 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
nullif 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
nullif 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,
nullif 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
nullif 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 conversionconv- 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 conversionconv- 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 conversionconv- 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:
trueif namespaces are defined,falseif not
-
getNamespaces
public java.util.ArrayList getNamespaces()
Get the namespaces defined in this context- Returns:
- namespace definitions (may be
nullif 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 handledmb- 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 handledmb- 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 JiBXExceptionGenerate 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 outputforce- create marshaller/unmarshaller even for abstract non-base mappings flag- Throws:
JiBXException- if error in transformation
-
linkMappings
public void linkMappings() throws JiBXExceptionLinks 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 JiBXExceptionSet 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)
-
-