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
  • Field Details

    • 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 ArrayList m_namespaces
      Namespaces defined at level (lazy create).
    • m_uriMap

      private Map m_uriMap
      Mapping from URI to namespace definition (lazy create).
    • m_overrideMap

      private 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 ArrayList m_mappings
      Class mappings defined at level (lazy create).
    • m_convertMap

      private Map m_convertMap
      Map from signatures to String conversions.
    • m_formatMap

      private Map m_formatMap
      Map from format qnames to String conversions.
    • m_namedStructureMap

      private Map m_namedStructureMap
      Named binding components (only for root context of a binding).
  • Constructor Details

    • 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 Details

    • 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(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 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(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(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(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(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 ArrayList getMappings()
      Get mapping definitions at level.
      Returns:
      mapping definitions, null if 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 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 ArrayList getNamespaces()
      Get the namespaces defined in this context
      Returns:
      namespace definitions (may be null if none)
    • genFillNamespaceIndexes

      private void genFillNamespaceIndexes(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(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)