- Added KindTest interface that allows in particular the representation of element and attribute tests - Added a "leaver" which is similar to a visitor but send callback after all children of a node were sent - javadoc...
diff --git a/xpath_rwapi/src2/org/apache/xpath/XPath20Utilities.java b/xpath_rwapi/src2/org/apache/xpath/XPath20Utilities.java index 4b40278..01b8496 100644 --- a/xpath_rwapi/src2/org/apache/xpath/XPath20Utilities.java +++ b/xpath_rwapi/src2/org/apache/xpath/XPath20Utilities.java
@@ -152,5 +152,15 @@ } return result; } + + /** + * Returns true whenever the specified expression is a + * <em>singleton sequence</em> (a sequence with only one item). + */ + public static boolean isSingletonSequence(Expr e) + { + return e != null && e.getExprType() == Expr.SEQUENCE_EXPR + && ((OperatorExpr) e).getOperandCount() == 1; + } }
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/CastOrTreatAsExpr.java b/xpath_rwapi/src2/org/apache/xpath/expression/CastOrTreatAsExpr.java index 008a437..967b61f 100644 --- a/xpath_rwapi/src2/org/apache/xpath/expression/CastOrTreatAsExpr.java +++ b/xpath_rwapi/src2/org/apache/xpath/expression/CastOrTreatAsExpr.java
@@ -58,9 +58,9 @@ import org.apache.xpath.datamodel.SequenceType; /** - * Represents "cast as" and 'treat as' expression. - * Use the method <code>getExprType()</code> to differentiate treat as and cast as - * expressions. + * Represents <em>cast as</em> and <em>treat as</em> expression. + * Use the method {@link #getExprType()} to differentiate + * <em>treat as</em> from <em>cast as</em> expressions. * @see <a href="http://www.w3.org/TR/xpath20/#id-cast"> * XPath 2.0 specification</a> */
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/CastableAsExpr.java b/xpath_rwapi/src2/org/apache/xpath/expression/CastableAsExpr.java index 88c5e1c..2b17b62 100644 --- a/xpath_rwapi/src2/org/apache/xpath/expression/CastableAsExpr.java +++ b/xpath_rwapi/src2/org/apache/xpath/expression/CastableAsExpr.java
@@ -58,7 +58,7 @@ import org.apache.xpath.datamodel.SequenceType; /** - * Represent "castable as" expression. + * Represent <em>castable as</em> expressions. * @see <a href="http://www.w3.org/TR/xpath20/#id-castable"> * XPath 2.0 specification</a> */
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/Expr.java b/xpath_rwapi/src2/org/apache/xpath/expression/Expr.java index 1aaf9c3..ab6dedb 100644 --- a/xpath_rwapi/src2/org/apache/xpath/expression/Expr.java +++ b/xpath_rwapi/src2/org/apache/xpath/expression/Expr.java
@@ -57,8 +57,8 @@ /** * Represents a XPath expression. - * <p>Use {@link #getExprType()} to query the expression type. - * More information about expression are obtained by casting it + * <p>Use {@link #getExprType()} to get the expression type. + * Then, more information about expression are obtained by casting it * to its corresponding java type. Here the XPath expression type to Java type mapping table: * </p> * <table cellpadding="2" cellspacing="2" border="1"> @@ -161,7 +161,7 @@ * } * } else * { - * System.out.println(e.getString(true) + " "); + * System.out.print(e.getString(true) + " "); * } * } * </pre> @@ -171,12 +171,13 @@ * </pre> * <p>XPath expressions are always fully expanded. For example, the expression * /a//b is expanded to fn:root(self::node())/descendant-or-self::node()/b. - * The number of steps is 3 (and not 2). + * The number of steps is then 3 (and not 2). * </p> * <p> - * An {@link Expr} object may be not a valid XPath expression but only a fragment. - * For example a {@link StepExpr} expression is a fragment but can't be executed by - * itself. To be valid, the top level expression must be an expression sequence. + * An {@link Expr} object may be not a valid XPath expression but only a fragment (or a part). + * For example {@link StepExpr} and {@link NodeTest} expression types are fragments + * and therefore can't be executed by themself. To be valid, the top level expression + * must be an expression sequence. * </p> * @see <a href="http://www.w3.org/TR/2002/WD-xpath20-20020816/#id-expressions">XPath 2.0 Specification</a> * @author <a href="mailto:villard@us.ibm.com">Lionel Villard</a> @@ -214,7 +215,7 @@ /** * The expression is a quantified expression of type some */ - static final short SOME_EXPR = 22; + static final short SOME_EXPR = 8; /** * The expression is a comparison expression type. @@ -254,11 +255,7 @@ */ static final short VARIABLE_REF_EXPR = 15; - /** - * The expression is a step - */ - static final short STEP = 17; - + /** * The expression is an instance of expression */ @@ -284,6 +281,17 @@ */ static final short LET_EXPR = 23; + // Expression parts + + /** + * The expression part is a step + */ + static final short STEP = 17; + + /** + * The expression part is a node test + */ + static final short NODE_TEST = 11; /** * Gets the expression type.
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/KindTest.java b/xpath_rwapi/src2/org/apache/xpath/expression/KindTest.java new file mode 100644 index 0000000..ca01349 --- /dev/null +++ b/xpath_rwapi/src2/org/apache/xpath/expression/KindTest.java
@@ -0,0 +1,147 @@ +/* + * Created on Aug 8, 2003 + */ +package org.apache.xpath.expression; + +import org.apache.xml.QName; +import org.apache.xpath.XPath20Exception; + +/** + * Represents <em>KindTest</em>. + * <p>The method {@link #getKindTestType()} returns the kind + * test type as following: + * <ul> + * <li><b>{@link #TEXT_TEST}</b> for text()</li> + * <li><b>{@link #PROCESSING_INSTRUCTION_TEST}</b> for processing-instruction()</b>. + * Use {@link #getPITarget()} to get the target when specified.</li> + * <li><b>{@link #COMMENT_TEST}</b> for comment()</li> + * <li><b>{@link #ANY_KIND_TEST}</b> for node()</li> + * <li><b>{@link #CONTEXT_ITEM_TEST}</b> for '.'</li> + * <li><b>{@link #ELEMENT_TEST}</b> for element tests. Use {@link #getKindTestSubtype()} to get which one: + * <ul> + * <li><b>{@link #WILDCARD}</b> for element(), or element(*), or element(*,*)</b> + * <li><b>{@link #NODE_TYPE}</b> for element(N, T)</li> + * <li><b>{@link #NODE_TYPE_NILLABLE}</b> for element(N, T nillable)</li> + * <li><b>{@link #NODE_WILDCARD}</b> for element(N, *)</li> + * <li><b>{@link #WILDCARD_TYPE}</b> for element(*, T)</li> + * <li><b>{@link #SCHEMA_PATH}</b> for element(P)</li> + * </ul> + * </li> + * <li><b>{@link #ATTRIBUTE_TEST}</b> for attribute test. Use {@link #getKindTestSubtype()} to get which one: + * <ul> + * <li><b>{@link #WILDCARD}</b> for attribute(), or attribute(*), or attribute(*,*)</b> + * <li><b>{@link #NODE_TYPE}</b> for attribute(@N, T)</li> + * <li><b>{@link #NODE}</b> for attribute(@N)</li> + * <li><b>{@link #NODE_WILDCARD}</b> for attribute(@N, *)</li> + * <li><b>{@link #WILDCARD_TYPE}</b> for attribute(@*, T)</li> + * <li><b>{@link #SCHEMA_PATH}</b> for attribute(P)</li> + * </ul> + * </ul> + * @author <a href="mailto:villard@us.ibm.com">Lionel Villard</a> + * @version $Id$ + */ +public interface KindTest extends NodeTest +{ + + /** + * Processing instruction test (kind test) + */ + static final short PROCESSING_INSTRUCTION_TEST = 0; + + /** + * Comment test (kind test) + */ + static final short COMMENT_TEST = 1; + + /** + * Any kind test (except context item test) + */ + static final short ANY_KIND_TEST = 2; + + /** + * Text test (kind test) + */ + static final short TEXT_TEST = 3; + + /** + * Document test (kind test) + */ + static final short DOCUMENT_TEST = 4; + + /** + * Element test (kind test) + */ + static final short ELEMENT_TEST = 5; + + /** + * Attribute test (kind test) + */ + static final short ATTRIBUTE_TEST = 6; + + /** + * The node test is a context item test (belong to the kind test group) + */ + static final short CONTEXT_ITEM_TEST = 7; + + // Subtypes + + static final short WILDCARD = 0; + static final short NODE_TYPE = 1; + static final short NODE = 6; + static final short NODE_TYPE_NILLABLE = 2; + static final short NODE_WILDCARD = 3; + static final short WILDCARD_TYPE = 4; + static final short SCHEMA_PATH = 5; + + /** + * Gets the kind test code. + * @return short One of the kind test constant value + */ + short getKindTestType(); + + /** + * Gets the subtype kind test code. + * @return short One of the subkind test constant value + */ + short getKindTestSubtype(); + + /** + * Gets the local name used to match either an element, + * an attribute or a document node. + * See class description to see when to use this method. + * @return The local name or null + * @throws XPath20Exception whenever the kind test type of is not + * {@link #ELEMENT_TEST} or {@link #ATTRIBUTE_TEST} + * or {@link #DOCUMENT_TEST}. + */ + QName getLocalName() throws XPath20Exception; + + /** + * + * @return + * @throws XPath20Exception + */ + QName getNodeName() throws XPath20Exception; + + /** + * Gets type name. See class description to see when to use this method. + * @return QName + * @throws XPath20Exception + */ + QName getTypeName() throws XPath20Exception; + + /** + * Gets schema context path. See class description to see when to use this method. + * @return String (?) + * @throws XPath20Exception + */ + String getSchemaContext() throws XPath20Exception; + + /** + * Gets the PITarget test or null if not specified. + * @return + * @throws XPath20Exception whenever the kind test is not + * {@link #PROCESSING_INSTRUCTION_TEST}. + */ + String getPITarget() throws XPath20Exception; +}
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/Leaver.java b/xpath_rwapi/src2/org/apache/xpath/expression/Leaver.java new file mode 100644 index 0000000..748894c --- /dev/null +++ b/xpath_rwapi/src2/org/apache/xpath/expression/Leaver.java
@@ -0,0 +1,56 @@ +/* + * Created on Aug 11, 2003 + */ +package org.apache.xpath.expression; + +/** + * Callbacks for receiving "leave" events. A "leave" event is sent + * for an given expression part when all its sub expression parts + * was visited. + * @author <a href="mailto:villard@us.ibm.com">Lionel Villard</a> + * @version $Id$ + */ +public interface Leaver +{ + /** + * Leave path expression + * @param path + */ + void leavePath(PathExpr path); + + /** + * Leave step expression + * @param + */ + void leaveStep(StepExpr step); + + /** + * Leave operator expression + * @param + * + */ + void leaveOperator(OperatorExpr operator); + + /** + * Leave conditional expression + * @param + */ + void leaveConditional(ConditionalExpr condition); + + /** + * Leave for or quantified expression + * @param + */ + void leaveForOrQuantifiedExpr(ForAndQuantifiedExpr expr); + + /** + * Leave instance of expression + */ + void leaveInstanceOf(InstanceOfExpr expr); + + /** + * Leave 'castable as' expression + */ + void leaveCastableAs(CastableAsExpr expr); + +}
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/Literal.java b/xpath_rwapi/src2/org/apache/xpath/expression/Literal.java index 916a2bd..e6517da 100644 --- a/xpath_rwapi/src2/org/apache/xpath/expression/Literal.java +++ b/xpath_rwapi/src2/org/apache/xpath/expression/Literal.java
@@ -62,18 +62,17 @@ /** - * Represents literal expression type. - * <pre> - * [59] Literal ::= NumericLiteral | StringLiteral - * [58] NumericLiteral ::= IntegerLiteral | DecimalLiteral | DoubleLiteral - * [1] IntegerLiteral ::= Digits - * [2] DecimalLiteral ::= ("." Digits) | (Digits "." [0-9]*) - * [3] DoubleLiteral ::= (("." Digits) | (Digits ("." [0-9]*)?)) ("e" | "E") ("+" | "-")? Digits - * [4] StringLiteral ::= ('"' (('"' '"') | [^"])* '"') | ("'" (("'" "'") | [^'])* "'") - * </pre> - * - * @see <a href="http://www.w3.org/TR/xpath20#id-literals">XPath 2.0 - * Specification</a> + * Represents <em>literal</em> expressions. + * Use {@link #getLiteralType()} to get the type of literal, as following + * <ul> + * <li>{@link #INTEGER_LITERAL}: xs:integer datatype</li> + * <li>{@link #DOUBLE_LITERAL}: xs:double datatype</li> + * <li>{@link #DECIMAL_LITERAL}: xs:decimal datatype</li> + * <li>{@link #STRING_LITERAL}: xs:string datatype</li> + * </ul> + * @author <a href="mailto:villard@us.ibm.com">Lionel Villard</a> + * @version $Id$ + * @see <a href="http://www.w3.org/TR/xpath20#id-literals">XPath 2.0 Specification</a> */ public interface Literal extends Expr { @@ -99,64 +98,52 @@ /** * Gets the literal type - * * @return short One of the four following literal type: - * <code>INTEGER_LITERAL</code>, <code>DECIMAL_LITERAL</code>, - * <code>STRING_LITERAL</code>, <code>DOUBLE_LITERAL</code>. + * {@link #INTEGER_LITERAL}, {@link #DECIMAL_LITERAL}, + * {@link #STRING_LITERAL}, {@link #DOUBLE_LITERAL}. */ short getLiteralType(); /** - * Gets the integer literal - * - * @return DOCUMENT ME! - * - * @throws XPath20Exception when the literal isn't an integer or cannot be - * represented by the primitive int type (in case of big integer) + * Gets the integer literal as primitive Java int type. + * @return int + * @throws XPath20Exception when the literal isn't an integer or when it cannot be + * represented as a primitive int type without approximations */ int getIntegerLiteralAsInt() throws XPath20Exception; /** - * Gets the integer literal - * - * @return DOCUMENT ME! - * + * Gets the integer literal. + * @return BigInteger * @throws XPath20Exception when the literal isn't an integer */ BigInteger getIntegerLiteral() throws XPath20Exception; /** * Gets the decimal literal - * - * @return DOCUMENT ME! - * + * @return BigDecimal * @throws XPath20Exception when the literal isn't a decimal */ BigDecimal getDecimalLiteral() throws XPath20Exception; /** * Gets the decimal literal as a double - * - * @return DOCUMENT ME! - * - * @throws XPath20Exception when the literal isn't a decimal + * @return double + * @throws XPath20Exception when the literal isn't a decimal or + * when it cannot be represented as a double without approximations */ double getDecimalLiteralAsDouble() throws XPath20Exception; /** * Gets the double literal - * - * @return DOCUMENT ME! - * + * @return double * @throws XPath20Exception when the literal isn't a double */ double getDoubleLiteral() throws XPath20Exception; /** * Gets the string literal - * - * @return DOCUMENT ME! - * + * @return String * @throws XPath20Exception when the literal isn't a string */ String getStringLiteral() throws XPath20Exception;
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/NameTest.java b/xpath_rwapi/src2/org/apache/xpath/expression/NameTest.java new file mode 100644 index 0000000..aea06cf --- /dev/null +++ b/xpath_rwapi/src2/org/apache/xpath/expression/NameTest.java
@@ -0,0 +1,50 @@ +/* + * Created on Aug 6, 2003 + */ +package org.apache.xpath.expression; + +import org.apache.xml.QName; +import org.apache.xpath.XPath20Exception; + +/** + * <em>NameTest</em> expression type. + * Dependings on the value returned by {@link #getNameTestType()}, + * a name test have the following forms: + * <ul> + * <li>{@link #WILDCARD}: *</li> + * <li>{@link #NCNAME_WILDCARD}: ns:*</li> + * <li>{@link #WILDCARD_NCNAME}: *:ln</li> + * <li>{@link #QNAME}: (prefix?):localName</li> + * </ul> + * @author <a href="mailto:villard@us.ibm.com">Lionel Villard</a> + * @version $Id$ + */ +public interface NameTest +{ + final short WILDCARD = 0; + final short NCNAME_WILDCARD = 1; + final short WILDCARD_NCNAME = 2; + final short QNAME = 3; + + /** + * Gets the name test type + * @return One of the constants defined above + */ + short getNameTestType(); + + /** + * Gets the qualified name of the name test. + * @return Qualified name + * @throws XPath20Exception when the name test type isn't + * {@link #QNAME} + */ + QName getName() throws XPath20Exception; + + /** + * Gets the namespace or the local part of the name test. + * @return NCName + * @throws XPath20Exception when the name test type isn't + * {@link #NCNAME_WILDCARD} or {@link #WILDCARD_NCNAME} + */ + String getNCName() throws XPath20Exception; +}
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/NodeTest.java b/xpath_rwapi/src2/org/apache/xpath/expression/NodeTest.java index 57f088c..4b96a95 100644 --- a/xpath_rwapi/src2/org/apache/xpath/expression/NodeTest.java +++ b/xpath_rwapi/src2/org/apache/xpath/expression/NodeTest.java
@@ -55,12 +55,11 @@ */ package org.apache.xpath.expression; -import org.apache.xml.QName; import org.apache.xpath.XPath20Exception; /** - * Represents an item test. An item test includes both node tests - * and the context item test (dot). + * Represents an <em>item test</em>. An item test includes both node tests + * and the context item test (the character '.'). * <p> * A node test is either a name test or a kind test. For the former, use * the method {@link #getNameTest()} to get the {@link QName} involved in the test. @@ -79,38 +78,53 @@ * @see <a href="http://www.w3.org/TR/xpath20/#doc-NodeTest">Node test specification</a> * @see <a href="http://www.w3.org/TR/xpath20/#abbrev">Context item specification</a> */ -public interface NodeTest { +public interface NodeTest extends Expr { /** - * The item test is a processing instruction kind test + * Processing instruction test (kind test) */ static final short PROCESSING_INSTRUCTION_TEST = 0; /** - * The item test is a comment kind test + * Comment test (kind test) */ static final short COMMENT_TEST = 1; /** - * The item test is any kind of test (except context item test) + * Any kind test (except context item test) */ static final short ANY_KIND_TEST = 2; /** - * The item test is a text kind test + * Text test (kind test) */ static final short TEXT_TEST = 3; /** + * Document test (kind test) + */ + static final short DOCUMENT_TEST = 4; + + /** + * Element test (kind test) + */ + static final short ELEMENT_TEST = 5; + + /** + * Attribute test (kind test) + */ + static final short ATTRIBUTE_TEST = 6; + + /** * The node test is a context item test (belong to the kind test group) */ - static final short CONTEXT_ITEM_TEST = 4; + static final short CONTEXT_ITEM_TEST = 7; /** - * Full name of kind tests. + * Full name of simple kind tests (whithout parameters). * This array is synchronized with the kind test constants */ - static final String[] KIND_TEST_NAME = { "processing-instruction()", "comment()", "node()", "text()", "." }; + static final String[] KIND_TEST_NAME = { "processing-instruction()", "comment()", "node()", "text()", "document-node()", "element()", "attribute()", "." }; /** * Return true whenever this node test is a name test @@ -128,6 +142,7 @@ * Gets the kind test code. * @return short One of the kind test constant value * @throws XPath20Exception whenever this node test isn't a kind test + * @deprecated cast to KindTest */ short getKindTest() throws XPath20Exception; @@ -138,8 +153,9 @@ * @return QName The name test * @throws XPath20Exception whenever this node test isn't a name test * or a pi kind test + * @deprecated cast to NameTest */ - QName getNameTest() throws XPath20Exception; + NameTest getNameTest() throws XPath20Exception; }
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/PathExpr.java b/xpath_rwapi/src2/org/apache/xpath/expression/PathExpr.java index fde3d24..cec1030 100644 --- a/xpath_rwapi/src2/org/apache/xpath/expression/PathExpr.java +++ b/xpath_rwapi/src2/org/apache/xpath/expression/PathExpr.java
@@ -56,8 +56,8 @@ package org.apache.xpath.expression; /** - * Represents <em>path</em> expression. <quote>It can be used to locate nodes within a tree.</quote> - * <p>A path expression consists of a series of {@link StepExpr}. + * Represents <em>path</em> expressions. <quote>It can be used to locate nodes within a tree.</quote> + * <p>A path expression consists of a sequence of {@link StepExpr}. * It's a {@link OperatorExpr operator-based} expression * with {@link OperatorExpr#SLASH_STEP} as the operator separator * and {@link Expr#PATH_EXPR} as the operator type.
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/StepExpr.java b/xpath_rwapi/src2/org/apache/xpath/expression/StepExpr.java index 3b4243e..76567aa 100644 --- a/xpath_rwapi/src2/org/apache/xpath/expression/StepExpr.java +++ b/xpath_rwapi/src2/org/apache/xpath/expression/StepExpr.java
@@ -57,189 +57,206 @@ import org.apache.xpath.XPath20Exception; - /** - * Represents a step. - * <quote>A step generates a sequence of items and then filters the sequence - * by zero or more predicates.</quote> + * Represents <em>step</em> expressions. + * A step is either a <em>axis step</em> or an <em>filter step</em>. * @see <a href="http://www.w3.org/TR/xpath20/#id-axis-steps">XPath 2.0 * specification</a> + * @author <a href="mailto:villard@us.ibm.com">Lionel Villard</a> + * @version $Id$ */ public interface StepExpr extends Expr { - /** - * Full name of axis. This array is kept in synchronization with axis - * constants. - */ - static final String[] FULL_AXIS_NAME = - { - "", "child", "descendant", - "parent", "attribute", "self", - "descendant-or-self", "ancestor", - "following-sibling", - "preceding-sibling", "following", - "preceding", "namespace", - "ancestor-or-self" - }; + /** + * Full name of axis. This array is kept in synchronization with axis + * constants. + */ + static final String[] FULL_AXIS_NAME = + { + "", + "child", + "descendant", + "parent", + "attribute", + "self", + "descendant-or-self", + "ancestor", + "following-sibling", + "preceding-sibling", + "following", + "preceding", + "namespace", + "ancestor-or-self" }; - /** - * The step axis is child - */ - static final short AXIS_CHILD = 1; + /** + * The step axis is child + */ + static final short AXIS_CHILD = 1; - /** - * The step axis is descendant - */ - static final short AXIS_DESCENDANT = 2; + /** + * The step axis is descendant + */ + static final short AXIS_DESCENDANT = 2; - /** - * The step axis is parent - */ - static final short AXIS_PARENT = 3; + /** + * The step axis is parent + */ + static final short AXIS_PARENT = 3; - /** - * The step axis is attribute - */ - static final short AXIS_ATTRIBUTE = 4; + /** + * The step axis is attribute + */ + static final short AXIS_ATTRIBUTE = 4; - /** - * The step axis is self - */ - static final short AXIS_SELF = 5; + /** + * The step axis is self + */ + static final short AXIS_SELF = 5; - /** - * The step axis is descendant or self - */ - static final short AXIS_DESCENDANT_OR_SELF = 6; + /** + * The step axis is descendant or self + */ + static final short AXIS_DESCENDANT_OR_SELF = 6; - /** - * The step axis is ancestor - */ - static final short AXIS_ANCESTOR = 7; + /** + * The step axis is ancestor + */ + static final short AXIS_ANCESTOR = 7; - /** - * The step axis is following sibling - */ - static final short AXIS_FOLLOWING_SIBLING = 8; + /** + * The step axis is following sibling + */ + static final short AXIS_FOLLOWING_SIBLING = 8; - /** - * The step axis is preceding sibling - */ - static final short AXIS_PRECEDING_SIBLING = 9; + /** + * The step axis is preceding sibling + */ + static final short AXIS_PRECEDING_SIBLING = 9; - /** - * The step axis is following - */ - static final short AXIS_FOLLOWING = 10; + /** + * The step axis is following + */ + static final short AXIS_FOLLOWING = 10; - /** - * The step axis is preceding - */ - static final short AXIS_PRECEDING = 11; + /** + * The step axis is preceding + */ + static final short AXIS_PRECEDING = 11; - /** - * The step axis is namespace - */ - static final short AXIS_NAMESPACE = 12; + /** + * The step axis is namespace + */ + static final short AXIS_NAMESPACE = 12; - /** - * The step axis is ancestor or self - */ - static final short AXIS_ANCESTOR_OR_SELF = 13; + /** + * The step axis is ancestor or self + */ + static final short AXIS_ANCESTOR_OR_SELF = 13; - /** - * Tells whether or not this step is a foward axis step - * @return boolean - */ - boolean isForwardStep(); + /** + * Tells whether this step is a forward axis step. + * Includes the follwing axis: + * <ul> + * <li>{@link #AXIS_CHILD}</li> + * <li>{@link #AXIS_DESCENDANT}</li> + * <li>{@link #AXIS_DESCENDANT_OR_SELF}</li> + * <li>{@link #AXIS_ATTRIBUTE}</li> + * <li>{@link #AXIS_SELF}</li> + * <li>{@link #AXIS_FOLLOWING}</li> + * <li>{@link #AXIS_FOLLOWING_SIBLING}</li> + * <li>{@link #AXIS_NAMESPACE}</li> + * </ul> + * @return true whenever {@link #getAxisType()} returns one the + * constants right above. + */ + boolean isForwardStep(); - /** - * Tells whether or not this step is a reversed axis step - * @return boolean - */ - boolean isReversedStep(); + /** + * Tells whether this step is a reversed axis step. + * Includes the following axis: + * <ul> + * <li>{@link #AXIS_PARENT}</li> + * <li>{@link #AXIS_ANCESTOR}</li> + * <li>{@link #AXIS_PRECEDING}</li> + * <li>{@link #AXIS_PRECEDING_SIBLING}</li> + * <li>{@link #AXIS_ANCESTOR_OR_SELF}</li> + * </ul> + * @return true whenever {@link #getAxisType()} returns one the + * constants right above. + */ + boolean isReversedStep(); - /** - * Tells whether or not this step is a filter step. - * @return boolean - */ - boolean isPrimaryExpr(); + /** + * Tells whether this step is a filter step + * @return boolean + */ + boolean isFilterStep(); - /** - * Gets the type of step axis - * - * @return short The axis type corresponding to one of the constants defined above. - * @throws XPath20Exception whenever the step is neither a forward step nor a reverse - * step. - */ - short getAxisType() throws XPath20Exception; + /** + * Gets the type of step axis + * @return short The axis type corresponding to one of the constants defined above. + * @throws XPath20Exception whenever the step isn't an axis step + */ + short getAxisType() throws XPath20Exception; - /** - * Sets the type of the step axis - * @param newType The new axis type - * @throws XPath20Exception whenever the step is not a forward or reverse - * step. - */ - void setAxisType(short newType) throws XPath20Exception; + /** + * Sets the type of the step axis + * @param newType The new axis type + * @throws XPath20Exception whenever the step isn't an axis step + */ + void setAxisType(short newType) throws XPath20Exception; - /** - * Gets the name of the step axis - * - * @return String Full name of the step axis - * @throws XPath20Exception whenever the step is not a forward or reverse - * step. - */ - String getAxisName() throws XPath20Exception; + /** + * Gets the name of the step axis + * @return String Full name of the step axis + * @throws XPath20Exception whenever the step isn't an axis step + */ + String getAxisName() throws XPath20Exception; - /** - * Gets the node test - * - * @return NodeTest - * @throws XPath20Exception whenever the step is not a forward or reverse - * step. - */ - NodeTest getNodeTest() throws XPath20Exception; - + /** + * Gets the node test + * @return NodeTest + * @throws XPath20Exception whenever the step isn't an axis step + */ + NodeTest getNodeTest() throws XPath20Exception; + /** * Sets the node test - * * @param NodeTest - * @throws XPath20Exception whenever the step is not a forward or reverse - * step. + * @throws XPath20Exception whenever the step isn't an axis step */ void setNodeTest(NodeTest test) throws XPath20Exception; + /** + * Gets the primary expression of the filter step. + * @return Expr The primary expression + * @throws XPath20Exception whenever the step isn't a filter step + */ + Expr getPrimaryExpr() throws XPath20Exception; - /** - * Gets the step as a primary expression. - * - * @return Expr The primary expression - */ - Expr getPrimaryExpr() throws XPath20Exception; + /** + * Gets the predicate expression at the specified position + * @param i index of the predicate to return + * @return The predicate at the ith position + * @throws java.lang.ArrayIndexOutOfBoundsException + */ + Expr getPredicateAt(int i); - /** - * Gets the predicate expression at the specified position - * @param i index of the predicate to return - * @return The predicate at the ith position - * @throws java.lang.ArrayIndexOutOfBoundsException - */ - Expr getPredicateAt(int i); + /** + * Gets the number of predicate + * @return The number of predicates + */ + int getPredicateCount(); - /** - * Gets the number of predicate - * - * @return The number of predicates - */ - int getPredicateCount(); + /** + * Append the specified predicate at the end of the list of + * predicates + * @param predicate The predicate to append + */ + void appendPredicate(Expr predicate); - /** - * Append the specified predicate - * @param predicate The predicate to append - */ - void appendPredicate(Expr predicate); - - /** - * Remove the specified predicate - */ - void removePredicate(Expr predicate); + /** + * Remove the specified predicate + */ + void removePredicate(Expr predicate); }
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/Variable.java b/xpath_rwapi/src2/org/apache/xpath/expression/Variable.java index c86af80..13eadf1 100644 --- a/xpath_rwapi/src2/org/apache/xpath/expression/Variable.java +++ b/xpath_rwapi/src2/org/apache/xpath/expression/Variable.java
@@ -59,16 +59,19 @@ import org.apache.xpath.XPath20Exception; /** - * Represents variable. + * Represents <em>variable</em> references. + * @author <a href="mailto:villard@us.ibm.com">Lionel Villard</a> + * @version $Id$ */ -public interface Variable extends Expr { +public interface Variable extends Expr +{ - /** - * Gets the name of the variable. - * @return String - */ - QName getVariableName(); - + /** + * Gets the name of the variable. + * @return String + */ + QName getVariableName(); + /** * Sets the name of the variable. * @param name New name of the variable
diff --git a/xpath_rwapi/src2/org/apache/xpath/expression/package.html b/xpath_rwapi/src2/org/apache/xpath/expression/package.html index 689ec96..c32a94f 100644 --- a/xpath_rwapi/src2/org/apache/xpath/expression/package.html +++ b/xpath_rwapi/src2/org/apache/xpath/expression/package.html
@@ -6,21 +6,25 @@ <body> <p>Public interfaces for XPath expression Abstract Syntax Tree nodes. Primary external APIs for this XPath AST model.</p> -<p>This XPath API is a compact set of Java interfaces that allow to -encode and handle XPath 2.0/XQuery 1.0 expressions (although only XPath -2.0 expressions are currently supported except for the let expression). -It was designed to fulfill +<p>This XPath API is a compact set of Java interfaces that allow the +in-memory representation and manipulation of XPath 2.0 expressions.The +main idea of this API is to manipulate XPath expressions independently +of their actual underlying representation.<br> +</p> +<p>It was designed to fulfill the following requirements:</p> <ul> <li style="font-weight: bold;">Read/Write: <span - style="font-weight: normal;">capability of visiting and modifying the -internal representation of expressions. The expression reading is + style="font-weight: normal;">it should be capable of querying/visiting +and modifying the +internal representation of XPath expressions. The expression reading is performed by using either the visitor pattern or get-like methods. Similarly, the</span><span style="font-weight: normal;"> expression </span><span style="font-weight: normal;">writing is done through a bunch of set-like methods.</span></li> <li style="font-weight: bold;"><span style="font-weight: normal;"><span - style="font-weight: bold;">Round-trip: </span>capability of getting + style="font-weight: bold;">Round-trip: </span>it should be capable of +getting string representation of expressions from its internal encoding.<br> </span></li> <li><span style="font-weight: bold;">Application-independent</span>: @@ -30,14 +34,15 @@ namespace/qname manager and AST generalization and specialisation (see implementation package).<span style="font-weight: bold;"><br> </span></li> - <li style="font-weight: bold;">Compactness: <span - style="font-weight: normal;">keep the interface set as minimal as -possible by factoring similar concepts. The best example is the -interface OperatorExpr which allows to represent more than ten + <li style="font-weight: bold;">Lightweight: <span + style="font-weight: normal;">it should be compact and therefore should +define a minimal set of Java interfaces in particular by factoring +similar concepts. The best example is the +interface OperatorExpr which allows the representation of more than ten expression types.</span></li> </ul> -Right now, the XPath API do not provide a standard way to evaluate -expressions. This should be done.<br> +Right now, the XPath API do not provide a standard way to request the +evaluation of expressions. This should be done.<br> <p></p> </body> </html>
diff --git a/xpath_rwapi/src2/org/apache/xpath/impl/KindTestImpl.java b/xpath_rwapi/src2/org/apache/xpath/impl/KindTestImpl.java index 25b0f4a..8e50990 100644 --- a/xpath_rwapi/src2/org/apache/xpath/impl/KindTestImpl.java +++ b/xpath_rwapi/src2/org/apache/xpath/impl/KindTestImpl.java
@@ -55,10 +55,11 @@ */ package org.apache.xpath.impl; -import org.apache.xml.QName; - import org.apache.xpath.XPath20Exception; +import org.apache.xpath.expression.Expr; +import org.apache.xpath.expression.NameTest; import org.apache.xpath.expression.NodeTest; +import org.apache.xpath.expression.Visitor; import org.apache.xpath.impl.parser.Node; import org.apache.xpath.impl.parser.SimpleNode; import org.apache.xpath.impl.parser.XPath; @@ -80,7 +81,7 @@ /** * PI target */ - protected QName m_pitarget; + protected NameTestImpl m_pitarget; /** * Creates an any kind test node. Internal uses only @@ -154,7 +155,7 @@ /** * @see org.apache.xpath.expression.NodeTest#getLocalNameTest() */ - public QName getNameTest() throws XPath20Exception + public NameTest getNameTest() throws XPath20Exception { if (m_kindTest == PROCESSING_INSTRUCTION_TEST) { @@ -166,14 +167,30 @@ } } - /** - * @see org.apache.xpath.expression.Expr#getString(boolean) - */ + // Implements Expr + public String getString(boolean abbreviate) { return KIND_TEST_NAME[m_kindTest]; } + public Expr cloneExpression() + { + // TODO Auto-generated method stub + return null; + } + + public short getExprType() + { + return Expr.NODE_TEST; + } + + public boolean visit(Visitor visitor) + { + // TODO Auto-generated method stub + return false; + } + /** * @see org.apache.xpath.impl.parser.Node#jjtAddChild(Node, int) */
diff --git a/xpath_rwapi/src2/org/apache/xpath/impl/NameTestImpl.java b/xpath_rwapi/src2/org/apache/xpath/impl/NameTestImpl.java index 7ead8fb..0542832 100644 --- a/xpath_rwapi/src2/org/apache/xpath/impl/NameTestImpl.java +++ b/xpath_rwapi/src2/org/apache/xpath/impl/NameTestImpl.java
@@ -56,111 +56,174 @@ package org.apache.xpath.impl; import org.apache.xml.QName; - import org.apache.xpath.XPath20Exception; +import org.apache.xpath.expression.Expr; +import org.apache.xpath.expression.NameTest; import org.apache.xpath.expression.NodeTest; +import org.apache.xpath.expression.Visitor; import org.apache.xpath.impl.parser.Node; +import org.apache.xpath.impl.parser.QNameWrapper; import org.apache.xpath.impl.parser.SimpleNode; import org.apache.xpath.impl.parser.XPathTreeConstants; - /** * Default implementation of name test. */ -public class NameTestImpl extends SimpleNode implements NodeTest +public class NameTestImpl extends SimpleNode implements NodeTest, NameTest { - /** - * Name test - */ - QName m_qname; + /** + * Name test + */ + QName m_qname; - /** - * Constructor for NameTestImpl. Internal uses only - * - * @param i - */ - public NameTestImpl(int i) - { - super(i); - } + /** + * NCName + */ + String m_ncname; - /** - * Constructor for NodeTestImpl. Internal uses only - */ - public NameTestImpl(QName qname) - { - super(XPathTreeConstants.JJTNAMETEST); + /** + * Nametest type + */ + short m_type; - m_qname = qname; - } - - /** - * @see org.apache.xpath.expression.NodeTest#isNameTest() - */ - public boolean isNameTest() - { - return true; - } + // Constructors - /** - * @see org.apache.xpath.expression.NodeTest#isKindTest() - */ - public boolean isKindTest() - { - return false; - } + /** + * Constructor for NameTestImpl. Internal uses only + * + * @param i + */ + public NameTestImpl(int i) + { + super(i); + } - /** - * @see org.apache.xpath.expression.NodeTest#getKindTest() - */ - public short getKindTest() throws XPath20Exception - { - throw new XPath20Exception("Invalid call of this method on NameTest node"); //I8 - } + /** + * Constructor for NodeTestImpl. Internal uses only + */ + public NameTestImpl(QName qname) + { + super(XPathTreeConstants.JJTNAMETEST); - /** - * @see org.apache.xpath.expression.NodeTest#getLocalNameTest() - */ - public QName getNameTest() throws XPath20Exception - { - return m_qname; - } - - /** - * @see org.apache.xpath.expression.Expr#getString(boolean) - */ - public String getString(boolean abbreviate) - { - return m_qname.toString(); - } + m_qname = qname; + m_type = QNAME; + } - - /** - * @see org.apache.xpath.impl.parser.Node#jjtAddChild(Node, int) - */ - public void jjtAddChild(Node n, int i) - { - // don't add n in the tree - m_qname = ((org.apache.xpath.impl.parser.QNameWrapper) n).getQName(); - } + /** + * @see org.apache.xpath.expression.NodeTest#isNameTest() + */ + public boolean isNameTest() + { + return true; + } - /** - * @see org.apache.xpath.impl.ExprImpl#getString(StringBuffer, - * boolean) - */ - public void getString(StringBuffer expr, boolean abbreviate) - { - expr.append(m_qname.toString()); - } + /** + * @see org.apache.xpath.expression.NodeTest#isKindTest() + */ + public boolean isKindTest() + { + return false; + } - /** - * Override to print out useful instance data. - * - * @see org.apache.xpath.impl.parser.SimpleNode#toString() - */ - public String toString() - { - return XPathTreeConstants.jjtNodeName[id] + " " + getClass() + " " - + getString(false); - } + /** + * @see org.apache.xpath.expression.NodeTest#getKindTest() + */ + public short getKindTest() throws XPath20Exception + { + throw new XPath20Exception("Invalid call of this method on NameTest node"); + //I8 + } + + /** + * @see org.apache.xpath.expression.NodeTest#getLocalNameTest() + */ + public NameTest getNameTest() throws XPath20Exception + { + return this; + } + + // Implements Expr + + public String getString(boolean abbreviate) + { + switch (m_type) + { + case WILDCARD : + return "*"; + case QNAME : + return m_qname.toString(); + case NCNAME_WILDCARD : + return m_ncname + ":*"; + case WILDCARD_NCNAME : + return "*:" + m_ncname; + default: + throw new IllegalStateException("Invalid NameTest type " + m_type); + } + } + + // + public Expr cloneExpression() + { + // TODO Auto-generated method stub + return null; + } + + public short getExprType() + { + return NODE_TEST; + } + + // + public boolean visit(Visitor visitor) + { + // TODO Auto-generated method stub + return false; + } + + public void jjtAddChild(Node n, int i) + { + QNameWrapper w = (QNameWrapper) n; + + m_type = w.m_type; + m_ncname = w.m_ncname; + m_qname = w.getQName(); + } + + public void getString(StringBuffer expr, boolean abbreviate) + { + expr.append(getString(abbreviate)); + } + + /** + * Override to print out useful instance data. + * + * @see org.apache.xpath.impl.parser.SimpleNode#toString() + */ + public String toString() + { + return XPathTreeConstants.jjtNodeName[id] + + " " + + getClass() + + " " + + getString(false); + } + + // Implements NameTest + + public QName getName() + { + return m_qname; + } + + public String getNCName() + { + return m_ncname; + } + + public short getNameTestType() + { + return m_type; + } + + }
diff --git a/xpath_rwapi/src2/org/apache/xpath/impl/PathExprImpl.java b/xpath_rwapi/src2/org/apache/xpath/impl/PathExprImpl.java index a50bb44..27f2f0c 100644 --- a/xpath_rwapi/src2/org/apache/xpath/impl/PathExprImpl.java +++ b/xpath_rwapi/src2/org/apache/xpath/impl/PathExprImpl.java
@@ -206,7 +206,7 @@ int et = step.getExprType(); return ( - ((et == STEP) && ((StepExpr) step).isPrimaryExpr()) + ((et == STEP) && ((StepExpr) step).isFilterStep()) || (et == LITERAL_EXPR) || (et == FUNCTION_CALL_EXPR) || (et == SEQUENCE_EXPR)
diff --git a/xpath_rwapi/src2/org/apache/xpath/impl/StepExprImpl.java b/xpath_rwapi/src2/org/apache/xpath/impl/StepExprImpl.java index 9355394..078614f 100644 --- a/xpath_rwapi/src2/org/apache/xpath/impl/StepExprImpl.java +++ b/xpath_rwapi/src2/org/apache/xpath/impl/StepExprImpl.java
@@ -194,7 +194,7 @@ /** * @see org.apache.xpath.expression.StepExpr#isPrimaryExpr() */ - public boolean isPrimaryExpr() + public boolean isFilterStep() { return m_axisType == STEP_IS_PRIMARYEXPR; }
diff --git a/xpath_rwapi/src2/org/apache/xpath/impl/parser/Axis.java b/xpath_rwapi/src2/org/apache/xpath/impl/parser/Axis.java index 9a09466..7d87244 100644 --- a/xpath_rwapi/src2/org/apache/xpath/impl/parser/Axis.java +++ b/xpath_rwapi/src2/org/apache/xpath/impl/parser/Axis.java
@@ -58,7 +58,7 @@ import org.apache.xpath.expression.StepExpr; /** - * Represent an Axis AST node. + * Represents an Axis AST node. */ public class Axis extends SimpleNode {
diff --git a/xpath_rwapi/src2/org/apache/xpath/impl/parser/DefaultNodeFactory.java b/xpath_rwapi/src2/org/apache/xpath/impl/parser/DefaultNodeFactory.java index a5458c5..d676604 100644 --- a/xpath_rwapi/src2/org/apache/xpath/impl/parser/DefaultNodeFactory.java +++ b/xpath_rwapi/src2/org/apache/xpath/impl/parser/DefaultNodeFactory.java
@@ -81,8 +81,6 @@ public class DefaultNodeFactory implements NodeFactory { - final static public String FACTORY_PROPERTY_KEY = "org.apache.xpath.impl.parser.NodeFactory"; - final static private NodeFactory DEFAULT_NODE_FACTORY = new DefaultNodeFactory(); static protected NodeFactory createNodeFactory()
diff --git a/xpath_rwapi/src2/org/apache/xpath/impl/parser/NodeFactory.java b/xpath_rwapi/src2/org/apache/xpath/impl/parser/NodeFactory.java index 64830dc..d185489 100644 --- a/xpath_rwapi/src2/org/apache/xpath/impl/parser/NodeFactory.java +++ b/xpath_rwapi/src2/org/apache/xpath/impl/parser/NodeFactory.java
@@ -75,6 +75,10 @@ */ public interface NodeFactory { + final static public String FACTORY_PROPERTY_KEY = "org.apache.xpath.impl.parser.NodeFactory"; + + + /** * Creates NameTest AST node *
diff --git a/xpath_rwapi/src2/org/apache/xpath/impl/parser/QNameWrapper.java b/xpath_rwapi/src2/org/apache/xpath/impl/parser/QNameWrapper.java index 507150d..cd6f407 100644 --- a/xpath_rwapi/src2/org/apache/xpath/impl/parser/QNameWrapper.java +++ b/xpath_rwapi/src2/org/apache/xpath/impl/parser/QNameWrapper.java
@@ -56,6 +56,7 @@ package org.apache.xpath.impl.parser; import org.apache.xml.QName; +import org.apache.xpath.expression.NameTest; /** * QNameNode wrappers a 'real' QName object. @@ -69,6 +70,9 @@ * The wrapped QName */ QName m_qname; + + public short m_type; + public String m_ncname; /** * Constructor for QName. @@ -89,36 +93,31 @@ super(p, i); } - /** - * @see org.apache.xpath.impl.parser.SimpleNode#processToken(Token) - */ public void processToken(Token t) { super.processToken(t); - String qname; + switch (id) { case XPathTreeConstants.JJTSTAR : - m_qname = - SimpleNode.getExpressionFactory().createQName( - null, - "*", - null); + m_type = NameTest.WILDCARD; break; case XPathTreeConstants.JJTSTARCOLONNCNAME : - qname = t.image.trim(); - qname = qname.substring(qname.indexOf(":") + 1); - m_qname = - SimpleNode.getExpressionFactory().createQName( - null, - qname, - "*"); + m_ncname = t.image.trim(); + m_ncname = m_ncname.substring(m_ncname.indexOf(":") + 1); + m_type = NameTest.WILDCARD_NCNAME; break; case XPathTreeConstants.JJTNCNAMECOLONSTAR : + m_ncname = t.image.trim(); + m_ncname = m_ncname.substring(0, m_ncname.indexOf(":")); + m_type = NameTest.NCNAME_WILDCARD; + + break; + case XPathTreeConstants.JJTQNAME : case XPathTreeConstants.JJTQNAMELPAR : - qname = t.image; + String qname = t.image; int parenIndex = qname.lastIndexOf("("); if (parenIndex > 0) { @@ -133,8 +132,7 @@ null, qname, null); - } - else + } else { m_qname = SimpleNode.getExpressionFactory().createQName( @@ -142,6 +140,7 @@ qname.substring(colonIdx + 1), qname.substring(0, colonIdx)); } + m_type = NameTest.QNAME; break; default : @@ -150,9 +149,7 @@ } } - /** - * @return org.apache.xml.QName - */ + public org.apache.xml.QName getQName() { return m_qname;
diff --git a/xpath_rwapi/src2/org/apache/xpath/impl/parser/SimpleNode.java b/xpath_rwapi/src2/org/apache/xpath/impl/parser/SimpleNode.java index a9984b6..b11b840 100644 --- a/xpath_rwapi/src2/org/apache/xpath/impl/parser/SimpleNode.java +++ b/xpath_rwapi/src2/org/apache/xpath/impl/parser/SimpleNode.java
@@ -243,15 +243,15 @@ break; // The nodes belows are filtered: no customisation possible - case XPathTreeConstants.JJTQNAME: - case XPathTreeConstants.JJTQNAMELPAR: + case XPathTreeConstants.JJTSTAR: case XPathTreeConstants.JJTNCNAMECOLONSTAR: case XPathTreeConstants.JJTSTARCOLONNCNAME: - newNode = new QNameWrapper(id); - - break; - + case XPathTreeConstants.JJTQNAME: + case XPathTreeConstants.JJTQNAMELPAR: + newNode = new QNameWrapper(id); + break; + case XPathTreeConstants.JJTDOTDOT: newNode = Singletons.DOTDOT;