Package org.jibx.binding.def
Class DefinitionContext
java.lang.Object
org.jibx.binding.def.DefinitionContext
Nesting level for definitions in binding. This tracks namespace and mapping
definitions that apply to all enclosed items.
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate NamespaceDefinition
Namespace used by default at this level for attributes.private ArrayMap
Mapping from fully qualified class name to mapping index (lazy create).private final IContainer
Containing binding definition component.private final DefinitionContext
Containing definition context.private Map
Map from signatures toString
conversions.private NamespaceDefinition
Namespace used by default at this level for elements.private Map
Map from format qnames toString
conversions.private ArrayList
Class mappings defined at level (lazy create).private Map
Named binding components (only for root context of a binding).private ArrayList
Namespaces defined at level (lazy create).private Map
Mapping from override namespace definition to original (lazy create).private Map
Mapping from URI to namespace definition (lazy create). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConversion
(QName name, StringConversion conv) Add named conversion.void
Add namespace declaration to set defined at this level.void
addMapping
(IMapping def) Add class mapping to set defined at this level.void
addNamedStructure
(String name, IComponent comp) Add named structure component to set defined at this level.void
Add namespace to set defined at this level.private boolean
Check for duplicate namespace definition.void
generateCode
(boolean verbose, boolean force) Generate code.private void
Internal method to generate code to fill array with namespace indexes.private void
Internal method to generate code to fill array with namespace prefixes.void
Generate code for loading namespace index and URI arrays.getClassMapping
(String name) Get mapping definition for class.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.getDefaultURI
(boolean attr) Get the default namespace URI for a contained name.getMappingAtLevel
(String name) Get mapping definition for class if defined at this level.Get mapping definitions at level.getNamedConversion
(QName name) Get named conversion definition.getNamedStructure
(String name) Get nested structure by name.int
getNamespaceIndex
(String uri, boolean attr) Get namespace index for a given URI.Get the namespaces defined in this contextgetSpecificConversion
(String name) Get specific conversion definition for type.boolean
Check if one or more namespaces are defined in this context.private void
Add namespace to internal tables.void
Links extension mappings to their base mappings.void
print
(int depth) void
Set specific conversion definition for type.void
setDefaultConversion
(QName name, StringConversion conv) Sets a conversion definition by both type and name.void
Set linkages between binding components.void
setNamedConversion
(QName name, StringConversion conv) Sets a named conversion definition.
-
Field Details
-
m_container
Containing binding definition component. -
m_context
Containing definition context. -
m_attributeDefault
Namespace used by default at this level for attributes. -
m_elementDefault
Namespace used by default at this level for elements. -
m_namespaces
Namespaces defined at level (lazy create). -
m_uriMap
Mapping from URI to namespace definition (lazy create). -
m_overrideMap
Mapping from override namespace definition to original (lazy create). -
m_classMap
Mapping from fully qualified class name to mapping index (lazy create). -
m_mappings
Class mappings defined at level (lazy create). -
m_convertMap
Map from signatures toString
conversions. -
m_formatMap
Map from format qnames toString
conversions. -
m_namedStructureMap
Named binding components (only for root context of a binding).
-
-
Constructor Details
-
DefinitionContext
Constructor. Uses the containing context to establish the hierarchy for resolving namespaces and class mappings.- Parameters:
contain
- containing binding definition component
-
-
Method Details
-
checkDuplicateNamespace
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
Add namespace to internal tables.- Parameters:
def
-
-
addNamespace
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
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
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
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 setcomp
- named component- Throws:
JiBXException
- on mapping definition conflict
-
getDefaultNamespace
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
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
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 foundattr
- flag for attribute name- Returns:
- namespace index for URI
- Throws:
JiBXException
- if URI not defined or not usable
-
getMappingAtLevel
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
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
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
Get mapping definitions at level.- Returns:
- mapping definitions,
null
if none defined at level
-
getSpecificConversion
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
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
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
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
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
Sets a named conversion definition.- Parameters:
name
- format name for this conversionconv
- conversion definition for class- Throws:
JiBXException
- if duplicate conversion definition
-
setDefaultConversion
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:
true
if namespaces are defined,false
if not
-
getNamespaces
Get the namespaces defined in this context- Returns:
- namespace definitions (may be
null
if none)
-
genFillNamespaceIndexes
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
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
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
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 outputforce
- create marshaller/unmarshaller even for abstract non-base mappings flag- Throws:
JiBXException
- if error in transformation
-
linkMappings
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
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)
-