Class DefinitionContext


  • public class DefinitionContext
    extends Object
    Definition context information. This is used to track definitions of items that can be referenced by other items. The contexts are nested, so that names not found in a context may be defined by a containing context. The access methods take this into account, automatically delegating to the containing context (if defined) when a lookup fails.
    Author:
    Dennis M. Sosnoski
    • Constructor Detail

      • DefinitionContext

        protected DefinitionContext​(DefinitionContext outer)
        Constructor.
        Parameters:
        outer - containing definition context (null if at root of tree)
    • Method Detail

      • getContaining

        public DefinitionContext getContaining()
        Get containing context.
        Returns:
        containing context information (null if at root of tree)
      • getElementDefaultNamespace

        public NamespaceElement getElementDefaultNamespace()
        Get the default namespace applied to element definitions. If there's no default namespace at this level of definitions this moves up the nested definitions contexts until one is found.
        Returns:
        default namespace (null if none)
      • getNamespaceForPrefix

        public NamespaceElement getNamespaceForPrefix​(String prefix)
        Get namespace for prefix.
        Parameters:
        prefix - Prefix
        Returns:
        namespace definition in this context, null if none
      • addNamespace

        public ValidationProblem addNamespace​(NamespaceElement def)
        Add namespace to set defined at this level.
        Parameters:
        def - namespace definition element to be added (duplicates ignored)
        Returns:
        problem information, or null if no problem
      • addImpliedNamespace

        public ValidationProblem addImpliedNamespace​(NamespaceElement def,
                                                     ElementBase ref)
        Add namespace declaration to set defined at this level.
        Parameters:
        def - namespace definition to be added (duplicates ignored)
        ref - binding element referencing the namespace
        Returns:
        problem information, or null if no problem
      • getElementNamespace

        public NamespaceElement getElementNamespace​(NameAttributes name,
                                                    ValidationContext vctx)
        Get namespace definition for element name. TODO: handle multiple prefixes for namespace, proper screening
        Parameters:
        name - attribute group defining name
        vctx - validation context in use
        Returns:
        namespace definition, or null if none that matches
      • getAttributeNamespace

        public NamespaceElement getAttributeNamespace​(NameAttributes name)
        Get namespace definition for attribute name. TODO: handle multiple prefixes for namespace, proper screening
        Parameters:
        name - attribute group defining name
        Returns:
        namespace definition, or null if none that matches
      • addFormat

        public void addFormat​(FormatElement def,
                              ValidationContext vctx)
        Add format to set defined at this level.
        Parameters:
        def - format definition element to be added
        vctx - validation context in use
      • getSpecificFormat

        public FormatElement getSpecificFormat​(String type)
        Get specific format definition for type. Finds with an exact match on the class name, checking the containing definitions if a format is not found at this level.
        Parameters:
        type - fully qualified class name to be converted
        Returns:
        conversion definition for class, or null if not found
      • getNamedFormat

        public FormatElement getNamedFormat​(String name)
        Get named format definition. Finds the format with the supplied name, checking the containing definitions if the format is not found at this level.
        Parameters:
        name - conversion name to be found
        Returns:
        conversion definition with specified name, or null if no conversion with that name
      • getBestFormat

        public FormatElement getBestFormat​(IClass clas)
        Get best format definition for class. Finds the format based on the inheritance hierarchy for the supplied class. If a specific format for the actual class is not found (either in this or a containing level) this returns the most specific superclass format.
        Parameters:
        clas - information for target conversion class
        Returns:
        conversion definition for class, or null if no compatible conversion defined
      • addMappedName

        public void addMappedName​(NameAttributes name,
                                  MappingElementBase def,
                                  ValidationContext vctx)
        Add mapped name to set defined at this level.
        Parameters:
        name - mapped name
        def - mapping definition
        vctx - validation context
      • addTemplate

        public void addTemplate​(MappingElementBase def,
                                ValidationContext vctx)
        Add template or mapping to set defined at this level.
        Parameters:
        def - template definition element to be added
        vctx - validation context in use
      • getSpecificTemplate

        public TemplateElementBase getSpecificTemplate​(String type)
        Get specific template definition for type. Finds with an exact match on the class name, checking the containing definitions if a template is not found at this level.
        Parameters:
        type - fully qualified class name to be converted
        Returns:
        template definition for type, or null if not found
      • getNamedTemplate

        public TemplateElementBase getNamedTemplate​(String name)
        Get named template definition. Finds the template with the supplied name, checking the containing definitions if the template is not found at this level. TODO: Make this specific to TemplateElement in 2.0
        Parameters:
        name - conversion name to be found
        Returns:
        template definition for class, or null if no template with that name
      • isCompatibleTemplateType

        public boolean isCompatibleTemplateType​(IClass clas)
        Checks if a class is compatible with one or more templates. This checks based on the inheritance hierarchy for the supplied class, looks for the class or interface itself as well as any subclasses or implementations.
        Parameters:
        clas - information for target class
        Returns:
        true if compatible type, false if not
      • addNamedStructure

        public ValidationProblem addNamedStructure​(ContainerElementBase def)
        Add named structure to set defined in this context. For named structures only the definition context associated with the binding element should be used. This is a kludge, but will go away in 2.0.
        Parameters:
        def - structure definition
        Returns:
        problem information, or null if no problem
      • getNamedStructure

        public ContainerElementBase getNamedStructure​(String label)
        Get labeled structure definition within this context. For named structures only the definition context associated with the binding element should be used. This is a kludge, but will go away in 2.0.
        Parameters:
        label - structure definition label
        Returns:
        structure definition with specified label, or null if not defined
      • getNamespaces

        public ArrayList getNamespaces()
        Get the namespaces defined in this context
        Returns:
        namespace definitions (may be null if none)