Examples of DBBroker


Examples of org.exist.storage.DBBroker

     * The method <code>getNodeValueSeparated</code>
     *
     * @return a <code>String</code> value
     */
    public String getNodeValueSeparated() {
        DBBroker broker = null;
        try {
            broker = doc.getBrokerPool().get(null);
            return broker.getNodeValue(new StoredNode(this), true);
        } catch (final EXistException e) {
            //TODO : raise an exception here !
        } finally {
            doc.getBrokerPool().release(broker);
        }
View Full Code Here

Examples of org.exist.storage.DBBroker

    public Node appendChild(Node child) throws DOMException {
        final TransactionManager transact = ownerDocument.getBrokerPool().getTransactionManager();
        final Txn transaction = transact.beginTransaction();
        final NodeListImpl nl = new NodeListImpl();
        nl.add(child);
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            appendChildren(transaction, nl, 0);
            broker.storeXMLResource(transaction, (DocumentImpl) getOwnerDocument());
            transact.commit(transaction); // bugID 3419602
            return getLastChild();
        } catch (final Exception e) {
            transact.abort(transaction);
            throw new DOMException(DOMException.INVALID_STATE_ERR, e.getMessage());
        } finally {
          if (broker != null) {
            try {
              transact.close(transaction);
            } finally {
              broker.release();
            }
          }
        }
    }
View Full Code Here

Examples of org.exist.storage.DBBroker

    public void appendChildren(Txn transaction, NodeList nodes, int child) throws DOMException {
        // attributes are handled differently. Call checkForAttributes to extract them.
        nodes = checkForAttributes(transaction, nodes);
        if (nodes == null || nodes.getLength() == 0)
            {return;}
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            final NodePath path = getPath();
            StreamListener listener = null;
            //May help getReindexRoot() to make some useful things
            broker.getIndexController().setDocument(ownerDocument);
            StoredNode reindexRoot = broker.getIndexController().getReindexRoot(this, path, true, true);
            broker.getIndexController().setMode(StreamListener.STORE);
            // only reindex if reindexRoot is an ancestor of the current node
            if (reindexRoot == null) {
                listener = broker.getIndexController().getStreamListener();
            }
            if (children == 0) {
                // no children: append a new child
                appendChildren(transaction, nodeId.newChild(), null, new NodeImplRef(this), path, nodes, listener);
            } else {
                if (child == 1) {
                    final Node firstChild = getFirstChild();
                    insertBefore(transaction, nodes, firstChild);
                } else {
                    if (child > 1 && child <= children) {
                        final NodeList cl = getChildNodes();
                        final StoredNode last = (StoredNode) cl.item(child - 2);
                        insertAfter(transaction, nodes, last);
                    } else {
                        final StoredNode last = (StoredNode) getLastChild();
                        appendChildren(transaction, last.getNodeId().nextSibling(), null,
                                new NodeImplRef(getLastNode(last)), path, nodes, listener);
                    }
                }
            }
            broker.updateNode(transaction, this, false);
            broker.getIndexController().reindex(transaction, reindexRoot, StreamListener.STORE);
            broker.flush();
        } catch (final EXistException e) {
            LOG.warn("Exception while appending child node: " + e.getMessage(), e);
        } finally {
          if (broker != null)
            broker.release();
        }
    }
View Full Code Here

Examples of org.exist.storage.DBBroker

            throws DOMException {
        if (last == null || last.getNode() == null)
            //TODO : same test as above ? -pb
            {throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "invalid node");}
        final DocumentImpl owner = (DocumentImpl)getOwnerDocument();
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            switch (child.getNodeType()) {
                case Node.DOCUMENT_FRAGMENT_NODE :
                    appendChildren(transaction, newNodeId, null, last, lastPath,
                        child.getChildNodes(), listener);
                    return null; // TODO: implement document fragments so
                    //we can return all newly appended children
                case Node.ELEMENT_NODE :
                    // create new element
                    final ElementImpl elem =
                        new ElementImpl(
                            new QName(child.getLocalName() == null ?
                                child.getNodeName() : child.getLocalName(),
                            child.getNamespaceURI(),
                            child.getPrefix()),
                            broker.getBrokerPool().getSymbols()
                        );
                    elem.setNodeId(newNodeId);
                    elem.setOwnerDocument(owner);
                    final NodeListImpl ch = new NodeListImpl();
                    final NamedNodeMap attribs = child.getAttributes();
                    int numActualAttribs = 0;
                    for (int i = 0; i < attribs.getLength(); i++) {
                        final Attr attr = (Attr) attribs.item(i);
                        if (!attr.getNodeName().startsWith("xmlns")) {
                            ch.add(attr);
                            numActualAttribs++;
                        } else {
                            final String xmlnsDecl = attr.getNodeName();
                            final String prefix = xmlnsDecl.length() == 5 ? "" : xmlnsDecl.substring(6);
                            elem.addNamespaceMapping(prefix,attr.getNodeValue());
                        }
                    }
                    final NodeList cl = child.getChildNodes();
                    for (int i = 0; i < cl.getLength(); i++) {
                        final Node n = cl.item(i);
                        if (n.getNodeType() != Node.ATTRIBUTE_NODE)
                            {ch.add(n);}
                    }
                    elem.setChildCount(ch.getLength());
                    if (numActualAttribs != (short) numActualAttribs)
                        {throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "Too many attributes");}
                    elem.setAttributes((short) numActualAttribs);
                    lastPath.addComponent(elem.getQName());
                    // insert the node
                    broker.insertNodeAfter(transaction, last.getNode(), elem);
                    broker.indexNode(transaction, elem, lastPath);
                    broker.getIndexController().indexNode(transaction, elem, lastPath, listener);
                    elem.setChildCount(0);
                    last.setNode(elem);
                    //process child nodes
                    elem.appendChildren(transaction, newNodeId.newChild(), null, last, lastPath, ch, listener);
                    broker.endElement(elem, lastPath, null);
                    broker.getIndexController().endElement(transaction, elem, lastPath, listener);
                    lastPath.removeLastComponent();
                    return elem;
                case Node.TEXT_NODE :
                    final TextImpl text = new TextImpl(newNodeId, ((Text) child).getData());
                    text.setOwnerDocument(owner);
                    // insert the node
                    broker.insertNodeAfter(transaction, last.getNode(), text);
                    broker.indexNode(transaction, text, lastPath);
                    broker.getIndexController().indexNode(transaction, text, lastPath, listener);
                    last.setNode(text);
                    return text;
                case Node.CDATA_SECTION_NODE :
                    final CDATASectionImpl cdata = new CDATASectionImpl(newNodeId, ((CDATASection) child).getData());
                    cdata.setOwnerDocument(owner);
                    // insert the node
                    broker.insertNodeAfter(transaction, last.getNode(), cdata);
                    broker.indexNode(transaction, cdata, lastPath);
                    last.setNode(cdata);
                    return cdata;
                case Node.ATTRIBUTE_NODE:
                    final Attr attr = (Attr) child;
                    final String ns = attr.getNamespaceURI();
                    final String prefix = (Namespaces.XML_NS.equals(ns) ? "xml" : attr.getPrefix());
                    String name = attr.getLocalName();
                    if (name == null) {name = attr.getName();}
                    final QName attrName = new QName(name, ns, prefix);
                    final AttrImpl attrib = new AttrImpl(attrName, attr.getValue(), broker.getBrokerPool().getSymbols());
                    attrib.setNodeId(newNodeId);
                    attrib.setOwnerDocument(owner);
                    if (ns != null && attrName.compareTo(Namespaces.XML_ID_QNAME) == Constants.EQUAL) {
                        // an xml:id attribute. Normalize the attribute and set its type to ID
                        attrib.setValue(StringValue.trimWhitespace(StringValue.collapseWhitespace(attrib.getValue())));
                        attrib.setType(AttrImpl.ID);
                    } else {
                        attrName.setNameType(ElementValue.ATTRIBUTE);
                    }
                    broker.insertNodeAfter(transaction, last.getNode(), attrib);
                    broker.indexNode(transaction, attrib, lastPath);
                    broker.getIndexController().indexNode(transaction, attrib, lastPath, listener);
                    last.setNode(attrib);
                    return attrib;
                case Node.COMMENT_NODE:
                    final CommentImpl comment = new CommentImpl(((Comment) child).getData());
                    comment.setNodeId(newNodeId);
                    comment.setOwnerDocument(owner);
                    // insert the node
                    broker.insertNodeAfter(transaction, last.getNode(), comment);
                    broker.indexNode(transaction, comment, lastPath);
                    last.setNode(comment);
                    return comment;
                case Node.PROCESSING_INSTRUCTION_NODE:
                    final ProcessingInstructionImpl pi =
                        new ProcessingInstructionImpl(newNodeId,
                            ((ProcessingInstruction) child).getTarget(),
                            ((ProcessingInstruction) child).getData());
                    pi.setOwnerDocument(owner);
                    //insert the node
                    broker.insertNodeAfter(transaction, last.getNode(), pi);
                    broker.indexNode(transaction, pi, lastPath);
                    last.setNode(pi);
                    return pi;
                default :
                    throw new DOMException(DOMException.INVALID_MODIFICATION_ERR,
                        "Unknown node type: " +
                        child.getNodeType() + " " + child.getNodeName());
            }
        } catch (final EXistException e) {
            LOG.warn("Exception while appending node: " + e.getMessage(), e);
        } finally {
          if (broker != null)
            broker.release();
        }
        return null;
    }
View Full Code Here

Examples of org.exist.storage.DBBroker

     */
    @Override
    public NamedNodeMap getAttributes() {
        final NamedNodeMapImpl map = new NamedNodeMapImpl();
        if (getAttributesCount() > 0) {
            DBBroker broker = null;
            try {
                broker = ownerDocument.getBrokerPool().get(null);
                final Iterator<StoredNode> iterator = broker.getNodeIterator(this);
                iterator.next();
                final int ccount = getChildCount();
                for (int i = 0; i < ccount; i++) {
                    final StoredNode next = iterator.next();
                    if (next.getNodeType() != Node.ATTRIBUTE_NODE)
                        {break;}
                    map.setNamedItem(next);
                }
            } catch (final EXistException e) {
                LOG.warn("Exception while retrieving attributes: " + e.getMessage());
            } finally {
              if (broker != null)
                broker.release();
            }
        }
        if (declaresNamespacePrefixes()) {
            for (final Iterator<Map.Entry<String, String>> i =
                    namespaceMappings.entrySet().iterator(); i.hasNext(); ) {
View Full Code Here

Examples of org.exist.storage.DBBroker

        }
        return map;
    }

    private AttrImpl findAttribute(String qname) {
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            final Iterator<StoredNode> iterator = broker.getNodeIterator(this);
            iterator.next();
            return findAttribute(qname, iterator, this);
        } catch (final EXistException e) {
            LOG.warn("Exception while retrieving attributes: " + e.getMessage());
        } finally {
          if (broker != null)
            broker.release();
        }
        return null;
    }
View Full Code Here

Examples of org.exist.storage.DBBroker

        }
        return null;
    }

    private AttrImpl findAttribute(QName qname) {
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            final Iterator<StoredNode> iterator = broker.getNodeIterator(this);
            iterator.next();
            return findAttribute(qname, iterator, this);
        } catch (final EXistException e) {
            LOG.warn("Exception while retrieving attributes: " + e.getMessage());
        } finally {
          if (broker != null)
            broker.release();
        }
        return null;
    }
View Full Code Here

Examples of org.exist.storage.DBBroker

    }

    @Override
    public NodeList getChildNodes() {
        final NodeListImpl childList = new NodeListImpl(1);
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            for (final EmbeddedXMLStreamReader reader = broker.getXMLStreamReader(this, true);
                    reader.hasNext();) {
                final int status = reader.next();
                if (status != XMLStreamConstants.END_ELEMENT) {
                    if (((NodeId) reader.getProperty(ExtendedXMLStreamReader.PROPERTY_NODE_ID)).isChildOf(nodeId))
                        {childList.add(reader.getNode());}
                }
            }
        } catch (final IOException e) {
            LOG.warn("Internal error while reading child nodes: " + e.getMessage(), e);
        } catch (final XMLStreamException e) {
            LOG.warn("Internal error while reading child nodes: " + e.getMessage(), e);
        } catch (final EXistException e) {
            LOG.warn("Internal error while reading child nodes: " + e.getMessage(), e);
        } finally {
          if (broker != null)
            broker.release();
        }
        return childList;
    }
View Full Code Here

Examples of org.exist.storage.DBBroker

     */
    @Override
    public Node getFirstChild() {
        if (!hasChildNodes() || getChildCount() == getAttributesCount())
            {return null;}
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            final Iterator<StoredNode> iterator = broker.getNodeIterator(this);
            iterator.next();
            StoredNode next;
            for (int i = 0; i < getChildCount(); i++) {
                next = iterator.next();
                if (next.getNodeType() != Node.ATTRIBUTE_NODE)
                    {return next;}
            }
        } catch (final EXistException e) {
            LOG.warn("Exception while retrieving child node: " + e.getMessage(), e);
        } finally {
          if (broker != null)
            broker.release();
        }
        return null;
    }
View Full Code Here

Examples of org.exist.storage.DBBroker

   
    //TODO getNodeValue() on org.exist.dom.ElementImpl should return null according to W3C spec, and getTextContent() should be implemented!
    @Override
    public String getNodeValue() /*throws DOMException*/ {
        //TODO : parametrize the boolean value ?
        DBBroker broker = null;
        try {
            broker = ownerDocument.getBrokerPool().get(null);
            return broker.getNodeValue(this, false);
        } catch (final EXistException e) {
            LOG.warn("Exception while reading node value: " + e.getMessage(), e);
        } finally {
          if (broker != null)
            broker.release();
        }
        return "";
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.