villard 2003/07/30 19:29:29
Modified: java/xpath_rwapi/src2/org/apache/xpath/test Tag: xslt20
TestSamples.java TestSamples.xml
java/xpath_rwapi/src2/org/apache/xpath/impl Tag: xslt20
PathExprImpl.java OperatorImpl.java
ExpressionFactoryImpl.java XPathFactoryImpl.java
java/xpath_rwapi/src2/org/apache/xpath/impl/parser Tag:
xslt20 NodeFactory.java QNameWrapper.java
SimpleNode.java
java/xpath_rwapi/src2/org/apache/xpath/expression Tag:
xslt20 StaticContext.java ExpressionFactory.java
Expr.java NodeTest.java
Log:
Added generic method for creating operators
Internal creations of QName now rely on the method createQName...
javadocs
Revision Changes Path
No revision
No revision
1.1.2.12 +7 -3
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/test/Attic/TestSamples.java
Index: TestSamples.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/test/Attic/TestSamples.java,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -u -r1.1.2.11 -r1.1.2.12
--- TestSamples.java 30 Jul 2003 18:52:59 -0000 1.1.2.11
+++ TestSamples.java 31 Jul 2003 02:29:28 -0000 1.1.2.12
@@ -61,6 +61,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.apache.xml.QName;
import org.apache.xpath.XPath20Factory;
import org.apache.xpath.expression.CastableAsExpr;
import org.apache.xpath.expression.ConditionalExpr;
@@ -142,12 +143,12 @@
PathExpr pathExpr = exprFct.createPathExpr(true);
System.out.println("/ =? " + pathExpr.getString(true));
- NodeTest nt = exprFct.createNameTest(null);
+ NodeTest nt = exprFct.createNameTest(new QName("toto"));
pathExpr.addOperand(exprFct.createStepExpr(StepExpr.AXIS_CHILD,
nt));
System.out.println("/toto =? " + pathExpr.getString(true));
System.out.println("/child::toto =? " +
pathExpr.getString(false));
- nt = exprFct.createNameTest(null);
+ nt = exprFct.createNameTest(new QName("titi"));
pathExpr.addOperand(exprFct.createStepExpr(
StepExpr.AXIS_DESCENDANT, nt));
@@ -170,7 +171,10 @@
System.out.println("/descendant::titi =? "
+ pathExpr.getString(false));
- // Test visitor - anonymous class used
+
+ System.out.println("clone=" +
pathExpr.cloneExpression().getString(false));
+
+ // Test visitor
pathExpr.visit(new TestVisitor());
Expr var = exprFct.createExpr("$var");
1.1.2.11 +3 -3
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/test/Attic/TestSamples.xml
Index: TestSamples.xml
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/test/Attic/TestSamples.xml,v
retrieving revision 1.1.2.10
retrieving revision 1.1.2.11
diff -u -r1.1.2.10 -r1.1.2.11
--- TestSamples.xml 25 Jul 2003 20:16:26 -0000 1.1.2.10
+++ TestSamples.xml 31 Jul 2003 02:29:28 -0000 1.1.2.11
@@ -11,7 +11,7 @@
</ast>
</expr>
- <expr value="-5">
+ <expr value="-5" normalized-round-trip="(-5)">
<ast>
<node name="ExprSequence">
<node name="UnaryExpr">
@@ -129,7 +129,7 @@
</ast>
</expr>
- <expr value="(toto, (), (10, ('str', -5)))"
normalized-round-trip="toto,10,'str',-5">
+ <expr value="(toto, (), (10, ('str', -5)))"
normalized-round-trip="toto,10,'str',(-5)">
<ast>
<node name="ExprSequence">
<node name="PathExpr">
@@ -645,7 +645,7 @@
</ast>
</expr>
- <expr value="-3">
+ <expr value="-3" normalized-round-trip="(-3)">
<ast>
<node name="ExprSequence">
<node name="UnaryExpr">
No revision
No revision
1.1.2.4 +126 -121
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/PathExprImpl.java
Index: PathExprImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/PathExprImpl.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- PathExprImpl.java 24 Jun 2003 21:09:07 -0000 1.1.2.3
+++ PathExprImpl.java 31 Jul 2003 02:29:28 -0000 1.1.2.4
@@ -65,150 +65,155 @@
import org.apache.xpath.impl.parser.XPath;
import org.apache.xpath.impl.parser.XPathTreeConstants;
-
/**
*
*/
public class PathExprImpl extends OperatorImpl implements PathExpr
{
- boolean m_isAbsolute;
+ boolean m_isAbsolute;
+
+ /**
+ * Constructor for PathExprImpl.
+ */
+ protected PathExprImpl()
+ {
+ this(XPathTreeConstants.JJTPATHEXPR);
+ }
- /**
- * Constructor for PathExprImpl.
- */
- protected PathExprImpl()
- {
- this(XPathTreeConstants.JJTPATHEXPR);
- }
-
- /**
- * Constructor for PathExprImpl.
- *
- * @param i
- */
- public PathExprImpl(int i)
- {
+ /**
+ * Constructor for PathExprImpl.
+ *
+ * @param i
+ */
+ public PathExprImpl(int i)
+ {
id = i;
- m_exprType = PATH_EXPR;
+ m_exprType = PATH_EXPR;
m_opType = SLASH_STEP;
- m_isAbsolute = false;
- }
+ m_isAbsolute = false;
+ }
- /**
- * Constructor for PathExprImpl.
- *
- * @param p
- * @param i
- */
- public PathExprImpl(XPath p, int i)
- {
- super(p, i);
+ /**
+ * Constructor for PathExprImpl.
+ *
+ * @param p
+ * @param i
+ */
+ public PathExprImpl(XPath p, int i)
+ {
+ super(p, i);
- m_isAbsolute = false;
- }
+ m_isAbsolute = false;
+ }
/**
* @param expr
*/
- protected PathExprImpl(PathExprImpl expr) {
+ protected PathExprImpl(PathExprImpl expr)
+ {
super(expr);
m_isAbsolute = expr.m_isAbsolute;
}
- /**
- * @see org.apache.xpath.expression.PathExpr#isAbsolute()
- */
- public boolean isAbsolute()
- {
- return m_isAbsolute;
- }
-
- /**
- * @see org.apache.xpath.expression.Visitable#visit(Visitor)
- */
- public boolean visit(Visitor visitor)
- {
- if (visitor.visitPath(this))
- {
- // visit each step (operand)
- return super.visit(visitor);
- }
-
- return false;
- }
-
- /**
- * @see org.apache.xpath.impl.ExprImpl#getString(StringBuffer, boolean)
- */
- public void getString(StringBuffer expr, boolean abbreviate)
- {
- if (m_isAbsolute)
- {
- expr.append("/");
- }
+ /**
+ * @see org.apache.xpath.expression.PathExpr#isAbsolute()
+ */
+ public boolean isAbsolute()
+ {
+ return m_isAbsolute;
+ }
+
+ /**
+ * @see org.apache.xpath.expression.Visitable#visit(Visitor)
+ */
+ public boolean visit(Visitor visitor)
+ {
+ if (visitor.visitPath(this))
+ {
+ // visit each step (operand)
+ return super.visit(visitor);
+ }
- super.getString(expr, abbreviate);
- }
+ return false;
+ }
- /* (non-Javadoc)
- * @see org.apache.xpath.expression.Expr#cloneExpression()
+ /**
+ * @see org.apache.xpath.impl.ExprImpl#getString(StringBuffer, boolean)
*/
- public Expr cloneExpression() {
+ public void getString(StringBuffer expr, boolean abbreviate)
+ {
+ if (m_isAbsolute)
+ {
+ expr.append("/");
+ }
+
+ super.getString(expr, abbreviate);
+ }
+
+
+ public Expr cloneExpression()
+ {
+
return new PathExprImpl(this);
}
- /**
- * @see org.apache.xpath.impl.parser.Node#jjtAddChild(Node, int)
- */
- public void jjtAddChild(Node n, int i)
- {
- if (n.getId() == XPathTreeConstants.JJTROOT)
- {
- m_isAbsolute = true;
- }
- else if (n.getId() == XPathTreeConstants.JJTROOTDESCENDANTS)
- {
- m_isAbsolute = true;
- super.jjtAddChild(Singletons.SLASHSLASH, i);
- }
- else
- {
- if (((SimpleNode) n).canBeReduced())
- {
- if ((m_exprType == PATH_EXPR) && (n.jjtGetNumChildren() > 0)
- && (n.jjtGetChild(0).getId() ==
XPathTreeConstants.JJTPATHEXPR))
- {
- super.jjtInsertNodeChildren(n.jjtGetChild(0));
- }
- else
- {
- super.jjtInsertChild(n.jjtGetChild(0));
- }
- }
- else
- {
- super.jjtInsertChild(n);
- }
- }
- }
-
- /**
- * @see org.apache.xpath.impl.parser.SimpleNode#canBeReduced()
- */
- public boolean canBeReduced()
- {
- // Can be reduced whenever there is only one step and this step is a
primary expression
- if ((m_children != null) && (m_children.length == 1))
- {
- Expr step = (Expr) m_children[0];
- int et = step.getExprType();
-
- return (((et == STEP) && ((StepExpr) step).isPrimaryExpr())
- || (et == LITERAL_EXPR) || (et == FUNCTION_CALL_EXPR)
- || (et == SEQUENCE_EXPR) || (et == VARIABLE_REF_EXPR)
- || (et == ARITHMETIC_EXPR));
- }
+ /**
+ * @see org.apache.xpath.impl.parser.Node#jjtAddChild(Node, int)
+ */
+ public void jjtAddChild(Node n, int i)
+ {
+ if (n.getId() == XPathTreeConstants.JJTROOT)
+ {
+ m_isAbsolute = true;
+ }
+ else if (n.getId() == XPathTreeConstants.JJTROOTDESCENDANTS)
+ {
+ m_isAbsolute = true;
+ super.jjtAddChild(Singletons.SLASHSLASH, i);
+ }
+ else
+ {
+ if (((SimpleNode) n).canBeReduced())
+ {
+ if ((m_exprType == PATH_EXPR)
+ && (n.jjtGetNumChildren() > 0)
+ && (n.jjtGetChild(0).getId()
+ ==
XPathTreeConstants.JJTPATHEXPR))
+ {
+
super.jjtInsertNodeChildren(n.jjtGetChild(0));
+ }
+ else
+ {
+ super.jjtInsertChild(n.jjtGetChild(0));
+ }
+ }
+ else
+ {
+ super.jjtInsertChild(n);
+ }
+ }
+ }
- return false;
- }
+ /**
+ * @see org.apache.xpath.impl.parser.SimpleNode#canBeReduced()
+ */
+ public boolean canBeReduced()
+ {
+ // Can be reduced whenever there is only one step and this step
is a primary expression
+ if ((m_children != null) && (m_children.length == 1))
+ {
+ Expr step = (Expr) m_children[0];
+ int et = step.getExprType();
+
+ return (
+ ((et == STEP) && ((StepExpr)
step).isPrimaryExpr())
+ || (et == LITERAL_EXPR)
+ || (et == FUNCTION_CALL_EXPR)
+ || (et == SEQUENCE_EXPR)
+ || (et == VARIABLE_REF_EXPR)
+ || (et == ARITHMETIC_EXPR));
+ }
+
+ return false;
+ }
}
1.1.2.10 +615 -507
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/OperatorImpl.java
Index: OperatorImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/OperatorImpl.java,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -u -r1.1.2.9 -r1.1.2.10
--- OperatorImpl.java 30 Jul 2003 18:52:58 -0000 1.1.2.9
+++ OperatorImpl.java 31 Jul 2003 02:29:28 -0000 1.1.2.10
@@ -66,531 +66,639 @@
import org.apache.xpath.impl.parser.XPathConstants;
import org.apache.xpath.impl.parser.XPathTreeConstants;
-
/**
- *
+ * Basic implementation of [EMAIL PROTECTED] OperatorExpr}.
+ * @author <a href="mailto:[EMAIL PROTECTED]>Lionel Villard</a>
+ * @version $Id$
*/
public class OperatorImpl extends ExprImpl implements OperatorExpr
{
- /**
- * Mapping between operation type and it's external representation
- */
- final private static String[] OPTYPE2STRING =
- {
- "|", "intersect", "except", "+", "-", "to", "eq", "ne", "lt", "le",
"gt",
- "ge", "=", "!=", "<", "<=", ">", ">=", "is", "isnot", "<<", ">>",
"and",
- "or", "+", "-", "/", "//", ",", "*", "div", "idiv", "mod"
- };
-
- /**
- * Indicate whether space is needed around the operator
- */
- final private static boolean[] SPACE_NEEDED =
- {
- false, true, true, false, false, true, true, true, true, true, true,
- true, false, false, false, false, false, false, true, true, false,
false,
- true, true, false, false, false, false, false, false, true, true,
true
- };
-
- /**
- * Type of the expression
- */
- short m_exprType;
-
- /**
- * Type of the operator
- */
- short m_opType;
+ /**
+ * Mapping between operation type and its expression type
+ */
+ final private static short[] OPTYPE2EXPRTYPE =
+ {
+ Expr.SEQUENCE_EXPR,
+ Expr.SEQUENCE_EXPR,
+ Expr.SEQUENCE_EXPR,
+ Expr.ARITHMETIC_EXPR,
+ Expr.ARITHMETIC_EXPR,
+ Expr.SEQUENCE_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.COMPARISON_EXPR,
+ Expr.LOGICAL_EXPR,
+ Expr.LOGICAL_EXPR,
+ Expr.ARITHMETIC_EXPR,
+ Expr.ARITHMETIC_EXPR,
+ Expr.PATH_EXPR,
+ -1,
+ Expr.SEQUENCE_EXPR,
+ Expr.ARITHMETIC_EXPR,
+ Expr.ARITHMETIC_EXPR,
+ Expr.ARITHMETIC_EXPR,
+ Expr.ARITHMETIC_EXPR };
+
+ /**
+ * Mapping between operation type and it's external representation
+ */
+ final private static String[] OPTYPE2STRING =
+ {
+ "|",
+ "intersect",
+ "except",
+ "+",
+ "-",
+ "to",
+ "eq",
+ "ne",
+ "lt",
+ "le",
+ "gt",
+ "ge",
+ "=",
+ "!=",
+ "<",
+ "<=",
+ ">",
+ ">=",
+ "is",
+ "isnot",
+ "<<",
+ ">>",
+ "and",
+ "or",
+ "+",
+ "-",
+ "/",
+ "//",
+ ",",
+ "*",
+ "div",
+ "idiv",
+ "mod" };
+
+ /**
+ * Indicate whether space is needed around the operator
+ */
+ final private static boolean[] SPACE_NEEDED =
+ {
+ false,
+ true,
+ true,
+ false,
+ false,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ false,
+ false,
+ true,
+ true,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true };
+
+ /**
+ * Type of the expression
+ */
+ short m_exprType;
+
+ /**
+ * Type of the operator
+ */
+ short m_opType;
/**
* Internal use only
*/
- protected OperatorImpl()
+ protected OperatorImpl()
+ {
+ }
+
+ /**
+ * Constructor for OperatorImpl. Internal uses only.
+ *
+ * @param i
+ */
+ public OperatorImpl(int i)
+ {
+ super(i);
+
+ switch (i)
+ {
+ case XPathTreeConstants.JJTEXPRSEQUENCE :
+ m_exprType = SEQUENCE_EXPR;
+ m_opType = COMMA;
+
+ break;
+
+ case XPathTreeConstants.JJTUNARYEXPR :
+ m_exprType = ARITHMETIC_EXPR;
+
+ break;
+
+ case XPathTreeConstants.JJTUNIONEXPR :
+ case XPathTreeConstants.JJTINTERSECTEXCEPTEXPR :
+ case XPathTreeConstants.JJTPATTERN :
+ m_exprType = SEQUENCE_EXPR;
+
+ // opType is not known yet
+ break;
+
+ case XPathTreeConstants.JJTFUNCTIONCALL :
+ case XPathTreeConstants.JJTIDKEYPATTERN :
+
+ // ignore : see FunctionCallImpl subclass
+ break;
+
+ case XPathTreeConstants.JJTADDITIVEEXPR :
+ case XPathTreeConstants.JJTMULTIPLICATIVEEXPR :
+ m_exprType = ARITHMETIC_EXPR;
+
+ // opType is not known yet
+ break;
+
+ case XPathTreeConstants.JJTOREXPR :
+ case XPathTreeConstants.JJTANDEXPR :
+ m_exprType = LOGICAL_EXPR;
+
+ // opType is not known yet
+ break;
+
+ case XPathTreeConstants.JJTCOMPARISONEXPR :
+ m_exprType = COMPARISON_EXPR;
+
+ // opType is not known yet
+ break;
+
+ case XPathTreeConstants.JJTRANGEEXPR :
+ m_exprType = SEQUENCE_EXPR;
+ m_opType = TO;
+
+ break;
+
+ default :
+
+ // Invalid parameter
+ throw new IllegalArgumentException("The
parameter value does not correspond to an operator identifier");
+ // I16
+ }
+ }
+
+ /**
+ * Constructor for OperatorImpl. Internal uses only.
+ *
+ * @param p
+ * @param i
+ */
+ public OperatorImpl(XPath p, int i)
+ {
+ super(p, i);
+ }
+
+ /**
+ * Create a clone
+ */
+ protected OperatorImpl(OperatorImpl expr)
+ {
+ super(expr.id);
+
+ m_exprType = expr.m_exprType;
+ m_opType = expr.m_opType;
+
+ m_children = expr.cloneChildren();
+ }
+
+ protected OperatorImpl(short exprType, short opType)
+ {
+ super();
+
+ m_exprType = exprType;
+ m_opType = opType;
+ }
+
+ // Methods
+
+ public boolean visit(Visitor visitor)
+ {
+ if (visitor.visitOperator(this))
+ {
+ int count = getOperandCount();
+
+ for (int i = 0; i < count; i++)
+ {
+ if (!getOperand(i).visit(visitor))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ // Implements Expr
+
+ /**
+ * @see org.apache.xpath.expression.Expr#getExprType()
+ */
+ public short getExprType()
{
+ return m_exprType;
}
- /**
- * Constructor for OperatorImpl. Internal uses only.
- *
- * @param i
- */
- public OperatorImpl(int i)
- {
- super(i);
-
- switch (i)
- {
- case XPathTreeConstants.JJTEXPRSEQUENCE:
- m_exprType = SEQUENCE_EXPR;
- m_opType = COMMA;
-
- break;
-
- case XPathTreeConstants.JJTUNARYEXPR:
- m_exprType = UNARY_EXPR;
-
- break;
-
- case XPathTreeConstants.JJTUNIONEXPR:
- case XPathTreeConstants.JJTINTERSECTEXCEPTEXPR:
- case XPathTreeConstants.JJTPATTERN:
- m_exprType = SEQUENCE_EXPR;
-
- // opType is not known yet
- break;
-
- case XPathTreeConstants.JJTFUNCTIONCALL:
- case XPathTreeConstants.JJTIDKEYPATTERN:
-
- // ignore : see FunctionCallImpl subclass
- break;
-
- case XPathTreeConstants.JJTADDITIVEEXPR:
- case XPathTreeConstants.JJTMULTIPLICATIVEEXPR:
- m_exprType = ARITHMETIC_EXPR;
-
- // opType is not known yet
- break;
-
- case XPathTreeConstants.JJTOREXPR:
- case XPathTreeConstants.JJTANDEXPR:
- m_exprType = LOGICAL_EXPR;
-
- // opType is not known yet
- break;
-
- case XPathTreeConstants.JJTCOMPARISONEXPR:
- m_exprType = COMPARISON_EXPR;
-
- // opType is not known yet
- break;
-
- case XPathTreeConstants.JJTRANGEEXPR:
- m_exprType = SEQUENCE_EXPR;
- m_opType = TO;
-
- break;
-
- default:
-
- // Invalid parameter
- throw new IllegalArgumentException(
- "The parameter value does not correspond to an operator
identifier"); // I16
- }
- }
-
- /**
- * Constructor for OperatorImpl. Internal uses only.
- *
- * @param p
- * @param i
- */
- public OperatorImpl(XPath p, int i)
- {
- super(p, i);
- }
-
- /**
- * Create a clone
- */
- protected OperatorImpl(OperatorImpl expr)
- {
- super(expr.id);
-
- m_exprType = expr.m_exprType;
- m_opType = expr.m_opType;
-
- m_children = expr.cloneChildren();
- }
-
-
- /**
- * Constructor for OperatorImpl.
- *
- * @param id
- * @param exprType DOCUMENT ME!
- * @param opType DOCUMENT ME!
- */
- protected OperatorImpl(short exprType, short opType)
- {
- super();
-
- m_exprType = exprType;
- m_opType = opType;
- }
-
- /**
- * @see org.apache.xpath.expression.Expr#getExprType()
- */
- public short getExprType()
- {
- return m_exprType;
- }
-
- /**
- * @see org.apache.xpath.expression.Expr#cloneExpression()
- */
- public Expr cloneExpression()
- {
- return new OperatorImpl(this);
- }
-
- /**
- * @see org.apache.xpath.expression.Visitable#visit(Visitor)
- */
- public boolean visit(Visitor visitor)
- {
- if (visitor.visitOperator(this))
- {
- int count = getOperandCount();
-
- for (int i = 0; i < count; i++)
- {
- if (!getOperand(i).visit(visitor))
- {
- return false;
- }
- }
-
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /**
- * @see org.apache.xpath.expression.OperatorExpr#addOperand(Expr)
- */
- public void addOperand(Expr operand) throws XPath20Exception
- {
- // do not performed the reduction during edition
- super.jjtAddChild((Node) operand,
- (m_children == null) ? 0 : m_children.length);
- }
+ /**
+ * @see org.apache.xpath.expression.Expr#cloneExpression()
+ */
+ public Expr cloneExpression()
+ {
+ try
+ {
+ return (Expr) clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ // Never
+ return null;
+ }
+ }
+
+ // Implements OperatorExpr
+
+ /**
+ * @see org.apache.xpath.expression.OperatorExpr#addOperand(Expr)
+ */
+ public void addOperand(Expr operand) throws XPath20Exception
+ {
+ // do not performed the reduction during edition
+ super.jjtAddChild(
+ (Node) operand,
+ (m_children == null) ? 0 : m_children.length);
+ }
/* (non-Javadoc)
* @see
org.apache.xpath.expression.OperatorExpr#append(org.apache.xpath.expression.OperatorExpr)
*/
- public void append(OperatorExpr expr) throws XPath20Exception {
- if (expr.getExprType() == m_exprType && expr.getOperatorType()
== m_opType ) {
+ public void append(OperatorExpr expr) throws XPath20Exception
+ {
+ if (expr.getExprType() == m_exprType
+ && expr.getOperatorType() == m_opType)
+ {
int size = expr.getOperandCount();
- for (int i = 0; i < size ; i ++ ) {
- addOperand(expr.getOperand(i));
+ for (int i = 0; i < size; i++)
+ {
+ addOperand(expr.getOperand(i));
}
- } else {
- throw new XPath20Exception("Mismatched operator
expressions"); // I16 + better msg
}
+ else
+ {
+ throw new XPath20Exception("Mismatched operator
expressions");
+ // I16 + better msg
+ }
+ }
+
+ /**
+ * @see org.apache.xpath.expression.OperatorExpr#getOperand(int)
+ */
+ public Expr getOperand(int i)
+ {
+ if (m_children == null)
+ {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ return (Expr) m_children[i];
}
- /**
- * @see org.apache.xpath.expression.OperatorExpr#getOperand(int)
- */
- public Expr getOperand(int i)
- {
- if (m_children == null)
- {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- return (Expr) m_children[i];
- }
-
- /**
- * @see org.apache.xpath.expression.OperatorExpr#getOperandCount()
- */
- public int getOperandCount()
- {
- return (m_children == null) ? 0 : m_children.length;
- }
-
- /**
- * @see org.apache.xpath.expression.OperatorExpr#getOperatorType()
- */
- public short getOperatorType()
- {
- return m_opType;
- }
-
- /**
- * @see org.apache.xpath.expression.OperatorExpr#removeOperand(Expr)
- */
- public void removeOperand(Expr operand) throws XPath20Exception
- {
- super.jjtRemoveChild((Node) operand);
- }
-
- /**
- * @see org.apache.xpath.impl.parser.Node#jjtAddChild(Node, int)
- */
- public void jjtAddChild(Node n, int i)
- {
- if (n.getId() == XPathTreeConstants.JJTMINUS)
- {
- // Minus expression
- m_opType = MINUS_UNARY;
- }
- else if (n.getId() == XPathTreeConstants.JJTPLUS)
- {
- // Plus expression
- m_opType = PLUS_UNARY;
- }
- else
- {
- if (((SimpleNode) n).canBeReduced())
- {
- if (((m_exprType == SEQUENCE_EXPR)
- && (n.jjtGetNumChildren() > 0)
- && (((Expr) n.jjtGetChild(0)).getExprType() ==
SEQUENCE_EXPR)
- && (((OperatorExpr)
n.jjtGetChild(0)).getOperatorType() == m_opType)
- )
- || ((id == XPathTreeConstants.JJTPATTERN)
- && (n.jjtGetNumChildren() > 0)
- && (n.jjtGetChild(0).getId() ==
XPathTreeConstants.JJTPATTERN)))
- {
- super.jjtInsertNodeChildren(n.jjtGetChild(0));
- }
- else
- {
- super.jjtInsertChild(n.jjtGetChild(0));
- }
- }
- else
- {
- super.jjtInsertChild(n);
- }
- }
- }
-
- /**
- * @see org.apache.xpath.impl.parser.SimpleNode#canBeReduced()
- */
- public boolean canBeReduced()
- {
- if (m_exprType == SEQUENCE_EXPR || id ==
XPathTreeConstants.JJTPATTERN)
- {
- return (m_children == null) || (m_children.length <= 1);
- }
-
-
- return super.canBeReduced();
- }
-
- /**
- * Gets operator as a char
- *
- * @return DOCUMENT ME!
- */
- protected String getOperatorChar()
- {
- return OPTYPE2STRING[m_opType];
- }
-
- /**
- * Tell is spaces are needed around the operator
- * @return
- */
- protected boolean isSpaceNeeded()
- {
- return SPACE_NEEDED[m_opType];
- }
-
- /**
- * Gets expression as external string representation
- *
- * @param expr
- * @param abbreviate
- */
- public void getString(StringBuffer expr, boolean abbreviate)
- {
- int size = getOperandCount();
- String oper = getOperatorChar();
- ExprImpl op;
-
- if ((m_opType == MINUS_UNARY) || (m_opType == PLUS_UNARY))
- {
- expr.append(oper);
- }
-
- for (int i = 0; i < size; i++)
- {
- op = (ExprImpl) getOperand(i);
-
- if ((op.getExprType() == ARITHMETIC_EXPR)
- || (op.getExprType() == SEQUENCE_EXPR))
- {
- expr.append('(');
- }
-
- op.getString(expr, abbreviate);
-
- if ((op.getExprType() == ARITHMETIC_EXPR)
- || (op.getExprType() == SEQUENCE_EXPR))
- {
- expr.append(')');
- }
-
- if (i < (size - 1))
- {
- if (isSpaceNeeded())
- {
- expr.append(' ');
- }
-
- expr.append(oper);
-
- if (isSpaceNeeded())
- {
- expr.append(' ');
- }
- }
- }
- }
-
-
- public void processToken(Token token)
- {
- switch (token.kind)
- {
- case XPathConstants.Plus:
- m_opType = PLUS_ADDITIVE;
-
- break;
-
- case XPathConstants.Minus:
- m_opType = MINUS_ADDITIVE;
-
- break;
-
- case XPathConstants.Multiply:
- m_opType = MULT_PRODUCT;
-
- break;
-
- case XPathConstants.Div:
- m_opType = MULT_DIV;
-
- break;
-
- case XPathConstants.Idiv:
- m_opType = MULT_IDIV;
-
- break;
-
- case XPathConstants.Mod:
- m_opType = MULT_MOD;
-
- break;
-
- case XPathConstants.Union:
- case XPathConstants.Vbar:
- m_opType = UNION_COMBINE;
-
- break;
-
- case XPathConstants.Intersect:
- m_opType = INTERSECT_COMBINE;
-
- break;
-
- case XPathConstants.Except:
- m_opType = EXCEPT_COMBINE;
-
- break;
-
- case XPathConstants.And:
- m_opType = AND_LOGICAL;
-
- break;
-
- case XPathConstants.Or:
- m_opType = OR_LOGICAL;
-
- break;
-
- case XPathConstants.Equals:
- m_opType = EQUAL_GENERAL_COMPARISON;
-
- break;
-
- case XPathConstants.NotEquals:
- m_opType = NOTEQUAL_GENERAL_COMPARISON;
-
- break;
-
- case XPathConstants.Lt:
- m_opType = LESSTHAN_GENERAL_COMPARISON;
-
- break;
-
- case XPathConstants.LtEquals:
- m_opType = LESSOREQUALTHAN_GENERAL_COMPARISON;
-
- break;
-
- case XPathConstants.Gt:
- m_opType = GREATTHAN_GENERAL_COMPARISON;
-
- break;
-
- case XPathConstants.GtEquals:
- m_opType = GREATOREQUALTHAN_GENERAL_COMPARISON;
-
- break;
-
- case XPathConstants.FortranEq:
- m_opType = EQUAL_VALUE_COMPARISON;
-
- break;
-
- case XPathConstants.FortranNe:
- m_opType = NOTEQUAL_VALUE_COMPARISON;
-
- break;
-
- case XPathConstants.FortranLt:
- m_opType = LESSTHAN_VALUE_COMPARISON;
-
- break;
-
- case XPathConstants.FortranLe:
- m_opType = LESSOREQUALTHAN_VALUE_COMPARISON;
-
- break;
-
- case XPathConstants.FortranGt:
- m_opType = GREATTHAN_VALUE_COMPARISON;
-
- break;
-
- case XPathConstants.FortranGe:
- m_opType = GREATOREQUALTHAN_VALUE_COMPARISON;
-
- break;
-
- case XPathConstants.Is:
- m_opType = IS_NODE_COMPARISON;
-
- break;
-
- case XPathConstants.IsNot:
- m_opType = ISNOT_NODE_COMPARISON;
-
- break;
-
- case XPathConstants.GtGt:
- m_opType = LATERTHAN_ORDER_COMPARISON;
-
- break;
-
- case XPathConstants.LtLt:
- m_opType = EARLIERTHAN_ORDER_COMPARISON;
-
- break;
-
- default:
- // never
- }
- }
+ /**
+ * @see org.apache.xpath.expression.OperatorExpr#getOperandCount()
+ */
+ public int getOperandCount()
+ {
+ return (m_children == null) ? 0 : m_children.length;
+ }
+
+ /**
+ * @see org.apache.xpath.expression.OperatorExpr#getOperatorType()
+ */
+ public short getOperatorType()
+ {
+ return m_opType;
+ }
+
+ /**
+ * @see org.apache.xpath.expression.OperatorExpr#removeOperand(Expr)
+ */
+ public void removeOperand(Expr operand) throws XPath20Exception
+ {
+ super.jjtRemoveChild((Node) operand);
+ }
+
+ /**
+ * @see org.apache.xpath.impl.parser.Node#jjtAddChild(Node, int)
+ */
+ public void jjtAddChild(Node n, int i)
+ {
+ if (n.getId() == XPathTreeConstants.JJTMINUS)
+ {
+ // Minus expression
+ m_opType = MINUS_UNARY;
+ }
+ else if (n.getId() == XPathTreeConstants.JJTPLUS)
+ {
+ // Plus expression
+ m_opType = PLUS_UNARY;
+ }
+ else
+ {
+ if (((SimpleNode) n).canBeReduced())
+ {
+ if (((m_exprType == SEQUENCE_EXPR)
+ && (n.jjtGetNumChildren() > 0)
+ && (((Expr)
n.jjtGetChild(0)).getExprType() == SEQUENCE_EXPR)
+ && (((OperatorExpr)
n.jjtGetChild(0)).getOperatorType()
+ == m_opType))
+ || ((id ==
XPathTreeConstants.JJTPATTERN)
+ && (n.jjtGetNumChildren() > 0)
+ && (n.jjtGetChild(0).getId()
+ ==
XPathTreeConstants.JJTPATTERN)))
+ {
+
super.jjtInsertNodeChildren(n.jjtGetChild(0));
+ }
+ else
+ {
+ super.jjtInsertChild(n.jjtGetChild(0));
+ }
+ }
+ else
+ {
+ super.jjtInsertChild(n);
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.xpath.impl.parser.SimpleNode#canBeReduced()
+ */
+ public boolean canBeReduced()
+ {
+ if (m_exprType == SEQUENCE_EXPR || id ==
XPathTreeConstants.JJTPATTERN)
+ {
+ return (m_children == null) || (m_children.length <= 1);
+ }
+
+ return super.canBeReduced();
+ }
+
+ /**
+ * Gets operator as a char
+ *
+ * @return DOCUMENT ME!
+ */
+ protected String getOperatorChar()
+ {
+ return OPTYPE2STRING[m_opType];
+ }
+
+ /**
+ * Tell is spaces are needed around the operator
+ * @return
+ */
+ protected boolean isSpaceNeeded()
+ {
+ return SPACE_NEEDED[m_opType];
+ }
+
+ /**
+ * Gets expression as external string representation
+ *
+ * @param expr
+ * @param abbreviate
+ */
+ public void getString(StringBuffer expr, boolean abbreviate)
+ {
+ int size = getOperandCount();
+ String oper = getOperatorChar();
+ ExprImpl op;
+
+ if ((m_opType == MINUS_UNARY) || (m_opType == PLUS_UNARY))
+ {
+ expr.append(oper);
+ }
+
+ for (int i = 0; i < size; i++)
+ {
+ op = (ExprImpl) getOperand(i);
+
+ if ((op.getExprType() == ARITHMETIC_EXPR)
+ || (op.getExprType() == SEQUENCE_EXPR))
+ {
+ expr.append('(');
+ }
+
+ op.getString(expr, abbreviate);
+
+ if ((op.getExprType() == ARITHMETIC_EXPR)
+ || (op.getExprType() == SEQUENCE_EXPR))
+ {
+ expr.append(')');
+ }
+
+ if (i < (size - 1))
+ {
+ if (isSpaceNeeded())
+ {
+ expr.append(' ');
+ }
+
+ expr.append(oper);
+
+ if (isSpaceNeeded())
+ {
+ expr.append(' ');
+ }
+ }
+ }
+ }
+
+ public void processToken(Token token)
+ {
+ switch (token.kind)
+ {
+ case XPathConstants.Plus :
+ m_opType = PLUS_ADDITIVE;
+
+ break;
+
+ case XPathConstants.Minus :
+ m_opType = MINUS_ADDITIVE;
+
+ break;
+
+ case XPathConstants.Multiply :
+ m_opType = MULT_PRODUCT;
+
+ break;
+
+ case XPathConstants.Div :
+ m_opType = MULT_DIV;
+
+ break;
+
+ case XPathConstants.Idiv :
+ m_opType = MULT_IDIV;
+
+ break;
+
+ case XPathConstants.Mod :
+ m_opType = MULT_MOD;
+
+ break;
+
+ case XPathConstants.Union :
+ case XPathConstants.Vbar :
+ m_opType = UNION_COMBINE;
+
+ break;
+
+ case XPathConstants.Intersect :
+ m_opType = INTERSECT_COMBINE;
+
+ break;
+
+ case XPathConstants.Except :
+ m_opType = EXCEPT_COMBINE;
+
+ break;
+
+ case XPathConstants.And :
+ m_opType = AND_LOGICAL;
+
+ break;
+
+ case XPathConstants.Or :
+ m_opType = OR_LOGICAL;
+
+ break;
+
+ case XPathConstants.Equals :
+ m_opType = EQUAL_GENERAL_COMPARISON;
+
+ break;
+
+ case XPathConstants.NotEquals :
+ m_opType = NOTEQUAL_GENERAL_COMPARISON;
+
+ break;
+
+ case XPathConstants.Lt :
+ m_opType = LESSTHAN_GENERAL_COMPARISON;
+
+ break;
+
+ case XPathConstants.LtEquals :
+ m_opType = LESSOREQUALTHAN_GENERAL_COMPARISON;
+
+ break;
+
+ case XPathConstants.Gt :
+ m_opType = GREATTHAN_GENERAL_COMPARISON;
+
+ break;
+
+ case XPathConstants.GtEquals :
+ m_opType = GREATOREQUALTHAN_GENERAL_COMPARISON;
+
+ break;
+
+ case XPathConstants.FortranEq :
+ m_opType = EQUAL_VALUE_COMPARISON;
+
+ break;
+
+ case XPathConstants.FortranNe :
+ m_opType = NOTEQUAL_VALUE_COMPARISON;
+
+ break;
+
+ case XPathConstants.FortranLt :
+ m_opType = LESSTHAN_VALUE_COMPARISON;
+
+ break;
+
+ case XPathConstants.FortranLe :
+ m_opType = LESSOREQUALTHAN_VALUE_COMPARISON;
+
+ break;
+
+ case XPathConstants.FortranGt :
+ m_opType = GREATTHAN_VALUE_COMPARISON;
+
+ break;
+
+ case XPathConstants.FortranGe :
+ m_opType = GREATOREQUALTHAN_VALUE_COMPARISON;
+
+ break;
+
+ case XPathConstants.Is :
+ m_opType = IS_NODE_COMPARISON;
+
+ break;
+
+ case XPathConstants.IsNot :
+ m_opType = ISNOT_NODE_COMPARISON;
+
+ break;
+
+ case XPathConstants.GtGt :
+ m_opType = LATERTHAN_ORDER_COMPARISON;
+
+ break;
+
+ case XPathConstants.LtLt :
+ m_opType = EARLIERTHAN_ORDER_COMPARISON;
+
+ break;
+
+ default :
+ // never
+ }
+ }
}
1.1.2.12 +84 -50
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/ExpressionFactoryImpl.java
Index: ExpressionFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/ExpressionFactoryImpl.java,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -u -r1.1.2.11 -r1.1.2.12
--- ExpressionFactoryImpl.java 30 Jul 2003 18:52:58 -0000 1.1.2.11
+++ ExpressionFactoryImpl.java 31 Jul 2003 02:29:28 -0000 1.1.2.12
@@ -80,106 +80,126 @@
import org.apache.xpath.impl.parser.XPathTreeConstants;
/**
- * Default implementation expression factory to create XPath AST nodes.
+ * Basic implementation expression factory to create XPath AST nodes.
+ * @author <a href="mailto:[EMAIL PROTECTED]>Lionel Villard</a>
+ * @version $Id$
*/
-public class ExpressionFactoryImpl implements ExpressionFactory {
+public class ExpressionFactoryImpl implements ExpressionFactory
+{
- public Expr createExpr(String expr) throws XPath20Exception {
+ public Expr createExpr(String expr) throws XPath20Exception
+ {
XPath parser = new XPath(new StringReader(expr));
- try {
+ try
+ {
return (Expr) parser.XPath2().jjtGetChild(0);
- } catch (ParseException e) {
- throw new XPath20Exception(e);
+ }
+ catch (ParseException e)
+ {
+ throw new XPath20Exception(e);
}
}
public Expr createExpr(StaticContext ctx, String expr)
throws XPath20Exception
{
+ // TODO : context
XPath parser = new XPath(new StringReader(expr));
- try {
+ try
+ {
return (Expr) parser.XPath2().jjtGetChild(0);
- } catch (ParseException e) {
+ }
+ catch (ParseException e)
+ {
throw new XPath20Exception(e);
}
}
- /**
- * @see
org.apache.xpath.expression.ExpressionFactory#createPathExpr(boolean)
- */
- public PathExpr createPathExpr(boolean isAbsolute) {
+ public PathExpr createPathExpr(boolean isAbsolute)
+ {
PathExprImpl e = new PathExprImpl();
e.m_isAbsolute = isAbsolute;
return e;
}
- /**
- * @see
org.apache.xpath.expression.ExpressionFactory#createStepExpr(short,
org.apache.xpath.expression.NodeTest)
- */
- public StepExpr createStepExpr(short axisType, NodeTest nodeTest) {
+ public StepExpr createStepExpr(short axisType, NodeTest nodeTest)
+ {
return new StepExprImpl(axisType, nodeTest);
}
- /**
- * @see
org.apache.xpath.expression.ExpressionFactory#createNameTest(java.lang.String,
java.lang.String)
- */
- public NodeTest createNameTest(QName qname) {
+ public NodeTest createNameTest(QName qname)
+ {
return new NameTestImpl(qname);
}
- /**
- * @see
org.apache.xpath.expression.ExpressionFactory#createCombineExpr(short)
- */
- public OperatorExpr createCombineExpr(short type) {
+ public OperatorExpr createCombineExpr(short type)
+ {
return new OperatorImpl(Expr.SEQUENCE_EXPR, type);
}
- /**
- * @see
org.apache.xpath.expression.ExpressionFactory#createSomeExpr(org.apache.xpath.expression.Expr)
- */
- public ForAndQuantifiedExpr createSomeExpr(Expr clause) {
- return null;
+ public OperatorExpr createOperatorExpr(short exprType, short
operatorType)
+ {
+ return new OperatorImpl(exprType, operatorType);
+ }
+
+ public ForAndQuantifiedExpr createSomeExpr(Expr clause)
+ {
+ throw new InternalError("Not implemented yet");
}
/**
* @see
org.apache.xpath.expression.ExpressionFactory#createEveryExpr(org.apache.xpath.expression.Expr)
*/
- public ForAndQuantifiedExpr createEveryExpr(Expr clause) {
- return null;
+ public ForAndQuantifiedExpr createEveryExpr(Expr clause)
+ {
+ throw new InternalError("Not implemented yet");
}
/**
* @see
org.apache.xpath.expression.ExpressionFactory#createAndExpr(org.apache.xpath.expression.Expr,
org.apache.xpath.expression.Expr)
*/
- public OperatorExpr createAndExpr(Expr firstOperand, Expr
secondOperand) {
+ public OperatorExpr createAndExpr(Expr firstOperand, Expr secondOperand)
+ {
return new OperatorImpl(Expr.LOGICAL_EXPR,
OperatorExpr.AND_LOGICAL);
}
/**
* @see
org.apache.xpath.expression.ExpressionFactory#createOrExpr(org.apache.xpath.expression.Expr,
org.apache.xpath.expression.Expr)
*/
- public OperatorExpr createOrExpr(Expr firstOperand, Expr secondOperand)
{
+ public OperatorExpr createOrExpr(Expr firstOperand, Expr secondOperand)
+ {
return new OperatorImpl(Expr.LOGICAL_EXPR,
OperatorExpr.OR_LOGICAL);
}
/**
* @see
org.apache.xpath.expression.ExpressionFactory#createIfExpr(org.apache.xpath.expression.Expr,
org.apache.xpath.expression.Expr, org.apache.xpath.expression.Expr)
*/
- public ConditionalExpr createIfExpr(Expr test, Expr thenExpr, Expr
elseExpr) {
+ public ConditionalExpr createIfExpr(
+ Expr test,
+ Expr thenExpr,
+ Expr elseExpr)
+ {
return new ConditionalExprImpl(test, thenExpr, elseExpr);
}
/**
* @see
org.apache.xpath.expression.ExpressionFactory#createForExpr(java.lang.String,
org.apache.xpath.expression.Expr, org.apache.xpath.expression.Expr)
*/
- public ForAndQuantifiedExpr createForExpr(String varName, Expr
clauseExpr, Expr quantifiedExpr) {
+ public ForAndQuantifiedExpr createForExpr(
+ String varName,
+ Expr clauseExpr,
+ Expr quantifiedExpr)
+ {
return null;
}
/**
* @see
org.apache.xpath.expression.ExpressionFactory#createCastExpr(org.apache.xpath.datamodel.SequenceType,
org.apache.xpath.expression.OperatorExpr)
*/
- public CastOrTreatAsExpr createCastAsExpr(SequenceType seqType,
OperatorExpr parExpr) {
+ public CastOrTreatAsExpr createCastAsExpr(
+ SequenceType seqType,
+ OperatorExpr parExpr)
+ {
return new CastOrTreatAsExprImpl(seqType, parExpr, true);
}
@@ -188,69 +208,83 @@
*/
public CastOrTreatAsExpr createTreatAsExpr(
SequenceType seqType,
- OperatorExpr parExpr) {
- return new CastOrTreatAsExprImpl(seqType, parExpr,
false);
+ OperatorExpr parExpr)
+ {
+ return new CastOrTreatAsExprImpl(seqType, parExpr, false);
}
/**
* @see
org.apache.xpath.expression.ExpressionFactory#createIntegerLiteralExpr(int)
*/
- public Literal createIntegerLiteralExpr(BigInteger value) {
+ public Literal createIntegerLiteralExpr(BigInteger value)
+ {
LiteralImpl lit = new LiteralImpl();
lit.setIntValue(value);
return lit;
}
-
+
/* (non-Javadoc)
* @see
org.apache.xpath.expression.ExpressionFactory#createIntegerLiteralExpr(int)
*/
- public Literal createIntegerLiteralExpr(int value) {
+ public Literal createIntegerLiteralExpr(int value)
+ {
return createIntegerLiteralExpr(BigInteger.valueOf(value));
}
-
/**
* @see
org.apache.xpath.expression.ExpressionFactory#createDecimalLiteralExpr(float)
*/
- public Literal createDecimalLiteralExpr(double value) {
+ public Literal createDecimalLiteralExpr(double value)
+ {
return createDecimalLiteralExpr(new BigDecimal(value));
}
-
+
/* (non-Javadoc)
* @see
org.apache.xpath.expression.ExpressionFactory#createDecimalLiteralExpr(java.math.BigDecimal)
*/
- public Literal createDecimalLiteralExpr(BigDecimal value) {
+ public Literal createDecimalLiteralExpr(BigDecimal value)
+ {
LiteralImpl lit = new LiteralImpl();
lit.setDecimalValue(value);
return lit;
}
- public Literal createStringLiteralExpr(String value) {
+ public Literal createStringLiteralExpr(String value)
+ {
LiteralImpl lit = new LiteralImpl();
lit.setStringValue(value);
return lit;
}
- public Literal createDoubleLiteralExpr(double value) {
+ public Literal createDoubleLiteralExpr(double value)
+ {
LiteralImpl lit = new LiteralImpl();
lit.setDoubleValue(value);
return lit;
}
- public OperatorExpr createSequence() {
+ public OperatorExpr createSequence()
+ {
return new OperatorImpl(XPathTreeConstants.JJTEXPRSEQUENCE);
}
-
+
public FunctionCall createFunctionCall(QName name)
{
return new FunctionCallImpl(name);
}
-
public QName createQName(String ns, String localPart, String prefix)
{
+ if (ns == null && prefix == null)
+ {
+ return new QName(localPart);
+ }
+ if (prefix == null)
+ {
+ return new QName(ns, localPart);
+ }
return new QName(ns, localPart, prefix);
}
1.1.2.3 +0 -3
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/XPathFactoryImpl.java
Index: XPathFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/XPathFactoryImpl.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- XPathFactoryImpl.java 30 Jul 2003 18:52:58 -0000 1.1.2.2
+++ XPathFactoryImpl.java 31 Jul 2003 02:29:28 -0000 1.1.2.3
@@ -63,9 +63,6 @@
*/
public class XPathFactoryImpl extends XPath20Factory {
- /**
- * @see org.apache.xpath.XPathFactory#newExpressionFactory()
- */
public ExpressionFactory newExpressionFactory() {
return new ExpressionFactoryImpl();
}
No revision
No revision
1.1.2.4 +0 -1
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/parser/Attic/NodeFactory.java
Index: NodeFactory.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/parser/Attic/NodeFactory.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- NodeFactory.java 26 Mar 2003 03:42:55 -0000 1.1.2.3
+++ NodeFactory.java 31 Jul 2003 02:29:28 -0000 1.1.2.4
@@ -70,7 +70,6 @@
* Applications which want to generate their own AST need to implement this
* interface.
*
- * @see org.apache.xpath.impl.parser.XPath#setNodeFactory
* @see org.apache.xpath.impl.parser.XPathTreeConstants
*/
public interface NodeFactory
1.1.2.5 +57 -32
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/parser/Attic/QNameWrapper.java
Index: QNameWrapper.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/parser/Attic/QNameWrapper.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- QNameWrapper.java 25 Jul 2003 20:16:26 -0000 1.1.2.4
+++ QNameWrapper.java 31 Jul 2003 02:29:28 -0000 1.1.2.5
@@ -56,24 +56,26 @@
package org.apache.xpath.impl.parser;
import org.apache.xml.QName;
-import org.apache.xpath.expression.NodeTest;
/**
* QNameNode wrappers a 'real' QName object.
+ * @author <a href="mailto:[EMAIL PROTECTED]>Lionel Villard</a>
+ * @version $Id$
*/
-public class QNameWrapper extends SimpleNode {
+public class QNameWrapper extends SimpleNode
+{
- /**
- * The wrapped QName
- */
- QName m_qname;
-
+ /**
+ * The wrapped QName
+ */
+ QName m_qname;
/**
* Constructor for QName.
* @param i
*/
- public QNameWrapper(int i) {
+ public QNameWrapper(int i)
+ {
super(i);
}
@@ -82,54 +84,77 @@
* @param p
* @param i
*/
- public QNameWrapper(XPath p, int i) {
+ public QNameWrapper(XPath p, int i)
+ {
super(p, i);
}
/**
* @see org.apache.xpath.impl.parser.SimpleNode#processToken(Token)
*/
- public void processToken(Token t) {
+ public void processToken(Token t)
+ {
super.processToken(t);
String qname;
- switch (id) {
+ switch (id)
+ {
case XPathTreeConstants.JJTSTAR :
- m_qname = NodeTest.WILDCARD;
+ m_qname =
+
SimpleNode.getExpressionFactory().createQName(
+ null,
+ "*",
+ null);
break;
- case XPathTreeConstants.JJTSTARCOLONNCNAME :
- qname = t.image.trim();
- qname = qname.substring(qname.indexOf(":")+1);
- m_qname = new QName("*", qname, "*");
-
+ case XPathTreeConstants.JJTSTARCOLONNCNAME :
+ qname = t.image.trim();
+ qname = qname.substring(qname.indexOf(":") + 1);
+ m_qname =
+
SimpleNode.getExpressionFactory().createQName(
+ null,
+ qname,
+ "*");
+
break;
case XPathTreeConstants.JJTNCNAMECOLONSTAR :
- case XPathTreeConstants.JJTQNAME :
- case XPathTreeConstants.JJTQNAMELPAR :
+ case XPathTreeConstants.JJTQNAME :
+ case XPathTreeConstants.JJTQNAMELPAR :
qname = t.image;
- int parenIndex = qname.lastIndexOf("(");
- if (parenIndex > 0) {
+ int parenIndex = qname.lastIndexOf("(");
+ if (parenIndex > 0)
+ {
qname = qname.substring(0, parenIndex);
}
qname = qname.trim();
int colonIdx = qname.indexOf(":");
- if ( colonIdx == -1 ) {
- m_qname = new QName(qname);
- } else {
- // TODO: Need to use qname factory
- m_qname = new QName("defaultns", qname.substring(colonIdx +
1), qname.substring(0, colonIdx ) );
- }
+ if (colonIdx == -1)
+ {
+ m_qname =
+
SimpleNode.getExpressionFactory().createQName(
+ null,
+ qname,
+ null);
+ }
+ else
+ {
+ m_qname =
+
SimpleNode.getExpressionFactory().createQName(
+ null,
+
qname.substring(colonIdx + 1),
+ qname.substring(0,
colonIdx));
+ }
break;
-
- default:
- throw new RuntimeException( "Invalid jjtree id: doesn't match a
QName id=" + id);
+
+ default :
+ throw new RuntimeException(
+ "Invalid jjtree id: doesn't match a
QName id=" + id);
}
}
-
/**
* @return org.apache.xml.QName
*/
- public org.apache.xml.QName getQName() {
+ public org.apache.xml.QName getQName()
+ {
return m_qname;
}
1.1.2.14 +9 -0
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/parser/Attic/SimpleNode.java
Index: SimpleNode.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/parser/Attic/SimpleNode.java,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -u -r1.1.2.13 -r1.1.2.14
--- SimpleNode.java 30 Jul 2003 18:52:59 -0000 1.1.2.13
+++ SimpleNode.java 31 Jul 2003 02:29:28 -0000 1.1.2.14
@@ -1,10 +1,12 @@
/* Generated By:JJTree: Do not edit this line. SimpleNode.java */
package org.apache.xpath.impl.parser;
+import org.apache.xpath.expression.ExpressionFactory;
import org.apache.xpath.impl.CastOrTreatAsExprImpl;
import org.apache.xpath.impl.CastableAsExprImpl;
import org.apache.xpath.impl.ConditionalExprImpl;
import org.apache.xpath.impl.DefaultNodeFactory;
+import org.apache.xpath.impl.ExpressionFactoryImpl;
import org.apache.xpath.impl.ForAndQuantifiedExprImpl;
import org.apache.xpath.impl.FunctionCallImpl;
import org.apache.xpath.impl.InstanceOfExprImpl;
@@ -58,6 +60,13 @@
{
this(i);
}
+
+ static ExpressionFactory m_exprFact = new ExpressionFactoryImpl();
+
+ protected static ExpressionFactory getExpressionFactory()
+ {
+ return m_exprFact;
+ }
/**
* DOCUMENT ME!
No revision
No revision
1.1.2.3 +3 -1
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/expression/Attic/StaticContext.java
Index: StaticContext.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/expression/Attic/StaticContext.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- StaticContext.java 25 Jul 2003 20:16:26 -0000 1.1.2.2
+++ StaticContext.java 31 Jul 2003 02:29:28 -0000 1.1.2.3
@@ -60,8 +60,10 @@
import org.apache.xml.NamespaceContext;
/**
- * Static context of expression.
+ * Static context of XPath expression.
* @see <a href="http://www.w3.org/TR/xpath20/#static_context">XPath 2.0
specification</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]>Lionel Villard</a>
+ * @version $Id$
*/
public interface StaticContext {
1.1.2.12 +16 -6
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/expression/Attic/ExpressionFactory.java
Index: ExpressionFactory.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/expression/Attic/ExpressionFactory.java,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -u -r1.1.2.11 -r1.1.2.12
--- ExpressionFactory.java 30 Jul 2003 18:52:58 -0000 1.1.2.11
+++ ExpressionFactory.java 31 Jul 2003 02:29:28 -0000 1.1.2.12
@@ -75,10 +75,10 @@
{
/**
* Creates a new XPath/XQuery expression from a string representation.
- * <p>For XPath expression, default element and function namespace are
+ * <p>For XPath expression, default element and function namespaces are
* used to resolve prefixes.
- * Moreover, various checking are not performed, like the existence test
- * of variable declaration</p>
+ * Various checking are not performed when the expression is built,
+ * like the existence test of variable declaration.</p>
* @return A XPath expression
* @throws XPath20Exception whenever the specified expression is not
valid
* syntaxically or semantically.
@@ -120,6 +120,16 @@
*/
public NodeTest createNameTest(QName qname);
+ /**
+ * Creates an [EMAIL PROTECTED] OperatorExpr operator expression} from
the
+ * specified type. The new operator contains no operand.
+ * @param exprType type of operator to create. See [EMAIL PROTECTED]
Expr} for existing
+ * operator type.
+ * @param operatorType One of the constants defined in [EMAIL
PROTECTED] OperatorExpr}
+ * @return A new operator
+ */
+ public OperatorExpr createOperatorExpr(short exprType, short
operatorType);
+
/**
* Creates a new [EMAIL PROTECTED] OperatorExpr combining expression} of
the specified type
* @param type The type of the combining expression to create.
@@ -241,14 +251,14 @@
*/
public FunctionCall createFunctionCall(QName name);
-
/**
* Creates a [EMAIL PROTECTED] QName qname} with the specified prefix,
namespace
* and local part.
* @param ns or null
* @param localPart
* @param prefix or null
- * @return A new QName or an existing one with the same namespace and
localpart
+ * @return A new QName or an existing one with the same
+ * namespace and localpart
*/
public QName createQName(String ns, String localPart, String prefix);
1.1.2.7 +1 -6
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/expression/Attic/Expr.java
Index: Expr.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/expression/Attic/Expr.java,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- Expr.java 29 Jul 2003 21:12:31 -0000 1.1.2.6
+++ Expr.java 31 Jul 2003 02:29:28 -0000 1.1.2.7
@@ -265,11 +265,6 @@
static final short INSTANCE_OF_EXPR = 18;
/**
- * The expression is an unary expression
- */
- static final short UNARY_EXPR = 19;
-
- /**
* The expression is a cast as expression
*/
static final short CAST_AS_EXPR = 20;
1.1.2.5 +18 -21
xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/expression/Attic/NodeTest.java
Index: NodeTest.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/expression/Attic/NodeTest.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- NodeTest.java 30 Jul 2003 18:52:58 -0000 1.1.2.4
+++ NodeTest.java 31 Jul 2003 02:29:29 -0000 1.1.2.5
@@ -59,32 +59,29 @@
import org.apache.xpath.XPath20Exception;
/**
- * Represents item test. An item test includes both node tests and the
context item
- * selection.
- * <pre>
- * [28] NodeTest ::= KindTest | NameTest
- * [29] NameTest ::= QName | Wildcard
- * [30] Wildcard ::= "*" | ":"? NCName ":" "*" | "*" ":" NCName
- * [31] KindTest ::= ProcessingInstructionTest
- * | CommentTest
- * | TextTest
- * | AnyKindTest
- * [32] ProcessingInstructionTest ::= "processing-instruction" "("
StringLiteral? ")"
- * [33] CommentTest ::= "comment" "(" ")"
- * [34] TextTest ::= "text" "(" ")"
- * [35] AnyKindTest ::= "node" "(" ")"
- * </pre>
+ * Represents an item test. An item test includes both node tests
+ * and the context item test (dot).
+ * <p>
+ * A node test is either a name test or a kind test. For the former, use
+ * the method [EMAIL PROTECTED] #getNameTest()} to get the [EMAIL PROTECTED]
QName} involved in the test.
+ * </p>
+ * <p>In the case of kind test, the method [EMAIL PROTECTED] #getKindTest()}
return the kind
+ * test type as following:
+ * <ul>
+ * <li><b>[EMAIL PROTECTED] #TEXT_TEST}</b> for text()</li>
+ * <li><b>[EMAIL PROTECTED] #PROCESSING_INSTRUCTION_TEST}</b> for
processing-instruction()</b>.
+ * Use [EMAIL PROTECTED] #getNameTest()}.getLocalPart() to get the
target.</li>
+ * <li><b>[EMAIL PROTECTED] #COMMENT_TEST}</b> for comment()</li>
+ * <li><b>[EMAIL PROTECTED] #ANY_KIND_TEST}</b> for node()</li>
+ * <li><b> [EMAIL PROTECTED] #CONTEXT_ITEM_TEST}</b> for '.'</li>
+ * </ul>
+ *
* @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 {
/**
- * The node test is a wildcard
- */
- static final QName WILDCARD = new QName("*");
-
- /**
* The item test is a processing instruction kind test
*/
static final short PROCESSING_INSTRUCTION_TEST = 0;
@@ -138,7 +135,7 @@
* Gets the qualified name of the name test or the name of the 'PITarget'
* when the node test is pi kind test. For the later, only the local
* part of the qualified name is relevant.
- * @return QName The name test or [EMAIL PROTECTED] #WILDCARD}
+ * @return QName The name test
* @throws XPath20Exception whenever this node test isn't a name test
* or a pi kind test
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]