Class Expression
- java.lang.Object
-
- com.sun.msv.grammar.Expression
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AttributeExp,BinaryExp,DataExp,ElementExp,OtherExp,ReferenceExp,UnaryExp,ValueExp
public abstract class Expression extends Object implements Serializable
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
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ExpressionanyStringspecial expression object that represents "any string".static ExpressionepsilonSpecial expression object that represents epsilon (ε).static ExpressionnullSetspecial expression object that represents the empty set (Φ).ObjectverifierTagthis field can be used by Verifier implementation to speed up validation.
-
Constructor Summary
Constructors Modifier Constructor Description protectedExpression()this constructor can be used for the ununified expressions.protectedExpression(int hashCode)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract booleancalcEpsilonReducibility()computes epsilon reducibilityprotected abstract intcalcHashCode()Computes the hashCode again.abstract booleanequals(Object o)ExpressiongetExpandedExp(ExpressionPool pool)Gets the expression after removing all ReferenceExps, until child AttributeExp or ElementExp.inthashCode()protected static inthashCode(Object o, int hashKey)protected static inthashCode(Object o1, Object o2, int hashKey)booleanisEpsilonReducible()returns true if this expression accepts empty sequence.ExpressionpeelOccurence()Peels the occurence expressions from this expression.protected ObjectreadResolve()abstract Objectvisit(ExpressionVisitor visitor)abstract booleanvisit(ExpressionVisitorBoolean visitor)abstract Expressionvisit(ExpressionVisitorExpression visitor)abstract voidvisit(ExpressionVisitorVoid visitor)Objectvisit(RELAXExpressionVisitor visitor)booleanvisit(RELAXExpressionVisitorBoolean visitor)Expressionvisit(RELAXExpressionVisitorExpression visitor)voidvisit(RELAXExpressionVisitorVoid visitor)
-
-
-
Field Detail
-
verifierTag
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.
-
epsilon
public static final Expression epsilon
Special expression object that represents epsilon (ε). This expression matches to "empty". Epsilon can be thought as an empty sequence.
-
nullSet
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.
-
anyString
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.
-
-
Method Detail
-
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
public Expression getExpandedExp(ExpressionPool pool)
Gets the expression after removing all ReferenceExps, until child AttributeExp or ElementExp.
-
peelOccurence
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.
-
visit
public abstract Object visit(ExpressionVisitor visitor)
-
visit
public abstract Expression visit(ExpressionVisitorExpression visitor)
-
visit
public abstract boolean visit(ExpressionVisitorBoolean visitor)
-
visit
public abstract void visit(ExpressionVisitorVoid visitor)
-
visit
public Object visit(RELAXExpressionVisitor visitor)
-
visit
public Expression visit(RELAXExpressionVisitorExpression visitor)
-
visit
public boolean visit(RELAXExpressionVisitorBoolean visitor)
-
visit
public void visit(RELAXExpressionVisitorVoid visitor)
-
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.
-
hashCode
protected static int hashCode(Object o, int hashKey)
-
readResolve
protected Object readResolve()
-
-