Class Expression
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AttributeExp
,BinaryExp
,DataExp
,ElementExp
,Expression.AnyStringExpression
,Expression.EpsilonExpression
,Expression.NullSetExpression
,OtherExp
,ReferenceExp
,UnaryExp
,ValueExp
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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Expression
special expression object that represents "any string".private int
Hash code of this object.static final Expression
Special expression object that represents epsilon (ε).private Boolean
cached value of epsilon reducibility.private Expression
Cached value of the expression after ReferenceExps are removed.static final Expression
special expression object that represents the empty set (Φ).private static final long
this field can be used by Verifier implementation to speed up validation. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
this constructor can be used for the ununified expressions.protected
Expression
(int hashCode) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
computes epsilon reducibilityprotected abstract int
Computes the hashCode again.abstract boolean
getExpandedExp
(ExpressionPool pool) Gets the expression after removing all ReferenceExps, until child AttributeExp or ElementExp.final int
hashCode()
protected static int
protected static int
boolean
returns true if this expression accepts empty sequence.final Expression
Peels the occurence expressions from this expression.protected Object
private final void
setHashCode
(int hashCode) abstract Object
visit
(ExpressionVisitor visitor) abstract boolean
visit
(ExpressionVisitorBoolean visitor) abstract Expression
visit
(ExpressionVisitorExpression visitor) abstract void
visit
(ExpressionVisitorVoid visitor) visit
(RELAXExpressionVisitor visitor) boolean
visit
(RELAXExpressionVisitorBoolean visitor) visit
(RELAXExpressionVisitorExpression visitor) void
visit
(RELAXExpressionVisitorVoid visitor)
-
Field Details
-
epsilonReducibility
cached value of epsilon reducibility. Epsilon reducibility can only be calculated after parsing the entire expression, because of forward reference to other pattern. -
expandedExp
Cached value of the expression after ReferenceExps are removed. This value is computed on demand. -
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. -
cachedHashCode
private transient int cachedHashCodeHash 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.
-
epsilon
Special expression object that represents epsilon (ε). This expression matches to "empty". Epsilon can be thought as an empty sequence. -
nullSet
special expression object that represents the empty set (Φ). This expression doesn't match to anything. NullSet can be thought as an empty choice. -
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.
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
Expression
protected Expression(int hashCode) -
Expression
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 Details
-
isEpsilonReducible
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.
-
calcEpsilonReducibility
protected abstract boolean calcEpsilonReducibility()computes epsilon reducibility -
getExpandedExp
Gets the expression after removing all ReferenceExps, until child AttributeExp or ElementExp. -
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.
-
visit
-
visit
-
visit
-
visit
-
visit
-
visit
-
visit
-
visit
-
hashCode
public final int hashCode() -
setHashCode
private final void setHashCode(int hashCode) -
calcHashCode
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.
-
equals
-
hashCode
-
hashCode
-
readResolve
-