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 SetSet of namespaces with multiple schemas.private intNumber of errors reported.private intNumber of fatals reported.private MapMap from identifier to schema.private MapMap from namespace URI to schema.private ArrayListList of problem items reported by validation.private SetSet of elements to be skipped in walking tree.private intNumber of unimplementeds reported.private intNumber of warnings reported.private static final LoggerLogger for class.Fields inherited from class org.jibx.schema.SchemaContextTracker
m_nameRegister -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd error item.voidAdd fatal item.voidaddProblem(ValidationProblem problem) Add problem report.protected voidAdd element to set to be skipped.voidaddUnimplemented(String msg, Object obj) Add unimplemented feature item for current element.voidaddWarning(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.intGet number of error problems reported.intGet number of fatal problems reported.Get list of problems.getSchemaById(String id) Get schema element by identifier.Get schema element by target namespace.intGet the number of schemas processed by this context.intGet number of unimplemented feature problems reported.intGet number of warning problems reported.booleanCheck if a component is being skipped due to a fatal error.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(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
nullif 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
nullif 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
nullif not registered
-
findAttributeGroup
Find attribute group by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findElement
Find global element by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findGroup
Find group by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findType
Find global type by name.- Parameters:
qname- name- Returns:
- definition, or
nullif 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:
trueif to continue validation,falseif 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:
trueif one or more errors,falseif not
-
isSkipped
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
-