org.apache.axiom.om.OMNode.getParent()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中org.apache.axiom.om.OMNode.getParent()方法的一些代码示例,展示了OMNode.getParent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OMNode.getParent()方法的具体详情如下:
包路径:org.apache.axiom.om.OMNode
类名称:OMNode
方法名:getParent

OMNode.getParent介绍

[英]Returns the parent containing node.

Returns the parent container, which may be either an OMDocument or OMElement.
[中]返回包含节点的父节点。
返回父容器,该容器可以是OMDocument或OmeElement。

代码示例

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

/**
 * Constructor.
 * 
 * @param root
 *            the root node of the object model subtree that is being serialized; this
 *            information is used by the serializer in scenarios that require access to the
 *            namespace context of the parent of the root node
 * @param namespaceRepairing
 *            indicates if the serializer should perform namespace repairing
 * @param preserveNamespaceContext
 *            indicates if the namespace context determined by the ancestors of the root node
 *            should be strictly preserved in the output
 */
public Serializer(OMSerializable root, boolean namespaceRepairing, boolean preserveNamespaceContext) {
  this.root = root;
  if (root instanceof OMNode) {
    OMContainer parent = ((OMNode)root).getParent();
    if (parent instanceof OMElement) {
      contextElement = (OMElement)parent; 
    } else {
      contextElement = null;
    }
  } else {
    contextElement = null;
  }
  this.namespaceRepairing = namespaceRepairing;
  this.preserveNamespaceContext = preserveNamespaceContext;
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

public final void endElement(String uri, String localName, String qName)
    throws SAXException {
  if (!inEntityReference) {
    completed((OMElement)target);
    target = ((OMNode)target).getParent();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

public Object next() {
  if (hasNext()) {
    currentNode = nextNode;
    currentParent = currentNode instanceof OMNode ? ((OMNode)currentNode).getParent() : null;
    nextNode = null;
    nextCalled = true;
    return currentNode;
  } else {
    throw new NoSuchElementException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

public Object next() {
  if (hasNext()) {
    currentNode = nextNode;
    currentParent = currentNode.getParent();
    nextNode = null;
    nextCalled = true;
    return currentNode;
  } else {
    throw new NoSuchElementException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

public final void endElement(String uri, String localName, String qName)
    throws SAXException {
  if (!inEntityReference) {
    completed((OMElement)target);
    target = ((OMNode)target).getParent();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-common-impl

public Object next() {
  if (hasNext()) {
    currentNode = nextNode;
    currentParent = currentNode instanceof OMNode ? ((OMNode)currentNode).getParent() : null;
    nextNode = null;
    nextCalled = true;
    return currentNode;
  } else {
    throw new NoSuchElementException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

public boolean hasNext() {
  if (noMoreNodes) {
    return false;
  } else if (nextNode != null) {
    return true;
  } else {
    if (currentNode.getParent() != currentParent) {
      throw new ConcurrentModificationException("The current node has been removed using a method other than Iterator#remove()");
    }
    nextNode = getNextNode(currentNode);
    noMoreNodes = nextNode == null;
    return !noMoreNodes;
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-c14n

public Node getParentNode() {
  return fac.getNode(node.getParent());
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

public boolean hasNext() {
  if (noMoreNodes) {
    return false;
  } else if (nextNode != null) {
    return true;
  } else {
    if (currentNode instanceof OMNode && ((OMNode)currentNode).getParent() != currentParent) {
      throw new ConcurrentModificationException("The current node has been removed using a method other than Iterator#remove()");
    }
    nextNode = getNextNode(currentNode);
    noMoreNodes = nextNode == null;
    return !noMoreNodes;
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-common-impl

public boolean hasNext() {
  if (noMoreNodes) {
    return false;
  } else if (nextNode != null) {
    return true;
  } else {
    if (currentNode instanceof OMNode && ((OMNode)currentNode).getParent() != currentParent) {
      throw new ConcurrentModificationException("The current node has been removed using a method other than Iterator#remove()");
    }
    nextNode = getNextNode(currentNode);
    noMoreNodes = nextNode == null;
    return !noMoreNodes;
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

/**
 * Returns the document node that contains the given context node.
 *
 * @param contextNode the context node
 * @return Returns the document of the context node.
 * @see #isDocument(Object)
 */
public Object getDocumentNode(Object contextNode) {
  if (contextNode instanceof OMDocument) {
    return contextNode;
  }
  OMContainer parent = ((OMNode) contextNode).getParent();
  if (parent == null) {
    // this node doesn't have a parent Document. So return the document element itself
    return contextNode;
  } else {
    return getDocumentNode(parent);
  }
}

代码示例来源:origin: org.bluestemsoftware.open.eoa.ext/open-eoa-aspect-axiom

/**
 * Constructor OMStAXWrapper
 *
 * @param builder
 * @param startNode
 * @param cache
 */
public DOMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode,
           boolean cache) {
  // create a navigator
  this.navigator = new DOMNavigator(startNode);
  this.builder = builder;
  this.rootNode = startNode;
  if (rootNode != null && rootNode.getParent() != null
      && rootNode.getParent() instanceof OMDocument) {
    needToThrowEndDocument = true;
  }
  // initaite the next and current nodes
  // Note - navigator is written in such a way that it first
  // returns the starting node at the first call to it
  currentNode = navigator.next();
  updateNextNode();
  switchingAllowed = !cache;
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

/**
 * Returns the parent of the given context node.
 * <p>
 * The parent of any node must either be a document node or an element node.
 *
 * @param contextNode the context node
 * @return Returns the parent of the context node, or null if this is a document node.
 * @throws UnsupportedAxisException if the parent axis is not supported by the model
 * @see #isDocument
 * @see #isElement
 */
public Object getParentNode(Object contextNode) throws UnsupportedAxisException {
  if (contextNode == null ||
      contextNode instanceof OMDocument) {
    return null;
  } else if (contextNode instanceof OMAttribute) {
    return ((OMAttribute) contextNode).getOwner();
  } else if (contextNode instanceof OMNamespaceEx) {
    return ((OMNamespaceEx) contextNode).getParent();
  }
  return ((OMNode) contextNode).getParent();
}

代码示例来源:origin: org.bluestemsoftware.open.eoa.ext/open-eoa-aspect-axiom

/** Private method to encapsulate the searching logic */
private void updateNextNode() {
  if ((next instanceof OMElement) && !visited) {
    ElementImpl e = (ElementImpl) next;
    if (e.firstChild != null) {
      next = e.firstChild;
    } else if (e.isComplete()) {
      backtracked = true;
    } else {
      next = null;
    }
  } else {
    OMNode nextSibling = ((ChildNode) next).nextSibling;
    OMContainer parent = next.getParent();
    if (nextSibling != null) {
      next = nextSibling;
    } else if ((parent != null) && parent.isComplete()) {
      next = (NodeImpl) parent;
      backtracked = true;
    } else {
      next = null;
    }
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-common-impl

protected OMSerializable getNextNode(OMSerializable currentNode) {
    if (currentNode instanceof OMContainer) {
      OMNode firstChild = ((OMContainer)currentNode).getFirstOMChild();
      if (firstChild != null) {
        level++;
        return firstChild;
      }
    }
    OMSerializable node = currentNode;
    while (true) {
      if (level == 0) {
        return null;
      }
      OMNode nextSibling = ((OMNode)node).getNextOMSibling();
      if (nextSibling != null) {
        return nextSibling;
      } else {
        node = ((OMNode)node).getParent();
        level--;
      }
    }
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

private Map<String,String> getAllNamespaces(OMSerializable contextNode) {
  if (contextNode == null) {
    return Collections.emptyMap();
  }
  OMContainer context;
  if (contextNode instanceof OMContainer) {
    context = (OMContainer)contextNode;
  } else {
    context = ((OMNode)contextNode).getParent();
  }
  Map<String,String> nsMap = new LinkedHashMap<String,String>();
  while (context != null && !(context instanceof OMDocument)) {
    OMElement element = (OMElement) context;
    for (Iterator it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
      addNamespaceToMap((OMNamespace) it.next(), nsMap);
    }
    if (element.getNamespace() != null) {
      addNamespaceToMap(element.getNamespace(), nsMap);
    }
    for (Iterator it = element.getAllAttributes(); it.hasNext(); ) {
      OMAttribute attr = (OMAttribute) it.next();
      if (attr.getNamespace() != null) {
        addNamespaceToMap(attr.getNamespace(), nsMap);
      }
    }
    context = element.getParent();
  }
  return nsMap;
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-c14n

public Node getPreviousSibling() {
  if (prev == null) {
    if (node.getParent() instanceof OMDocument) {
      OMNode n = node.getPreviousOMSibling();
      do {
        if (!(n instanceof OMText)) {
          prev = fac.getNode(n);
          break;
        }
        n = n.getPreviousOMSibling();
      } while (true);
    } else {
      prev = fac.getNode(node.getPreviousOMSibling());
    }
  }
  return prev;
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

/**
 * Retrieves an <code>Iterator</code> matching the <code>parent</code> XPath axis.
 *
 * @param contextNode the original context node
 * @return Returns an Iterator capable of traversing the axis, not null.
 * @throws UnsupportedAxisException if the semantics of the parent axis are not supported by
 *                                  this object model
 */
public Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException {
  if (contextNode instanceof OMNode) {
    return new SingleObjectIterator(((OMNode) contextNode).getParent());
  } else if (contextNode instanceof OMNamespaceEx) {
    return new SingleObjectIterator(
        ((OMNamespaceEx) contextNode).getParent());
  } else if (contextNode instanceof OMAttribute) {
    return new SingleObjectIterator(
        ((OMAttribute) contextNode).getOwner());
  }
  return JaxenConstants.EMPTY_ITERATOR;
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-c14n

public Node getNextSibling() {
  if (next == null) {
    if (node.getParent() instanceof OMDocument) {
      OMNode n = node.getNextOMSibling();
      do {
        if (!(n instanceof OMText)) {
          next = fac.getNode(n);
          break;
        }
        n = n.getNextOMSibling();
      } while (true);
    } else {
      next = fac.getNode(node.getNextOMSibling());
    }
  }
  return next;
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-common-impl

/** Private method to encapsulate the searching logic. */
private void updateNextNode() {
  if (!isLeaf(next) && !visited) {
    OMNode firstChild = _getFirstChild((OMContainer) next);
    if (firstChild != null) {
      next = firstChild;
    } else if (next.isComplete()) {
      backtracked = true;
    } else {
      next = null;
    }
  } else {
    if (next instanceof OMDocument) {
      next = null;
    } else {
      OMNode nextNode = (OMNode)next;
      OMContainer parent = nextNode.getParent();
      OMNode nextSibling = getNextSibling(nextNode);
      if (nextSibling != null) {
        next = nextSibling;
      } else if ((parent != null) && parent.isComplete()) {
        next = parent;
        backtracked = true;
      } else {
        next = null;
      }
    }
  }
}

相关文章