Package nu.xom

Examples of nu.xom.ParentNode


              prefixes.add(prefix);
            }
          }
        }
       
        ParentNode parent = elem.getParent();
        elem = (parent instanceof Element ? (Element) parent : null);
      } while (elem != null); // walk towards the root

      return Collections.unmodifiableList(prefixes).iterator();
    }
View Full Code Here


        case END_ELEMENT: {
          Element elem = stack.pop();
          if (elem == null) {
            continue; // skip element
          }
          ParentNode parent = elem.getParent();
          if (parent == null) throwTamperedWithParent();
          if (parent instanceof Document) {
            return; // we're done with the root element
          }
         
View Full Code Here

        case XMLStreamConstants.END_ELEMENT: {
          Element elem = (Element) stack.remove(stack.size()-1); // pop
          if (elem == null) {
            continue; // skip element
          }
          ParentNode parent = elem.getParent();
          if (parent == null) throwTamperedWithParent();
          if (parent instanceof Document) {
            return; // we're done with the root element
          }
         
View Full Code Here

     
      if (size == 1 && node == results.get(0)) {
        continue; // nothing to do (replace X with X)
      }

      ParentNode parent = node.getParent();
      StringBuffer atomics = null;
      boolean isInitialized = false;
      int position = 0;
      if (size > 1) {
        if (identities == null) {
          identities = new HashSet();
        } else {
          identities.clear();
        }
      }
     
      for (int j=0; j < size; j++) {
        Node result = results.get(j);       
        if (DefaultResultSequence.isAtomicValue(result)) { // concat atomic values
          String value = result.getValue();
          if (atomics == null) {
            atomics = new StringBuffer(value.length());
          } else {
            atomics.append(' ');
          }
          atomics.append(value);
        } else if (parent != null) {
          if (size > 1 && !identities.add(result)) {
            result = result.copy(); // multiple identical nodes in results
//            throw new MultipleParentException(
//            "XQuery morpher result sequence must not contain multiple identical nodes");
          }
          boolean isRoot = parent instanceof Document && node instanceof Element;
          if (!isInitialized) {
            if (!(node instanceof Attribute)) position = parent.indexOf(node);
            if (!isRoot) node.detach();
            isInitialized = true;
          }
         
          if (result instanceof Attribute) {
            result.detach();
            ((Element) parent).addAttribute((Attribute)result);
          } else {
            if (isRoot && result instanceof Element) {
              parent.replaceChild(node, result);
            } else {
              result.detach();
              parent.insertChild(result, position);
            }
            position++;
          }
        }
      }
View Full Code Here

 
  private static void toStatisticsString(Node node, Statistics stats) {
    stats.nodes++;
    String value = "";
    if (node instanceof ParentNode) {
      ParentNode parent = (ParentNode) node;
      for (int i=0; i < parent.getChildCount(); i++) {
        toStatisticsString(parent.getChild(i), stats);
      }
      if (node instanceof Element) {
        stats.elements++;
        Element elem = (Element) node;
        value = elem.getQualifiedName();
View Full Code Here

     
      public Nodes finishMakingElement(Element element) {
        level--;
        log("finish", element);
       
        ParentNode parent = null;
        if (element != null) parent = element.getParent();
        String parents = "{";
        while (parent != null) {
          parents += parent.toString() + ",";
          parent = parent.getParent();
        }
        if (parents.endsWith(",")) parents = parents.substring(0, parents.length()-1);
        parents += "}";
        log("parents", parents);
       
View Full Code Here

//    int ARRLIST = HEADER + 4 + PTR + HEADER + 4; // ArrayList
    int ARR = HEADER + 4; // Object[]

    int size = HEADER + PTR + 4; // object header + parent + siblingPosition
    if (node instanceof ParentNode) {
      ParentNode parent = (ParentNode) node;
      size += PTR + PTR + 4; // baseURI + childrenPtr + childCount
      int count = parent.getChildCount();
      if (count > 0) size += ARR + count*PTR;
      for (int i = count; --i >= 0; ) {
        size += getMemorySize(parent.getChild(i));
      }
     
      if (node instanceof Element) {
        Element elem = (Element) node;
        size += 5*PTR + 4;
View Full Code Here

          }
        } else { // any other node type
          if (node instanceof Element) {
            if (mayBreakLine && indentYes) breakLine();
            // root elements need no special toplevel namespace treatment
            ParentNode parent = node.getParent();
            this.writeNamespaceDeclarationsInScope =
              parent != null && !(parent instanceof Document);
          }
          writeChild(node);
          this.writeNamespaceDeclarationsInScope = false;
View Full Code Here

          if (!namespaces.containsKey(prefix)) {
            String uri = element.getNamespaceURI(prefix);
            namespaces.put(prefix, uri);
          }
        }
        ParentNode parent = element.getParent();
        element = (parent instanceof Element ? (Element) parent : null);
      } while (element != null);
     
      return namespaces;
    }
View Full Code Here

      try {
        Element elem = (Element) stacks[i].remove(stacks[i].size()-1); // pop
        if (elem == null) {
          continue; // skip element
        }
        ParentNode parent = elem.getParent();
        if (parent == null) throwTamperedWithParent();
        currents[i] = parent; // recurse up
       
        Nodes nodes = receivers[i].finishMakingElement(elem);
        if (nodes.size()==1 && nodes.get(0)==elem) { // same node? (common case)
          if (parent instanceof Document) hasRootElement[i] = true;
          continue; // optimization: no need to remove and then readd same element
        }

        if (parent.getChildCount()-1 < 0) throwTamperedWithParent();       
        if (parent instanceof Element) { // can't remove root element
          parent.removeChild(parent.getChildCount()-1);
        }
        appendNodes(parent, nodes, i);
      } catch (RuntimeException e) {
        onException(i, e);
      }
View Full Code Here

TOP

Related Classes of nu.xom.ParentNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.