Search in sources :

Example 61 with XObject

use of org.apache.xpath.objects.XObject in project j2objc by google.

the class UnionPattern method execute.

/**
   * Test a node to see if it matches any of the patterns in the union.
   *
   * @param xctxt XPath runtime context.
   *
   * @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
    XObject bestScore = null;
    int n = m_patterns.length;
    for (int i = 0; i < n; i++) {
        XObject score = m_patterns[i].execute(xctxt);
        if (score != NodeTest.SCORE_NONE) {
            if (null == bestScore)
                bestScore = score;
            else if (score.num() > bestScore.num())
                bestScore = score;
        }
    }
    if (null == bestScore) {
        bestScore = NodeTest.SCORE_NONE;
    }
    return bestScore;
}
Also used : XObject(org.apache.xpath.objects.XObject)

Example 62 with XObject

use of org.apache.xpath.objects.XObject in project j2objc by google.

the class VariableStack method getLocalVariable.

/**
   * Get a local variable or parameter in the current stack frame.
   *
   *
   * @param xctxt The XPath context, which must be passed in order to
   * lazy evaluate variables.
   *
   * @param index Local variable index relative to the current stack
   * frame bottom.
   *
   * @return The value of the variable.
   *
   * @throws TransformerException
   */
public XObject getLocalVariable(XPathContext xctxt, int index, boolean destructiveOK) throws TransformerException {
    index += _currentFrameBottom;
    XObject val = _stackFrames[index];
    if (null == val)
        throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null), xctxt.getSAXLocator());
    // Lazy execution of variables.
    if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE)
        return (_stackFrames[index] = val.execute(xctxt));
    return destructiveOK ? val : val.getFresh();
}
Also used : XObject(org.apache.xpath.objects.XObject) TransformerException(javax.xml.transform.TransformerException)

Example 63 with XObject

use of org.apache.xpath.objects.XObject in project j2objc by google.

the class VariableStack method getLocalVariable.

/**
   * Get a local variable or parameter in the current stack frame.
   *
   *
   * @param xctxt The XPath context, which must be passed in order to
   * lazy evaluate variables.
   *
   * @param index Local variable index relative to the current stack
   * frame bottom.
   *
   * @return The value of the variable.
   *
   * @throws TransformerException
   */
public XObject getLocalVariable(XPathContext xctxt, int index) throws TransformerException {
    index += _currentFrameBottom;
    XObject val = _stackFrames[index];
    if (null == val)
        throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null), xctxt.getSAXLocator());
    // Lazy execution of variables.
    if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE)
        return (_stackFrames[index] = val.execute(xctxt));
    return val;
}
Also used : XObject(org.apache.xpath.objects.XObject) TransformerException(javax.xml.transform.TransformerException)

Example 64 with XObject

use of org.apache.xpath.objects.XObject in project j2objc by google.

the class XPath method getMatchScore.

/**
   * Get the match score of the given node.
   *
   * @param xctxt XPath runtime context.
   * @param context The current source tree context node.
   * 
   * @return score, one of {@link #MATCH_SCORE_NODETEST},
   * {@link #MATCH_SCORE_NONE}, {@link #MATCH_SCORE_OTHER}, 
   * or {@link #MATCH_SCORE_QNAME}.
   *
   * @throws javax.xml.transform.TransformerException
   */
public double getMatchScore(XPathContext xctxt, int context) throws javax.xml.transform.TransformerException {
    xctxt.pushCurrentNode(context);
    xctxt.pushCurrentExpressionNode(context);
    try {
        XObject score = m_mainExp.execute(xctxt);
        if (DEBUG_MATCHES) {
            DTM dtm = xctxt.getDTM(context);
            System.out.println("score: " + score.num() + " for " + dtm.getNodeName(context) + " for xpath " + this.getPatternString());
        }
        return score.num();
    } finally {
        xctxt.popCurrentNode();
        xctxt.popCurrentExpressionNode();
    }
// return XPath.MATCH_SCORE_NONE;
}
Also used : DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 65 with XObject

use of org.apache.xpath.objects.XObject in project j2objc by google.

the class ElemVariable method execute.

/**
   * Execute a variable declaration and push it onto the variable stack.
   * @see <a href="http://www.w3.org/TR/xslt#variables">variables in XSLT Specification</a>
   *
   * @param transformer non-null reference to the the current transform-time state.
   *
   * @throws TransformerException
   */
public void execute(TransformerImpl transformer) throws TransformerException {
    int sourceNode = transformer.getXPathContext().getCurrentNode();
    XObject var = getValue(transformer, sourceNode);
    // transformer.getXPathContext().getVarStack().pushVariable(m_qname, var);
    transformer.getXPathContext().getVarStack().setLocalVariable(m_index, var);
}
Also used : XObject(org.apache.xpath.objects.XObject)

Aggregations

XObject (org.apache.xpath.objects.XObject)102 TransformerException (javax.xml.transform.TransformerException)24 DTM (org.apache.xml.dtm.DTM)24 XPathContext (org.apache.xpath.XPathContext)24 XNodeSet (org.apache.xpath.objects.XNodeSet)14 DTMIterator (org.apache.xml.dtm.DTMIterator)12 VariableStack (org.apache.xpath.VariableStack)10 Vector (java.util.Vector)8 QName (org.apache.xml.utils.QName)8 Expression (org.apache.xpath.Expression)8 Node (org.w3c.dom.Node)7 DTMAxisTraverser (org.apache.xml.dtm.DTMAxisTraverser)6 XMLString (org.apache.xml.utils.XMLString)6 org.apache.xpath (org.apache.xpath)6 XString (org.apache.xpath.objects.XString)6 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4 QName (javax.xml.namespace.QName)4 XPathFunction (javax.xml.xpath.XPathFunction)4 XPathFunctionException (javax.xml.xpath.XPathFunctionException)4