Package nu.xom

Examples of nu.xom.Element


        try {
          serializer.writeXMLDeclaration();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
        return new Document(new Element("dummy")); // unused dummy
      }
     
      public void finishMakingDocument(Document document) {
        buffer = null;
        try {
View Full Code Here


      for (int i = count; --i >= 0; ) {
        size += getMemorySize(parent.getChild(i));
      }
     
      if (node instanceof Element) {
        Element elem = (Element) node;
        size += 5*PTR + 4;
        count = elem.getAttributeCount();
        if (count > 0) size += ARR + count*PTR;
        for (int i = count; --i >= 0; ) {
          size += getMemorySize(elem.getAttribute(i));
        }
        // for the moment assume no additional namespace declarations (common case)
      }
    } else if (node instanceof Attribute) {
      size += 5*PTR;
 
View Full Code Here

     
      for (int i=0; i < doc.getChildCount(); i++) {
        Node child = doc.getChild(i);
        Nodes nodes;
        if (child instanceof Element) {
          Element elem = (Element) child;
          Element root = factory.makeRootElement(
              elem.getQualifiedName(), elem.getNamespaceURI());
          if (root == null) {
            throw new NullPointerException("Factory failed to create root element.");
          }
          result.setRootElement(root);
View Full Code Here

    private static void build(Element parent, NodeFactory factory, Element result) {
      for (int i=0; i < parent.getChildCount(); i++) {
        Nodes nodes;
        Node child = parent.getChild(i);
        if (child instanceof Element) {
          Element elem = (Element) child;
          Element copy = factory.startMakingElement(
              elem.getQualifiedName(), elem.getNamespaceURI());
         
          if (copy != null) {
            result.appendChild(copy);
            result = copy;
            appendNamespaces(elem, result);
            appendAttributes(elem, factory, result);
          }

          build(elem, factory, result); // recurse down
         
          if (copy == null) continue; // skip element
          result = (Element) copy.getParent(); // recurse up
          nodes = factory.finishMakingElement(copy);
          if (nodes.size()==1 && nodes.get(0)==copy) { // same node? (common case)
            continue; // optimization: no need to remove and then readd same element
          }       
          if (result.getChildCount()-1 < 0) {
View Full Code Here

    }
   
    /** Wraps each item in the result sequence into a decorated element wrapper. */
    private static Document wrapSequence(Nodes nodes) {
      // make a copy of the template for sequences:
      Element items = (Element) TEMPLATES.get(Nodes.class.getName());
      items = new Element(items);
     
      int size = nodes.size();
      for (int i=0; i < size; i++) {
        items.appendChild(wrap(nodes.get(i)));
      }
     
      return new Document(items);
    }
View Full Code Here

      if (DefaultResultSequence.isAtomicValue(node)) {
        return (Element) node.copy(); // atomic values are already properly wrapped
      }
     
      // make a copy of the template associated with the given node type:
      Element item = (Element) TEMPLATES.get(node.getClass().getName());
      if (item == null) // FIXME: also allow Node subclasses
        throw new IllegalArgumentException("Unrecognized node type: " + node.getClass());
      item = new Element(item);

      // add copy of content to wrapper:
      if (node instanceof Attribute) {
        Attribute attr = (Attribute) node;         
        item.addAttribute((Attribute) attr.copy());
      } else if (node instanceof Document) {
        Document doc = (Document) node;         
        for (int j=0; j < doc.getChildCount(); j++) {
          item.appendChild(doc.getChild(j).copy());
        }
//      } else if (node instanceof Namespace) { // xom >= 1.1 only
//        Namespace ns = (Namespace) node;
////        item.addNamespaceDeclaration(ns.getPrefix(), ns.getValue());
//        if (ns.getPrefix().length() > 0) {
//          item.addAttribute(new Attribute("prefix", ns.getPrefix()));
//        }
//        item.addAttribute(new Attribute("uri", ns.getValue()));
      } else if (node instanceof DocType) {
        DocType docType = (DocType) node;
        Element e;
       
        e = new Element("rootName");
        e.appendChild(docType.getRootElementName());
        item.appendChild(e);
       
        if (docType.getPublicID() != null) {
          e = new Element("publicID");
          e.appendChild(docType.getPublicID());
          item.appendChild(e);
        }
        if (docType.getSystemID() != null) {
          e = new Element("systemID");
          e.appendChild(docType.getSystemID());
          item.appendChild(e);
        }
        if (docType.getInternalDTDSubset().length() > 0) {
          e = new Element("internalDTDSubset");
          e.appendChild(docType.getInternalDTDSubset());
          item.appendChild(e);
        }
      } else { // Element, Text, Comment, ProcessingInstruction
        item.appendChild(node.copy());
      }
View Full Code Here

   
    /** Prefabricate template elements for efficient WRAPPED_ALGORITHM. */
    private static HashMap initTemplates() {
      HashMap templates = new HashMap();
      String ns = "http://dsd.lbl.gov/nux";
      Element template;
     
      template = new Element("item:document", ns);
      templates.put(Document.class.getName(), template);
     
      template = new Element("item:element", ns);
      templates.put(Element.class.getName(), template);
     
      template = new Element("item:attribute", ns);
      templates.put(Attribute.class.getName(), template);
     
      template = new Element("item:text", ns);
      templates.put(Text.class.getName(), template);
     
      template = new Element("item:comment", ns);
      templates.put(Comment.class.getName(), template);
     
      template = new Element("item:pi", ns);
      templates.put(ProcessingInstruction.class.getName(), template);

      template = new Element("item:docType", ns);
      templates.put(DocType.class.getName(), template);
     
//      template = new Element("item:namespace", ns); // xom >= 1.1 only
//      templates.put(Namespace.class.getName(), template);
     
      template = new Element("item:items", ns);
      template.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
      templates.put(Nodes.class.getName(), template);

      return templates;
    }
View Full Code Here

    int runs = 1000;
    String query = "element myelem { . }"; // tree copy leads to namepool allocations
   
    int k = 0;
    for (int i=1; i < runs; i++) {
      Element root = new Element("root");
      int j = k + 10000;
      while (k < j) {
        root.appendChild(new Element("elem" + (k++)));
      }
     
      XQueryUtil.xquery(new Document(root), query);
     
      if (i % 1 == 0) System.out.print(".");
View Full Code Here

          types = new int[paths.size()];
          expected = new Object[paths.size()];
         
          // precompute all the info necessary to run the bench
          for (int i=0; i < paths.size(); i++) {
            Element path = (Element) paths.get(i);
            Attribute ctxAttr = path.getAttribute("context");
           
            contexts[i] = ctxAttr == null ? doc : XQueryUtil.xquery(doc, ctxAttr.getValue()).get(0);
            selects[i] = path.getAttribute("select").getValue();
            types[i] = 0;
            if (path.getAttribute("type") != null) {
              String[] flavours = {"count", "string", "double", "boolean"};
              types[i] = java.util.Arrays.asList(flavours).indexOf(path.getAttribute("type").getValue());
            }
            expected[i] = path.getValue();
          }
        }
       
        // for each query
        for (int i=0; i < selects.length; i++) {
View Full Code Here

    finishMakingElement(elem);
  }
 
  /** {@inheritDoc} */
  public Document startMakingDocument() {
    current = new Element("root");
    return super.startMakingDocument();
  }
View Full Code Here

TOP

Related Classes of nu.xom.Element

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.