Search in sources :

Example 1 with ItemDefinitionProvider

use of org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider in project jackrabbit by apache.

the class SessionItemStateManager method visit.

//---------------------------------------------------< OperationVisitor >---
/**
     * @see OperationVisitor#visit(AddNode)
     */
public void visit(AddNode operation) throws LockException, ConstraintViolationException, AccessDeniedException, ItemExistsException, NoSuchNodeTypeException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
    NodeState parent = operation.getParentState();
    ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
    QNodeDefinition def = defProvider.getQNodeDefinition(parent.getAllNodeTypeNames(), operation.getNodeName(), operation.getNodeTypeName());
    List<ItemState> newStates = addNodeState(parent, operation.getNodeName(), operation.getNodeTypeName(), operation.getUuid(), def, operation.getOptions());
    operation.addedState(newStates);
    if (!(operation instanceof IgnoreOperation)) {
        transientStateMgr.addOperation(operation);
    }
}
Also used : ItemDefinitionProvider(org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider) IgnoreOperation(org.apache.jackrabbit.jcr2spi.operation.IgnoreOperation) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition)

Example 2 with ItemDefinitionProvider

use of org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider in project jackrabbit by apache.

the class SessionItemStateManager method addNodeState.

private List<ItemState> addNodeState(NodeState parent, Name nodeName, Name nodeTypeName, String uuid, QNodeDefinition definition, int options) throws RepositoryException, ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, NoSuchNodeTypeException, ItemExistsException, VersionException {
    // check if add node is possible. note, that the options differ if
    // the 'addNode' is called from inside a regular add-node to create
    // autocreated child nodes that may be 'protected'.
    validator.checkAddNode(parent, nodeName, nodeTypeName, options);
    // a new NodeState doesn't have mixins defined yet -> ent is ent of primarytype
    EffectiveNodeType ent = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeTypeName);
    if (nodeTypeName == null) {
        // no primary node type specified,
        // try default primary type from definition
        nodeTypeName = definition.getDefaultPrimaryType();
        if (nodeTypeName == null) {
            String msg = "No applicable node type could be determined for " + nodeName;
            log.debug(msg);
            throw new ConstraintViolationException(msg);
        }
    }
    List<ItemState> addedStates = new ArrayList<ItemState>();
    // create new nodeState. NOTE, that the uniqueID is not added to the
    // state for consistency between 'addNode' and importXML
    NodeState nodeState = transientStateMgr.createNewNodeState(nodeName, null, nodeTypeName, definition, parent);
    addedStates.add(nodeState);
    if (uuid != null) {
        QValue[] value = getQValues(uuid, qValueFactory);
        ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
        QPropertyDefinition pDef = defProvider.getQPropertyDefinition(NameConstants.MIX_REFERENCEABLE, NameConstants.JCR_UUID, PropertyType.STRING, false);
        addedStates.add(addPropertyState(nodeState, NameConstants.JCR_UUID, PropertyType.STRING, value, pDef, 0));
    }
    // add 'auto-create' properties defined in node type
    for (QPropertyDefinition pd : ent.getAutoCreateQPropertyDefinitions()) {
        if (!nodeState.hasPropertyName(pd.getName())) {
            QValue[] autoValue = computeSystemGeneratedPropertyValues(nodeState, pd);
            if (autoValue != null) {
                int propOptions = ItemStateValidator.CHECK_NONE;
                // execute 'addProperty' without adding operation.
                addedStates.add(addPropertyState(nodeState, pd.getName(), pd.getRequiredType(), autoValue, pd, propOptions));
            }
        }
    }
    // recursively add 'auto-create' child nodes defined in node type
    for (QNodeDefinition nd : ent.getAutoCreateQNodeDefinitions()) {
        // execute 'addNode' without adding the operation.
        int opt = ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_COLLISION;
        addedStates.addAll(addNodeState(nodeState, nd.getName(), nd.getDefaultPrimaryType(), null, nd, opt));
    }
    return addedStates;
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) ArrayList(java.util.ArrayList) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ItemDefinitionProvider(org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider)

Example 3 with ItemDefinitionProvider

use of org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider in project jackrabbit by apache.

the class SessionItemStateManager method visit.

/**
     * @see OperationVisitor#visit(SetMixin)
     */
public void visit(SetMixin operation) throws ConstraintViolationException, AccessDeniedException, NoSuchNodeTypeException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
    // NOTE: nodestate is only modified upon save of the changes!
    Name[] mixinNames = operation.getMixinNames();
    NodeState nState = operation.getNodeState();
    NodeEntry nEntry = nState.getNodeEntry();
    // assert the existence of the property entry and set the array of
    // mixinNames to be set on the corresponding property state
    PropertyEntry mixinEntry = nEntry.getPropertyEntry(NameConstants.JCR_MIXINTYPES);
    if (mixinNames.length > 0) {
        // update/create corresponding property state
        if (mixinEntry != null) {
            // execute value of existing property
            PropertyState pState = mixinEntry.getPropertyState();
            setPropertyStateValue(pState, getQValues(mixinNames, qValueFactory), PropertyType.NAME, operation.getOptions());
        } else {
            // create new jcr:mixinTypes property
            ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
            QPropertyDefinition pd = defProvider.getQPropertyDefinition(nState.getAllNodeTypeNames(), NameConstants.JCR_MIXINTYPES, PropertyType.NAME, true);
            QValue[] mixinValue = getQValues(mixinNames, qValueFactory);
            addPropertyState(nState, pd.getName(), pd.getRequiredType(), mixinValue, pd, operation.getOptions());
        }
        nState.markModified();
        transientStateMgr.addOperation(operation);
    } else if (mixinEntry != null) {
        // remove the jcr:mixinTypes property state if already present
        PropertyState pState = mixinEntry.getPropertyState();
        removeItemState(pState, operation.getOptions());
        nState.markModified();
        transientStateMgr.addOperation(operation);
    }
// else: empty Name array and no mixin-prop-entry (should not occur)
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ItemDefinitionProvider(org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider) Name(org.apache.jackrabbit.spi.Name)

Example 4 with ItemDefinitionProvider

use of org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider in project jackrabbit by apache.

the class SessionItemStateManager method visit.

/**
     * @see OperationVisitor#visit(Move)
     */
public void visit(Move operation) throws LockException, ConstraintViolationException, AccessDeniedException, ItemExistsException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
    // retrieve states and assert they are modifiable
    NodeState srcState = operation.getSourceState();
    NodeState srcParent = operation.getSourceParentState();
    NodeState destParent = operation.getDestinationParentState();
    // state validation: move-Source can be removed from old/added to new parent
    validator.checkRemoveItem(srcState, operation.getOptions());
    validator.checkAddNode(destParent, operation.getDestinationName(), srcState.getNodeTypeName(), operation.getOptions());
    // retrieve applicable definition at the new place
    ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
    QNodeDefinition newDefinition = defProvider.getQNodeDefinition(destParent.getAllNodeTypeNames(), operation.getDestinationName(), srcState.getNodeTypeName());
    // perform the move (modifying states)
    srcParent.moveChildNodeEntry(destParent, srcState, operation.getDestinationName(), newDefinition);
    // remember operation
    transientStateMgr.addOperation(operation);
}
Also used : ItemDefinitionProvider(org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition)

Aggregations

ItemDefinitionProvider (org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider)4 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)3 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)2 QValue (org.apache.jackrabbit.spi.QValue)2 ArrayList (java.util.ArrayList)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)1 PropertyEntry (org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry)1 EffectiveNodeType (org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType)1 IgnoreOperation (org.apache.jackrabbit.jcr2spi.operation.IgnoreOperation)1 Name (org.apache.jackrabbit.spi.Name)1