Search in sources :

Example 11 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class InternalVersionManagerBase method internalCreateActivity.

/**
     * Creates a new activity.
     *
     * @param title title of the new activity
     * @return the id of the newly created activity
     * @throws RepositoryException if an error occurs
     */
NodeStateEx internalCreateActivity(String title) throws RepositoryException {
    WriteOperation operation = startWriteOperation();
    try {
        // create deep path
        NodeId activityId = nodeIdFactory.newNodeId();
        NodeStateEx parent = getParentNode(getActivitiesRoot(), activityId.toString(), NameConstants.REP_ACTIVITIES);
        Name name = getName(activityId.toString());
        // create new activity node in the persistent state
        NodeStateEx pNode = InternalActivityImpl.create(parent, name, activityId, title);
        // end update
        operation.save();
        log.debug("Created new activity " + activityId + " with title " + title + ".");
        return pNode;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        operation.close();
    }
}
Also used : 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 12 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class NodeStateEx method getProperties.

/**
     * Returns the properties of this node
     *
     * @return the properties of this node
     * @throws ItemStateException if an error occurs
     */
public PropertyState[] getProperties() throws ItemStateException {
    Set<Name> set = nodeState.getPropertyNames();
    PropertyState[] props = new PropertyState[set.size()];
    int i = 0;
    for (Name propName : set) {
        PropertyId propId = new PropertyId(nodeState.getNodeId(), propName);
        props[i++] = (PropertyState) stateMgr.getItemState(propId);
    }
    return props;
}
Also used : Name(org.apache.jackrabbit.spi.Name) PropertyState(org.apache.jackrabbit.core.state.PropertyState) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 13 with Name

use of org.apache.jackrabbit.spi.Name 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 14 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class InternalVersionManagerBase method getVersionHistoryOfNode.

/**
     * {@inheritDoc}
     */
public InternalVersionHistory getVersionHistoryOfNode(NodeId id) throws RepositoryException {
    VersioningLock.ReadLock lock = acquireReadLock();
    try {
        String uuid = id.toString();
        Name name = getName(uuid);
        NodeStateEx parent = getParentNode(getHistoryRoot(), uuid, null);
        if (parent != null && parent.hasNode(name)) {
            NodeStateEx history = parent.getNode(name, 1);
            if (history == null) {
                throw new InconsistentVersioningState("Unexpected failure to get child node " + name + " on parent node" + parent.getNodeId());
            }
            return getVersionHistory(history.getNodeId());
        } else {
            throw new ItemNotFoundException("Version history of node " + id + " not found.");
        }
    } finally {
        lock.release();
    }
}
Also used : Name(org.apache.jackrabbit.spi.Name) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 15 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class InternalVersionManagerBase method internalCreateVersionHistory.

/**
     * Creates a new Version History.
     *
     * @param node the node for which the version history is to be initialized
     * @param copiedFrom node id for the jcr:copiedFrom parameter
     * @return the identifiers of the newly created version history and root version
     * @throws RepositoryException if an error occurs
     */
NodeStateEx internalCreateVersionHistory(NodeState node, NodeId copiedFrom) throws RepositoryException {
    WriteOperation operation = startWriteOperation();
    try {
        // create deep path
        String uuid = node.getNodeId().toString();
        NodeStateEx parent = getParentNode(getHistoryRoot(), uuid, NameConstants.REP_VERSIONSTORAGE);
        Name name = getName(uuid);
        if (parent.hasNode(name)) {
            // already exists
            return null;
        }
        // create new history node in the persistent state
        NodeStateEx history = InternalVersionHistoryImpl.create(this, parent, name, node, copiedFrom);
        // end update
        operation.save();
        log.debug("Created new version history " + history.getNodeId() + " for " + node + ".");
        return history;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        operation.close();
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

Name (org.apache.jackrabbit.spi.Name)382 RepositoryException (javax.jcr.RepositoryException)101 ArrayList (java.util.ArrayList)57 QValue (org.apache.jackrabbit.spi.QValue)42 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)39 HashSet (java.util.HashSet)38 Path (org.apache.jackrabbit.spi.Path)38 NodeId (org.apache.jackrabbit.core.id.NodeId)37 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)33 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)32 NodeId (org.apache.jackrabbit.spi.NodeId)32 PropertyId (org.apache.jackrabbit.core.id.PropertyId)29 HashMap (java.util.HashMap)28 NamespaceException (javax.jcr.NamespaceException)28 NodeState (org.apache.jackrabbit.core.state.NodeState)28 Value (javax.jcr.Value)25 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)25 InternalValue (org.apache.jackrabbit.core.value.InternalValue)23 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)22 PropertyState (org.apache.jackrabbit.core.state.PropertyState)22