com.sun.org.apache.xpath.internal.objects.XNodeSet

Here are the examples of the java api class com.sun.org.apache.xpath.internal.objects.XNodeSet taken from open source projects.

1. VariableSafeAbsRef#execute()

Project: openjdk
Source File: VariableSafeAbsRef.java
View license
/**
   * Dereference the variable, and return the reference value.  Note that lazy
   * evaluation will occur.  If a variable within scope is not found, a warning
   * will be sent to the error listener, and an empty nodeset will be returned.
   *
   *
   * @param xctxt The runtime execution context.
   *
   * @return The evaluated variable, or an empty nodeset if not found.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt, boolean destructiveOK) throws javax.xml.transform.TransformerException {
    XNodeSet xns = (XNodeSet) super.execute(xctxt, destructiveOK);
    DTMManager dtmMgr = xctxt.getDTMManager();
    int context = xctxt.getContextNode();
    if (dtmMgr.getDTM(xns.getRoot()).getDocument() != dtmMgr.getDTM(context).getDocument()) {
        Expression expr = (Expression) xns.getContainedIter();
        xns = (XNodeSet) expr.asIterator(xctxt, context);
    }
    return xns;
}

2. LocPathIterator#execute()

Project: openjdk
Source File: LocPathIterator.java
View license
/**
   * Execute this iterator, meaning create a clone that can
   * store state, and initialize it for fast execution from
   * the current runtime state.  When this is called, no actual
   * query from the current context node is performed.
   *
   * @param xctxt The XPath execution context.
   *
   * @return An XNodeSet reference that holds this iterator.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
    XNodeSet iter = new XNodeSet((LocPathIterator) m_clones.getInstance());
    iter.setRoot(xctxt.getCurrentNode(), xctxt);
    return iter;
}

3. LocPathIterator#asIterator()

Project: openjdk
Source File: LocPathIterator.java
View license
/**
   * Given an select expression and a context, evaluate the XPath
   * and return the resulting iterator.
   *
   * @param xctxt The execution context.
   * @param contextNode The node that "." expresses.
   * @throws TransformerException thrown if the active ProblemListener decides
   * the error condition is severe enough to halt processing.
   *
   * @throws javax.xml.transform.TransformerException
   * @xsl.usage experimental
   */
public DTMIterator asIterator(XPathContext xctxt, int contextNode) throws javax.xml.transform.TransformerException {
    XNodeSet iter = new XNodeSet((LocPathIterator) m_clones.getInstance());
    iter.setRoot(contextNode, xctxt);
    return iter;
}

4. FuncHere#execute()

Project: jdk7u-jdk
Source File: FuncHere.java
View license
/**
    * The here function returns a node-set containing the attribute or
    * processing instruction node or the parent element of the text node
    * that directly bears the XPath expression.  This expression results
    * in an error if the containing XPath expression does not appear in the
    * same XML document against which the XPath expression is being evaluated.
    *
    * @param xctxt
    * @return the xobject
    * @throws javax.xml.transform.TransformerException
    */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();
    if (xpathOwnerNode == null) {
        return null;
    }
    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);
    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();
    if (DTM.NULL == docContext) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }
    {
        // check whether currentNode and the node containing the XPath expression
        // are in the same document
        Document currentDoc = XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
        Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);
        if (currentDoc != xpathOwnerDoc) {
            throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
        }
    }
    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();
    {
        int hereNode = DTM.NULL;
        switch(dtm.getNodeType(xpathOwnerNodeDTM)) {
            case Node.ATTRIBUTE_NODE:
                {
                    // returns a node-set containing the attribute
                    hereNode = xpathOwnerNodeDTM;
                    nodeSet.addNode(hereNode);
                    break;
                }
            case Node.PROCESSING_INSTRUCTION_NODE:
                {
                    // returns a node-set containing the processing instruction node
                    hereNode = xpathOwnerNodeDTM;
                    nodeSet.addNode(hereNode);
                    break;
                }
            case Node.TEXT_NODE:
                {
                    // returns a node-set containing the parent element of the
                    // text node that directly bears the XPath expression
                    hereNode = dtm.getParent(xpathOwnerNodeDTM);
                    nodeSet.addNode(hereNode);
                    break;
                }
            default:
                break;
        }
    }
    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();
    return nodes;
}

5. FilterExprIteratorSimple#executeFilterExpr()

View license
/**
   * Execute the expression.  Meant for reuse by other FilterExpr iterators
   * that are not derived from this object.
   */
public static XNodeSet executeFilterExpr(int context, XPathContext xctxt, PrefixResolver prefixResolver, boolean isTopLevel, int stackFrame, Expression expr) throws com.sun.org.apache.xml.internal.utils.WrappedRuntimeException {
    PrefixResolver savedResolver = xctxt.getNamespaceContext();
    XNodeSet result = null;
    try {
        xctxt.pushCurrentNode(context);
        xctxt.setNamespaceContext(prefixResolver);
        if (isTopLevel) {
            // System.out.println("calling m_expr.execute(getXPathContext())");
            VariableStack vars = xctxt.getVarStack();
            // These three statements need to be combined into one operation.
            int savedStart = vars.getStackFrame();
            vars.setStackFrame(stackFrame);
            result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt);
            result.setShouldCacheNodes(true);
            // These two statements need to be combined into one operation.
            vars.setStackFrame(savedStart);
        } else
            result = (com.sun.org.apache.xpath.internal.objects.XNodeSet) expr.execute(xctxt);
    } catch (javax.xml.transform.TransformerException se) {
        throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(se);
    } finally {
        xctxt.popCurrentNode();
        xctxt.setNamespaceContext(savedResolver);
    }
    return result;
}

6. FuncHere#execute()

Project: openjdk
Source File: FuncHere.java
View license
@Override
public XObject execute(XPathContext xctxt) throws TransformerException {
    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();
    if (xpathOwnerNode == null) {
        return null;
    }
    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);
    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();
    if (docContext == DTM.NULL) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }
    // check whether currentNode and the node containing the XPath
    // expression are in the same document
    Document currentDoc = getOwnerDocument(dtm.getNode(currentNode));
    Document xpathOwnerDoc = getOwnerDocument(xpathOwnerNode);
    if (currentDoc != xpathOwnerDoc) {
        throw new TransformerException("Owner documents differ");
    }
    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();
    int hereNode = DTM.NULL;
    switch(dtm.getNodeType(xpathOwnerNodeDTM)) {
        case Node.ATTRIBUTE_NODE:
        case Node.PROCESSING_INSTRUCTION_NODE:
            {
                // returns a node-set containing the attribute /  processing
                // instruction node
                hereNode = xpathOwnerNodeDTM;
                nodeSet.addNode(hereNode);
                break;
            }
        case Node.TEXT_NODE:
            {
                // returns a node-set containing the parent element of the
                // text node that directly bears the XPath expression
                hereNode = dtm.getParent(xpathOwnerNodeDTM);
                nodeSet.addNode(hereNode);
                break;
            }
        default:
            break;
    }
    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();
    return nodes;
}

7. FuncId#execute()

Project: openjdk
Source File: FuncId.java
View license
/**
   * Execute the function.  The function must return
   * a valid object.
   * @param xctxt The current execution context.
   * @return A valid XObject.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
    int context = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    int docContext = dtm.getDocument();
    if (DTM.NULL == docContext)
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    XObject arg = m_arg0.execute(xctxt);
    int argType = arg.getType();
    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();
    if (XObject.CLASS_NODESET == argType) {
        DTMIterator ni = arg.iter();
        StringVector usedrefs = null;
        int pos = ni.nextNode();
        while (DTM.NULL != pos) {
            DTM ndtm = ni.getDTM(pos);
            String refval = ndtm.getStringValue(pos).toString();
            pos = ni.nextNode();
            usedrefs = getNodesByID(xctxt, docContext, refval, usedrefs, nodeSet, DTM.NULL != pos);
        }
    // ni.detach();
    } else if (XObject.CLASS_NULL == argType) {
        return nodes;
    } else {
        String refval = arg.str();
        getNodesByID(xctxt, docContext, refval, null, nodeSet, false);
    }
    return nodes;
}

8. FuncHere#execute()

Project: openjdk
Source File: FuncHere.java
View license
/**
     * The here function returns a node-set containing the attribute or
     * processing instruction node or the parent element of the text node
     * that directly bears the XPath expression.  This expression results
     * in an error if the containing XPath expression does not appear in the
     * same XML document against which the XPath expression is being evaluated.
     *
     * @param xctxt
     * @return the xobject
     * @throws javax.xml.transform.TransformerException
     */
@Override
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();
    if (xpathOwnerNode == null) {
        return null;
    }
    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);
    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();
    if (DTM.NULL == docContext) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }
    {
        // check whether currentNode and the node containing the XPath expression
        // are in the same document
        Document currentDoc = XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
        Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);
        if (currentDoc != xpathOwnerDoc) {
            throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
        }
    }
    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();
    {
        int hereNode = DTM.NULL;
        switch(dtm.getNodeType(xpathOwnerNodeDTM)) {
            case Node.ATTRIBUTE_NODE:
            case Node.PROCESSING_INSTRUCTION_NODE:
                {
                    // returns a node-set containing the attribute /  processing instruction node
                    hereNode = xpathOwnerNodeDTM;
                    nodeSet.addNode(hereNode);
                    break;
                }
            case Node.TEXT_NODE:
                {
                    // returns a node-set containing the parent element of the
                    // text node that directly bears the XPath expression
                    hereNode = dtm.getParent(xpathOwnerNodeDTM);
                    nodeSet.addNode(hereNode);
                    break;
                }
            default:
                break;
        }
    }
    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();
    return nodes;
}