Package org.exist.dom

Examples of org.exist.dom.StoredNode


                                                e.printStackTrace();
                                                return( new ErrorReport.IndexError( ErrorReport.DOM_INDEX, "Failed to access node " + nodeId + " through dom.dbx index.", e, doc.getDocId() ) );
                                            }
                                        }

                                        final StoredNode node = reader.getNode();
                                        if( node.getNodeType() != Node.ELEMENT_NODE ) {
                                            return( new org.exist.backup.ErrorReport.ResourceError( ErrorReport.INCORRECT_NODE_TYPE, "Expected an element node, received node of type " + node.getNodeType() ) );
                                        }
                                        elementStack.push( new ElementNode( (ElementImpl)node ) );
                                        attribsAllowed  = true;
                                        attributeCount  = 0;
                                        expectedAttribs = reader.getAttributeCount();
View Full Code Here


                LOG.warn("Failed to acquire read lock on " + db.getFile().getName());
                //TODO : throw exception here ? -pb
                return null;
            }
            db.setOwnerObject(broker);
            StoredNode nextNode = null;
            if (gotoNextPosition()) {
                long backLink = 0;
                do {
                    final DOMFile.DOMFilePageHeader pageHeader = page.getPageHeader();
                    //Next value larger than length of the current page?
                    if (offset >= pageHeader.getDataLength()) {
                        //Load next page in chain
                        long nextPageNum = pageHeader.getNextDataPage();
                        if (nextPageNum == Page.NO_PAGE) {
                            SanityCheck.TRACE("bad link to next " + page.page.getPageInfo() +
                                "; previous: " + pageHeader.getPreviousDataPage() +
                                "; offset = " + offset + "; lastTupleID = " + lastTupleID);
                            System.out.println(db.debugPageContents(page));
                            //TODO : throw exception here ? -pb
                            return null;
                        }
                        pageNum = nextPageNum;
                        page = db.getDOMPage(nextPageNum);
                        db.addToBuffer(page);
                        offset = 0;
                    }
                    //Extract the tuple ID
                    lastTupleID = ByteConversion.byteToShort(page.data, offset);
                    offset += DOMFile.LENGTH_TID;
                    //Check if this is just a link to a relocated node
                    if(ItemId.isLink(lastTupleID)) {
                        //Skip this
                        offset += DOMFile.LENGTH_FORWARD_LOCATION;
                        //Continue the iteration
                        continue;
                    }
                    //Read data length
                    short vlen = ByteConversion.byteToShort(page.data, offset);
                    offset += DOMFile.LENGTH_DATA_LENGTH;
                    if (vlen < 0) {
                        LOG.error("Got negative length" + vlen + " at offset " + offset + "!!!");
                        LOG.debug(db.debugPageContents(page));
                        //TODO : throw an exception right now ?
                    }
                    if(ItemId.isRelocated(lastTupleID)) {
                        //Found a relocated node. Read the original address
                        backLink = ByteConversion.byteToLong(page.data, offset);
                        offset += DOMFile.LENGTH_ORIGINAL_LOCATION;
                    }
                    //Overflow page? Load the overflow value
                    if (vlen == DOMFile.OVERFLOW) {
                        vlen = DOMFile.LENGTH_OVERFLOW_LOCATION;
                        final long overflow = ByteConversion.byteToLong(page.data, offset);
                        offset += DOMFile.LENGTH_OVERFLOW_LOCATION;
                        try {
                            final byte[] overflowValue = db.getOverflowValue(overflow);
                            nextNode = StoredNode.deserialize(overflowValue, 0, overflowValue.length,
                                doc, useNodePool);
                        } catch(final Exception e) {
                            LOG.warn("Exception while loading overflow value: " + e.getMessage() +
                                "; originating page: " + page.page.getPageInfo());
                            //TODO : rethrow exception ? -pb
                        }
                    //Normal node
                    } else {
                        try {
                            nextNode = StoredNode.deserialize(page.data, offset, vlen, doc, useNodePool);
                            offset += vlen;
                        } catch(final Exception e) {
                            LOG.error("Error while deserializing node: " + e.getMessage(), e);
                            LOG.error("Reading from offset: " + offset + "; len = " + vlen);
                            LOG.debug(db.debugPageContents(page));
                            System.out.println(db.debugPageContents(page));
                            throw new RuntimeException(e);
                        }
                    }
                    if (nextNode == null) {
                        LOG.error("illegal node on page " + page.getPageNum() +
                            "; tid = " + ItemId.getId(lastTupleID) +
                            "; next = " + page.getPageHeader().getNextDataPage() +
                            "; prev = " + page.getPageHeader().getPreviousDataPage() +
                            "; offset = " + (offset - vlen) +
                            "; len = " + page.getPageHeader().getDataLength());
                        System.out.println(db.debugPageContents(page));
                        //TODO : throw an exception here ? -pb
                        return null;
                    }
                    if (ItemId.isRelocated(lastTupleID)) {
                        nextNode.setInternalAddress(backLink);
                    } else {
                        nextNode.setInternalAddress(StorageAddress.createPointer((int) pageNum,
                            ItemId.getId(lastTupleID)));
                    }
                    nextNode.setOwnerDocument(doc);
                } while (nextNode == null);
            }
            return nextNode;
        } catch (final BTreeException e) {
            LOG.error(e.getMessage(), e);
View Full Code Here

                    //The broker has no right on the document
                    LOG.error(e);
                    return false;
                }
                NodeId nodeId = new DLN(rs.getInt("NODE_ID_UNITS"), rs.getBytes("NODE_ID"), 0);
                StoredNode node = broker.objectWith(new NodeProxy(doc, nodeId));
                if (node == null) {
                    LOG.info("Node " + nodeId + "doesn't exist");
                    return false;
                }
                if (!AbstractGMLJDBCIndexWorker.GML_NS.equals(node.getNamespaceURI())) {
                    LOG.info("GML indexed node (" + node.getNodeId()+ ") is in the '" +
                            node.getNamespaceURI() + "' namespace. '" +
                            AbstractGMLJDBCIndexWorker.GML_NS + "' was expected !");
                    return false;
                }
                if (!original_geometry.getGeometryType().equals(node.getLocalName())) {
                    if ("Box".equals(node.getLocalName()) && "Polygon".equals(original_geometry.getGeometryType())) {
                        LOG.debug("GML indexed node (" + node.getNodeId() + ") is a gml:Box indexed as a polygon");
                    } else {
                        LOG.info("GML indexed node (" + node.getNodeId() + ") has '" +
                            node.getLocalName() + "' as its local name. '" +
                            original_geometry.getGeometryType() + "' was expected !");
                        return false;
                    }
                }
                LOG.info(node);
View Full Code Here

                    NodeId nodeId = reader.getAttributeId(i);

                    // check if an attribute has to be inserted before the current attribute
                    ElementImpl insertedNode = insertedNodes.get(nodeId);
                    if (insertedNode != null) {
                        StoredNode child = (StoredNode) insertedNode.getFirstChild();
                        while (child != null) {
                            if (StandardDiff.NAMESPACE.equals(child.getNamespaceURI()) && "attribute".equals(child.getLocalName())) {
                                NamedNodeMap map = child.getAttributes();
                                for (int j = 0; j < map.getLength(); j++) {
                                    AttrImpl attr = (AttrImpl) map.item(j);
                                    if (!attr.getName().startsWith("xmlns"))
                                        attrs.addAttribute(attr.getQName(), attr.getValue(),
                                                attr.getType(), attr.getNodeId());
                                }
                            }
                            child = (StoredNode) child.getNextSibling();
                        }
                    }

                    if (deletedNodes.get(nodeId) == null) {
                        QName attrQn = new QName(reader.getAttributeLocalName(i), reader.getAttributeNamespace(i),
View Full Code Here

        // acquire a lock on all documents
          // we have to avoid that node positions change
          // during the modification
          lockedDocuments.lock(broker, true, false);
         
        final StoredNode ql[] = new StoredNode[nl.getLength()];       
      for (int i = 0; i < ql.length; i++) {
        ql[i] = (StoredNode)nl.item(i);
        final DocumentImpl doc = (DocumentImpl)ql[i].getOwnerDocument();
       
        // call the eventual triggers
View Full Code Here

      final IndexListener listener = new IndexListener(ql);
      final NotificationService notifier = broker.getBrokerPool()
          .getNotificationService();
      NodeImpl parent;
      for (int i = 0; i < ql.length; i++) {
        final StoredNode node = ql[i];
                final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
        if (!doc.getPermissions().validate(broker.getSubject(),
            Permission.WRITE)) {
                    throw new PermissionDeniedException("User '" + broker.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                                }
        doc.getMetadata().setIndexListener(listener);
        parent = (NodeImpl) node.getParentNode();
                if (parent == null || parent.getNodeType() != Node.ELEMENT_NODE) {
          throw new EXistException(
              "you cannot remove the document element. Use update "
                  + "instead");
        } else
View Full Code Here

      final NodeList children = content;
      if(children.getLength() == 0)
          {return 0;}
   
      try {
          final StoredNode ql[] = selectAndLock(transaction);
      final IndexListener listener = new IndexListener(ql);
      final NotificationService notifier = broker.getBrokerPool().getNotificationService();
      for(int i = 0; i < ql.length; i++) {
        final StoredNode node = ql[i];
        final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
        doc.getMetadata().setIndexListener(listener);
        if (!doc.getPermissions().validate(broker.getSubject(), Permission.WRITE)) {
          throw new PermissionDeniedException("User '" + broker.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                                }
                node.appendChildren(transaction, children, child);
                doc.getMetadata().clearIndexListener();
                doc.getMetadata().setLastModified(System.currentTimeMillis());
                modifiedDocuments.add(doc);
                broker.storeXMLResource(transaction, doc);
                notifier.notifyUpdate(doc, UpdateListener.UPDATE);
View Full Code Here

        if (children.getLength() > 1)
          {throw new EXistException("xupdate:replace requires exactly one content node");}
        LOG.debug("processing replace ...");
        int modifications = children.getLength();
        try {
            final StoredNode ql[] = selectAndLock(transaction);
            final IndexListener listener = new IndexListener(ql);
            final NotificationService notifier = broker.getBrokerPool().getNotificationService();
            Node temp;
            TextImpl text;
            AttrImpl attribute;
            ElementImpl parent;
            for (int i = 0; i < ql.length; i++) {
                final StoredNode node = ql[i];
                if (node == null) {
                    LOG.warn("select " + selectStmt + " returned empty node set");
                    continue;
                }
                final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
                doc.getMetadata().setIndexListener(listener);
                if (!doc.getPermissions().validate(broker.getSubject(), Permission.WRITE)) {
                        throw new PermissionDeniedException("User '" + broker.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                }
                parent = (ElementImpl) node.getParentStoredNode();
                if (parent == null)
                    {throw new EXistException("The root element of a document can not be replaced with 'xu:replace'. " +
                        "Please consider removing the document or use 'xu:update' to just replace the children of the root.");}
                switch (node.getNodeType()) {
                    case Node.ELEMENT_NODE:
                        if (modifications == 0) {modifications = 1;}
                        temp = children.item(0);
                        parent.replaceChild(transaction, temp, node);
                        break;
View Full Code Here

            NodeImpl parent;            
            final int len = children.getLength();
            if (LOG.isDebugEnabled())
                {LOG.debug("found " + len + " nodes to insert");}
            for (int i = 0; i < ql.length; i++) {
                final StoredNode node = ql[i];
                final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
                doc.getMetadata().setIndexListener(listener);
                if (!doc.getPermissions().validate(broker.getSubject(), Permission.WRITE)) {
                        throw new PermissionDeniedException("permission to update document denied");
                }
                parent = (NodeImpl) node.getParentNode();
                switch (mode) {
                    case INSERT_BEFORE:
                        parent.insertBefore(transaction, children, node);
                        break;
                    case INSERT_AFTER:
View Full Code Here

            NodeImpl parent;
            final IndexListener listener = new IndexListener(ql);
            final NotificationService notifier = broker.getBrokerPool().getNotificationService();
            final String newName = children.item(0).getNodeValue();
            for (int i = 0; i < ql.length; i++) {
                final StoredNode node = ql[i];
                final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
                if (!doc.getPermissions().validate(broker.getSubject(), Permission.WRITE)) {
                        throw new PermissionDeniedException("User '" + broker.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                }
                doc.getMetadata().setIndexListener(listener);
                parent = (NodeImpl) node.getParentNode();
                switch (node.getNodeType()) {
                    case Node.ELEMENT_NODE:
                        final ElementImpl newElem = new ElementImpl((ElementImpl) node);
                        newElem.setNodeName(new QName(newName, "", null));
                        parent.updateChild(transaction, node, newElem);
                        modificationCount++;
View Full Code Here

TOP

Related Classes of org.exist.dom.StoredNode

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.