Search in sources :

Example 6 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class InternalXAVersionManager method makeLocalCopy.

/**
     * Make a local copy of an internal version item. This will recreate the
     * (global) version item with state information from our own state
     * manager.
     * @param act source
     * @return the new copy
     * @throws RepositoryException if an error occurs
     */
private InternalActivityImpl makeLocalCopy(InternalActivityImpl act) throws RepositoryException {
    VersioningLock.ReadLock lock = acquireReadLock();
    try {
        NodeState state = (NodeState) stateMgr.getItemState(act.getId());
        NodeStateEx stateEx = new NodeStateEx(stateMgr, ntReg, state, null);
        return new InternalActivityImpl(this, stateEx);
    } catch (ItemStateException e) {
        throw new RepositoryException("Unable to make local copy", e);
    } finally {
        lock.release();
    }
}
Also used : VirtualNodeState(org.apache.jackrabbit.core.virtual.VirtualNodeState) NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 7 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class NodeStateEx method moveFrom.

/**
     * Moves the source node to this node using the given name.
     * @param src shareable source node
     * @param name name of new node
     * @param createShare if <code>true</code> a share is created instead.
     * @return child node
     * @throws RepositoryException if an error occurs
     */
public NodeStateEx moveFrom(NodeStateEx src, Name name, boolean createShare) throws RepositoryException {
    if (name == null) {
        name = src.getName();
    }
    EffectiveNodeType ent = getEffectiveNodeType();
    // (4) check for name collisions
    QNodeDefinition def;
    try {
        def = ent.getApplicableChildNodeDef(name, nodeState.getNodeTypeName(), ntReg);
    } catch (RepositoryException re) {
        String msg = "no definition found in parent node's node type for new node";
        throw new ConstraintViolationException(msg, re);
    }
    ChildNodeEntry cne = nodeState.getChildNodeEntry(name, 1);
    if (cne != null) {
        // check same-name sibling setting of new node
        if (!def.allowsSameNameSiblings()) {
            throw new ItemExistsException(getNodeId() + "/" + name);
        }
        NodeState existingChild;
        try {
            // check same-name sibling setting of existing node
            existingChild = (NodeState) stateMgr.getItemState(cne.getId());
        } catch (ItemStateException e) {
            throw new RepositoryException(e);
        }
        QNodeDefinition existingChildDef = ent.getApplicableChildNodeDef(cne.getName(), existingChild.getNodeTypeName(), ntReg);
        if (!existingChildDef.allowsSameNameSiblings()) {
            throw new ItemExistsException(existingChild.toString());
        }
    } else {
        // check if 'add' is allowed
        if (getDefinition().isProtected()) {
            String msg = "not allowed to modify a protected node";
            throw new ConstraintViolationException(msg);
        }
    }
    if (createShare) {
        // (5) do clone operation
        NodeId parentId = getNodeId();
        src.addShareParent(parentId);
        // attach to this parent
        nodeState.addChildNodeEntry(name, src.getNodeId());
        if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
            nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        return new NodeStateEx(stateMgr, ntReg, src.getState(), name);
    } else {
        // detach from parent
        NodeStateEx parent = getNode(src.getParentId());
        parent.nodeState.removeChildNodeEntry(src.getNodeId());
        if (parent.nodeState.getStatus() == ItemState.STATUS_EXISTING) {
            parent.nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        // attach to this parent
        nodeState.addChildNodeEntry(name, src.getNodeId());
        if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
            nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        NodeState srcState = src.getState();
        srcState.setParentId(getNodeId());
        if (srcState.getStatus() == ItemState.STATUS_EXISTING) {
            srcState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        return new NodeStateEx(stateMgr, ntReg, srcState, name);
    }
}
Also used : EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) NodeState(org.apache.jackrabbit.core.state.NodeState) ItemExistsException(javax.jcr.ItemExistsException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 8 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class NodeStateEx method removeNode.

/**
     * removes recursively the node with the given id
     *
     * @param id node id
     * @throws ItemStateException if an error occurs
     */
private void removeNode(NodeId id) throws ItemStateException {
    NodeState state = (NodeState) stateMgr.getItemState(id);
    // remove properties
    for (Name name : state.getPropertyNames()) {
        PropertyId propId = new PropertyId(id, name);
        PropertyState propState = (PropertyState) stateMgr.getItemState(propId);
        stateMgr.destroy(propState);
    }
    state.removeAllPropertyNames();
    // remove child nodes
    for (ChildNodeEntry entry : state.getChildNodeEntries()) {
        removeNode(entry.getId());
    }
    state.removeAllChildNodeEntries();
    // destroy the state itself
    stateMgr.destroy(state);
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 9 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class InternalVersionManagerBase method createInternalVersionItem.

/**
     * Creates an {@link InternalVersionItem} based on the {@link NodeState}
     * identified by <code>id</code>.
     *
     * @param id    the node id of the version item.
     * @return the version item or <code>null</code> if there is no node state
     *         with the given <code>id</code>.
     * @throws RepositoryException if an error occurs while reading from the
     *                             version storage.
     */
protected InternalVersionItem createInternalVersionItem(NodeId id) throws RepositoryException {
    try {
        if (stateMgr.hasItemState(id)) {
            NodeState state = (NodeState) stateMgr.getItemState(id);
            NodeStateEx pNode = new NodeStateEx(stateMgr, ntReg, state, null);
            NodeId parentId = pNode.getParentId();
            InternalVersionItem parent = getItem(parentId);
            Name ntName = state.getNodeTypeName();
            if (ntName.equals(NameConstants.NT_FROZENNODE)) {
                return new InternalFrozenNodeImpl(this, pNode, parent);
            } else if (ntName.equals(NameConstants.NT_VERSIONEDCHILD)) {
                return new InternalFrozenVHImpl(this, pNode, parent);
            } else if (ntName.equals(NameConstants.NT_VERSION)) {
                return ((InternalVersionHistory) parent).getVersion(id);
            } else if (ntName.equals(NameConstants.NT_VERSIONHISTORY)) {
                return new InternalVersionHistoryImpl(this, pNode);
            } else if (ntName.equals(NameConstants.NT_ACTIVITY)) {
                return new InternalActivityImpl(this, pNode);
            } else {
                return null;
            }
        } else {
            return null;
        }
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 10 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class NodeStateEx method getName.

/**
     * returns the name of this node
     *
     * @return the name of this node
     */
public Name getName() {
    if (name == null) {
        try {
            NodeId parentId = nodeState.getParentId();
            NodeState parent = (NodeState) stateMgr.getItemState(parentId);
            name = parent.getChildNodeEntry(nodeState.getNodeId()).getName();
        } catch (ItemStateException e) {
            // should never occur
            throw new IllegalStateException(e.toString());
        }
    }
    return name;
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NodeId(org.apache.jackrabbit.core.id.NodeId) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

NodeState (org.apache.jackrabbit.core.state.NodeState)114 RepositoryException (javax.jcr.RepositoryException)53 NodeId (org.apache.jackrabbit.core.id.NodeId)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)44 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)34 Name (org.apache.jackrabbit.spi.Name)28 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)26 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 Path (org.apache.jackrabbit.spi.Path)24 PropertyId (org.apache.jackrabbit.core.id.PropertyId)23 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)16 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)16 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 ArrayList (java.util.ArrayList)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)12 InternalValue (org.apache.jackrabbit.core.value.InternalValue)12 HashSet (java.util.HashSet)10 ItemExistsException (javax.jcr.ItemExistsException)10 IOException (java.io.IOException)8 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)7