Package org.exist.storage

Examples of org.exist.storage.NotificationService


            {return 0;}
        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");
                    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() + "'!");
                }
                switch (node.getNodeType()) {
                    case Node.ELEMENT_NODE:
                        if (modifications == 0) {modifications = 1;}
                        ((ElementImpl) node).update(transaction, children);
                        break;
                    case Node.TEXT_NODE:
                        parent = (ElementImpl) node.getParentNode();
                      temp = children.item(0);
                      text = new TextImpl(temp.getNodeValue());
                        modifications = 1;
                        text.setOwnerDocument(doc);
                        parent.updateChild(transaction, node, text);
                        break;
                    case Node.ATTRIBUTE_NODE:
                        parent = (ElementImpl) node.getParentNode();
                        if (parent == null) {
                            LOG.warn("parent node not found for "
                                    + node.getNodeId());
                            break;
                        }
                        final AttrImpl attr = (AttrImpl) node;
                        temp = children.item(0);
                        attribute = new AttrImpl(attr.getQName(), temp.getNodeValue(), broker.getBrokerPool().getSymbols());
                        attribute.setOwnerDocument(doc);
                        parent.updateChild(transaction, node, attribute);
                        break;
                    default:
                        throw new EXistException("unsupported node-type");
                }
                doc.getMetadata().clearIndexListener();
                doc.getMetadata().setLastModified(System.currentTimeMillis());
                modifiedDocuments.add(doc);
                broker.storeXMLResource(transaction, doc);
                notifier.notifyUpdate(doc, UpdateListener.UPDATE);
            }
            checkFragmentation(transaction, modifiedDocuments);
        } finally {
            unlockDocuments(transaction);
        }
View Full Code Here


  public long process(Txn transaction) throws PermissionDeniedException,
      LockException, EXistException, XPathException, TriggerException {
    try {
      final StoredNode[] ql = selectAndLock(transaction);
      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
          {parent.removeChild(transaction, node);}
        doc.getMetadata().clearIndexListener();
        doc.getMetadata().setLastModified(System.currentTimeMillis());
        modifiedDocuments.add(doc);
        broker.storeXMLResource(transaction, doc);
        notifier.notifyUpdate(doc, UpdateListener.UPDATE);
            }
      checkFragmentation(transaction, modifiedDocuments);
      return ql.length;
    } finally {
      unlockDocuments(transaction);
View Full Code Here

          {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);
      }
      checkFragmentation(transaction, modifiedDocuments);
      return ql.length;
      } finally {
          // release all acquired locks
View Full Code Here

        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;
                    case Node.TEXT_NODE:
                        temp = children.item(0);
                        text = new TextImpl(temp.getNodeValue());
                        modifications = 1;
                        text.setOwnerDocument(doc);
                        parent.updateChild(transaction, node, text);
                        break;
                    case Node.ATTRIBUTE_NODE:
                        final AttrImpl attr = (AttrImpl) node;
                        temp = children.item(0);
                        attribute = new AttrImpl(attr.getQName(), temp.getNodeValue(), broker.getBrokerPool().getSymbols());
                        attribute.setOwnerDocument(doc);
                        parent.updateChild(transaction, node, attribute);
                        break;
                    default:
                        throw new EXistException("unsupported node-type");
                }
                doc.getMetadata().clearIndexListener();
                doc.getMetadata().setLastModified(System.currentTimeMillis());
                modifiedDocuments.add(doc);
                broker.storeXMLResource(transaction, doc);
                notifier.notifyUpdate(doc, UpdateListener.UPDATE);
            }
            checkFragmentation(transaction, modifiedDocuments);
        } finally {
            unlockDocuments(transaction);
        }
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();      
            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:
                        parent.insertAfter(transaction, children, node);
                        break;
                }
                doc.getMetadata().clearIndexListener();
                doc.getMetadata().setLastModified(System.currentTimeMillis());
                modifiedDocuments.add(doc);
                broker.storeXMLResource(transaction, doc);
                notifier.notifyUpdate(doc, UpdateListener.UPDATE);
            }
            checkFragmentation(transaction, modifiedDocuments);
            return ql.length;
        } finally {
            unlockDocuments(transaction);
View Full Code Here

        int modificationCount = 0;
        try {
            final StoredNode[] ql = selectAndLock(transaction);
            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++;
                        break;
                    case Node.ATTRIBUTE_NODE:
                        final AttrImpl newAttr = new AttrImpl((AttrImpl) node);
                        newAttr.setNodeName(new QName(newName, "", null));
                        parent.updateChild(transaction, node, newAttr);
                        modificationCount++;
                        break;
                    default:
                        throw new EXistException("unsupported node-type");
                }

                doc.getMetadata().clearIndexListener();
                doc.getMetadata().setLastModified(System.currentTimeMillis());
                modifiedDocuments.add(doc);
                broker.storeXMLResource(transaction, doc);
                notifier.notifyUpdate(doc, UpdateListener.UPDATE);
            }
            checkFragmentation(transaction, modifiedDocuments);
        } finally {
            unlockDocuments(transaction);
        }
View Full Code Here

       
    if (!inSeq.isEmpty()) {
            //start a transaction
            final Txn transaction = getTransaction();
        try {
          final NotificationService notifier = context.getBroker().getBrokerPool().getNotificationService();
                final StoredNode[] ql = selectAndLock(transaction, inSeq);
                final IndexListener listener = new IndexListener(ql);
                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(context.getUser(), Permission.WRITE)) {
                        //transact.abort(transaction);   
                        throw new PermissionDeniedException("User '" + context.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                    }
                    doc.getMetadata().setIndexListener(listener);
                   
                    //update the document
                    parent = (NodeImpl) node.getParentNode();
                    if (parent==null) {
                        LOG.debug("Cannot remove the document element (no parent node)");
                        throw new XPathException(this,
                                "It is not possible to remove the document element.");

                    } else if (parent.getNodeType() != Node.ELEMENT_NODE) {
                        LOG.debug("parent = " + parent.getNodeType() + "; " + parent.getNodeName());
                        //transact.abort(transaction);
                        throw new XPathException(this,
                                "you cannot remove the document element. Use update "
                                        + "instead");
                    } else {
                        parent.removeChild(transaction, node);
                    }
                   
                    doc.getMetadata().clearIndexListener();
                    doc.getMetadata().setLastModified(System.currentTimeMillis());
                    modifiedDocuments.add(doc);
                    context.getBroker().storeXMLResource(transaction, doc);
                    notifier.notifyUpdate(doc, UpdateListener.UPDATE);
                }
                finishTriggers(transaction);
                //commit the transaction
                commitTransaction(transaction);
            } catch (final EXistException e) {
View Full Code Here

        if (!inSeq.isEmpty()) {         
          context.pushInScopeNamespaces();
            //start a transaction
            final Txn transaction = getTransaction();
        try {
          final NotificationService notifier = context.getBroker().getBrokerPool().getNotificationService();

                final StoredNode ql[] = selectAndLock(transaction, inSeq);
                final IndexListener listener = new IndexListener(ql);
                TextImpl text;
                AttrImpl attribute;
                ElementImpl parent;
                for (int i = 0; i < ql.length; i++) {
                    final StoredNode node = ql[i];
                    final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
                    if (!doc.getPermissions().validate(context.getUser(),
                            Permission.WRITE)){
                            throw new XPathException(this, "User '" + context.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                    }
                    doc.getMetadata().setIndexListener(listener);
                                       
                    //update the document
                    switch (node.getNodeType())
                    {
                        case Node.ELEMENT_NODE:
                final NodeListImpl content = new NodeListImpl();
                for (final SequenceIterator j = contentSeq.iterate(); j.hasNext(); ) {
                  final Item next = j.nextItem();
                  if (Type.subTypeOf(next.getType(), Type.NODE))
                    {content.add(((NodeValue)next).getNode());}
                  else {
                    text = new TextImpl(next.getStringValue());
                    content.add(text);
                  }
                }
                            ((ElementImpl) node).update(transaction, content);
                            break;
                        case Node.TEXT_NODE:
                            parent = (ElementImpl) node.getParentNode();
                          text = new TextImpl(contentSeq.getStringValue());
                            text.setOwnerDocument(doc);
                            parent.updateChild(transaction, node, text);
                            break;
                        case Node.ATTRIBUTE_NODE:
                            parent = (ElementImpl) node.getParentNode();
                            if (parent == null) {
                                LOG.warn("parent node not found for "
                                        + node.getNodeId());
                                break;
                            }
                            final AttrImpl attr = (AttrImpl) node;
                            attribute = new AttrImpl(attr.getQName(), contentSeq.getStringValue(), context.getBroker().getBrokerPool().getSymbols());
                            attribute.setOwnerDocument(doc);
                            parent.updateChild(transaction, node, attribute);
                            break;
                        default:
                            throw new XPathException(this, "unsupported node-type");
                    }
                    doc.getMetadata().clearIndexListener();
                    doc.getMetadata().setLastModified(System.currentTimeMillis());
                    modifiedDocuments.add(doc);
                    context.getBroker().storeXMLResource(transaction, doc);
                    notifier.notifyUpdate(doc, UpdateListener.UPDATE);
                }
                finishTriggers(transaction);
                //commit the transaction
                commitTransaction(transaction);
            } catch (final LockException e) {
View Full Code Here

            final Txn transaction = getTransaction();
        try {
                final StoredNode[] ql = selectAndLock(transaction, inSeq);
                NodeImpl parent;
                final IndexListener listener = new IndexListener(ql);
                final NotificationService notifier = context.getBroker().getBrokerPool().getNotificationService();
                for (int i = 0; i < ql.length; i++) {
                    final StoredNode node = ql[i];
                    final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
                    if (!doc.getPermissions().validate(context.getUser(), Permission.WRITE)) {
                            throw new PermissionDeniedException("User '" + context.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                    }
                    doc.getMetadata().setIndexListener(listener);
                   
                    //update the document
                    parent = (NodeImpl) node.getParentNode();
                    switch (node.getNodeType()) {
                        case Node.ELEMENT_NODE:
                            final ElementImpl newElem = new ElementImpl((ElementImpl) node);
                            newElem.setNodeName(newQName, context.getBroker().getBrokerPool().getSymbols());
                            parent.updateChild(transaction, node, newElem);
                            break;
                        case Node.ATTRIBUTE_NODE:
                            final AttrImpl newAttr = new AttrImpl((AttrImpl) node);
                            newAttr.setNodeName(newQName, context.getBroker().getBrokerPool().getSymbols());
                            parent.updateChild(transaction, node, newAttr);
                            break;
                        default:
                            throw new XPathException(this, "unsupported node-type");
                    }
   
                    doc.getMetadata().clearIndexListener();
                    doc.getMetadata().setLastModified(System.currentTimeMillis());
                    modifiedDocuments.add(doc);
                    context.getBroker().storeXMLResource(transaction, doc);
                    notifier.notifyUpdate(doc, UpdateListener.UPDATE);
                }
                finishTriggers(transaction);
               
                //commit the transaction
                commitTransaction(transaction);
View Full Code Here

        //start a transaction
        final Txn transaction = getTransaction();
        try {
            final StoredNode ql[] = selectAndLock(transaction, inSeq);
            final IndexListener listener = new IndexListener(ql);
            final NotificationService notifier = context.getBroker().getBrokerPool().getNotificationService();
            Item temp;
            TextImpl text;
            AttrImpl attribute;
            ElementImpl parent;
            for (int i = 0; i < ql.length; i++) {
                final StoredNode node = ql[i];
                final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
                if (!doc.getPermissions().validate(context.getUser(), Permission.WRITE)) {
                        throw new PermissionDeniedException("User '" + context.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
                }
                doc.getMetadata().setIndexListener(listener);
               
                //update the document
                parent = (ElementImpl) node.getParentStoredNode();
                if (parent == null)
                    {throw new XPathException(this, "The root element of a document can not be replaced with 'update replace'. " +
                            "Please consider removing the document or use 'update value' to just replace the children of the root.");}
                switch (node.getNodeType()) {
                    case Node.ELEMENT_NODE:
                        temp = contentSeq.itemAt(0);
            if (!Type.subTypeOf(temp.getType(), Type.NODE))
              {throw new XPathException(this,
                  Messages.getMessage(Error.UPDATE_REPLACE_ELEM_TYPE,
                      Type.getTypeName(temp.getType())));}
                        parent.replaceChild(transaction, ((NodeValue)temp).getNode(), node);
                        break;
                    case Node.TEXT_NODE:
                        text = new TextImpl(contentSeq.getStringValue());
                        text.setOwnerDocument(doc);
                        parent.updateChild(transaction, node, text);
                        break;
                    case Node.ATTRIBUTE_NODE:
                        final AttrImpl attr = (AttrImpl) node;
                        attribute = new AttrImpl(attr.getQName(), contentSeq.getStringValue(), context.getBroker().getBrokerPool().getSymbols());
                        attribute.setOwnerDocument(doc);
                        parent.updateChild(transaction, node, attribute);
                        break;
                    default:
                        throw new EXistException("unsupported node-type");
                }
                doc.getMetadata().clearIndexListener();
                doc.getMetadata().setLastModified(System.currentTimeMillis());
                modifiedDocuments.add(doc);
                context.getBroker().storeXMLResource(transaction, doc);
                notifier.notifyUpdate(doc, UpdateListener.UPDATE);
            }
            finishTriggers(transaction);
            //commit the transaction
            commitTransaction(transaction);
        } catch (final LockException e) {
View Full Code Here

TOP

Related Classes of org.exist.storage.NotificationService

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.