Package org.jibx.binding.def
Class DefinitionContext
- java.lang.Object
-
- org.jibx.binding.def.DefinitionContext
-
public class DefinitionContext extends Object
Nesting level for definitions in binding. This tracks namespace and mapping definitions that apply to all enclosed items.- Author:
- Dennis M. Sosnoski
-
-
Constructor Summary
Constructors Constructor Description DefinitionContext(IContainer contain)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConversion(org.jibx.runtime.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(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.voidgenerateCode(boolean verbose, boolean force)Generate code.voidgenLoadNamespaces(MethodBuilder mb)Generate code for loading namespace index and URI arrays.IMappinggetClassMapping(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.StringgetDefaultURI(boolean attr)Get the default namespace URI for a contained name.IMappinggetMappingAtLevel(String name)Get mapping definition for class if defined at this level.ArrayListgetMappings()Get mapping definitions at level.StringConversiongetNamedConversion(org.jibx.runtime.QName name)Get named conversion definition.IComponentgetNamedStructure(String name)Get nested structure by name.intgetNamespaceIndex(String uri, boolean attr)Get namespace index for a given URI.ArrayListgetNamespaces()Get the namespaces defined in this contextStringConversiongetSpecificConversion(String name)Get specific conversion definition for type.booleanhasNamespace()Check if one or more namespaces are defined in this context.voidlinkMappings()Links extension mappings to their base mappings.voidprint(int depth)voidsetConversion(StringConversion conv)Set specific conversion definition for type.voidsetDefaultConversion(org.jibx.runtime.QName name, StringConversion conv)Sets a conversion definition by both type and name.voidsetLinkages()Set linkages between binding components.voidsetNamedConversion(org.jibx.runtime.QName name, StringConversion conv)Sets a named conversion definition.
-
-
-
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
-
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 org.jibx.runtime.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:
org.jibx.runtime.JiBXException- on mapping definition conflict
-
addNamedStructure
public void addNamedStructure(String name, IComponent comp) throws org.jibx.runtime.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 setcomp- named component- Throws:
org.jibx.runtime.JiBXException- on mapping definition conflict
-
getDefaultURI
public 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(String uri, boolean attr) throws org.jibx.runtime.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 foundattr- flag for attribute name- Returns:
- namespace index for URI
- Throws:
org.jibx.runtime.JiBXException- if URI not defined or not usable
-
getMappingAtLevel
public IMapping getMappingAtLevel(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(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(String name) throws org.jibx.runtime.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:
org.jibx.runtime.JiBXException- if name not defined
-
getMappings
public ArrayList getMappings()
Get mapping definitions at level.- Returns:
- mapping definitions,
nullif none defined at level
-
getSpecificConversion
public StringConversion getSpecificConversion(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(org.jibx.runtime.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(org.jibx.runtime.QName name, StringConversion conv) throws org.jibx.runtime.JiBXExceptionAdd 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:
org.jibx.runtime.JiBXException- if duplicate conversion definition
-
setConversion
public void setConversion(StringConversion conv) throws org.jibx.runtime.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:
org.jibx.runtime.JiBXException- if duplicate conversion definition
-
setNamedConversion
public void setNamedConversion(org.jibx.runtime.QName name, StringConversion conv) throws org.jibx.runtime.JiBXExceptionSets a named conversion definition.- Parameters:
name- format name for this conversionconv- conversion definition for class- Throws:
org.jibx.runtime.JiBXException- if duplicate conversion definition
-
setDefaultConversion
public void setDefaultConversion(org.jibx.runtime.QName name, StringConversion conv) throws org.jibx.runtime.JiBXExceptionSets 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:
org.jibx.runtime.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 ArrayList getNamespaces()
Get the namespaces defined in this context- Returns:
- namespace definitions (may be
nullif none)
-
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 org.jibx.runtime.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:
org.jibx.runtime.JiBXException- if error in transformation
-
linkMappings
public void linkMappings() throws org.jibx.runtime.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:
org.jibx.runtime.JiBXException- if error in linking
-
setLinkages
public void setLinkages() throws org.jibx.runtime.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:
org.jibx.runtime.JiBXException- if error in configuration
-
print
public void print(int depth)
-
-