Package org.jibx.schema.validation
Class ValidationContext
java.lang.Object
org.jibx.schema.SchemaContextTracker
org.jibx.schema.validation.ValidationContext
- All Implemented Interfaces:
ISchemaListener
,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
FieldsModifier and TypeFieldDescriptionprivate Set
Set of namespaces with multiple schemas.private int
Number of errors reported.private int
Number of fatals reported.private Map
Map from identifier to schema.private Map
Map from namespace URI to schema.private ArrayList
List of problem items reported by validation.private Set
Set of elements to be skipped in walking tree.private int
Number of unimplementeds reported.private int
Number of warnings reported.private static final Logger
Logger for class.Fields inherited from class org.jibx.schema.SchemaContextTracker
m_nameRegister
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add error item.void
Add fatal item.void
addProblem
(ValidationProblem problem) Add problem report.protected void
Add element to set to be skipped.void
addUnimplemented
(String msg, Object obj) Add unimplemented feature item for current element.void
addWarning
(String msg, Object obj) Add warning item.findAttribute
(QName qname) Find global attribute by name.findAttributeGroup
(QName qname) Find attribute group by name.findElement
(QName qname) Find global element by name.Find group by name.Find global type by name.int
Get number of error problems reported.int
Get number of fatal problems reported.Get list of problems.getSchemaById
(String id) Get schema element by identifier.Get schema element by target namespace.int
Get the number of schemas processed by this context.int
Get number of unimplemented feature problems reported.int
Get number of warning problems reported.boolean
Check if a component is being skipped due to a fatal error.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.boolean
reportProblems
(ProblemHandler handler) Report problems using handler.void
reset()
Reset context for reuse.void
setSchema
(String id, SchemaElement schema) Add schema element with identifier.Methods inherited from class org.jibx.schema.SchemaContextTracker
clearTraversed, enterSchema, exitSchema, getCurrentSchema, getNameRegister, setNameRegister
-
Field Details
-
s_logger
private static final Logger s_loggerLogger for class. -
m_idSchemaMap
Map from identifier to schema. -
m_namespaceSchemaMap
Map from namespace URI to schema. -
m_duplicateNamespaces
Set of namespaces with multiple schemas. -
m_unimplementedCount
private int m_unimplementedCountNumber of unimplementeds reported. -
m_warningCount
private int m_warningCountNumber of warnings reported. -
m_errorCount
private int m_errorCountNumber of errors reported. -
m_fatalCount
private int m_fatalCountNumber of fatals reported. -
m_problemList
List of problem items reported by validation. -
m_skipSet
Set of elements to be skipped in walking tree.
-
-
Constructor Details
-
ValidationContext
public ValidationContext()Constructor.
-
-
Method Details
-
reset
public void reset()Reset context for reuse. -
getSchemaByNamespace
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
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
Get iterator for all schemas defined in this context.- Returns:
- iterator
-
setSchema
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
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
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
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
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
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
Find global attribute by name.- Parameters:
qname
- name- Returns:
- definition, or
null
if not registered
-
findAttributeGroup
Find attribute group by name.- Parameters:
qname
- name- Returns:
- definition, or
null
if not registered
-
findElement
Find global element by name.- Parameters:
qname
- name- Returns:
- definition, or
null
if not registered
-
findGroup
Find group by name.- Parameters:
qname
- name- Returns:
- definition, or
null
if not registered
-
findType
Find global type by name.- Parameters:
qname
- name- Returns:
- definition, or
null
if not registered
-
addUnimplemented
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
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
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:
true
if to continue validation,false
if not
-
addFatal
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
Add problem report. The problem is added and counted as appropriate.- Parameters:
problem
- details of problem report
-
getProblems
Get list of problems.- Returns:
- problem list
-
addSkip
Add element to set to be skipped.- Parameters:
skip
-
-
reportProblems
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
Description copied from interface:ISkipElements
Check if a component is being skipped due to a fatal error.- Specified by:
isSkipped
in interfaceISkipElements
- Parameters:
obj
- component to be checked- Returns:
- flag for component being skipped
-