Package org.jibx.schema.validation
Class ValidationContext
- java.lang.Object
-
- org.jibx.schema.SchemaContextTracker
-
- 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
Fields Modifier and Type Field Description private java.util.Setm_duplicateNamespacesSet of namespaces with multiple schemas.private intm_errorCountNumber of errors reported.private intm_fatalCountNumber of fatals reported.private java.util.Mapm_idSchemaMapMap from identifier to schema.private java.util.Mapm_namespaceSchemaMapMap from namespace URI to schema.private java.util.ArrayListm_problemListList of problem items reported by validation.private java.util.Setm_skipSetSet of elements to be skipped in walking tree.private intm_unimplementedCountNumber of unimplementeds reported.private intm_warningCountNumber of warnings reported.private static Loggers_loggerLogger for class.-
Fields inherited from class org.jibx.schema.SchemaContextTracker
m_nameRegister
-
-
Constructor Summary
Constructors Constructor Description ValidationContext()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddError(java.lang.String msg, java.lang.Object obj)Add error item.voidaddFatal(java.lang.String msg, java.lang.Object obj)Add fatal item.voidaddProblem(ValidationProblem problem)Add problem report.protected voidaddSkip(java.lang.Object skip)Add element to set to be skipped.voidaddUnimplemented(java.lang.String msg, java.lang.Object obj)Add unimplemented feature item for current element.voidaddWarning(java.lang.String msg, java.lang.Object obj)Add warning item.AttributeElementfindAttribute(QName qname)Find global attribute by name.AttributeGroupElementfindAttributeGroup(QName qname)Find attribute group by name.ElementElementfindElement(QName qname)Find global element by name.GroupElementfindGroup(QName qname)Find group by name.CommonTypeDefinitionfindType(QName qname)Find global type by name.intgetErrorCount()Get number of error problems reported.intgetFatalCount()Get number of fatal problems reported.java.util.ArrayListgetProblems()Get list of problems.SchemaElementgetSchemaById(java.lang.String id)Get schema element by identifier.SchemaElementgetSchemaByNamespace(java.lang.String uri)Get schema element by target namespace.intgetSchemaCount()Get the number of schemas processed by this context.intgetUnimplementedCount()Get number of unimplemented feature problems reported.intgetWarningCount()Get number of warning problems reported.booleanisSkipped(java.lang.Object obj)Check if a component is being skipped due to a fatal error.java.util.IteratoriterateSchemas()Get iterator for all schemas defined in this context.voidregisterAttribute(QName qname, AttributeElement def)Register global attribute in the current schema definition.voidregisterAttributeGroup(QName qname, AttributeGroupElement def)Register global attribute group in the current schema definition.voidregisterElement(QName qname, ElementElement def)Register global element in the current schema definition.voidregisterGroup(QName qname, GroupElement def)Register global group in the current schema definition.voidregisterType(QName qname, CommonTypeDefinition def)Register global type in the current schema definition.booleanreportProblems(ProblemHandler handler)Report problems using handler.voidreset()Reset context for reuse.voidsetSchema(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
-
-
-
-
Field Detail
-
s_logger
private static final Logger s_logger
Logger for class.
-
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.
-
-
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
nullif 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
nullif 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- namedef- 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- namedef- 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- namedef- 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- namedef- 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- namedef- attribute definition
-
findAttribute
public AttributeElement findAttribute(QName qname)
Find global attribute by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findAttributeGroup
public AttributeGroupElement findAttributeGroup(QName qname)
Find attribute group by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findElement
public ElementElement findElement(QName qname)
Find global element by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findGroup
public GroupElement findGroup(QName qname)
Find group by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findType
public CommonTypeDefinition findType(QName qname)
Find global type by name.- Parameters:
qname- name- Returns:
- definition, or
nullif 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 descriptionobj- 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 descriptionobj- 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 descriptionobj- source object for validation error- Returns:
trueif to continue validation,falseif 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 descriptionobj- 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-
-
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:
trueif one or more errors,falseif not
-
isSkipped
public boolean isSkipped(java.lang.Object obj)
Description copied from interface:ISkipElementsCheck if a component is being skipped due to a fatal error.- Specified by:
isSkippedin interfaceISkipElements- Parameters:
obj- component to be checked- Returns:
- flag for component being skipped
-
-