sk.baka.xml.schematic.msv
Class ValidatorImpl

java.lang.Object
  extended by sk.baka.xml.schematic.msv.ValidatorImpl

public final class ValidatorImpl
extends Object

Implements functionality of validator. Validates one 'island' only - only elements from selected namespace.

Author:
Martin Vysny

Constructor Summary
ValidatorImpl(SchemaImpl schema)
          Constructs new instance of validator.
 
Method Summary
 com.sun.msv.verifier.regexp.ExpressionAcceptor createAcceptor(com.sun.msv.grammar.Expression exp)
          Creates acceptor for given expression.
 Attributes createAttributes(Element element)
          Creates an instance of SAX Attributes interface from given element's attributes.
 com.sun.msv.util.StartTagInfo createSTI(Element e)
          Creates a StartTagInfo instance for given element.
 com.sun.msv.util.StartTagInfo createSTI(Element e, String namespace)
          Creates a StartTagInfo instance for given element.
 com.sun.msv.util.StartTagInfo createSTI(Element e, String namespace, Attributes attrs)
          Creates a StartTagInfo instance for given element.
 void feedAttributes(com.sun.msv.verifier.Acceptor acc, Element element, boolean checkForeign, boolean finish)
          Helper function, feeds the acceptor with all attributes.
 boolean stepForward(com.sun.msv.verifier.regexp.ExpressionAcceptor acc, ContentInfo dpi, boolean deep, boolean throughNamespaces)
          Tries to step with given acceptor over given content.
 boolean stepForward(com.sun.msv.verifier.regexp.ExpressionAcceptor acc, Element e, String text, Node parent)
          Tries to step with given acceptor over given content.
 boolean stepForward(com.sun.msv.verifier.regexp.ExpressionAcceptor acc, String uri, String name, Node parent)
          Tries to step forward with given acceptor over given element name.
 void validate(Element element, com.sun.msv.verifier.regexp.ExpressionAcceptor acc, boolean deep, boolean throughNamespaces)
          Tries to validate element with given acceptor.
 void validate(Element element, com.sun.msv.grammar.Expression exp, boolean deep, boolean throughNamespaces)
          Tries to validate element with given expression.
 void validate(Element element, String namespace, com.sun.msv.verifier.regexp.ExpressionAcceptor acc, boolean deep, boolean throughNamespaces, SchemaLevelNodeIterator contextIterator)
          Tries to validate element with given acceptor.
 void validateIterator(com.sun.msv.verifier.regexp.ExpressionAcceptor acc, SchemaLevelNodeIterator ipIterator, boolean deep, boolean throughNamespaces, int stepOver)
          Validates contents, that are given to us by iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValidatorImpl

ValidatorImpl(SchemaImpl schema)
Constructs new instance of validator.

Parameters:
schema - SchemaImpl instance.
Method Detail

validate

public void validate(Element element,
                     com.sun.msv.grammar.Expression exp,
                     boolean deep,
                     boolean throughNamespaces)
              throws SchemaException
Tries to validate element with given expression. This expression should contain rule for this element. For example, validating element with its expression content model may fail, because validator expects to see rule for given element amongst direct ElementExp descendants of given expression.

Parameters:
element - element to validate.
exp - expression, defining element and its content. It may not be ElementExp of this element, of course :-).
throughNamespaces - if the validation must validate element from another namespace - if it must ask EuromathSchemaProvider to do so. This has higher priority than parameter deep - even if deep is true, this parameter can forbid walking through namespaces.
deep - if validator must perform deep check, that is, verify complete tree rooted in element. If not, then each element, that is context-free, is just validated itself, no validation is performed over its contents. That allows faster validation.

The idea beyond is this: if deep==false, then we take for granted, that document is valid, and we are just curious, whether this expression is the right one to generate given element. When element is context-free and acceptor.createChildAcceptor() goes OK, we don't need to validate content - they can be described by only one rule in whole schema, and we know that the content is valid. But if element is not context-free, then there are multiple rules generating element's content. This content may be valid for one rule, but invalid for other rules. So, we must check, whether our rule is the valid one. That is done by validating the content.

If deep==false, we know that document is valid, and this schema doesn't describe correct content for element from another namespace. So, even when rule for this element is not context-free, we cannot tell whether our rule is the correct one. Thus, there is no point in walking through namespaces even when throughNamespaces==true.

Throws:
SchemaException - when validity error occurs.

validate

public void validate(Element element,
                     com.sun.msv.verifier.regexp.ExpressionAcceptor acc,
                     boolean deep,
                     boolean throughNamespaces)
              throws SchemaException
Tries to validate element with given acceptor. This acceptor should be set to state, where amongst next elements, that it expects, will be given element.

Parameters:
element - element to validate.
acc - Acceptor. On succesfull validation this acceptor has eaten this element and is ready to eat next. If validation was unsuccesfull (exception was thrown), then this acceptor is in undefined state and should not be used.
deep - if validator must perform deep check, that is, verify complete tree rooted in element. If not, then each element with context-free rule is skipped to allow fast validation. For further description, see the other validate method.
throughNamespaces - if the validation must validate element from another namespace - if it must ask EuromathSchemaProvider to do so. This has higher priority than parameter deep - even if deep is true, this parameter can forbid walking through namespaces.
Throws:
SchemaException - signalizes a validity or schema error.
See Also:
validate(Element, Expression, boolean, boolean)

validate

public void validate(Element element,
                     String namespace,
                     com.sun.msv.verifier.regexp.ExpressionAcceptor acc,
                     boolean deep,
                     boolean throughNamespaces,
                     SchemaLevelNodeIterator contextIterator)
              throws SchemaException
Tries to validate element with given acceptor. Before calling this method, acceptor should be set to state, where amongst next elements, that it expects, will be given element.

Parameters:
element - element to validate.
namespace - If null, then do a normal processing. If not null, then pretend, that given element has this namespace. This is used for selecting elements. So in this case, we take given element as element from our namespace. We even don't go through namespaces (regardless of the throughNamespaces value.
acc - Acceptor. When method is finished, this acceptor had eaten this element and is ready to eat next. If validation was unsuccesfull (exception was thrown), then this acceptor is in undefined state and should not be used.
deep - if validator must perform deep check, that is, verify complete tree rooted in element. If not, then each element with context-free rule is skipped to allow fast validation. For further description, see the other validate method.
throughNamespaces - if the validation must validate element from another namespace. If so, then we must ask EuromathSchemaProvider to do so. This has higher priority than parameter deep - even if deep is true, this parameter can forbid walking through namespaces.
contextIterator - iterates the 'siblings' of given element (the parent element of given element). If null then default iterator is used.
Throws:
SchemaException - when an validity mismatch had been found.
See Also:
validate(Element, Expression, boolean, boolean)

validateIterator

public void validateIterator(com.sun.msv.verifier.regexp.ExpressionAcceptor acc,
                             SchemaLevelNodeIterator ipIterator,
                             boolean deep,
                             boolean throughNamespaces,
                             int stepOver)
                      throws SchemaException
Validates contents, that are given to us by iterator. No attributes are fed to acceptor.

Parameters:
acc - acceptor, that will accept this iterator sequence. If function succeeds, then acceptor had eaten last item of iterator. If function fails, then contents of acceptor are undefined.
ipIterator - iterator, that describes contents, that will be validated. Validation starts from actual position of iterator.
deep - if validator must perform deep check, that is, verify complete tree rooted in element. If not, then each element with context-free rule is skipped to allow fast validation. For further description, see the other validate method.
throughNamespaces - if the validation must validate element from another namespace. If so, then we must ask EuromathSchemaProvider to do so. This has higher priority than parameter deep - even if deep is true, this parameter can forbid walking through namespaces.
stepOver - the number of items of iterator that shall be stepped over. If -1 is given then all items are processed.
Throws:
SchemaException - when an validity mismatch had been found.

feedAttributes

public void feedAttributes(com.sun.msv.verifier.Acceptor acc,
                           Element element,
                           boolean checkForeign,
                           boolean finish)
                    throws SchemaException
Helper function, feeds the acceptor with all attributes. This must be done after creation of acceptor and before element contents are given to acceptor.

Parameters:
acc - acceptor to feed.
element - element, which attributes have to be given to acceptor.
checkForeign - if check validity of foreign attributes thoroughly - with the EuromathSchemaProvider.validate() function.
finish - if true, then announce end of attributes after succesfull attribute feeding.
Throws:
SchemaException - if acceptor finds an validity mismatch.

createAttributes

public Attributes createAttributes(Element element)
Creates an instance of SAX Attributes interface from given element's attributes.

Parameters:
element - return attributes from this element.
Returns:
SAX Attributes interface.

stepForward

public boolean stepForward(com.sun.msv.verifier.regexp.ExpressionAcceptor acc,
                           String uri,
                           String name,
                           Node parent)
Tries to step forward with given acceptor over given element name. The element does not exist, so it can have any content. Returns true, if it succesfully steps over given element name, or false, when acceptor cannot accept any element with this name.

Parameters:
acc - acceptor, which will step forward. When true is returned, then acceptor is ready to step over next node. When false, acceptor state is undefined.
uri - namespace of an element.
name - local name of an element.
parent - the parent node, used to provide correct context.
Returns:
true, if it succesfully steps over given element name, or false, when acceptor cannot accept any element with this name.

stepForward

public boolean stepForward(com.sun.msv.verifier.regexp.ExpressionAcceptor acc,
                           Element e,
                           String text,
                           Node parent)
Tries to step with given acceptor over given content. If element is given, then contents of this element must be valid against the schema (if this element is from our namespace).

Parameters:
acc - acceptor, which will step forward. When true is returned, then acceptor is ready to step over next node. When false, acceptor state is undefined.
e - reference to element. When not null, then acceptor will step over this element. When null, acceptor will step over given text.
text - reference to text.
parent - the parent node, used to provide a context to the acceptor when e is null.
Returns:
true, if it succesfully steps over given element name, or false, when acceptor cannot accept given content.

stepForward

public boolean stepForward(com.sun.msv.verifier.regexp.ExpressionAcceptor acc,
                           ContentInfo dpi,
                           boolean deep,
                           boolean throughNamespaces)
Tries to step with given acceptor over given content. If element is given, then contents of this element must be valid against the schema (if this element is from our namespace).

Parameters:
acc - acceptor, which will step forward. When true is returned, then acceptor is ready to step over next node. When false, acceptor state is undefined.
dpi - the next contents that the acceptor will eat.
deep - if validator must perform deep check, that is, verify complete tree rooted in element. If not, then each element with context-free rule is skipped to allow fast validation. For further description, see the other validate method.
throughNamespaces - if the validation must validate element from another namespace. If so, then we must ask EuromathSchemaProvider to do so. This has higher priority than parameter deep - even if deep is true, this parameter can forbid walking through namespaces.
Returns:
true, if it succesfully steps over given element name, or false, when acceptor cannot accept given content.

createAcceptor

public com.sun.msv.verifier.regexp.ExpressionAcceptor createAcceptor(com.sun.msv.grammar.Expression exp)
Creates acceptor for given expression.

Parameters:
exp - expression, that the acceptor will work with.
Returns:
Acceptor.

createSTI

public com.sun.msv.util.StartTagInfo createSTI(Element e)
Creates a StartTagInfo instance for given element.

Parameters:
e - the element
Returns:
starttaginfo instance.

createSTI

public com.sun.msv.util.StartTagInfo createSTI(Element e,
                                               String namespace)
Creates a StartTagInfo instance for given element. It pretends, that this element has the namespace namespace.

Parameters:
e - the element
namespace - overrides elements' namespace with this value.
Returns:
starttaginfo instance.

createSTI

public com.sun.msv.util.StartTagInfo createSTI(Element e,
                                               String namespace,
                                               Attributes attrs)
Creates a StartTagInfo instance for given element. It pretends, that this element has the namespace namespace.

Parameters:
e - the element
namespace - overrides elements' namespace with this value.
attrs - attributes of this element.
Returns:
starttaginfo instance.


Copyright © 2006 Martin Vysny - baka. All Rights Reserved.