Search in sources :

Example 1 with NodeTypeManagerImpl

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

the class NodeImpl method canAddMixin.

/**
     *
     * @param mixinName
     * @return
     * @throws NoSuchNodeTypeException
     * @throws ConstraintViolationException
     */
private boolean canAddMixin(Name mixinName) throws NoSuchNodeTypeException, ConstraintViolationException {
    NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
    // first check characteristics of each mixin
    NodeType mixin = ntMgr.getNodeType(mixinName);
    if (!mixin.isMixin()) {
        log.error(mixin.getName() + ": not a mixin node type");
        return false;
    }
    // get list of existing nodetypes
    Name[] existingNts = getNodeState().getNodeTypeNames();
    // build effective node type representing primary type including existing mixins
    EffectiveNodeType entExisting = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(existingNts);
    // check if the base type supports adding this mixin
    if (!entExisting.supportsMixin(mixinName)) {
        log.debug(mixin.getName() + ": not supported on node type " + getPrimaryNodeTypeName());
        return false;
    }
    // second, build new effective node type for nts including the new mixin
    // types, detecting eventual incompatibilities
    Name[] resultingNts = new Name[existingNts.length + 1];
    System.arraycopy(existingNts, 0, resultingNts, 0, existingNts.length);
    resultingNts[existingNts.length] = mixinName;
    session.getEffectiveNodeTypeProvider().getEffectiveNodeType(resultingNts);
    // all validations succeeded: return true
    return true;
}
Also used : EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) NodeType(javax.jcr.nodetype.NodeType) EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) NodeTypeManagerImpl(org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl) Name(org.apache.jackrabbit.spi.Name)

Example 2 with NodeTypeManagerImpl

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

the class NodeImpl method setPrimaryType.

/**
     * @see javax.jcr.Node#setPrimaryType(String)
     */
public void setPrimaryType(String nodeTypeName) throws RepositoryException {
    checkStatus();
    if (getNodeState().isRoot()) {
        String msg = "The primary type of the root node may not be changed.";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    Name ntName = getQName(nodeTypeName);
    if (ntName.equals(getPrimaryNodeTypeName())) {
        log.debug("Changing the primary type has no effect: '" + nodeTypeName + "' already is the primary node type.");
        return;
    }
    NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
    NodeType nt = ntMgr.getNodeType(ntName);
    if (nt.isMixin() || nt.isAbstract()) {
        throw new ConstraintViolationException("Cannot change the primary type: '" + nodeTypeName + "' is a mixin type or abstract.");
    }
    // perform the operation
    Operation op = SetPrimaryType.create(getNodeState(), ntName);
    session.getSessionItemStateManager().execute(op);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) NodeTypeManagerImpl(org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) Name(org.apache.jackrabbit.spi.Name)

Aggregations

NodeType (javax.jcr.nodetype.NodeType)2 EffectiveNodeType (org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType)2 NodeTypeManagerImpl (org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl)2 Name (org.apache.jackrabbit.spi.Name)2 RepositoryException (javax.jcr.RepositoryException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 Operation (org.apache.jackrabbit.jcr2spi.operation.Operation)1