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 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(String msg, Object obj)Add error item.voidaddFatal(String msg, Object obj)Add fatal item.voidaddProblem(ValidationProblem problem)Add problem report.protected voidaddSkip(Object skip)Add 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.AttributeElementfindAttribute(org.jibx.runtime.QName qname)Find global attribute by name.AttributeGroupElementfindAttributeGroup(org.jibx.runtime.QName qname)Find attribute group by name.ElementElementfindElement(org.jibx.runtime.QName qname)Find global element by name.GroupElementfindGroup(org.jibx.runtime.QName qname)Find group by name.CommonTypeDefinitionfindType(org.jibx.runtime.QName qname)Find global type by name.intgetErrorCount()Get number of error problems reported.intgetFatalCount()Get number of fatal problems reported.ArrayListgetProblems()Get list of problems.SchemaElementgetSchemaById(String id)Get schema element by identifier.SchemaElementgetSchemaByNamespace(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(Object obj)Check if a component is being skipped due to a fatal error.IteratoriterateSchemas()Get iterator for all schemas defined in this context.voidregisterAttribute(org.jibx.runtime.QName qname, AttributeElement def)Register global attribute in the current schema definition.voidregisterAttributeGroup(org.jibx.runtime.QName qname, AttributeGroupElement def)Register global attribute group in the current schema definition.voidregisterElement(org.jibx.runtime.QName qname, ElementElement def)Register global element in the current schema definition.voidregisterGroup(org.jibx.runtime.QName qname, GroupElement def)Register global group in the current schema definition.voidregisterType(org.jibx.runtime.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
-
-
-
-
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
nullif 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
nullif 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- IDschema- 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- namedef- 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- namedef- 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- namedef- 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- namedef- 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- namedef- attribute definition
-
findAttribute
public AttributeElement findAttribute(org.jibx.runtime.QName qname)
Find global attribute by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findAttributeGroup
public AttributeGroupElement findAttributeGroup(org.jibx.runtime.QName qname)
Find attribute group by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findElement
public ElementElement findElement(org.jibx.runtime.QName qname)
Find global element by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findGroup
public GroupElement findGroup(org.jibx.runtime.QName qname)
Find group by name.- Parameters:
qname- name- Returns:
- definition, or
nullif not registered
-
findType
public CommonTypeDefinition findType(org.jibx.runtime.QName qname)
Find global type by name.- Parameters:
qname- name- Returns:
- definition, or
nullif 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 descriptionobj- 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 descriptionobj- 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 descriptionobj- source object for validation error- Returns:
trueif to continue validation,falseif 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 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 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:
trueif one or more errors,falseif not
-
isSkipped
public boolean isSkipped(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
-
-