From: Wolfgang M. M. <wol...@us...> - 2004-05-03 13:09:25
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/memtree In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19067/src/org/exist/memtree Modified Files: DocumentImpl.java NodeImpl.java ElementImpl.java Receiver.java MemTreeBuilder.java Added Files: ReferenceNode.java Log Message: Implemented lazy evaluation for XQuery enclosed expressions. --- NEW FILE: ReferenceNode.java --- /* * eXist Open Source Native XML Database * Copyright (C) 2001-04 Wolfgang M. Meier * wol...@ex... * http://exist-db.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: ReferenceNode.java,v 1.1 2004/05/03 13:08:43 wolfgang_m Exp $ */ package org.exist.memtree; import org.exist.dom.NodeProxy; /** * @author wolf */ public class ReferenceNode extends NodeImpl { /** * @param doc * @param nodeNumber */ public ReferenceNode(DocumentImpl doc, int nodeNumber) { super(doc, nodeNumber); } public NodeProxy getReference() { int p = document.alpha[nodeNumber]; return document.references[p]; } } Index: DocumentImpl.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/memtree/DocumentImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DocumentImpl.java 2 Mar 2004 08:35:44 -0000 1.6 --- DocumentImpl.java 3 May 2004 13:08:43 -0000 1.7 *************** *** 1,23 **** /* ! * eXist Open Source Native XML Database ! * Copyright (C) 2001-03 Wolfgang M. Meier ! * wol...@ex... ! * http://exist.sourceforge.net ! * ! * This program is free software; you can redistribute it and/or ! * modify it under the terms of the GNU Lesser General Public License ! * as published by the Free Software Foundation; either version 2 ! * of the License, or (at your option) any later version. ! * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License ! * along with this program; if not, write to the Free Software ! * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! * ! * $Id$ */ package org.exist.memtree; --- 1,21 ---- /* ! * eXist Open Source Native XML Database Copyright (C) 2001-03 Wolfgang M. Meier ! * wol...@ex... http://exist.sourceforge.net ! * ! * This program is free software; you can redistribute it and/or modify it under ! * the terms of the GNU Lesser General Public License as published by the Free ! * Software Foundation; either version 2 of the License, or (at your option) any ! * later version. ! * ! * This program is distributed in the hope that it will be useful, but WITHOUT ! * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ! * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more ! * details. ! * ! * You should have received a copy of the GNU Lesser General Public License ! * along with this program; if not, write to the Free Software Foundation, Inc., ! * 675 Mass Ave, Cambridge, MA 02139, USA. ! * ! * $Id$ */ package org.exist.memtree; *************** *** 25,28 **** --- 23,27 ---- import java.util.Arrays; + import org.exist.dom.NodeProxy; import org.exist.dom.QName; import org.exist.util.hashtable.NamePool; *************** *** 41,392 **** import org.w3c.dom.Text; import org.w3c.dom.Document; public class DocumentImpl extends NodeImpl implements Document { ! protected NamePool namePool = new NamePool(); ! ! protected short[] nodeKind; ! protected short[] treeLevel; ! protected int[] next; ! protected int[] nodeName; ! protected int[] alpha; ! protected int[] alphaLen; ! protected char[] characters; ! protected int nextChar = 0; ! protected int[] attrName; ! protected int[] attrParent; ! protected String[] attrValue; ! protected int nextAttr = 0; ! ! protected int size = 1; ! protected int documentRootNode = -1; ! public DocumentImpl(int nodeSize, int attrSize, int charBufSize) { ! super(null, 0); ! nodeKind = new short[nodeSize]; ! treeLevel = new short[nodeSize]; ! next = new int[nodeSize]; ! Arrays.fill(next, -1); ! nodeName = new int[nodeSize]; ! alpha = new int[nodeSize]; ! alphaLen = new int[nodeSize]; ! characters = new char[charBufSize]; ! attrName = new int[attrSize]; ! attrParent = new int[attrSize]; ! attrValue = new String[attrSize]; ! treeLevel[0] = 0; ! nodeKind[0] = Node.DOCUMENT_NODE; ! document = this; ! } ! public int addNode(short kind, short level, QName qname) { ! if (size == nodeKind.length) ! grow(); ! nodeKind[size] = kind; ! treeLevel[size] = level; ! nodeName[size] = (qname != null ? namePool.add(qname) : -1); ! alpha[size] = -1; // undefined ! next[size] = -1; ! return size++; ! } ! public void addChars(int nodeNr, char[] ch, int start, int len) { ! if (nextChar + len >= characters.length) { ! int newLen = (characters.length * 3) / 2; ! if(newLen < nextChar + len) ! newLen = nextChar + len; ! char[] nc = new char[newLen]; ! System.arraycopy(characters, 0, nc, 0, characters.length); ! characters = nc; ! } ! alpha[nodeNr] = nextChar; ! alphaLen[nodeNr] = len; ! System.arraycopy(ch, start, characters, nextChar, len); ! nextChar += len; ! } ! public void addChars(int nodeNr, CharSequence s) { ! int len = s.length(); ! if (nextChar + len >= characters.length) { ! int newLen = (characters.length * 3) / 2; ! if(newLen < nextChar + len) ! newLen = nextChar + len; ! char[] nc = new char[newLen]; ! System.arraycopy(characters, 0, nc, 0, characters.length); ! characters = nc; ! } ! alpha[nodeNr] = nextChar; ! alphaLen[nodeNr] = len; ! for(int i = 0; i < len; i++) { ! characters[nextChar++] = s.charAt(i); ! } ! } ! public int addAttribute(int nodeNr, QName qname, String value) throws DOMException { ! if (nextAttr == attrName.length) ! growAttributes(); ! attrParent[nextAttr] = nodeNr; ! attrName[nextAttr] = namePool.add(qname); ! attrValue[nextAttr] = value; ! if (alpha[nodeNr] < 0) ! alpha[nodeNr] = nextAttr; ! return nextAttr++; ! } ! ! public int getLastNode() { ! return size - 1; ! } ! ! private void grow() { ! int newSize = (size * 3) / 2; ! short[] newNodeKind = new short[newSize]; ! System.arraycopy(nodeKind, 0, newNodeKind, 0, size); ! nodeKind = newNodeKind; ! short[] newTreeLevel = new short[newSize]; ! System.arraycopy(treeLevel, 0, newTreeLevel, 0, size); ! treeLevel = newTreeLevel; ! int[] newNext = new int[newSize]; ! Arrays.fill(newNext, -1); ! System.arraycopy(next, 0, newNext, 0, size); ! next = newNext; ! int[] newNodeName = new int[newSize]; ! System.arraycopy(nodeName, 0, newNodeName, 0, size); ! nodeName = newNodeName; ! int[] newAlpha = new int[newSize]; ! System.arraycopy(alpha, 0, newAlpha, 0, size); ! alpha = newAlpha; ! int[] newAlphaLen = new int[newSize]; ! System.arraycopy(alphaLen, 0, newAlphaLen, 0, size); ! alphaLen = newAlphaLen; ! } ! private void growAttributes() { ! int size = attrName.length; ! int newSize = (size * 3) / 2; ! int[] newAttrName = new int[newSize]; ! System.arraycopy(attrName, 0, newAttrName, 0, size); ! attrName = newAttrName; ! int[] newAttrParent = new int[newSize]; ! System.arraycopy(attrParent, 0, newAttrParent, 0, size); ! attrParent = newAttrParent; ! String[] newAttrValue = new String[newSize]; ! System.arraycopy(attrValue, 0, newAttrValue, 0, size); ! attrValue = newAttrValue; ! } ! public NodeImpl getNode(int nodeNr) throws DOMException { ! if (nodeNr == 0) ! return this; ! if (nodeNr >= size) ! throw new DOMException( ! DOMException.HIERARCHY_REQUEST_ERR, ! "node not found"); ! NodeImpl node; ! switch (nodeKind[nodeNr]) { ! case Node.ELEMENT_NODE : ! node = new ElementImpl(this, nodeNr); ! break; ! case Node.TEXT_NODE : ! node = new TextImpl(this, nodeNr); ! break; ! case Node.COMMENT_NODE: ! node = new CommentImpl(this, nodeNr); ! break; ! case Node.PROCESSING_INSTRUCTION_NODE: ! node = new ProcessingInstructionImpl(this, nodeNr); ! break; ! default : ! throw new DOMException( ! DOMException.NOT_FOUND_ERR, ! "node not found"); ! } ! return node; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Node#getParentNode() ! */ ! public Node getParentNode() { ! return null; ! } ! ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#getDoctype() ! */ ! public DocumentType getDoctype() { ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#getImplementation() ! */ ! public DOMImplementation getImplementation() { ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#getDocumentElement() ! */ ! public Element getDocumentElement() { ! if (size == 1) ! return null; ! int nodeNr = 1; ! while (nodeKind[nodeNr] != Node.ELEMENT_NODE) { ! if (next[nodeNr] < nodeNr) { ! return null; ! } else ! nodeNr = next[nodeNr]; ! } ! return (Element) getNode(nodeNr); ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Node#getFirstChild() ! */ ! public Node getFirstChild() { ! if (size > 1) ! return getNode(1); ! else ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createElement(java.lang.String) ! */ ! public Element createElement(String arg0) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createDocumentFragment() ! */ ! public DocumentFragment createDocumentFragment() { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createTextNode(java.lang.String) ! */ ! public Text createTextNode(String arg0) { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createComment(java.lang.String) ! */ ! public Comment createComment(String arg0) { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createCDATASection(java.lang.String) ! */ ! public CDATASection createCDATASection(String arg0) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createProcessingInstruction(java.lang.String, java.lang.String) ! */ ! public ProcessingInstruction createProcessingInstruction( ! String arg0, ! String arg1) ! throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createAttribute(java.lang.String) ! */ ! public Attr createAttribute(String arg0) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createEntityReference(java.lang.String) ! */ ! public EntityReference createEntityReference(String arg0) ! throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#getElementsByTagName(java.lang.String) ! */ ! public NodeList getElementsByTagName(String arg0) { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#importNode(org.w3c.dom.Node, boolean) ! */ ! public Node importNode(Node arg0, boolean arg1) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createElementNS(java.lang.String, java.lang.String) ! */ ! public Element createElementNS(String arg0, String arg1) ! throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#createAttributeNS(java.lang.String, java.lang.String) ! */ ! public Attr createAttributeNS(String arg0, String arg1) ! throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#getElementsByTagNameNS(java.lang.String, java.lang.String) ! */ ! public NodeList getElementsByTagNameNS(String arg0, String arg1) { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Document#getElementById(java.lang.String) ! */ ! public Element getElementById(String arg0) { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.w3c.dom.Node#getOwnerDocument() ! */ ! public org.w3c.dom.Document getOwnerDocument() { ! return this; ! } ! } --- 40,543 ---- import org.w3c.dom.Text; import org.w3c.dom.Document; + import org.xml.sax.SAXException; + /** + * An in-memory implementation of Document. + * + * This implementation stores all node data in the document object. Nodes from + * another document, i.e. a persistent document in the database, can be stored + * as reference nodes, i.e. the nodes are not copied into this document object. + * Instead a reference is inserted which will only be expanded during + * serialization. + * + * @author wolf + */ public class DocumentImpl extends NodeImpl implements Document { ! protected NamePool namePool = new NamePool(); ! protected short[] nodeKind; ! protected short[] treeLevel; ! protected int[] next; ! protected int[] nodeName; ! protected int[] alpha; ! protected int[] alphaLen; ! protected char[] characters; ! protected int nextChar = 0; ! protected int[] attrName; ! protected int[] attrParent; ! protected String[] attrValue; ! protected int nextAttr = 0; ! protected int size = 1; ! protected int documentRootNode = -1; ! protected NodeProxy references[]; ! protected int nextRef = 0; ! public DocumentImpl(int nodeSize, int attrSize, int charBufSize, int refSize) { ! super(null, 0); ! nodeKind = new short[nodeSize]; ! treeLevel = new short[nodeSize]; ! next = new int[nodeSize]; ! Arrays.fill(next, -1); ! nodeName = new int[nodeSize]; ! alpha = new int[nodeSize]; ! alphaLen = new int[nodeSize]; ! characters = new char[charBufSize]; ! attrName = new int[attrSize]; ! attrParent = new int[attrSize]; ! attrValue = new String[attrSize]; ! references = new NodeProxy[refSize]; ! treeLevel[0] = 0; ! nodeKind[0] = Node.DOCUMENT_NODE; ! document = this; ! } ! public int addNode(short kind, short level, QName qname) { ! if (size == nodeKind.length) grow(); ! nodeKind[size] = kind; ! treeLevel[size] = level; ! nodeName[size] = (qname != null ? namePool.add(qname) : -1); ! alpha[size] = -1; // undefined ! next[size] = -1; ! return size++; ! } ! public void addChars(int nodeNr, char[] ch, int start, int len) { ! if (nextChar + len >= characters.length) { ! int newLen = (characters.length * 3) / 2; ! if (newLen < nextChar + len) newLen = nextChar + len; ! char[] nc = new char[newLen]; ! System.arraycopy(characters, 0, nc, 0, characters.length); ! characters = nc; ! } ! alpha[nodeNr] = nextChar; ! alphaLen[nodeNr] = len; ! System.arraycopy(ch, start, characters, nextChar, len); ! nextChar += len; ! } ! public void addChars(int nodeNr, CharSequence s) { ! int len = s.length(); ! if (nextChar + len >= characters.length) { ! int newLen = (characters.length * 3) / 2; ! if (newLen < nextChar + len) newLen = nextChar + len; ! char[] nc = new char[newLen]; ! System.arraycopy(characters, 0, nc, 0, characters.length); ! characters = nc; ! } ! alpha[nodeNr] = nextChar; ! alphaLen[nodeNr] = len; ! for (int i = 0; i < len; i++) { ! characters[nextChar++] = s.charAt(i); ! } ! } ! public void addReferenceNode(int nodeNr, NodeProxy proxy) { ! if (nextRef == references.length) growReferences(); ! references[nextRef] = proxy; ! alpha[nodeNr] = nextRef++; ! } ! public int addAttribute(int nodeNr, QName qname, String value) ! throws DOMException { ! if (nextAttr == attrName.length) growAttributes(); ! attrParent[nextAttr] = nodeNr; ! attrName[nextAttr] = namePool.add(qname); ! attrValue[nextAttr] = value; ! if (alpha[nodeNr] < 0) alpha[nodeNr] = nextAttr; ! return nextAttr++; ! } ! public int getLastNode() { ! return size - 1; ! } ! private void grow() { ! int newSize = (size * 3) / 2; ! short[] newNodeKind = new short[newSize]; ! System.arraycopy(nodeKind, 0, newNodeKind, 0, size); ! nodeKind = newNodeKind; ! short[] newTreeLevel = new short[newSize]; ! System.arraycopy(treeLevel, 0, newTreeLevel, 0, size); ! treeLevel = newTreeLevel; ! int[] newNext = new int[newSize]; ! Arrays.fill(newNext, -1); ! System.arraycopy(next, 0, newNext, 0, size); ! next = newNext; ! int[] newNodeName = new int[newSize]; ! System.arraycopy(nodeName, 0, newNodeName, 0, size); ! nodeName = newNodeName; ! int[] newAlpha = new int[newSize]; ! System.arraycopy(alpha, 0, newAlpha, 0, size); ! alpha = newAlpha; ! int[] newAlphaLen = new int[newSize]; ! System.arraycopy(alphaLen, 0, newAlphaLen, 0, size); ! alphaLen = newAlphaLen; ! } ! private void growAttributes() { ! int size = attrName.length; ! int newSize = (size * 3) / 2; ! int[] newAttrName = new int[newSize]; ! System.arraycopy(attrName, 0, newAttrName, 0, size); ! attrName = newAttrName; ! int[] newAttrParent = new int[newSize]; ! System.arraycopy(attrParent, 0, newAttrParent, 0, size); ! attrParent = newAttrParent; ! String[] newAttrValue = new String[newSize]; ! System.arraycopy(attrValue, 0, newAttrValue, 0, size); ! attrValue = newAttrValue; ! } ! private void growReferences() { ! int size = references.length; ! int newSize = (size * 3) / 2; ! NodeProxy newReferences[] = new NodeProxy[newSize]; ! System.arraycopy(references, 0, newReferences, 0, size); ! references = newReferences; ! } ! public NodeImpl getNode(int nodeNr) throws DOMException { ! if (nodeNr == 0) return this; ! if (nodeNr >= size) ! throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, ! "node not found"); ! NodeImpl node; ! switch (nodeKind[nodeNr]) { ! case Node.ELEMENT_NODE: ! node = new ElementImpl(this, nodeNr); ! break; ! case Node.TEXT_NODE: ! node = new TextImpl(this, nodeNr); ! break; ! case Node.COMMENT_NODE: ! node = new CommentImpl(this, nodeNr); ! break; ! case Node.PROCESSING_INSTRUCTION_NODE: ! node = new ProcessingInstructionImpl(this, nodeNr); ! break; ! case NodeImpl.REFERENCE_NODE: ! node = new ReferenceNode(this, nodeNr); ! break; ! default: ! throw new DOMException(DOMException.NOT_FOUND_ERR, ! "node not found"); ! } ! return node; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Node#getParentNode() ! */ ! public Node getParentNode() { ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#getDoctype() ! */ ! public DocumentType getDoctype() { ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#getImplementation() ! */ ! public DOMImplementation getImplementation() { ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#getDocumentElement() ! */ ! public Element getDocumentElement() { ! if (size == 1) return null; ! int nodeNr = 1; ! while (nodeKind[nodeNr] != Node.ELEMENT_NODE) { ! if (next[nodeNr] < nodeNr) { ! return null; ! } else ! nodeNr = next[nodeNr]; ! } ! return (Element) getNode(nodeNr); ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Node#getFirstChild() ! */ ! public Node getFirstChild() { ! if (size > 1) ! return getNode(1); ! else ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createElement(java.lang.String) ! */ ! public Element createElement(String arg0) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createDocumentFragment() ! */ ! public DocumentFragment createDocumentFragment() { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createTextNode(java.lang.String) ! */ ! public Text createTextNode(String arg0) { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createComment(java.lang.String) ! */ ! public Comment createComment(String arg0) { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createCDATASection(java.lang.String) ! */ ! public CDATASection createCDATASection(String arg0) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createProcessingInstruction(java.lang.String, ! * java.lang.String) ! */ ! public ProcessingInstruction createProcessingInstruction(String arg0, ! String arg1) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createAttribute(java.lang.String) ! */ ! public Attr createAttribute(String arg0) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createEntityReference(java.lang.String) ! */ ! public EntityReference createEntityReference(String arg0) ! throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#getElementsByTagName(java.lang.String) ! */ ! public NodeList getElementsByTagName(String arg0) { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#importNode(org.w3c.dom.Node, boolean) ! */ ! public Node importNode(Node arg0, boolean arg1) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createElementNS(java.lang.String, ! * java.lang.String) ! */ ! public Element createElementNS(String arg0, String arg1) ! throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#createAttributeNS(java.lang.String, ! * java.lang.String) ! */ ! public Attr createAttributeNS(String arg0, String arg1) throws DOMException { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#getElementsByTagNameNS(java.lang.String, ! * java.lang.String) ! */ ! public NodeList getElementsByTagNameNS(String arg0, String arg1) { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Document#getElementById(java.lang.String) ! */ ! public Element getElementById(String arg0) { ! // TODO Auto-generated method stub ! return null; ! } ! ! /* ! * (non-Javadoc) ! * ! * @see org.w3c.dom.Node#getOwnerDocument() ! */ ! public org.w3c.dom.Document getOwnerDocument() { ! return this; ! } ! ! /** ! * Copy the document fragment starting at the specified node to the given ! * receiver. ! * ! * @param node ! * @param receiver ! */ ! public void copyTo(NodeImpl node, Receiver receiver) throws SAXException { ! NodeImpl top = node; ! while (node != null) { ! startNode(node, receiver); ! NodeImpl nextNode = (NodeImpl) node.getFirstChild(); ! while (nextNode == null) { ! endNode(node, receiver); ! if (top != null && top.nodeNumber == node.nodeNumber) break; ! nextNode = (NodeImpl) node.getNextSibling(); ! if (nextNode == null) { ! node = (NodeImpl) node.getParentNode(); ! if (node == null || (top != null && top.nodeNumber == node.nodeNumber)) { ! endNode(node, receiver); ! nextNode = null; ! break; ! } ! } ! } ! node = nextNode; ! } ! } ! ! private void startNode(NodeImpl node, Receiver receiver) ! throws SAXException { ! int nr = node.nodeNumber; ! switch (nodeKind[nr]) { ! case Node.ELEMENT_NODE: ! QName nodeName = (QName) document.namePool ! .get(document.nodeName[nr]); ! receiver.startElement(nodeName); ! int attr = document.alpha[nr]; ! if (-1 < attr) { ! while (attr < document.nextAttr ! && document.attrParent[attr] == nr) { ! QName attrQName = (QName) document.namePool ! .get(document.attrName[attr]); ! receiver.attribute(attrQName, attrValue[attr]); ! ++attr; ! } ! } ! break; ! case Node.TEXT_NODE: ! receiver.characters(document.characters, document.alpha[nr], ! document.alphaLen[nr]); ! break; ! case Node.COMMENT_NODE: ! receiver.comment(document.characters, document.alpha[nr], ! document.alphaLen[nr]); ! break; ! case Node.PROCESSING_INSTRUCTION_NODE: ! QName qn = (QName) document.namePool.get(document.nodeName[nr]); ! String data = new String(document.characters, ! document.alpha[nr], document.alphaLen[nr]); ! receiver.processingInstruction(qn.getLocalName(), data); ! break; ! case NodeImpl.REFERENCE_NODE: ! receiver ! .addReferenceNode(document.references[document.alpha[nr]]); ! break; ! } ! } ! ! private void endNode(NodeImpl node, Receiver receiver) throws SAXException { ! if(node.getNodeType() == Node.ELEMENT_NODE) ! receiver.endElement(node.getQName()); ! } ! } \ No newline at end of file Index: Receiver.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/memtree/Receiver.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Receiver.java 27 Apr 2004 15:47:01 -0000 1.3 --- Receiver.java 3 May 2004 13:08:43 -0000 1.4 *************** *** 23,26 **** --- 23,27 ---- package org.exist.memtree; + import org.exist.dom.NodeProxy; import org.exist.dom.QName; import org.w3c.dom.Document; *************** *** 29,32 **** --- 30,34 ---- import org.xml.sax.Locator; import org.xml.sax.SAXException; + import org.xml.sax.ext.LexicalHandler; /** *************** *** 35,39 **** * @author Wolfgang <wol...@ex...> */ ! public class Receiver implements ContentHandler { private MemTreeBuilder builder = null; --- 37,41 ---- * @author Wolfgang <wol...@ex...> */ ! public class Receiver implements ContentHandler, LexicalHandler { private MemTreeBuilder builder = null; *************** *** 115,118 **** --- 117,124 ---- builder.endElement(); } + + public void addReferenceNode(NodeProxy proxy) throws SAXException { + builder.addReferenceNode(proxy); + } public void characters(CharSequence seq) throws SAXException { *************** *** 142,147 **** * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String) */ ! public void processingInstruction(String arg0, String arg1) throws SAXException { } --- 148,154 ---- * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String) */ ! public void processingInstruction(String target, String data) throws SAXException { + builder.processingInstruction(target, data); } *************** *** 152,154 **** --- 159,206 ---- } + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#endCDATA() + */ + public void endCDATA() throws SAXException { + // TODO ignored + + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#endDTD() + */ + public void endDTD() throws SAXException { + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#startCDATA() + */ + public void startCDATA() throws SAXException { + // TODO Ignored + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int) + */ + public void comment(char[] ch, int start, int length) throws SAXException { + builder.comment(ch, start, length); + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String) + */ + public void endEntity(String name) throws SAXException { + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String) + */ + public void startEntity(String name) throws SAXException { + } + + /* (non-Javadoc) + * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String) + */ + public void startDTD(String name, String publicId, String systemId) throws SAXException { + } } Index: NodeImpl.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/memtree/NodeImpl.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** NodeImpl.java 2 Mar 2004 08:35:44 -0000 1.12 --- NodeImpl.java 3 May 2004 13:08:43 -0000 1.13 *************** *** 26,29 **** --- 26,30 ---- import org.exist.dom.QName; import org.exist.storage.DBBroker; + import org.exist.storage.serializers.Serializer; import org.exist.util.serializer.DOMStreamer; import org.exist.util.serializer.DOMStreamerPool; *************** *** 47,50 **** --- 48,53 ---- public class NodeImpl implements Node, NodeValue { + public final static short REFERENCE_NODE = 100; + protected int nodeNumber; protected DocumentImpl document; *************** *** 93,96 **** --- 96,118 ---- } + public QName getQName() { + switch (getNodeType()) { + case Node.DOCUMENT_NODE : + return QName.DOCUMENT_QNAME; + case Node.ATTRIBUTE_NODE : + case Node.ELEMENT_NODE : + case Node.PROCESSING_INSTRUCTION_NODE : + QName qn = (QName) + document.namePool.get(document.nodeName[nodeNumber]); + return qn; + case Node.COMMENT_NODE: + return QName.COMMENT_QNAME; + case Node.TEXT_NODE : + return QName.TEXT_QNAME; + default : + return null; + } + } + /* (non-Javadoc) * @see org.w3c.dom.Node#getNodeValue() *************** *** 486,495 **** */ public void toSAX(DBBroker broker, ContentHandler handler) throws SAXException { try { ! DOMStreamer streamer = DOMStreamerPool.getInstance().borrowDOMStreamer(); streamer.setContentHandler(handler); streamer.serialize(this, false); - DOMStreamerPool.getInstance().returnDOMStreamer(streamer); } catch (Exception e) { throw new SAXException(e); } --- 508,523 ---- */ public void toSAX(DBBroker broker, ContentHandler handler) throws SAXException { + DOMStreamer streamer = null; try { ! Serializer serializer = broker.getSerializer(); ! serializer.reset(); ! serializer.setProperty(Serializer.GENERATE_DOC_EVENTS, "false"); ! serializer.setContentHandler(handler); ! streamer = DOMStreamerPool.getInstance().borrowDOMStreamer(serializer); streamer.setContentHandler(handler); streamer.serialize(this, false); } catch (Exception e) { + DOMStreamerPool.getInstance().returnDOMStreamer(streamer); + e.printStackTrace(); throw new SAXException(e); } *************** *** 497,501 **** public void copyTo(DBBroker broker, Receiver receiver) throws SAXException { ! toSAX(broker, receiver); } --- 525,530 ---- public void copyTo(DBBroker broker, Receiver receiver) throws SAXException { ! // toSAX(broker, receiver); ! document.copyTo(this, receiver); } Index: ElementImpl.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/memtree/ElementImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ElementImpl.java 2 Mar 2004 15:30:43 -0000 1.3 --- ElementImpl.java 3 May 2004 13:08:43 -0000 1.4 *************** *** 49,52 **** --- 49,53 ---- document.namePool.get(document.nodeName[nodeNumber]); } + /* (non-Javadoc) * @see org.w3c.dom.Node#hasChildNodes() Index: MemTreeBuilder.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/memtree/MemTreeBuilder.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MemTreeBuilder.java 27 Apr 2004 15:47:02 -0000 1.7 --- MemTreeBuilder.java 3 May 2004 13:08:43 -0000 1.8 *************** *** 25,28 **** --- 25,29 ---- import java.util.Arrays; + import org.exist.dom.NodeProxy; import org.exist.dom.QName; import org.exist.xquery.XQueryContext; *************** *** 68,72 **** */ public void startDocument() { ! this.doc = new DocumentImpl(500, 50, 1000); } --- 69,73 ---- */ public void startDocument() { ! this.doc = new DocumentImpl(500, 50, 1000, 50); } *************** *** 152,155 **** --- 153,167 ---- } + public int addReferenceNode(NodeProxy proxy) { + int nodeNr = doc.addNode(NodeImpl.REFERENCE_NODE, level, null); + doc.addReferenceNode(nodeNr, proxy); + int prevNr = prevNodeInLevel[level]; + if (prevNr > -1) + doc.next[prevNr] = nodeNr; + doc.next[nodeNr] = prevNodeInLevel[level - 1]; + prevNodeInLevel[level] = nodeNr; + return nodeNr; + } + public void addAttribute(QName qname, String value) { int lastNode = doc.getLastNode(); *************** *** 204,207 **** --- 216,230 ---- } + public int comment(char ch[], int start, int len) { + int nodeNr = doc.addNode(Node.COMMENT_NODE, level, null); + doc.addChars(nodeNr, ch, start, len); + int prevNr = prevNodeInLevel[level]; + if (prevNr > -1) + doc.next[prevNr] = nodeNr; + doc.next[nodeNr] = prevNodeInLevel[level - 1]; + prevNodeInLevel[level] = nodeNr; + return nodeNr; + } + public int processingInstruction(String target, String data) { QName qn = new QName(target, null, null); |