use of org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType 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.jcr2spi.nodetype.EffectiveNodeType in project jackrabbit by apache.
the class ItemStateValidator method validate.
/**
* Checks whether the given node state satisfies the constraints specified
* by its primary and mixin node types. The following validations/checks are
* performed:
* <ul>
* <li>check if its node type satisfies the 'required node types' constraint
* specified in its definition</li>
* <li>check if all 'mandatory' child items exist</li>
* <li>for every property: check if the property value satisfies the
* value constraints specified in the property's definition</li>
* </ul>
*
* @param nodeState state of node to be validated
* @throws ConstraintViolationException if any of the validations fail
* @throws RepositoryException if another error occurs
*/
public void validate(NodeState nodeState) throws ConstraintViolationException, RepositoryException {
// effective primary node type
EffectiveNodeType entPrimary = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeState.getNodeTypeName());
QNodeDefinition def = nodeState.getDefinition();
// check if primary type satisfies the 'required node types' constraint
Name[] requiredPrimaryTypes = def.getRequiredPrimaryTypes();
for (int i = 0; i < requiredPrimaryTypes.length; i++) {
if (!entPrimary.includesNodeType(requiredPrimaryTypes[i])) {
String msg = safeGetJCRPath(nodeState) + ": missing required primary type " + requiredPrimaryTypes[i];
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
// mandatory properties
// effective node type (primary type incl. mixins)
Name[] ntNames = nodeState.getAllNodeTypeNames();
EffectiveNodeType entPrimaryAndMixins = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
QPropertyDefinition[] pda = entPrimaryAndMixins.getMandatoryQPropertyDefinitions();
for (int i = 0; i < pda.length; i++) {
QPropertyDefinition pd = pda[i];
if (!nodeState.hasPropertyName(pd.getName())) {
String msg = safeGetJCRPath(nodeState) + ": mandatory property " + pd.getName() + " does not exist";
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
// mandatory child nodes
QNodeDefinition[] cnda = entPrimaryAndMixins.getMandatoryQNodeDefinitions();
for (int i = 0; i < cnda.length; i++) {
QNodeDefinition cnd = cnda[i];
if (!nodeState.getNodeEntry().hasNodeEntry(cnd.getName())) {
String msg = safeGetJCRPath(nodeState) + ": mandatory child node " + cnd.getName() + " does not exist";
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
}
Aggregations