Search in sources :

Example 96 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class NodeImpl method addShareParent.

/**
     * Add a share-parent to this node. This method checks, whether:
     * <ul>
     * <li>this node is shareable</li>
     * <li>adding the given would create a share cycle</li>
     * <li>the given parent is already a share-parent</li>
     * </ul>
     * @param parentId parent to add to the shared set
     * @throws RepositoryException if an error occurs
     */
void addShareParent(NodeId parentId) throws RepositoryException {
    // verify that we're shareable
    if (!isShareable()) {
        String msg = this + " is not shareable.";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    // detect share cycle
    NodeId srcId = getNodeId();
    HierarchyManager hierMgr = sessionContext.getHierarchyManager();
    if (parentId.equals(srcId) || hierMgr.isAncestor(srcId, parentId)) {
        String msg = "This would create a share cycle.";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    // quickly verify whether the share is already contained before creating
    // a transient state in vain
    NodeState state = data.getNodeState();
    if (!state.containsShare(parentId)) {
        state = (NodeState) getOrCreateTransientItemState();
        if (state.addShare(parentId)) {
            return;
        }
    }
    String msg = "Adding a shareable node twice to the same parent is not supported.";
    log.debug(msg);
    throw new UnsupportedRepositoryOperationException(msg);
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NodeState(org.apache.jackrabbit.core.state.NodeState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException)

Example 97 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class NodeImpl method getIndex.

/**
     * {@inheritDoc}
     */
public int getIndex() throws RepositoryException {
    // check state of this instance
    sanityCheck();
    NodeId parentId = getParentId();
    if (parentId == null) {
        // the root node cannot have same-name siblings; always return 1
        return 1;
    }
    try {
        NodeState parent = (NodeState) stateMgr.getItemState(parentId);
        ChildNodeEntry parentEntry = parent.getChildNodeEntry(getNodeId());
        return parentEntry.getIndex();
    } catch (ItemStateException ise) {
        // should never get here...
        String msg = "internal error: failed to determine index";
        log.error(msg, ise);
        throw new RepositoryException(msg, ise);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 98 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class NodeImpl method clone.

/**
     * Create a child node that is a clone of a shareable node.
     *
     * @param src shareable source node
     * @param name name of new node
     * @return child node
     * @throws ItemExistsException if there already is a child node with the
     *             name given and the definition does not allow creating another one
     * @throws VersionException if this node is not checked out
     * @throws ConstraintViolationException if no definition is found in this
     *             node that would allow creating the child node
     * @throws LockException if this node is locked
     * @throws RepositoryException if some other error occurs
     */
public synchronized NodeImpl clone(NodeImpl src, Name name) throws ItemExistsException, VersionException, ConstraintViolationException, LockException, RepositoryException {
    Path nodePath;
    try {
        nodePath = PathFactoryImpl.getInstance().create(getPrimaryPath(), name, true);
    } catch (MalformedPathException e) {
        // should never happen
        String msg = "internal error: invalid path " + this;
        log.debug(msg);
        throw new RepositoryException(msg, e);
    }
    // (1) make sure that parent node is checked-out
    // (2) check lock status
    // (3) check protected flag of parent (i.e. this) node
    int options = ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CHECKED_OUT | ItemValidator.CHECK_CONSTRAINTS;
    sessionContext.getItemValidator().checkModify(this, options, Permission.NONE);
    // (4) check for name collisions
    NodeDefinitionImpl def;
    try {
        def = getApplicableChildNodeDefinition(name, null);
    } catch (RepositoryException re) {
        String msg = "no definition found in parent node's node type for new node";
        log.debug(msg);
        throw new ConstraintViolationException(msg, re);
    }
    NodeState thisState = data.getNodeState();
    ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
    if (cne != null) {
        // check same-name sibling setting of new node
        if (!def.allowsSameNameSiblings()) {
            throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath));
        }
        // check same-name sibling setting of existing node
        NodeId newId = cne.getId();
        if (!((NodeImpl) itemMgr.getItem(newId)).getDefinition().allowsSameNameSiblings()) {
            throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath));
        }
    }
    // (5) do clone operation
    NodeId parentId = getNodeId();
    src.addShareParent(parentId);
    // (6) modify the state of 'this', i.e. the parent node
    NodeId srcId = src.getNodeId();
    thisState = (NodeState) getOrCreateTransientItemState();
    // add new child node entry
    thisState.addChildNodeEntry(name, srcId);
    return itemMgr.getNode(srcId, parentId);
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl) NodeState(org.apache.jackrabbit.core.state.NodeState) ItemExistsException(javax.jcr.ItemExistsException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException)

Example 99 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class NodeImpl method hasNode.

/**
     * {@inheritDoc}
     */
public boolean hasNode(String relPath) throws RepositoryException {
    // check state of this instance
    sanityCheck();
    NodeId id = resolveRelativeNodePath(relPath);
    if (id != null) {
        return itemMgr.itemExists(id);
    } else {
        return false;
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 100 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class NodeImpl method onRemove.

protected void onRemove(NodeId parentId) throws RepositoryException {
    // modify the state of 'this', i.e. the target node
    NodeState thisState = (NodeState) getOrCreateTransientItemState();
    // remove this node from its shared set
    if (thisState.isShareable()) {
        if (thisState.removeShare(parentId) > 0) {
            // this state is still connected to some parents, so
            // leave the child node entries and properties
            // set state of this instance to 'invalid'
            data.setStatus(STATUS_INVALIDATED);
            // notify the item manager that this instance has been
            // temporarily invalidated
            itemMgr.itemInvalidated(id, data);
            return;
        }
    }
    if (thisState.hasChildNodeEntries()) {
        // remove child nodes
        // use temp array to avoid ConcurrentModificationException
        ArrayList<ChildNodeEntry> tmp = new ArrayList<ChildNodeEntry>(thisState.getChildNodeEntries());
        // remove from tail to avoid problems with same-name siblings
        for (int i = tmp.size() - 1; i >= 0; i--) {
            ChildNodeEntry entry = tmp.get(i);
            // recursively remove child node
            NodeId childId = entry.getId();
            //NodeImpl childNode = (NodeImpl) itemMgr.getItem(childId);
            try {
                /* omit the read-permission check upon retrieving the
                       child item as this is an internal call to remove the
                       subtree which may contain (protected) child items which
                       are not visible to the caller of the removal. the actual
                       validation of the remove permission however is only
                       executed during Item.save(). 
                     */
                NodeImpl childNode = itemMgr.getNode(childId, getNodeId(), false);
                childNode.onRemove(thisState.getNodeId());
            // remove the child node entry
            } catch (ItemNotFoundException e) {
                boolean ignoreError = false;
                if (parentId != null && sessionContext.getSessionImpl().autoFixCorruptions()) {
                    // it might be an access right problem
                    // we need to check if the item doesn't exist in the ism
                    ItemStateManager ism = sessionContext.getItemStateManager();
                    if (!ism.hasItemState(childId)) {
                        log.warn("Child named " + entry.getName() + " (index " + entry.getIndex() + ", " + "node id " + childId + ") " + "not found when trying to remove " + getPath() + " " + "(node id " + getNodeId() + ") - ignored", e);
                        ignoreError = true;
                    }
                }
                if (!ignoreError) {
                    throw e;
                }
            }
            thisState.removeChildNodeEntry(childId);
        }
    }
    // remove properties
    // use temp set to avoid ConcurrentModificationException
    HashSet<Name> tmp = new HashSet<Name>(thisState.getPropertyNames());
    for (Name propName : tmp) {
        // remove the property entry
        thisState.removePropertyName(propName);
        // remove property
        PropertyId propId = new PropertyId(thisState.getNodeId(), propName);
        /* omit the read-permission check upon retrieving the
               child item as this is an internal call to remove the
               subtree which may contain (protected) child items which
               are not visible to the caller of the removal. the actual
               validation of the remove permission however is only
               executed during Item.save().
             */
        itemMgr.getItem(propId, false).setRemoved();
    }
    // finally remove this node
    thisState.setParentId(null);
    setRemoved();
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) ArrayList(java.util.ArrayList) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) NodeId(org.apache.jackrabbit.core.id.NodeId) ItemStateManager(org.apache.jackrabbit.core.state.ItemStateManager) ItemNotFoundException(javax.jcr.ItemNotFoundException) HashSet(java.util.HashSet)

Aggregations

NodeId (org.apache.jackrabbit.core.id.NodeId)203 RepositoryException (javax.jcr.RepositoryException)68 NodeState (org.apache.jackrabbit.core.state.NodeState)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)48 Name (org.apache.jackrabbit.spi.Name)37 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)31 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)23 Path (org.apache.jackrabbit.spi.Path)23 ItemNotFoundException (javax.jcr.ItemNotFoundException)22 NodeImpl (org.apache.jackrabbit.core.NodeImpl)20 InternalValue (org.apache.jackrabbit.core.value.InternalValue)20 ArrayList (java.util.ArrayList)19 PropertyId (org.apache.jackrabbit.core.id.PropertyId)16 HashSet (java.util.HashSet)15 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)14 PropertyState (org.apache.jackrabbit.core.state.PropertyState)14 Session (javax.jcr.Session)13 HashMap (java.util.HashMap)12 ItemExistsException (javax.jcr.ItemExistsException)12