Search in sources :

Example 1 with NodeTypeImpl

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

the class NodeImpl method removeMixin.

/**
     * @see Node#removeMixin(String)
     */
public void removeMixin(String mixinName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
    checkIsWritable();
    Name ntName = getQName(mixinName);
    List<Name> mixinValue = getMixinTypes();
    // remove name of target mixin
    if (!mixinValue.remove(ntName)) {
        throw new NoSuchNodeTypeException("Cannot remove mixin '" + mixinName + "': Nodetype is not present on this node.");
    }
    // mix:referenceable needs additional assertion: the mixin cannot be
    // removed, if any references are left to this node.
    NodeTypeImpl mixin = session.getNodeTypeManager().getNodeType(ntName);
    if (mixin.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
        EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
        if (!entRemaining.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
            PropertyIterator iter = getReferences();
            if (iter.hasNext()) {
                throw new ConstraintViolationException("Mixin type " + mixinName + " can not be removed: the node is being referenced through at least one property of type REFERENCE");
            }
        }
    }
    /*
         * mix:lockable: the mixin cannot be removed if the node is currently
         * locked even if the editing session is the lock holder.
         */
    if (mixin.isNodeType((NameConstants.MIX_LOCKABLE))) {
        EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
        if (!entRemaining.includesNodeType(NameConstants.MIX_LOCKABLE) && isLocked()) {
            throw new ConstraintViolationException(mixinName + " can not be removed: the node is locked.");
        }
    }
    // delegate to operation
    Name[] mixins = mixinValue.toArray(new Name[mixinValue.size()]);
    Operation op = SetMixin.create(getNodeState(), mixins);
    session.getSessionItemStateManager().execute(op);
}
Also used : EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) NodeTypeImpl(org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeImpl) PropertyIterator(javax.jcr.PropertyIterator) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Aggregations

PropertyIterator (javax.jcr.PropertyIterator)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)1 EffectiveNodeType (org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType)1 NodeTypeImpl (org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeImpl)1 Operation (org.apache.jackrabbit.jcr2spi.operation.Operation)1 Name (org.apache.jackrabbit.spi.Name)1