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);
}
}
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();
}
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);
}
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);
}
}
}
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);
}
}
Aggregations