org.jibx.schema.validation
Class ValidationContext

java.lang.Object
  extended by org.jibx.schema.SchemaContextTracker
      extended by org.jibx.schema.validation.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

Field Summary
private  java.util.Set m_duplicateNamespaces
          Set of namespaces with multiple schemas.
private  int m_errorCount
          Number of errors reported.
private  int m_fatalCount
          Number of fatals reported.
private  java.util.Map m_idSchemaMap
          Map from identifier to schema.
private  java.util.Map m_namespaceSchemaMap
          Map from namespace URI to schema.
private  java.util.ArrayList m_problemList
          List of problem items reported by validation.
private  java.util.Set m_skipSet
          Set of elements to be skipped in walking tree.
private  int m_unimplementedCount
          Number of unimplementeds reported.
private  int m_warningCount
          Number of warnings reported.
 
Fields inherited from class org.jibx.schema.SchemaContextTracker
m_nameRegister
 
Constructor Summary
ValidationContext()
          Constructor.
 
Method Summary
 boolean addError(java.lang.String msg, java.lang.Object obj)
          Add error item.
 void addFatal(java.lang.String msg, java.lang.Object obj)
          Add fatal item.
 void addProblem(ValidationProblem problem)
          Add problem report.
protected  void addSkip(java.lang.Object skip)
          Add element to set to be skipped.
 void addUnimplemented(java.lang.String msg, java.lang.Object obj)
          Add unimplemented feature item for current element.
 void addWarning(java.lang.String msg, java.lang.Object obj)
          Add warning item.
 AttributeElement findAttribute(QName qname)
          Find global attribute by name.
 AttributeGroupElement findAttributeGroup(QName qname)
          Find attribute group by name.
 ElementElement findElement(QName qname)
          Find global element by name.
 GroupElement findGroup(QName qname)
          Find group by name.
 CommonTypeDefinition findType(QName qname)
          Find global type by name.
 int getErrorCount()
          Get number of error problems reported.
 int getFatalCount()
          Get number of fatal problems reported.
 java.util.ArrayList getProblems()
          Get list of problems.
 SchemaElement getSchemaById(java.lang.String id)
          Get schema element by identifier.
 SchemaElement getSchemaByNamespace(java.lang.String uri)
          Get schema element by target namespace.
 int getSchemaCount()
          Get the number of schemas processed by this context.
 int getUnimplementedCount()
          Get number of unimplemented feature problems reported.
 int getWarningCount()
          Get number of warning problems reported.
 boolean isSkipped(java.lang.Object obj)
          Check if a component is being skipped due to a fatal error.
 java.util.Iterator iterateSchemas()
          Get iterator for all schemas defined in this context.
 void registerAttribute(QName qname, AttributeElement def)
          Register global attribute in the current schema definition.
 void registerAttributeGroup(QName qname, AttributeGroupElement def)
          Register global attribute group in the current schema definition.
 void registerElement(QName qname, ElementElement def)
          Register global element in the current schema definition.
 void registerGroup(QName qname, GroupElement def)
          Register global group in the current schema definition.
 void registerType(QName qname, CommonTypeDefinition def)
          Register global type in the current schema definition.
 void reset()
          Reset context for reuse.
 void setSchema(java.lang.String id, SchemaElement schema)
          Add schema element with identifier.
 
Methods inherited from class org.jibx.schema.SchemaContextTracker
clearTraversed, enterSchema, exitSchema, getCurrentSchema, getNameRegister, setNameRegister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_idSchemaMap

private java.util.Map m_idSchemaMap
Map from identifier to schema.


m_namespaceSchemaMap

private java.util.Map m_namespaceSchemaMap
Map from namespace URI to schema.


m_duplicateNamespaces

private java.util.Set m_duplicateNamespaces
Set of namespaces with multiple schemas.


m_unimplementedCount

private int m_unimplementedCount
Number of unimplementeds reported.


m_warningCount

private int m_warningCount
Number of warnings reported.


m_errorCount

private int m_errorCount
Number of errors reported.


m_fatalCount

private int m_fatalCount
Number of fatals reported.


m_problemList

private java.util.ArrayList m_problemList
List of problem items reported by validation.


m_skipSet

private java.util.Set m_skipSet
Set of elements to be skipped in walking tree.

Constructor Detail

ValidationContext

public ValidationContext()
Constructor.

Method Detail

reset

public void reset()
Reset context for reuse.


getSchemaByNamespace

public SchemaElement getSchemaByNamespace(java.lang.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(java.lang.String id)
Get schema element by identifier. This uses the unique schema identifier to locate a loaded schema instance.

Parameters:
id -
Returns:
schema, or null if not loaded

iterateSchemas

public java.util.Iterator iterateSchemas()
Get iterator for all schemas defined in this context.

Returns:
iterator

setSchema

public void setSchema(java.lang.String id,
                      SchemaElement schema)
Add schema element with identifier. TODO: is the namespace handling sufficient?

Parameters:
id -
schema -

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(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(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(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(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(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(QName qname)
Find global attribute by name.

Parameters:
qname - name
Returns:
definition, or null if not registered

findAttributeGroup

public AttributeGroupElement findAttributeGroup(QName qname)
Find attribute group by name.

Parameters:
qname - name
Returns:
definition, or null if not registered

findElement

public ElementElement findElement(QName qname)
Find global element by name.

Parameters:
qname - name
Returns:
definition, or null if not registered

findGroup

public GroupElement findGroup(QName qname)
Find group by name.

Parameters:
qname - name
Returns:
definition, or null if not registered

findType

public CommonTypeDefinition findType(QName qname)
Find global type by name.

Parameters:
qname - name
Returns:
definition, or null if not registered

addUnimplemented

public void addUnimplemented(java.lang.String msg,
                             java.lang.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(java.lang.String msg,
                       java.lang.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(java.lang.String msg,
                        java.lang.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(java.lang.String msg,
                     java.lang.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 java.util.ArrayList getProblems()
Get list of problems.

Returns:
problem list

addSkip

protected void addSkip(java.lang.Object skip)
Add element to set to be skipped.

Parameters:
skip -

isSkipped

public boolean isSkipped(java.lang.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


Project Web Site