📄 xmlcontainer.java
字号:
* @return the content handler which stores all XML data it recieves into the * database. * * @throws IllegalStateException if the underlying document has already been deleted. * @throws IllegalStateException if the current thread has not joined a * {@link org.ozoneDB.ExternalTransaction transaction}. * @see org.ozoneDB.ExternalTransaction * @see org.ozoneDB.ExternalDatabase#newTransaction() */ public ContentHandler storeSAX(Node _pNode) throws Exception { if (helper == null) { throw new IllegalStateException("Document has already been deleted."); } // thread must have joined a transaction if (runsExternal && ((ExternalDatabase) db).currentTransaction() == null) { throw new IllegalStateException("Thread must have joined a transaction!"); } // this eventually blocks if there is another thread storing something already SAXChunkConsumer consumer = helper.beginInputSequence(_pNode); SAXChunkProducer producer = new SAXChunkProducer(this); producer.dbConsumer = consumer; return producer; } /** * This method is for internal use only. <b>Don't call it directly.</b> */ public void processChunk(SAXChunkProducer _producer) throws Exception { if (XMLContainer.debug) { System.out.print("XMLContainer.processChunk()... "); } ChunkOutputStream cos = _producer.chunkStream(); if (XMLContainer.debug) { System.out.print("putChunk(" + cos.count + ")... "); } _producer.dbConsumer = helper.putChunk(cos.toByteArray(), _producer.dbConsumer); } /** * @see #extractDOM(Document, Node, Node , int) */ public Document extractDOM(Document _domFactory) throws Exception { return (Document) extractDOM(_domFactory, (Node) null, null, -1); } /** * @see #extractDOM(Document, Node, Node , int) */ public Node extractDOM(Document _domFactory, Node _pNode, Node _appendTo) throws Exception { return extractDOM(_domFactory, _pNode, _appendTo, -1); } /** * Extracts a given DOM node and all its descendants. * * <p>Before calling this method the current thread <b>must</b> have joined an * {@link org.ozoneDB.ExternalTransaction explicit Transaction}. This is an * exception to the normal case, where an implicit transaction (handled by * Ozone) is more appropriate.</p> * * <p><dl><dt>Note:</dt><dd>If possible, the corresponding * {@link #extractSAX(ContentHandler) SAX method} should be used, because the * performance of SAX retrieval is much better.</dd></dl></p> * * @param _domFactory The DOM Document that is used to create the extracted DOM nodes. * @param _pNode The persistent DOM node * @param _appendTo The transient DOM node where the extracted content will * will be appended to. * @param _depth The number of hierarchy steps that should be extracted or * null if the entire hierarchy should be extracted. */ public Node extractDOM(Document _domFactory, Node _pNode, Node _appendTo, int _depth) throws Exception { ModifiableNodeList mnl = null; if (_pNode != null) { mnl = new ModifiableNodeList(1); mnl.addNode(_pNode); } NodeList resultList = extractDOM(_domFactory, mnl, _appendTo, _depth); return resultList.item(0);/* if (helper == null) { throw new IllegalStateException ("Document has already been deleted."); } // thread must have joined a transaction if (runsExternal && ((ExternalDatabase)db).currentTransaction() == null) { throw new IllegalStateException( "Thread must have joined a transaction!" ); } SAXChunkProducer producer = helper.beginOutputSequence( _pNode, _depth ); SAXChunkConsumer consumer = new SAXChunkConsumer(_domFactory, _appendTo); ChunkOutputStream cos; do { producer = helper.createNextChunk( producer ); cos = producer.chunkStream(); consumer.processChunk( cos.toByteArray() ); cos.reset(); } while (!cos.getEndFlag()); return consumer.getResultNode();*/ } public NodeList extractDOM(Document _domFactory, NodeList _pNodes, Node _appendTo, int _depth) throws Exception { if (helper == null) { throw new IllegalStateException("Document has already been deleted."); } // thread must have joined a transaction if (runsExternal && ((ExternalDatabase) db).currentTransaction() == null) { throw new IllegalStateException("Thread must have joined a transaction!"); } SAXChunkProducer producer = helper.beginOutputSequence(_pNodes, _depth); SAXChunkConsumer consumer = new SAXChunkConsumer(_domFactory, _appendTo); ChunkOutputStream cos; do { producer = helper.createNextChunk(producer); cos = producer.chunkStream(); consumer.processChunk(cos.toByteArray()); cos.reset(); } while (!cos.getEndFlag()); return consumer.getResultNodeList(); } /** * @see #extractSAX(ContentHandler, Node, int) */ public void extractSAX(ContentHandler _contentHandler) throws Exception { extractSAX(_contentHandler, null, -1); } /** * @see #extractSAX(ContentHandler, Node , int ) */ public void extractSAX(ContentHandler _contentHandler, Node _pNode) throws Exception { extractSAX(_contentHandler, _pNode, -1); } /** * Extracts a given DOM node and all its descendants. * * <p>Before calling this method the current thread <b>must</b> have joined an * {@link org.ozoneDB.ExternalTransaction explicit Transaction}. This is an * exception to the normal case, where an implicit transaction (handled by * Ozone) is more appropriate.</p> * * @param _contentHandler The ContentHandler that will receive the generated * SAX events. * @param _pNode The persistent DOM node that is the starting point, or null * if the entire document should be extracted. * @param _depth The number of hierarchy steps that should be extracted or * null if the entire hierarchy should be extracted. */ public void extractSAX(ContentHandler _contentHandler, Node _pNode, int _depth) throws Exception { if (helper == null) { throw new IllegalStateException("Document has already been deleted."); } // thread must have joined a transaction if (runsExternal && ((ExternalDatabase) db).currentTransaction() == null) { throw new IllegalStateException("Thread must have joined a transaction!"); } ModifiableNodeList mnl = null; if (_pNode != null) { mnl = new ModifiableNodeList(1); mnl.addNode(_pNode); } SAXChunkProducer producer = helper.beginOutputSequence(mnl, _depth); SAXChunkConsumer consumer = new SAXChunkConsumer(_contentHandler); ChunkOutputStream cos; do { producer = helper.createNextChunk(producer); cos = producer.chunkStream(); consumer.processChunk(cos.toByteArray()); cos.reset(); } while (!cos.getEndFlag()); } /** * Create a new XUpdate query. XUpdate is a descriptive XML update * language. XUpdate is the recommended way to change a document in the * database. See <a href=http://www.xmldb.org>www.xmldb.org</a> for more * information and some XUpdate documentation. * * @see OzoneXUpdateQuery */ public OzoneXUpdateQuery newXUpdateQuery() { return new OzoneXUpdateQuery(this); } /** * Create a new XPath query. * * @see OzoneXPathQuery */ public OzoneXPathQuery newXPathQuery() { return new OzoneXPathQuery(this); } protected void executeXUpdate(OzoneXUpdateQuery _query) throws Exception { if (_query == null) { throw new IllegalArgumentException("_query == null."); } helper.executeXUpdate(_query); } protected XObject executeXPath(OzoneXPathQuery _query) throws Exception { if (_query == null) { throw new IllegalArgumentException("_query == null."); } return helper.executeXPath(_query); } /** * Determines the absolute XPath for the given node. * * @param _pnode The W3C DOM node whose XPath is to determine. * @return The string representing the absolute XPath for this node. */ public String xpathForNode(Node _pnode) { if (helper == null) { throw new IllegalStateException("Document has already been deleted."); } return helper.xpathForNode(_pnode); } public void writeExternal(ObjectOutput _out) throws IOException { if (runsExternal) { throw new IllegalStateException("XMLContainer cannot be serialized outside an ozone server."); } _out.writeObject(helper); } public void readExternal(ObjectInput _in) throws IOException, ClassNotFoundException { if (runsExternal) { throw new IllegalStateException("XMLContainer cannot be deserialized outside an ozone server."); } helper = (XMLContainerHelper) _in.readObject(); db = org.ozoneDB.core.Env.currentEnv().database; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -