org.inria.ns.reflex.processor.asl
Class ElementValidatorHandler

java.lang.Object
  extended by org.inria.ns.reflex.processor.asl.ElementValidatorHandler
All Implemented Interfaces:
SchemaClientHandler

public class ElementValidatorHandler
extends Object
implements SchemaClientHandler

A schema client handler designed to validate an element.

The validation of an element consists on using its element definition and checking upon it its content and its attributes.

Author:
Philippe Poulard

Constructor Summary
ElementValidatorHandler(ElementDefinition elementDefinition, Element element, List reportErrorList, MasterSchema masterSchema)
          Construct a new element validator.
ElementValidatorHandler(ElementDefinition elementDefinition, Element element, List reportErrorList, MasterSchema masterSchema, int position)
          Construct a new element validator.
 
Method Summary
 void feedContext(ItemMatcher matcher, TypedData data, DataSet dataSet)
          Feeds the context with an item if the material is a
 Node getCandidate()
          Return the candidate material.
 Element getHostElement()
          Return the host element.
 MasterSchema getMasterSchema()
          Return the master schema responsible of schema management for this checking.
 TypedData matches(TypedData match, ItemMatcher matcher, DataSet dataSet)
          Test a matcher with precaution : a text candidate is restored and the error raised are ignored if the matching fails.
 void nextCandidate()
          Return the candidate material.
 void nextCandidate(TypedData data)
          Return the candidate material, according to the previous result matched.
 void processEndStep(List matchers)
          Reports an error for each matcher unsatisfied in the list.
 void processList(AbstractStepAction.ItemsLists itemsLists, int occurs, int minOccurs, int maxOccurs, DataSet dataSet)
          Callback method for lists processing.
 void reportError(Node node, Node candidate, QName level, QName reason, Schema schema, Node schemaRule)
          Reports an error of validation.
 void reportError(Node node, QName level, QName reason, Schema schema, Node schemaRule)
          Reports an error of validation.
 void reportError(ValidationError error)
          Reports an error.
 void setCandidate(Node candidate)
          Set the candidate material.
 void validate()
          Perform a surface validation without PSVI.
 void validate(boolean augment)
          Perform the validation.
 void validateAttribute(Attr attr, AttributeDefinition attrDef, DataSet dataSet)
          Validates an attribute with its definition.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementValidatorHandler

public ElementValidatorHandler(ElementDefinition elementDefinition,
                               Element element,
                               List reportErrorList,
                               MasterSchema masterSchema)
Construct a new element validator.

Parameters:
elementDefinition - The definition of the element.
element - The element to validate.
reportErrorList - The report error list.
masterSchema - Used for PSVI.

ElementValidatorHandler

public ElementValidatorHandler(ElementDefinition elementDefinition,
                               Element element,
                               List reportErrorList,
                               MasterSchema masterSchema,
                               int position)
Construct a new element validator.

Parameters:
elementDefinition - The definition of the element.
element - The element to validate.
reportErrorList - The report error list.
position - The child position until perform the validation.
Method Detail

validate

public void validate()
              throws ExecutionException
Perform a surface validation without PSVI.

Throws:
ExecutionException

validate

public void validate(boolean augment)
              throws ExecutionException
Perform the validation.

Parameters:
augment - true for PSVI augmentation, false otherwise.
Throws:
ExecutionException

validateAttribute

public void validateAttribute(Attr attr,
                              AttributeDefinition attrDef,
                              DataSet dataSet)
Validates an attribute with its definition. This method is called by processList(AbstractStepAction.ItemsLists, int, int, int, DataSet) when the current element definition contains attribute definitions.

Parameters:
attr - The attribute to validate.
attrDef - The definition to use for the validation.
dataSet - The data set in use when validating the attribute.

processList

public void processList(AbstractStepAction.ItemsLists itemsLists,
                        int occurs,
                        int minOccurs,
                        int maxOccurs,
                        DataSet dataSet)
Callback method for lists processing. Void lists are ignored. This implementation validates the element to validate.

Specified by:
processList in interface SchemaClientHandler
Parameters:
itemsLists - The set of items lists.
occurs - The current occurs counter.
minOccurs - The minimum occurs expected.
maxOccurs - The maximum occurs expected.
dataSet - The data set in use.

matches

public TypedData matches(TypedData match,
                         ItemMatcher matcher,
                         DataSet dataSet)
Test a matcher with precaution : a text candidate is restored and the error raised are ignored if the matching fails. This is necessary when successive matchers are involving a text candidate. If a matcher fails, the next matcher must test the text candidate in the state it was before, that's why the text candidate is reset and the error raised are ignored. Nothing special is made for non-text candidates.

Parameters:
match - The previous match value, surely initialized to NOT_FOUND.
matcher - The matcher that will test this candidate.
dataSet - The data set in use when testing the matcher.
Returns:
The new match value. If the matcher has matched, it is FOUND or a TypedData.

feedContext

public void feedContext(ItemMatcher matcher,
                        TypedData data,
                        DataSet dataSet)
Feeds the context with an item if the material is a TextAction.Matcher. Feeding the context is necessary to build the data model of typed datas.

Parameters:
matcher - The matcher to test.
data - The typed data that will be the current object temporarily.
dataSet - The data set for which the context will be feed.

getHostElement

public Element getHostElement()
Return the host element.

Specified by:
getHostElement in interface SchemaClientHandler
Returns:
The host element.

getCandidate

public Node getCandidate()
Return the candidate material.

Specified by:
getCandidate in interface SchemaClientHandler
Returns:
The candidate material.

setCandidate

public void setCandidate(Node candidate)
Set the candidate material.

Specified by:
setCandidate in interface SchemaClientHandler
Parameters:
candidate - The new candidate used for validation.
See Also:
org.inria.ns.reflex.processor.asl.SchemaClientHandler#setCandidate(Object)

nextCandidate

public void nextCandidate(TypedData data)
Return the candidate material, according to the previous result matched. If the data is a typed data that contains a remainder, the next candidate is a text candidate with this remainder.

Parameters:
data - The typed data. nextCandidate() is called if the data is ItemMatcher.FOUND,ItemMatcher.NOT_FOUND, or a real typed data with no remainder.

nextCandidate

public void nextCandidate()
Return the candidate material.


getMasterSchema

public MasterSchema getMasterSchema()
Return the master schema responsible of schema management for this checking.

Specified by:
getMasterSchema in interface SchemaClientHandler
Returns:
The master schema, used also for PSVI.

reportError

public void reportError(Node node,
                        Node candidate,
                        QName level,
                        QName reason,
                        Schema schema,
                        Node schemaRule)
Reports an error of validation.

Specified by:
reportError in interface SchemaClientHandler
Parameters:
node - The node on which the error occurs.
candidate - The candidate node that raise the error.
level - The level of error : fatal, error, warning.
reason - The reason of the error.
schema - The schema that raise the error.
schemaRule - The schema rule in violation.

reportError

public void reportError(Node node,
                        QName level,
                        QName reason,
                        Schema schema,
                        Node schemaRule)
Reports an error of validation.

Specified by:
reportError in interface SchemaClientHandler
Parameters:
node - The node on which the error occurs.
level - The level of error.
reason - The reason of the error.
schema - The schema that raise the error.
schemaRule - The schema rule in violation.

reportError

public void reportError(ValidationError error)
Reports an error.

Specified by:
reportError in interface SchemaClientHandler
Parameters:
error - The error to report.

processEndStep

public void processEndStep(List matchers)
Reports an error for each matcher unsatisfied in the list. (matchers that must be used and that has not been used)

Specified by:
processEndStep in interface SchemaClientHandler
Parameters:
matchers - The list of ItemMatchers to check.
See Also:
ItemMatcher, SchemaClientHandler.processEndStep(java.util.List)