Class ValidationContext

  • All Implemented Interfaces:
    ISchemaListener, ISkipElements

    public class ValidationContext
    extends SchemaContextTracker
    implements ISkipElements
    Tracks the schema validation state. This includes order-dependent state information collected while walking the tree structure of a schema model. Collects all errors and warnings and maintains a summary of the severity of the problems found. For ease of use, this also wraps the schema name register with convenience methods for validation. TODO: separate out a generalized base class and move the base out of the schema package
    Author:
    Dennis M. Sosnoski
    • Constructor Detail

      • ValidationContext

        public ValidationContext()
        Constructor.
    • Method Detail

      • reset

        public void reset()
        Reset context for reuse.
      • getSchemaByNamespace

        public SchemaElement getSchemaByNamespace​(String uri)
        Get schema element by target namespace. The target namespace must be unique.
        Parameters:
        uri - unique namespace URI
        Returns:
        schema, or null if not loaded or non-unique namespace
      • getSchemaById

        public SchemaElement getSchemaById​(String id)
        Get schema element by identifier. This uses the unique schema identifier to locate a loaded schema instance.
        Parameters:
        id - ID
        Returns:
        schema, or null if not loaded
      • iterateSchemas

        public Iterator iterateSchemas()
        Get iterator for all schemas defined in this context.
        Returns:
        iterator
      • setSchema

        public void setSchema​(String id,
                              SchemaElement schema)
        Add schema element with identifier. TODO: is the namespace handling sufficient?
        Parameters:
        id - ID
        schema - Schema Element
      • getSchemaCount

        public int getSchemaCount()
        Get the number of schemas processed by this context.
        Returns:
        count
      • getUnimplementedCount

        public int getUnimplementedCount()
        Get number of unimplemented feature problems reported.
        Returns:
        unimplemented feature problem count
      • getWarningCount

        public int getWarningCount()
        Get number of warning problems reported.
        Returns:
        warning problem count
      • getErrorCount

        public int getErrorCount()
        Get number of error problems reported.
        Returns:
        error problem count
      • getFatalCount

        public int getFatalCount()
        Get number of fatal problems reported.
        Returns:
        fatal problem count
      • registerAttribute

        public void registerAttribute​(org.jibx.runtime.QName qname,
                                      AttributeElement def)
        Register global attribute in the current schema definition. If the name has already been registered this creates an error for the new definition.
        Parameters:
        qname - name
        def - attribute definition
      • registerAttributeGroup

        public void registerAttributeGroup​(org.jibx.runtime.QName qname,
                                           AttributeGroupElement def)
        Register global attribute group in the current schema definition. If the name has already been registered this creates an error for the new definition.
        Parameters:
        qname - name
        def - attribute definition
      • registerElement

        public void registerElement​(org.jibx.runtime.QName qname,
                                    ElementElement def)
        Register global element in the current schema definition. If the name has already been registered this creates an error for the new definition.
        Parameters:
        qname - name
        def - element definition
      • registerGroup

        public void registerGroup​(org.jibx.runtime.QName qname,
                                  GroupElement def)
        Register global group in the current schema definition. If the name has already been registered this creates an error for the new definition.
        Parameters:
        qname - name
        def - attribute definition
      • registerType

        public void registerType​(org.jibx.runtime.QName qname,
                                 CommonTypeDefinition def)
        Register global type in the current schema definition. If the name has already been registered this creates an error for the new definition.
        Parameters:
        qname - name
        def - attribute definition
      • findAttribute

        public AttributeElement findAttribute​(org.jibx.runtime.QName qname)
        Find global attribute by name.
        Parameters:
        qname - name
        Returns:
        definition, or null if not registered
      • findAttributeGroup

        public AttributeGroupElement findAttributeGroup​(org.jibx.runtime.QName qname)
        Find attribute group by name.
        Parameters:
        qname - name
        Returns:
        definition, or null if not registered
      • findElement

        public ElementElement findElement​(org.jibx.runtime.QName qname)
        Find global element by name.
        Parameters:
        qname - name
        Returns:
        definition, or null if not registered
      • findGroup

        public GroupElement findGroup​(org.jibx.runtime.QName qname)
        Find group by name.
        Parameters:
        qname - name
        Returns:
        definition, or null if not registered
      • findType

        public CommonTypeDefinition findType​(org.jibx.runtime.QName qname)
        Find global type by name.
        Parameters:
        qname - name
        Returns:
        definition, or null if not registered
      • addUnimplemented

        public void addUnimplemented​(String msg,
                                     Object obj)
        Add unimplemented feature item for current element. Adds an unimplemented feature item to the problem list, reporting a schema feature which is not supported but does not prevent allows reasonable operation.
        Parameters:
        msg - problem description
        obj - source object for validation error
      • addWarning

        public void addWarning​(String msg,
                               Object obj)
        Add warning item. Adds a warning item to the problem list, which is a possible problem that still allows reasonable operation.
        Parameters:
        msg - problem description
        obj - source object for validation error
      • addError

        public boolean addError​(String msg,
                                Object obj)
        Add error item. Adds an error item to the problem list, which is a definite problem that still allows validation to proceed.
        Parameters:
        msg - problem description
        obj - source object for validation error
        Returns:
        true if to continue validation, false if not
      • addFatal

        public void addFatal​(String msg,
                             Object obj)
        Add fatal item. Adds a fatal item to the problem list, which is a severe problem that blocks further validation within the tree branch involved. The object associated with a fatal error should always be an element.
        Parameters:
        msg - problem description
        obj - source object for validation error (should be an element)
      • addProblem

        public void addProblem​(ValidationProblem problem)
        Add problem report. The problem is added and counted as appropriate.
        Parameters:
        problem - details of problem report
      • getProblems

        public ArrayList getProblems()
        Get list of problems.
        Returns:
        problem list
      • addSkip

        protected void addSkip​(Object skip)
        Add element to set to be skipped.
        Parameters:
        skip - element to set to be skipped
      • reportProblems

        public boolean reportProblems​(ProblemHandler handler)
        Report problems using handler. This clears the problem list after they've been reported, to avoid multiple reports of the same problems.
        Parameters:
        handler - problem handler
        Returns:
        true if one or more errors, false if not
      • isSkipped

        public boolean isSkipped​(Object obj)
        Description copied from interface: ISkipElements
        Check if a component is being skipped due to a fatal error.
        Specified by:
        isSkipped in interface ISkipElements
        Parameters:
        obj - component to be checked
        Returns:
        flag for component being skipped