/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: StepPattern.java,v 1.2.4.2 2005/09/15 00:21:16 jeffsuttor Exp $
*/
/**
* This class represents a single pattern match step.
* @xsl.usage advanced
*/
{
/** The axis for this test. */
protected int m_axis;
/**
* Construct a StepPattern that tests for namespaces and node names.
*
*
* @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
* @param namespace The namespace to be tested.
* @param name The local name to be tested.
* @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
* @param axisForPredicate No longer used.
*/
int axisForPredicate)
{
}
/**
* Construct a StepPattern that doesn't test for node names.
*
*
* @param whatToShow Bit set defined mainly by {@link org.w3c.dom.traversal.NodeFilter}.
* @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
* @param axisForPredicate No longer used.
*/
{
super(whatToShow);
}
/**
* The target local name or psuedo name, for hash table lookup optimization.
* @serial
*/
/**
* Calculate the local name or psuedo name of the node that this pattern will test,
* for hash table lookup optimization.
*
* @see com.sun.org.apache.xpath.internal.compiler.PsuedoNames
*/
public void calcTargetString()
{
int whatToShow = getWhatToShow();
switch (whatToShow)
{
case DTMFilter.SHOW_COMMENT :
break;
case DTMFilter.SHOW_CDATA_SECTION :
break;
break;
case DTMFilter.SHOW_DOCUMENT :
break;
case DTMFilter.SHOW_ELEMENT :
else
break;
default :
break;
}
}
/**
* Get the local name or psuedo name of the node that this pattern will test,
* for hash table lookup optimization.
*
*
* @return local name or psuedo name of the node.
* @see com.sun.org.apache.xpath.internal.compiler.PsuedoNames
*/
{
return m_targetString;
}
/**
* Reference to nodetest and predicate for
* parent or ancestor.
* @serial
*/
/**
* This function is used to fixup variables from QNames to stack frame
* indexes at stylesheet build time.
* @param vars List of QNames that correspond to variables. This list
* should be searched backwards for the first qualified name that
* corresponds to the variable reference qname. The position of the
* QName in the vector from the start of the vector will be its position
* in the stack frame (but variables above the globalsTop value will need
* to be offset to the current stack frame).
* @param globalsSize The number of variables in the global variable area.
*/
{
if (null != m_predicates)
{
{
}
}
if (null != m_relativePathPattern)
{
}
}
/**
* Set the reference to nodetest and predicate for
* parent or ancestor.
*
*
* @param expr The relative pattern expression.
*/
{
expr.exprSetParent(this);
calcScore();
}
/**
* Get the reference to nodetest and predicate for
* parent or ancestor.
*
*
* @return The relative pattern expression.
*/
{
return m_relativePathPattern;
}
// /**
// * Set the list of predicate expressions for this pattern step.
// * @param predicates List of expression objects.
// */
// public void setPredicates(Expression[] predicates)
// {
// m_predicates = predicates;
// }
/**
* Set the list of predicate expressions for this pattern step.
* @return List of expression objects.
*/
{
return m_predicates;
}
/**
* The list of predicate expressions for this pattern step.
* @serial
*/
/**
* Tell if this expression or it's subexpressions can traverse outside
* the current subtree.
*
* NOTE: Ancestors tests with predicates are problematic, and will require
* special treatment.
*
* @return true if traversal outside the context node's subtree can occur.
*/
public boolean canTraverseOutsideSubtree()
{
int n = getPredicateCount();
for (int i = 0; i < n; i++)
{
if (getPredicate(i).canTraverseOutsideSubtree())
return true;
}
return false;
}
/**
* Get a predicate expression.
*
*
* @param i The index of the predicate.
*
* @return A predicate expression.
*/
{
return m_predicates[i];
}
/**
* Get the number of predicates for this match pattern step.
*
*
* @return the number of predicates for this match pattern step.
*/
public final int getPredicateCount()
{
}
/**
* Set the predicates for this match pattern step.
*
*
* @param predicates An array of expressions that define predicates
* for this step.
*/
{
if(null != predicates)
{
{
predicates[i].exprSetParent(this);
}
}
calcScore();
}
/**
* Static calc of match score.
*/
public void calcScore()
{
{
}
else
super.calcScore();
if (null == m_targetString)
}
/**
* Execute this pattern step, including predicates.
*
*
* @param xctxt XPath runtime context.
* @param currentNode The current node context.
*
* @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
{
{
}
return NodeTest.SCORE_NONE;
}
/**
* Execute this pattern step, including predicates.
*
*
* @param xctxt XPath runtime context.
*
* @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
{
}
/**
* Execute an expression in the XPath runtime context, and return the
* result of the expression.
*
*
* @param xctxt The XPath runtime context.
* @param currentNode The currentNode.
* @param dtm The DTM of the current node.
* @param expType The expanded type ID of the current node.
*
* @return The result of the expression in the form of a <code>XObject</code>.
*
* @throws javax.xml.transform.TransformerException if a runtime exception
* occurs.
*/
{
{
if (null != m_relativePathPattern)
{
}
else
return NodeTest.SCORE_NONE;
}
return NodeTest.SCORE_NONE;
if (getPredicateCount() != 0)
{
return NodeTest.SCORE_NONE;
}
if (null != m_relativePathPattern)
return score;
}
/**
* New Method to check whether the current node satisfies a position predicate
*
* @param xctxt The XPath runtime context.
* @param predPos Which predicate we're evaluating of foo[1][2][3].
* @param dtm The DTM of the current node.
* @param context The currentNode.
* @param pos The position being requested, i.e. the value returned by
* m_predicates[predPos].execute(xctxt).
*
* @return true of the position of the context matches pos, false otherwise.
*/
{
try
{
{
try
{
{
boolean pass = true;
try
{
xctxt.pushSubContextList(this);
for (int i = 0; i < predPos; i++)
{
try
{
try
{
{
throw new Error("Why: Should never have been called");
}
else if (!pred.boolWithSideEffects())
{
pass = false;
break;
}
}
finally
{
}
}
finally
{
}
}
}
finally
{
}
if (pass)
pos--;
if (pos < 1)
return false;
}
}
finally
{
}
}
}
{
// TODO: should keep throw sax exception...
}
return (pos == 1);
}
/**
* Get the proximity position index of the current node based on this
* node test.
*
*
* @param xctxt XPath runtime context.
* @param predPos Which predicate we're evaluating of foo[1][2][3].
* @param findLast If true, don't terminate when the context node is found.
*
* @return the proximity position index of the current node based on the
* node test.
*/
boolean findLast)
{
int pos = 0;
try
{
{
try
{
{
boolean pass = true;
try
{
xctxt.pushSubContextList(this);
for (int i = 0; i < predPos; i++)
{
try
{
try
{
{
{
pass = false;
break;
}
}
else if (!pred.boolWithSideEffects())
{
pass = false;
break;
}
}
finally
{
}
}
finally
{
}
}
}
finally
{
}
if (pass)
pos++;
{
return pos;
}
}
}
finally
{
}
}
}
{
// TODO: should keep throw sax exception...
}
return pos;
}
/**
* Get the proximity position index of the current node based on this
* node test.
*
*
* @param xctxt XPath runtime context.
*
* @return the proximity position index of the current node based on the
* node test.
*/
{
}
/**
* Get the count of the nodes that match the test, which is the proximity
* position of the last node that can pass this test in the sub context
* selection. In XSLT 1-based indexing, this count is the index of the last
* node.
*
*
* @param xctxt XPath runtime context.
*
* @return the count of the nodes that match the test.
*/
{
}
/**
* Execute the match pattern step relative to another step.
*
*
* @param xctxt The XPath runtime context.
* @param dtm The DTM of the current node.
* @param currentNode The current node context.
*
* @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
{
int context = currentNode;
{
try
{
break;
}
finally
{
}
}
return score;
}
/**
* Execute the predicates on this step to determine if the current node
* should be filtered or accepted.
*
* @param xctxt The XPath runtime context.
* @param dtm The DTM of the current node.
* @param currentNode The current node context.
*
* @return true if the node should be accepted, false otherwise.
*
* @throws javax.xml.transform.TransformerException
*/
protected final boolean executePredicates(
{
boolean result = true;
boolean positionAlreadySeen = false;
int n = getPredicateCount();
try
{
xctxt.pushSubContextList(this);
for (int i = 0; i < n; i++)
{
try
{
try
{
{
if (positionAlreadySeen)
{
break;
}
else
{
positionAlreadySeen = true;
{
result = false;
break;
}
}
}
else if (!pred.boolWithSideEffects())
{
result = false;
break;
}
}
finally
{
}
}
finally
{
}
}
}
finally
{
}
return result;
}
/**
* Get the string represenentation of this step for diagnostic purposes.
*
*
* @return A string representation of this step, built by reverse-engineering
* the contained info.
*/
{
{
if (pat != this)
{
}
{
}
{
}
{
}
{
{
}
}
{
}
{
{
}
{
}
}
{
}
== pat.m_whatToShow)
{
}
else
{
}
{
{
}
}
}
}
/** Set to true to send diagnostics about pattern matches to the consol. */
private static final boolean DEBUG_MATCHES = false;
/**
* Get the match score of the given node.
*
* @param xctxt The XPath runtime context.
* @param context The node to be tested.
*
* @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
* {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
{
try
{
}
finally
{
}
// return XPath.MATCH_SCORE_NONE;
}
/**
* Set the axis that this step should follow.
*
*
* @param axis The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
*/
{
}
/**
* Get the axis that this step follows.
*
*
* @return The Axis for this test, one of of Axes.ANCESTORORSELF, etc.
*/
public int getAxis()
{
return m_axis;
}
{
int m_index;
{
}
/**
* @see ExpressionOwner#getExpression()
*/
{
return m_predicates[m_index];
}
/**
* @see ExpressionOwner#setExpression(Expression)
*/
{
}
}
/**
* @see com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
*/
{
{
}
}
/**
* Call the visitors on the subtree. Factored out from callVisitors
* so it may be called by derived classes.
*/
{
if (null != m_predicates)
{
int n = m_predicates.length;
for (int i = 0; i < n; i++)
{
{
}
}
}
if (null != m_relativePathPattern)
{
}
}
/**
* @see ExpressionOwner#getExpression()
*/
{
return m_relativePathPattern;
}
/**
* @see ExpressionOwner#setExpression(Expression)
*/
{
exp.exprSetParent(this);
}
/**
* @see Expression#deepEquals(Expression)
*/
{
if(!super.deepEquals(expr))
return false;
if (null != m_predicates)
{
int n = m_predicates.length;
return false;
for (int i = 0; i < n; i++)
{
return false;
}
}
return false;
if(null != m_relativePathPattern)
{
return false;
}
return false;
return true;
}
}