Top Description Fields Constructors Methods
com.sun.msv.verifier.regexp

public abstract Class ExpressionAcceptor

extends Object
implements Acceptor
Class Inheritance
All Implemented Interfaces
com.sun.msv.verifier.Acceptor
Known Direct Subclasses
com.sun.msv.verifier.regexp.ContentModelAcceptor
Imports
java.util.Collections, .Comparator, .Iterator, .List, .Set, .Vector, org.relaxng.datatype.DatatypeException, com.sun.msv.grammar.AttributeExp, .ChoiceExp, .DataOrValueExp, .ElementExp, .Expression, .IDContextProvider2, .NameClass, .NamespaceNameClass, .NotNameClass, .SimpleNameClass, .ValueExp, com.sun.msv.grammar.util.IDContextProviderWrapper, com.sun.msv.util.DatatypeRef, .StartTagInfo, .StringRef, com.sun.msv.verifier.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

Field Summary

Modifier and TypeField and Description
protected final REDocumentDeclaration
docDecl

this object provides various function objects

private Expression
protected final boolean
ignoreUndeclaredAttributes

If true, this acceptor will ignore all undeclared attributes.

Constructor Summary

AccessConstructor and Description
public
ExpressionAcceptor(REDocumentDeclaration docDecl, Expression exp, boolean ignoreUndeclaredAttributes)

Method Summary

Modifier and TypeMethod and Description
private String
concatenateMessages(List<String> items, boolean more, String separatorStr, String moreStr)

format list of candidates to one string.

private String
concatenateMessages(Set<String> items, boolean more, String separatorStr, String moreStr)

protected abstract Acceptor
createAcceptor(Expression contentModel, Expression continuation, ElementExp[] primitives, int numPrimitives)

public 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.
createChildAcceptor
(StartTagInfo
this parameter provides the information about the start tag to the acceptor object. Usually attribute information is ignored, but sometimes they are used as hints.
tag
,
StringRef
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.
errRef
)

Implements com.sun.msv.verifier.Acceptor.createChildAcceptor.

creates combined child acceptor and primitive child acceptors (if necessary).
private final Acceptor
createRecoveryAcceptors()

creates Acceptor that recovers from errors.

private String

Returns:

null if diagnosis fails.
diagnoseBadAttributeValue
(AttributeRecoveryToken
wild card AttributeToken that was used.
rtoken
)

computes diagnosis message for bad attribute value

private String

Returns:

null if diagnosis fails.
diagnoseBadTagName
(StartTagInfo sti)

computes diagnosis message for bad tag name

private String

Returns:

null if diagnosis fails.
diagnoseMissingAttribute
(StartTagInfo sti)

computes diagnosis message for missing attribute

protected String
diagnoseUncompletedContent()

diagnoses "uncompleted content model" error.

private String
diagnoseUnexpectedLiteral(StringToken token)

diagnoses an error when a StringToken is rejected.

private String

Returns:

null if diagnosis failed.
getDiagnosisFromTypedString
(DataOrValueExp exp, StringToken value)

gets error diagnosis message from datatype.

public Expression
getExpression()

gets the residual content model.

public int
getStringCareLevel()

Implements com.sun.msv.verifier.Acceptor.getStringCareLevel.

gets how this acceptor handles characters.
public boolean
isAcceptState(StringRef
If this value is non-null, implementation can diagnose the error and sets the message to the object.
errRef
)

Implements com.sun.msv.verifier.Acceptor.isAcceptState.

checks if this Acceptor is satisifed
public final boolean
onAttribute(String namespaceURI, String localName, String qName, String value, IDContextProvider context, StringRef refErr, DatatypeRef refType)

Implements com.sun.msv.verifier.Acceptor.onAttribute.

Deprecated
protected boolean
public final boolean
onAttribute2(String namespaceURI, String localName, String qName, String value, IDContextProvider2 context, StringRef
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.
refErr
,
DatatypeRef
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.

refType
)

Implements com.sun.msv.verifier.Acceptor.onAttribute2.

processes an attribute.
public boolean
onEndAttributes(StartTagInfo
This information is used to produce the error message if that is necessary.
sti
,
StringRef
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.
refErr
)

Implements com.sun.msv.verifier.Acceptor.onEndAttributes.

notifies the end of attributes.
public final boolean
onText(String literal, IDContextProvider context, StringRef refErr, DatatypeRef refType)

Implements com.sun.msv.verifier.Acceptor.onText.

Deprecated
public boolean
onText2(String literal, IDContextProvider2
an object that provides context information necessary to validate some datatypes.
provider
,
StringRef
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.
refErr
,
DatatypeRef
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.
refType
)

Implements com.sun.msv.verifier.Acceptor.onText2.

processes a string literal.
protected boolean
stepForward(Token token, StringRef errRef)

public final boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

docDeclback to summary
protected final REDocumentDeclaration docDecl

this object provides various function objects

expressionback to summary
private Expression expression
ignoreUndeclaredAttributesback to summary
protected final boolean ignoreUndeclaredAttributes

If true, this acceptor will ignore all undeclared attributes. If false, this acceptor will signal an error for an undeclared attribute.

This flag is used to implement the semantics of RELAX Core, where undeclared attributes are allowed.

Constructor Detail

ExpressionAcceptorback to summary
public ExpressionAcceptor(REDocumentDeclaration docDecl, Expression exp, boolean ignoreUndeclaredAttributes)

Method Detail

concatenateMessagesback to summary
private String concatenateMessages(List<String> items, boolean more, String separatorStr, String moreStr)

format list of candidates to one string. this method (1) inserts separator into appropriate positions (2) appends "more" message when items are only a portion of candidates.

concatenateMessagesback to summary
private String concatenateMessages(Set<String> items, boolean more, String separatorStr, String moreStr)
createAcceptorback to summary
protected abstract Acceptor createAcceptor(Expression contentModel, Expression continuation, ElementExp[] primitives, int numPrimitives)
createChildAcceptorback to summary
public Acceptor createChildAcceptor(StartTagInfo tag, StringRef errRef)

Implements com.sun.msv.verifier.Acceptor.createChildAcceptor.

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.

Parameters
tag:StartTagInfo

Doc from com.sun.msv.verifier.Acceptor.createChildAcceptor.

this parameter provides the information about the start tag to the acceptor object. Usually attribute information is ignored, but sometimes they are used as hints.

errRef:StringRef

Doc from com.sun.msv.verifier.Acceptor.createChildAcceptor.

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.

Returns:Acceptor

null if errRef is null and this expression cannot accept given start tag. if errRef is non-null and error recovery is not possible.

createRecoveryAcceptorsback to summary
private final Acceptor createRecoveryAcceptors()

creates Acceptor that recovers from errors. This method also modifies the current expression in preparation to accept newly created child acceptor. Recovery will be done by preparing to accept two possibilities.

  1. We may get back to sync by ignoring the newly found illegal element. ( this is for mistake like "abcXdefg")
  2. We may get back to sync by replacing newly found illegal element by one of the valid elements. ( this is for mistake like "abcXefg")
diagnoseBadAttributeValueback to summary
private String diagnoseBadAttributeValue(AttributeRecoveryToken rtoken)

computes diagnosis message for bad attribute value

Parameters
rtoken:AttributeRecoveryToken

wild card AttributeToken that was used.

Returns:String

null if diagnosis fails.

diagnoseBadTagNameback to summary
private String diagnoseBadTagName(StartTagInfo sti)

computes diagnosis message for bad tag name

Returns:String

null if diagnosis fails.

diagnoseMissingAttributeback to summary
private String diagnoseMissingAttribute(StartTagInfo sti)

computes diagnosis message for missing attribute

Returns:String

null if diagnosis fails.

diagnoseUncompletedContentback to summary
protected String diagnoseUncompletedContent()

diagnoses "uncompleted content model" error. It basically provides what we were expected.

diagnoseUnexpectedLiteralback to summary
private String diagnoseUnexpectedLiteral(StringToken token)

diagnoses an error when a StringToken is rejected.

getDiagnosisFromTypedStringback to summary
private String getDiagnosisFromTypedString(DataOrValueExp exp, StringToken value)

gets error diagnosis message from datatype.

Returns:String

null if diagnosis failed.

getExpressionback to summary
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).

getStringCareLevelback to summary
public int getStringCareLevel()

Implements com.sun.msv.verifier.Acceptor.getStringCareLevel.

Doc from com.sun.msv.verifier.Acceptor.getStringCareLevel.

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 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 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 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.

Returns:int

one of the three constant values shown below.

isAcceptStateback to summary
public boolean isAcceptState(StringRef errRef)

Implements com.sun.msv.verifier.Acceptor.isAcceptState.

checks if this Acceptor is satisifed

Parameters
errRef:StringRef

Doc from com.sun.msv.verifier.Acceptor.isAcceptState.

If this value is non-null, implementation can diagnose the error and sets the message to the object.

onAttributeback to summary
public final boolean onAttribute(String namespaceURI, String localName, String qName, String value, IDContextProvider context, StringRef refErr, DatatypeRef refType)

Implements com.sun.msv.verifier.Acceptor.onAttribute.

Deprecated

onAttributeback to summary
protected boolean onAttribute(AttributeToken token, StringRef refErr)
onAttribute2back to summary
public final boolean onAttribute2(String namespaceURI, String localName, String qName, String value, IDContextProvider2 context, StringRef refErr, DatatypeRef refType)

Implements com.sun.msv.verifier.Acceptor.onAttribute2.

Doc from com.sun.msv.verifier.Acceptor.onAttribute2.

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.
Parameters
refErr:StringRef

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:DatatypeRef

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:boolean

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

onEndAttributesback to summary
public boolean onEndAttributes(StartTagInfo sti, StringRef refErr)

Implements com.sun.msv.verifier.Acceptor.onEndAttributes.

Doc from com.sun.msv.verifier.Acceptor.onEndAttributes.

notifies the end of attributes.

This method needs to be called after the onAttribute method is called for each present attribute.

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

Parameters
sti:StartTagInfo

This information is used to produce the error message if that is necessary.

refErr:StringRef

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:boolean

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

onTextback to summary
public final boolean onText(String literal, IDContextProvider context, StringRef refErr, DatatypeRef refType)

Implements com.sun.msv.verifier.Acceptor.onText.

Deprecated

onText2back to summary
public boolean onText2(String literal, IDContextProvider2 provider, StringRef refErr, DatatypeRef refType)

Implements com.sun.msv.verifier.Acceptor.onText2.

Doc from com.sun.msv.verifier.Acceptor.onText2.

processes a string literal.

Parameters
provider:IDContextProvider2

an object that provides context information necessary to validate some datatypes.

refErr:StringRef

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:DatatypeRef

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:boolean

false if the literal at this position is not allowed.

stepForwardback to summary
protected boolean stepForward(Token token, StringRef errRef)
stepForwardByContinuationback to summary
public final boolean stepForwardByContinuation(Expression continuation, StringRef errRef)