com.sun.msv.verifier.regexp
Class ExpressionAcceptor

java.lang.Object
  |
  +--com.sun.msv.verifier.regexp.ExpressionAcceptor
All Implemented Interfaces:
Acceptor
Direct Known Subclasses:
ContentModelAcceptor

public abstract class ExpressionAcceptor
extends Object
implements Acceptor

Acceptor implementation.

When you are using REDocumentDeclaration, then the acceptor is always guaranteed to be a subclass of this class. Therefore, by using this regexp implementation of VGM, you can always downcast Acceptor to this class and access its contents to get more information.

If you consider VGM as an automaton, this class can be thought as a lazy automaton acceptor.

Author:
Kohsuke KAWAGUCHI

Fields inherited from interface com.sun.msv.verifier.Acceptor
STRING_IGNORE, STRING_PROHIBITED, STRING_STRICT
 
Constructor Summary
ExpressionAcceptor(REDocumentDeclaration docDecl, Expression exp, boolean ignoreUndeclaredAttributes)
           
 
Method Summary
 Acceptor createChildAcceptor(StartTagInfo tag, StringRef errRef)
          creates combined child acceptor and primitive child acceptors (if necessary).
 Expression getExpression()
          gets the residual content model.
 int getStringCareLevel()
          gets how this acceptor handles characters.
 boolean isAcceptState(StringRef errRef)
          checks if this Acceptor is satisifed
 boolean onAttribute(String namespaceURI, String localName, String qName, String value, IDContextProvider context, StringRef refErr, DatatypeRef refType)
          processes an attribute.
 boolean onEndAttributes(StartTagInfo sti, StringRef refErr)
          notifies the end of attributes.
 boolean onText(String literal, IDContextProvider provider, StringRef refErr, DatatypeRef refType)
          processes a string literal.
 boolean stepForwardByContinuation(Expression continuation, StringRef errRef)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.msv.verifier.Acceptor
createClone, getOwnerType, stepForward
 

Constructor Detail

ExpressionAcceptor

public ExpressionAcceptor(REDocumentDeclaration docDecl,
                          Expression exp,
                          boolean ignoreUndeclaredAttributes)
Method Detail

getExpression

public Expression getExpression()
gets the residual content model.

This method returns the expression that represents the expected content model it will read. For example, if the original content model is (A,(B|C)) and this acceptor has already read A, then this method returns (B|C).

The returned residual is useful to find out what elements can appear next.

If you consider VGM as an automaton, the residual content model can be thought as the current state. Also, At the same time, right language (a regular expression that represents the language it can accept from now on).


createChildAcceptor

public Acceptor createChildAcceptor(StartTagInfo tag,
                                    StringRef errRef)
creates combined child acceptor and primitive child acceptors (if necessary). be careful not to keep returned object too long because it is reused whenever the method is called.
Specified by:
createChildAcceptor in interface Acceptor
Returns:
null if errRef is null and this expression cannot accept given start tag. if errRef is non-null and error recovery is not possible.

onAttribute

public final boolean onAttribute(String namespaceURI,
                                 String localName,
                                 String qName,
                                 String value,
                                 IDContextProvider context,
                                 StringRef refErr,
                                 DatatypeRef refType)
Description copied from interface: Acceptor
processes an attribute.

For every attribute present in the document, you need to call this method.

An error at this method typically indicates that

  1. this attribute is not allowed to appear here
  2. the attribute name was OK, but the value was incorrect.
Specified by:
onAttribute in interface Acceptor
Following copied from interface: com.sun.msv.verifier.Acceptor
Parameters:
refErr - In case of an error, this object will receive the localized error message. Null is a valid value for this parameter. The implementation must provide some kind of message.
refType - If this parameter is non-null, this object will receive the datatype assigned to the attribute value.

This feature is optional and therefore the implementation is not necessarily provide this information.

Returns:
false if an error happens and refErr parameter was not provided. Otherwise true.

onEndAttributes

public boolean onEndAttributes(StartTagInfo sti,
                               StringRef refErr)
Description copied from interface: Acceptor
notifies the end of attributes.

This method needs to be called after the Acceptor.onAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.sun.msv.grammar.IDContextProvider, com.sun.msv.util.StringRef, com.sun.msv.util.DatatypeRef) method is called for each present attribute.

An error at this method typically indicates that some required attributes are missing.

Specified by:
onEndAttributes in interface Acceptor
Following copied from interface: com.sun.msv.verifier.Acceptor
Parameters:
sti - This information is used to produce the error message if that is necessary.
refErr - In case of an error, this object will receive the localized error message. Null is a valid value for this parameter. The implementation must provide some kind of message.
Returns:
false if an error happens and refErr parameter was not provided. Otherwise true.

onText

public boolean onText(String literal,
                      IDContextProvider provider,
                      StringRef refErr,
                      DatatypeRef refType)
Description copied from interface: Acceptor
processes a string literal.
Specified by:
onText in interface Acceptor
Following copied from interface: com.sun.msv.verifier.Acceptor
Parameters:
context - an object that provides context information necessary to validate some datatypes.
refErr - if this parameter is non-null, the implementation should try to detect the reason of error and recover from it. and this object should have the error message as its str field.
refType - if this parameter is non-null and the callee supports type-assignment, the callee will assign the DataType object to this variable. Caller must initialize refType.type to null before calling this method. If the callee doesn't support type-assignment or type-assignment is impossible for this literal (possibly by ambiguous grammar), this variable must kept null.
Returns:
false if the literal at this position is not allowed.

stepForwardByContinuation

public final boolean stepForwardByContinuation(Expression continuation,
                                               StringRef errRef)

isAcceptState

public boolean isAcceptState(StringRef errRef)
checks if this Acceptor is satisifed
Specified by:
isAcceptState in interface Acceptor
Following copied from interface: com.sun.msv.verifier.Acceptor
Parameters:
errRef - If this value is non-null, implementation can diagnose the error and sets the message to the object.

getStringCareLevel

public int getStringCareLevel()
Description copied from interface: Acceptor
gets how this acceptor handles characters.

This method makes it possible to optimize character handling. For many elements of data-oriented schemas, characters are completely prohibited. For example, In SVG, only handful elements are allowed to have #PCDATA and all other elements have element-only content model. Also, for many elements of document-oriented schemas, #PCDATA is allowed just about anywhere.

In the former case, this method returns Acceptor.STRING_PROHIBITED. In other words, this declares that any onText(String) method with non-whitespace characters will always result in a failure. The caller can then exploit this property of the content model and can immediately signal an error when it finds characters, or discard any whitespace characters without keeping them in memory.

In the latter case, this method returns Acceptor.STRING_IGNORE. This declares that any onText(String) call does not change anything at all. The caller can then exploit this property and discard any characeters it found.

If non of the above applies, or the implementation is simply not capable of providing this information, then this method returns Acceptor.STRING_STRICT. In this case, the caller has to faithfully call the onText(String) method for all characeters it found.

Although this method can be called anytime, it is intended to be called only once when the acceptor is first created.

Specified by:
getStringCareLevel in interface Acceptor
Following copied from interface: com.sun.msv.verifier.Acceptor
Returns:
one of the three constant values shown below.