Java Code Examples for com.sun.org.apache.xml.internal.dtm.DTM#NULL

The following examples show how to use com.sun.org.apache.xml.internal.dtm.DTM#NULL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AxesWalker.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Set the root node of the TreeWalker.
 * (Not part of the DOM2 TreeWalker interface).
 *
 * @param root The context node of this step.
 */
public void setRoot(int root)
{
  // %OPT% Get this directly from the lpi.
  XPathContext xctxt = wi().getXPathContext();
  m_dtm = xctxt.getDTM(root);
  m_traverser = m_dtm.getAxisTraverser(m_axis);
  m_isFresh = true;
  m_foundLast = false;
  m_root = root;
  m_currentNode = root;

  if (DTM.NULL == root)
  {
    throw new RuntimeException(
      XSLMessages.createXPATHMessage(XPATHErrorResources.ER_SETTING_WALKER_ROOT_TO_NULL, null)); //"\n !!!! Error! Setting the root of a walker to null!!!");
  }

  resetProximityPositions();
}
 
Example 2
Source File: ChildTestIterator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
   * Get the next node via getNextXXX.  Bottlenecked for derived class override.
   * @return The next node on the axis, or DTM.NULL.
   */
  protected int getNextNode()
  {
    if(true /* 0 == m_extendedTypeID */)
    {
      m_lastFetched = (DTM.NULL == m_lastFetched)
                   ? m_traverser.first(m_context)
                   : m_traverser.next(m_context, m_lastFetched);
    }
//    else
//    {
//      m_lastFetched = (DTM.NULL == m_lastFetched)
//                   ? m_traverser.first(m_context, m_extendedTypeID)
//                   : m_traverser.next(m_context, m_lastFetched,
//                                      m_extendedTypeID);
//    }

    return m_lastFetched;
  }
 
Example 3
Source File: SAXImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Set start to END should 'close' the iterator,
 * i.e. subsequent call to next() should return END.
 *
 * @param node Sets the root of the iteration.
 *
 * @return A DTMAxisIterator set to the start of the iteration.
 */
public DTMAxisIterator setStartNode(int node) {
    //%HZ%: Added reference to DTMDefaultBase.ROOTNODE back in, temporarily
    if (node == DTMDefaultBase.ROOTNODE) {
        node = getDocument();
    }

    if (_isRestartable) {
        _startNode = node;
        _currentNode = (node == DTM.NULL) ? DTM.NULL : NOTPROCESSED;

        return resetPosition();
    }

    return this;
}
 
Example 4
Source File: XObject.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Cast result object to a result tree fragment.
 *
 * @param support XPath context to use for the conversion
 *
 * @return the objec as a result tree fragment.
 */
public int rtf(XPathContext support)
{

  int result = rtf();

  if (DTM.NULL == result)
  {
    DTM frag = support.createDocumentFragment();

    // %OPT%
    frag.appendTextChild(str());

    result = frag.getDocument();
  }

  return result;
}
 
Example 5
Source File: LocPathIterator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Bottleneck the return of a next node, to make returns
 * easier from nextNode().
 *
 * @param nextNode The next node found, may be null.
 *
 * @return The same node that was passed as an argument.
 */
protected int returnNextNode(int nextNode)
{

  if (DTM.NULL != nextNode)
  {
    m_pos++;
  }

  m_lastFetched = nextNode;

  if (DTM.NULL == nextNode)
    m_foundLast = true;

  return nextNode;
}
 
Example 6
Source File: NodeSequence.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see DTMIterator#previousNode()
 */
public int previousNode()
{
      if(hasCache())
      {
              if(m_next <= 0)
                      return DTM.NULL;
              else
              {
                      m_next--;
                      return item(m_next);
              }
      }
      else
      {
          int n = m_iter.previousNode();
          m_next = m_iter.getCurrentPos();
          return m_next;
      }
}
 
Example 7
Source File: SAX2DTM.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Determine if the string-value of a node is whitespace
 *
 * @param nodeHandle The node Handle.
 *
 * @return Return true if the given node is whitespace.
 */
public boolean isWhitespace(int nodeHandle)
{
  int identity = makeNodeIdentity(nodeHandle);
  int type;
  if(identity==DTM.NULL) // Separate lines because I wanted to breakpoint it
    type = DTM.NULL;
  else
    type= _type(identity);

  if (isTextType(type))
  {
    int dataIndex = _dataOrQName(identity);
    int offset = m_data.elementAt(dataIndex);
    int length = m_data.elementAt(dataIndex + 1);

    return m_chars.isWhitespace(offset, length);
  }
  return false;
}
 
Example 8
Source File: SAXImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Lookup a namespace URI from a prefix starting at node. This method
 * is used in the execution of xsl:element when the prefix is not known
 * at compile time.
 */
public String lookupNamespace(int node, String prefix)
    throws TransletException
{
    int anode, nsnode;
    final AncestorIterator ancestors = new AncestorIterator();

    if (isElement(node)) {
        ancestors.includeSelf();
    }

    ancestors.setStartNode(node);
    while ((anode = ancestors.next()) != DTM.NULL) {
        final NamespaceIterator namespaces = new NamespaceIterator();

        namespaces.setStartNode(anode);
        while ((nsnode = namespaces.next()) != DTM.NULL) {
            if (getLocalName(nsnode).equals(prefix)) {
                return getNodeValue(nsnode);
            }
        }
    }

    BasisLibrary.runTimeError(BasisLibrary.NAMESPACE_PREFIX_ERR, prefix);
    return null;
}
 
Example 9
Source File: SimpleResultTreeImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public int getExpandedTypeID(final int nodeHandle)
{
    int nodeID = getNodeIdent(nodeHandle);
    if (nodeID == RTF_TEXT)
        return DTM.TEXT_NODE;
    else if (nodeID == RTF_ROOT)
        return DTM.ROOT_NODE;
    else
        return DTM.NULL;
}
 
Example 10
Source File: DTMNodeProxy.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the owner element of an attribute.
 *
 *
 * @see org.w3c.dom.Attr as of DOM Level 2
 */
@Override
public final Element getOwnerElement()
{
  if (getNodeType() != Node.ATTRIBUTE_NODE)
    return null;
  // In XPath and DTM data models, unlike DOM, an Attr's parent is its
  // owner element.
  int newnode = dtm.getParent(node);
  return (newnode == DTM.NULL) ? null : (Element)(dtm.getNode(newnode));
}
 
Example 11
Source File: SAXImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the namespace URI to which a node belongs
 */
public String getNamespaceName(final int node)
{
    if (node == DTM.NULL) {
        return "";
    }

    String s;
    return (s = getNamespaceURI(node)) == null ? EMPTYSTRING : s;
}
 
Example 12
Source File: DTMNodeIterator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** @return the next previous in the set and advance the position of the
 * iterator in the set.
 *
 * @throws DOMException - INVALID_STATE_ERR Raised if this method is
 * called after the detach method was invoked.
 *  */
public Node previousNode()
  {
    if(!valid)
      throw new DTMDOMException(DOMException.INVALID_STATE_ERR);

    int handle=dtm_iter.previousNode();
    if (handle==DTM.NULL)
      return null;
    return dtm_iter.getDTM(handle).getNode(handle);
  }
 
Example 13
Source File: DTMNamedNodeMap.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves a node specified by name.
 * @param name The <code>nodeName</code> of a node to retrieve.
 * @return A <code>Node</code> (of any type) with the specified
 *   <code>nodeName</code>, or <code>null</code> if it does not identify
 *   any node in this map.
 */
public Node getNamedItem(String name)
{

  for (int n = dtm.getFirstAttribute(element); n != DTM.NULL;
          n = dtm.getNextAttribute(n))
  {
    if (dtm.getNodeName(n).equals(name))
      return dtm.getNode(n);
  }

  return null;
}
 
Example 14
Source File: OneStepIteratorForward.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Get the next node via getFirstAttribute && getNextAttribute.
 */
protected int getNextNode()
{
  m_lastFetched = (DTM.NULL == m_lastFetched)
                   ? m_traverser.first(m_context)
                   : m_traverser.next(m_context, m_lastFetched);
  return m_lastFetched;
}
 
Example 15
Source File: MultiDOM.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public String shallowCopy(final int node, SerializationHandler handler)
        throws TransletException
{
    if (node == DTM.NULL) {
        return "";
    }
    return _adapters[node >>> DTMManager.IDENT_DTM_NODE_BITS].shallowCopy(node, handler);
}
 
Example 16
Source File: DTMTreeWalker.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/** Perform a non-recursive pre-order/post-order traversal,
 * operating as a Visitor. startNode (preorder) and endNode
 * (postorder) are invoked for each node as we traverse over them,
 * with the result that the node is written out to m_contentHandler.
 *
 * @param pos Node in the tree at which to start (and end) traversal --
 * in other words, the root of the subtree to traverse over.
 *
 * @throws TransformerException */
public void traverse(int pos) throws org.xml.sax.SAXException
{
  // %REVIEW% Why isn't this just traverse(pos,pos)?

  int top = pos;              // Remember the root of this subtree

  while (DTM.NULL != pos)
  {
    startNode(pos);
    int nextNode = m_dtm.getFirstChild(pos);
    while (DTM.NULL == nextNode)
    {
      endNode(pos);

      if (top == pos)
        break;

      nextNode = m_dtm.getNextSibling(pos);

      if (DTM.NULL == nextNode)
      {
        pos = m_dtm.getParent(pos);

        if ((DTM.NULL == pos) || (top == pos))
        {
          // %REVIEW% This condition isn't tested in traverse(pos,top)
          // -- bug?
          if (DTM.NULL != pos)
            endNode(pos);

          nextNode = DTM.NULL;

          break;
        }
      }
    }

    pos = nextNode;
  }
}
 
Example 17
Source File: SimpleResultTreeImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public int getFirstAttribute(int nodeHandle)
{
    return DTM.NULL;
}
 
Example 18
Source File: FuncPosition.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the position in the current context node list.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The current position of the itteration in the context node list,
 *         or -1 if there is no active context node list.
 */
public int getPositionInContextNodeList(XPathContext xctxt)
{

  // System.out.println("FuncPosition- entry");
  // If we're in a predicate, then this will return non-null.
  SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();

  if (null != iter)
  {
    int prox = iter.getProximityPosition(xctxt);

    // System.out.println("FuncPosition- prox: "+prox);
    return prox;
  }

  DTMIterator cnl = xctxt.getContextNodeList();

  if (null != cnl)
  {
    int n = cnl.getCurrentNode();
    if(n == DTM.NULL)
    {
      if(cnl.getCurrentPos() == 0)
        return 0;

      // Then I think we're in a sort.  See sort21.xsl. So the iterator has
      // already been spent, and is not on the node we're processing.
      // It's highly possible that this is an issue for other context-list
      // functions.  Shouldn't be a problem for last(), and it shouldn't be
      // a problem for current().
      try
      {
        cnl = cnl.cloneWithReset();
      }
      catch(CloneNotSupportedException cnse)
      {
        throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(cnse);
      }
      int currentNode = xctxt.getContextNode();
      // System.out.println("currentNode: "+currentNode);
      while(DTM.NULL != (n = cnl.nextNode()))
      {
        if(n == currentNode)
          break;
      }
    }
    // System.out.println("n: "+n);
    // System.out.println("FuncPosition- cnl.getCurrentPos(): "+cnl.getCurrentPos());
    return cnl.getCurrentPos();
  }

  // System.out.println("FuncPosition - out of guesses: -1");
  return -1;
}
 
Example 19
Source File: StepPattern.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 */
private final boolean checkProximityPosition(XPathContext xctxt,
        int predPos, DTM dtm, int context, int pos)
{

  try
  {
    DTMAxisTraverser traverser =
      dtm.getAxisTraverser(Axis.PRECEDINGSIBLING);

    for (int child = traverser.first(context); DTM.NULL != child;
            child = traverser.next(context, child))
    {
      try
      {
        xctxt.pushCurrentNode(child);

        if (NodeTest.SCORE_NONE != super.execute(xctxt, child))
        {
          boolean pass = true;

          try
          {
            xctxt.pushSubContextList(this);

            for (int i = 0; i < predPos; i++)
            {
              xctxt.pushPredicatePos(i);
              try
              {
                XObject pred = m_predicates[i].execute(xctxt);

                try
                {
                  if (XObject.CLASS_NUMBER == pred.getType())
                  {
                    throw new Error("Why: Should never have been called");
                  }
                  else if (!pred.boolWithSideEffects())
                  {
                    pass = false;

                    break;
                  }
                }
                finally
                {
                  pred.detach();
                }
              }
              finally
              {
                xctxt.popPredicatePos();
              }
            }
          }
          finally
          {
            xctxt.popSubContextList();
          }

          if (pass)
            pos--;

          if (pos < 1)
            return false;
        }
      }
      finally
      {
        xctxt.popCurrentNode();
      }
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: should keep throw sax exception...
    throw new java.lang.RuntimeException(se.getMessage());
  }

  return (pos == 1);
}
 
Example 20
Source File: OneStepIterator.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Get the current sub-context position.  In order to do the
 * reverse axes count, for the moment this re-searches the axes
 * up to the predicate.  An optimization on this is to cache
 * the nodes searched, but, for the moment, this case is probably
 * rare enough that the added complexity isn't worth it.
 *
 * @param predicateIndex The predicate index of the proximity position.
 *
 * @return The pridicate index, or -1.
 */
protected int getProximityPosition(int predicateIndex)
{
  if(!isReverseAxes())
    return super.getProximityPosition(predicateIndex);

  // A negative predicate index seems to occur with
  // (preceding-sibling::*|following-sibling::*)/ancestor::*[position()]/*[position()]
  // -sb
  if(predicateIndex < 0)
    return -1;

  if (m_proximityPositions[predicateIndex] <= 0)
  {
    XPathContext xctxt = getXPathContext();
    try
    {
      OneStepIterator clone = (OneStepIterator) this.clone();

      int root = getRoot();
      xctxt.pushCurrentNode(root);
      clone.setRoot(root, xctxt);

      // clone.setPredicateCount(predicateIndex);
      clone.m_predCount = predicateIndex;

      // Count 'em all
      int count = 1;
      int next;

      while (DTM.NULL != (next = clone.nextNode()))
      {
        count++;
      }

      m_proximityPositions[predicateIndex] += count;
    }
    catch (CloneNotSupportedException cnse)
    {

      // can't happen
    }
    finally
    {
      xctxt.popCurrentNode();
    }
  }

  return m_proximityPositions[predicateIndex];
}