Top Description Inners Fields Constructors Methods
com.sun.msv.grammar

public abstract Class Expression

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
com.sun.msv.grammar.Expression.EpsilonExpression, com.sun.msv.grammar.Expression.NullSetExpression, com.sun.msv.grammar.Expression.AnyStringExpression, com.sun.msv.grammar.OtherExp, com.sun.msv.grammar.ReferenceExp, com.sun.msv.grammar.UnaryExp, com.sun.msv.grammar.ValueExp, com.sun.msv.grammar.AttributeExp, com.sun.msv.grammar.BinaryExp, com.sun.msv.grammar.DataExp, com.sun.msv.grammar.ElementExp
Imports
com.sun.msv.grammar.util.RefExpRemover

Primitive of the tree regular expression. most of the derived class is immutable (except ReferenceExp, ElementExp and OtherExp).

By making it immutable, it becomes possible to share subexpressions among expressions. This is very important for regular-expression-derivation based validation algorithm, as well as for smaller memory footprint. This sharing is automatically achieved by ExpressionPool.

ReferebceExp, ElementExp, and OtherExp are also placed in the pool, but these are not unified. Since they are not unified, application can derive classes from these expressions and mix them into AGM. This technique is heavily used to introduce schema language specific primitives into AGM. See various sub-packages of this package for examples.

The equals method must be implemented by the derived type. equals method will be used to unify the expressions. equals method can safely assume that its children are already unified (therefore == can be used to test the equality, rather than equals method).

To achieve unification, we overload the equals method so that o1.equals(o2) is true if o1 and o2 are identical. There, those two objects must return the same hash code. For this purpose, the hash code is calculated statically and cached internally.

Author
Kohsuke KAWAGUCHI

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final Expression
anyString

special expression object that represents "any string".

private transient int
cachedHashCode

Hash code of this object.

public static final Expression
epsilon

Special expression object that represents epsilon (ε).

private Boolean
epsilonReducibility

cached value of epsilon reducibility.

private Expression
expandedExp

Cached value of the expression after ReferenceExps are removed.

public static final Expression
nullSet

special expression object that represents the empty set (Φ).

private static final long
public transient Object
verifierTag

this field can be used by Verifier implementation to speed up validation.

Constructor Summary

AccessConstructor and Description
protected
Expression(int hashCode)

protected
Expression()

this constructor can be used for the ununified expressions.

Method Summary

Modifier and TypeMethod and Description
protected abstract boolean
calcEpsilonReducibility()

computes epsilon reducibility

protected abstract int
calcHashCode()

Computes the hashCode again.

public abstract boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Expression
getExpandedExp(ExpressionPool pool)

Gets the expression after removing all ReferenceExps, until child AttributeExp or ElementExp.

public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
protected static int
hashCode(Object o1, Object o2, int hashKey)

protected static int
hashCode(Object o, int hashKey)

public boolean
isEpsilonReducible()

returns true if this expression accepts empty sequence.

public final Expression
peelOccurence()

Peels the occurence expressions from this expression.

protected Object
private final void
setHashCode(int hashCode)

public abstract Object
public abstract Expression
public abstract boolean
public abstract void
public Object
public Expression
public boolean
public void
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

anyStringback to summary
public static final Expression anyString

special expression object that represents "any string". It is close to xsd:string datatype, but they have different semantics in several things.

This object is used as <anyString/> pattern of TREX and <text/> pattern of RELAX NG.

cachedHashCodeback to summary
private transient int cachedHashCode

Hash code of this object.

To memorize every sub expression, hash code is frequently used. And computation of the hash code requires full-traversal of the expression. Therefore, hash code is computed when the object is constructed, and kept cached thereafter.

This field is essentially final, but because of the serialization support, we cannot declare it as such.

epsilonback to summary
public static final Expression epsilon

Special expression object that represents epsilon (ε). This expression matches to "empty". Epsilon can be thought as an empty sequence.

epsilonReducibilityback to summary
private Boolean epsilonReducibility

cached value of epsilon reducibility. Epsilon reducibility can only be calculated after parsing the entire expression, because of forward reference to other pattern.

expandedExpback to summary
private Expression expandedExp

Cached value of the expression after ReferenceExps are removed. This value is computed on demand.

nullSetback to summary
public static final Expression nullSet

special expression object that represents the empty set (Φ). This expression doesn't match to anything. NullSet can be thought as an empty choice.

serialVersionUIDback to summary
private static final long serialVersionUID
verifierTagback to summary
public transient Object verifierTag

this field can be used by Verifier implementation to speed up validation. Due to its nature, this field is not serialized. TODO: revisit this decision of not to serialize this field.

Constructor Detail

Expressionback to summary
protected Expression(int hashCode)
Expressionback to summary
protected Expression()

this constructor can be used for the ununified expressions. the only reason there are two parameters is to prevent unintentional use of the default constructor.

Method Detail

calcEpsilonReducibilityback to summary
protected abstract boolean calcEpsilonReducibility()

computes epsilon reducibility

calcHashCodeback to summary
protected abstract int calcHashCode()

Computes the hashCode again.

This method and the parameter to the constructor has to be the same. This method is used when the object is being read from the stream.

equalsback to summary
public abstract boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

getExpandedExpback to summary
public Expression getExpandedExp(ExpressionPool pool)

Gets the expression after removing all ReferenceExps, until child AttributeExp or ElementExp.

hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

hashCodeback to summary
protected static int hashCode(Object o1, Object o2, int hashKey)
hashCodeback to summary
protected static int hashCode(Object o, int hashKey)
isEpsilonReducibleback to summary
public boolean isEpsilonReducible()

returns true if this expression accepts empty sequence.

If this method is called while creating Expressions, then this method may return approximated value. When this method is used while validation, this method is guaranteed to return the correct value.

peelOccurenceback to summary
public final Expression peelOccurence()

Peels the occurence expressions from this expression.

In AGM, 'X?','X+' and 'X*' are represented by using other primitives. This method returns the 'X' part by removing occurence related expressions.

readResolveback to summary
protected Object readResolve()
setHashCodeback to summary
private final void setHashCode(int hashCode)
visitback to summary
public abstract Object visit(ExpressionVisitor visitor)
visitback to summary
public abstract Expression visit(ExpressionVisitorExpression visitor)
visitback to summary
public abstract boolean visit(ExpressionVisitorBoolean visitor)
visitback to summary
public abstract void visit(ExpressionVisitorVoid visitor)
visitback to summary
public Object visit(RELAXExpressionVisitor visitor)
visitback to summary
public Expression visit(RELAXExpressionVisitorExpression visitor)
visitback to summary
public boolean visit(RELAXExpressionVisitorBoolean visitor)
visitback to summary
public void visit(RELAXExpressionVisitorVoid visitor)
com.sun.msv.grammar back to summary

private Class Expression.AnyStringExpression

extends Expression
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.sun.msv.grammar.Expression:
anyStringepsilonnullSetverifierTag

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected boolean
calcEpsilonReducibility()

Implements abstract com.sun.msv.grammar.Expression.calcEpsilonReducibility.

computes epsilon reducibility
protected final int
calcHashCode()

Implements abstract com.sun.msv.grammar.Expression.calcHashCode.

Computes the hashCode again.
public boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract com.sun.msv.grammar.Expression.equals.

Indicates whether some other object is "equal to" this one.
protected Object
public Object
public Expression
public boolean
public void
Inherited from com.sun.msv.grammar.Expression:
getExpandedExphashCodehashCodehashCodeisEpsilonReduciblepeelOccurencevisitvisitvisitvisit

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.sun.msv.grammar.Expression.serialVersionUID.

Constructor Detail

AnyStringExpressionback to summary
pack-priv AnyStringExpression()

Method Detail

calcEpsilonReducibilityback to summary
protected boolean calcEpsilonReducibility()

Implements abstract com.sun.msv.grammar.Expression.calcEpsilonReducibility.

Doc from com.sun.msv.grammar.Expression.calcEpsilonReducibility.

computes epsilon reducibility

calcHashCodeback to summary
protected final int calcHashCode()

Implements abstract com.sun.msv.grammar.Expression.calcHashCode.

Doc from com.sun.msv.grammar.Expression.calcHashCode.

Computes the hashCode again.

This method and the parameter to the constructor has to be the same. This method is used when the object is being read from the stream.

equalsback to summary
public boolean equals(Object o)

Implements abstract com.sun.msv.grammar.Expression.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

readResolveback to summary
protected Object readResolve()

Overrides com.sun.msv.grammar.Expression.readResolve.

visitback to summary
public Object visit(ExpressionVisitor visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

visitback to summary
public Expression visit(ExpressionVisitorExpression visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

visitback to summary
public boolean visit(ExpressionVisitorBoolean visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

visitback to summary
public void visit(ExpressionVisitorVoid visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

com.sun.msv.grammar back to summary

private Class Expression.EpsilonExpression

extends Expression
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.sun.msv.grammar.Expression:
anyStringepsilonnullSetverifierTag

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected boolean
calcEpsilonReducibility()

Implements abstract com.sun.msv.grammar.Expression.calcEpsilonReducibility.

computes epsilon reducibility
protected final int
calcHashCode()

Implements abstract com.sun.msv.grammar.Expression.calcHashCode.

Computes the hashCode again.
public boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract com.sun.msv.grammar.Expression.equals.

Indicates whether some other object is "equal to" this one.
protected Object
public Object
public Expression
public boolean
public void
Inherited from com.sun.msv.grammar.Expression:
getExpandedExphashCodehashCodehashCodeisEpsilonReduciblepeelOccurencevisitvisitvisitvisit

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.sun.msv.grammar.Expression.serialVersionUID.

Constructor Detail

EpsilonExpressionback to summary
pack-priv EpsilonExpression()

Method Detail

calcEpsilonReducibilityback to summary
protected boolean calcEpsilonReducibility()

Implements abstract com.sun.msv.grammar.Expression.calcEpsilonReducibility.

Doc from com.sun.msv.grammar.Expression.calcEpsilonReducibility.

computes epsilon reducibility

calcHashCodeback to summary
protected final int calcHashCode()

Implements abstract com.sun.msv.grammar.Expression.calcHashCode.

Doc from com.sun.msv.grammar.Expression.calcHashCode.

Computes the hashCode again.

This method and the parameter to the constructor has to be the same. This method is used when the object is being read from the stream.

equalsback to summary
public boolean equals(Object o)

Implements abstract com.sun.msv.grammar.Expression.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

readResolveback to summary
protected Object readResolve()

Overrides com.sun.msv.grammar.Expression.readResolve.

visitback to summary
public Object visit(ExpressionVisitor visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

visitback to summary
public Expression visit(ExpressionVisitorExpression visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

visitback to summary
public boolean visit(ExpressionVisitorBoolean visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

visitback to summary
public void visit(ExpressionVisitorVoid visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

com.sun.msv.grammar back to summary

private Class Expression.NullSetExpression

extends Expression
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.sun.msv.grammar.Expression:
anyStringepsilonnullSetverifierTag

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected boolean
calcEpsilonReducibility()

Implements abstract com.sun.msv.grammar.Expression.calcEpsilonReducibility.

computes epsilon reducibility
protected final int
calcHashCode()

Implements abstract com.sun.msv.grammar.Expression.calcHashCode.

Computes the hashCode again.
public boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract com.sun.msv.grammar.Expression.equals.

Indicates whether some other object is "equal to" this one.
protected Object
public Object
public Expression
public boolean
public void
Inherited from com.sun.msv.grammar.Expression:
getExpandedExphashCodehashCodehashCodeisEpsilonReduciblepeelOccurencevisitvisitvisitvisit

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.sun.msv.grammar.Expression.serialVersionUID.

Constructor Detail

NullSetExpressionback to summary
pack-priv NullSetExpression()

Method Detail

calcEpsilonReducibilityback to summary
protected boolean calcEpsilonReducibility()

Implements abstract com.sun.msv.grammar.Expression.calcEpsilonReducibility.

Doc from com.sun.msv.grammar.Expression.calcEpsilonReducibility.

computes epsilon reducibility

calcHashCodeback to summary
protected final int calcHashCode()

Implements abstract com.sun.msv.grammar.Expression.calcHashCode.

Doc from com.sun.msv.grammar.Expression.calcHashCode.

Computes the hashCode again.

This method and the parameter to the constructor has to be the same. This method is used when the object is being read from the stream.

equalsback to summary
public boolean equals(Object o)

Implements abstract com.sun.msv.grammar.Expression.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

readResolveback to summary
protected Object readResolve()

Overrides com.sun.msv.grammar.Expression.readResolve.

visitback to summary
public Object visit(ExpressionVisitor visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

visitback to summary
public Expression visit(ExpressionVisitorExpression visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

visitback to summary
public boolean visit(ExpressionVisitorBoolean visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.

visitback to summary
public void visit(ExpressionVisitorVoid visitor)

Implements abstract com.sun.msv.grammar.Expression.visit.