Search in sources :

Example 46 with QNodeTypeDefinition

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

the class ItemStateValidator method checkAddNode.

/**
 * Checks if adding a child node called <code>nodeName</code> of node type
 * <code>nodeTypeName</code> to the given parent node is allowed in the
 * current context.
 *
 * @param parentState
 * @param nodeName
 * @param nodeTypeName
 * @param options      bit-wise OR'ed flags specifying the checks that should be
 *                     performed; any combination of the following constants:
 * <ul>
 * <li><code>{@link #CHECK_ACCESS}</code>: make sure current session is
 * granted read access on parent node and can add a child node with the
 * given name.</li>
 * <li><code>{@link #CHECK_LOCK}</code>: make sure there's no foreign lock
 * on parent node</li>
 * <li><code>{@link #CHECK_VERSIONING}</code>: make sure parent node is
 * checked-out</li>
 * <li><code>{@link #CHECK_CONSTRAINTS}</code>: make sure no node type
 * constraints would be violated</li>
 * <li><code>{@link #CHECK_COLLISION}</code>: check for collision with
 * existing properties or nodes</li>
 * </ul>
 *
 * @throws ConstraintViolationException
 * @throws AccessDeniedException
 * @throws VersionException
 * @throws LockException
 * @throws ItemNotFoundException
 * @throws ItemExistsException
 * @throws RepositoryException
 */
public void checkAddNode(NodeState parentState, Name nodeName, Name nodeTypeName, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ItemExistsException, RepositoryException {
    checkIsWritable(parentState, options);
    // access restrictions on new node
    if ((options & CHECK_ACCESS) == CHECK_ACCESS) {
        // make sure current session is granted write access on parent node
        Path relPath = pathFactory.create(nodeName);
        if (!mgrProvider.getAccessManager().isGranted(parentState, relPath, new String[] { AccessManager.ADD_NODE_ACTION })) {
            throw new AccessDeniedException(safeGetJCRPath(parentState) + ": not allowed to add child node '" + nodeName + "'");
        }
    }
    // node type constraints
    if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
        // make sure there's an applicable definition for new child node
        Name[] ntNames = parentState.getAllNodeTypeNames();
        EffectiveNodeType entParent = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
        QNodeTypeDefinition def = mgrProvider.getNodeTypeDefinitionProvider().getNodeTypeDefinition(nodeTypeName);
        entParent.checkAddNodeConstraints(nodeName, def, mgrProvider.getItemDefinitionProvider());
    }
    // collisions
    if ((options & CHECK_COLLISION) == CHECK_COLLISION) {
        checkCollision(parentState, nodeName, nodeTypeName);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) AccessDeniedException(javax.jcr.AccessDeniedException) EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) Name(org.apache.jackrabbit.spi.Name)

Example 47 with QNodeTypeDefinition

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

the class CompactNodeTypeDefWriter method write.

/**
 * Writes the given list of QNodeTypeDefinition to the output writer including the
 * used namespaces.
 *
 * @param defs collection of definitions
 * @param r namespace resolver
 * @param npResolver name-path resolver
 * @param out output writer
 * @throws IOException if an I/O error occurs
 */
public static void write(Collection<? extends QNodeTypeDefinition> defs, NamespaceResolver r, NamePathResolver npResolver, Writer out) throws IOException {
    CompactNodeTypeDefWriter w = new CompactNodeTypeDefWriter(out, r, npResolver, true);
    for (QNodeTypeDefinition def : defs) {
        w.write(def);
    }
    w.close();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition)

Example 48 with QNodeTypeDefinition

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

the class CompactNodeTypeDefWriter method write.

/**
 * Write one QNodeTypeDefinition to this writer
 *
 * @param ntd node type definition
 * @throws IOException if an I/O error occurs
 */
public void write(QNodeTypeDefinition ntd) throws IOException {
    NodeTypeDefinition def = new NodeTypeDefinitionImpl(ntd, npResolver, new ValueFactoryQImpl(QValueFactoryImpl.getInstance(), npResolver));
    super.write(def);
}
Also used : NodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionImpl) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl)

Example 49 with QNodeTypeDefinition

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

the class NodeTypeRegistry method getEffectiveNodeType.

/**
 * @param ntName node type name
 * @param entCache cache of already-built effective node types
 * @param ntdCache cache of node type definitions
 * @return the effective node type
 * @throws NoSuchNodeTypeException if a node type reference (e.g. a supertype)
 *                                 could not be resolved.
 */
static EffectiveNodeType getEffectiveNodeType(Name ntName, EffectiveNodeTypeCache entCache, Map<Name, QNodeTypeDefinition> ntdCache) throws NoSuchNodeTypeException {
    // 1. check if effective node type has already been built
    EffectiveNodeTypeCache.Key key = entCache.getKey(new Name[] { ntName });
    EffectiveNodeType ent = entCache.get(key);
    if (ent != null) {
        return ent;
    }
    // 2. make sure we've got the definition of the specified node type
    QNodeTypeDefinition ntd = ntdCache.get(ntName);
    if (ntd == null) {
        throw new NoSuchNodeTypeException(ntName.toString());
    }
    // 3. build effective node type
    synchronized (entCache) {
        try {
            ent = EffectiveNodeType.create(ntd, entCache, ntdCache);
            // store new effective node type
            entCache.put(ent);
            return ent;
        } catch (NodeTypeConflictException ntce) {
            // should never get here as all known node types should be valid!
            String msg = "internal error: encountered invalid registered node type " + ntName;
            log.debug(msg);
            throw new NoSuchNodeTypeException(msg, ntce);
        }
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 50 with QNodeTypeDefinition

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

the class NodeTypeRegistry method registerNodeTypes.

/**
 * Internal implementation of {@link #registerNodeTypes(Collection)}
 *
 * @param ntDefs a collection of <code>QNodeTypeDefinition<code> objects
 * @param external whether this invocation should be considered external
 * @throws InvalidNodeTypeDefException if the given node type definition is invalid.
 * @throws RepositoryException if a repository error occurs.
 */
private void registerNodeTypes(Collection<QNodeTypeDefinition> ntDefs, boolean external) throws InvalidNodeTypeDefException, RepositoryException {
    synchronized (this) {
        // validate and register new node type definitions
        internalRegister(ntDefs, external);
        // persist new node type definitions
        for (QNodeTypeDefinition ntDef : ntDefs) {
            customNTDefs.add(ntDef);
        }
        persistCustomNodeTypeDefs(customNTDefs);
        // notify listeners
        for (QNodeTypeDefinition ntDef : ntDefs) {
            notifyRegistered(ntDef.getName());
        }
    }
    // inform cluster if this is not an external invocation
    if (!external && eventChannel != null) {
        eventChannel.registered(ntDefs);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition)

Aggregations

QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)58 Name (org.apache.jackrabbit.spi.Name)21 ArrayList (java.util.ArrayList)13 RepositoryException (javax.jcr.RepositoryException)11 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)9 NodeType (javax.jcr.nodetype.NodeType)7 QNodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)6 HashMap (java.util.HashMap)5 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)5 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)5 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)4 InvalidNodeTypeDefException (org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException)4 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)4 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4 QNodeTypeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)4 CompactNodeTypeDefReader (org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader)3 NamespaceMapping (org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping)3 QDefinitionBuilderFactory (org.apache.jackrabbit.spi.commons.nodetype.QDefinitionBuilderFactory)3 QNodeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder)3