use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class DefinitionUtil method createQNodeTypeDefinition.
static QNodeTypeDefinition createQNodeTypeDefinition(Element ntdElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
QNodeTypeDefinitionBuilder builder = new QNodeTypeDefinitionBuilder();
// NOTE: the server should send the namespace-mappings as addition ns-defininitions
try {
if (ntdElement.hasAttribute(NAME_ATTRIBUTE)) {
builder.setName(resolver.getQName(ntdElement.getAttribute(NAME_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(PRIMARYITEMNAME_ATTRIBUTE)) {
builder.setPrimaryItemName(resolver.getQName(ntdElement.getAttribute(PRIMARYITEMNAME_ATTRIBUTE)));
}
Element child = DomUtil.getChildElement(ntdElement, SUPERTYPES_ELEMENT, null);
if (child != null) {
ElementIterator stIter = DomUtil.getChildren(child, SUPERTYPE_ELEMENT, null);
List<Name> qNames = new ArrayList<Name>();
while (stIter.hasNext()) {
Name st = resolver.getQName(DomUtil.getTextTrim(stIter.nextElement()));
qNames.add(st);
}
builder.setSupertypes(qNames.toArray(new Name[qNames.size()]));
}
if (ntdElement.hasAttribute(ISMIXIN_ATTRIBUTE)) {
builder.setMixin(Boolean.valueOf(ntdElement.getAttribute(ISMIXIN_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)) {
builder.setOrderableChildNodes(Boolean.valueOf(ntdElement.getAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(ISABSTRACT_ATTRIBUTE)) {
builder.setAbstract(Boolean.valueOf(ntdElement.getAttribute(ISABSTRACT_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(ISQUERYABLE_ATTRIBUTE)) {
builder.setQueryable(Boolean.valueOf(ntdElement.getAttribute(ISQUERYABLE_ATTRIBUTE)));
}
// nodeDefinitions
ElementIterator it = DomUtil.getChildren(ntdElement, CHILDNODEDEFINITION_ELEMENT, null);
List<QNodeDefinition> nds = new ArrayList<QNodeDefinition>();
while (it.hasNext()) {
nds.add(createQNodeDefinition(builder.getName(), it.nextElement(), resolver));
}
builder.setChildNodeDefs(nds.toArray(new QNodeDefinition[nds.size()]));
// propertyDefinitions
it = DomUtil.getChildren(ntdElement, PROPERTYDEFINITION_ELEMENT, null);
List<QPropertyDefinition> pds = new ArrayList<QPropertyDefinition>();
while (it.hasNext()) {
pds.add(createQPropertyDefinition(builder.getName(), it.nextElement(), resolver, qValueFactory));
}
builder.setPropertyDefs(pds.toArray(new QPropertyDefinition[pds.size()]));
} catch (NameException e) {
log.error(e.getMessage());
throw new RepositoryException(e);
}
return builder.build();
}
use of org.apache.jackrabbit.spi.QNodeDefinition 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);
}
}
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class SessionItemStateManager method visit.
/**
* @see OperationVisitor#visit(Move)
*/
public void visit(Move operation) throws LockException, ConstraintViolationException, AccessDeniedException, ItemExistsException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
// retrieve states and assert they are modifiable
NodeState srcState = operation.getSourceState();
NodeState srcParent = operation.getSourceParentState();
NodeState destParent = operation.getDestinationParentState();
// state validation: move-Source can be removed from old/added to new parent
validator.checkRemoveItem(srcState, operation.getOptions());
validator.checkAddNode(destParent, operation.getDestinationName(), srcState.getNodeTypeName(), operation.getOptions());
// retrieve applicable definition at the new place
ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
QNodeDefinition newDefinition = defProvider.getQNodeDefinition(destParent.getAllNodeTypeNames(), operation.getDestinationName(), srcState.getNodeTypeName());
// perform the move (modifying states)
srcParent.moveChildNodeEntry(destParent, srcState, operation.getDestinationName(), newDefinition);
// remember operation
transientStateMgr.addOperation(operation);
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class QNodeTypeDefinitionImpl method getDependencies.
/**
* {@inheritDoc}
*/
public Collection<Name> getDependencies() {
if (dependencies == null) {
Collection<Name> deps = new HashSet<Name>();
// supertypes
deps.addAll(Arrays.asList(supertypes));
// child node definitions
for (QNodeDefinition childNodeDef : childNodeDefs) {
// default primary type
Name ntName = childNodeDef.getDefaultPrimaryType();
if (ntName != null && !name.equals(ntName)) {
deps.add(ntName);
}
// required primary type
Name[] ntNames = childNodeDef.getRequiredPrimaryTypes();
for (Name ntName1 : ntNames) {
if (ntName1 != null && !name.equals(ntName1)) {
deps.add(ntName1);
}
}
}
// property definitions
for (QPropertyDefinition propertyDef : propertyDefs) {
// [WEAK]REFERENCE value constraints
if (propertyDef.getRequiredType() == PropertyType.REFERENCE || propertyDef.getRequiredType() == PropertyType.WEAKREFERENCE) {
QValueConstraint[] ca = propertyDef.getValueConstraints();
if (ca != null) {
for (QValueConstraint aCa : ca) {
NameFactory factory = NameFactoryImpl.getInstance();
Name ntName = factory.create(aCa.getString());
if (!name.equals(ntName)) {
deps.add(ntName);
}
}
}
}
}
dependencies = Collections.unmodifiableCollection(deps);
}
return dependencies;
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class QNodeTypeDefinitionImpl method createQNodeDefinitions.
private static QNodeDefinition[] createQNodeDefinitions(Name declName, NodeDefinition[] nds, NamePathResolver resolver) throws RepositoryException {
if (nds == null || nds.length == 0) {
return QNodeDefinition.EMPTY_ARRAY;
}
QNodeDefinition[] declaredNodeDefs = new QNodeDefinition[nds.length];
for (int i = 0; i < nds.length; i++) {
NodeDefinition nodeDef = nds[i];
Name name = nodeDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(nodeDef.getName());
// check if propDef provides declaring node type and if it matches 'this' one.
if (nodeDef.getDeclaringNodeType() != null) {
if (!declName.equals(resolver.getQName(nodeDef.getDeclaringNodeType().getName()))) {
throw new RepositoryException("Childnode definition specified invalid declaring nodetype: " + nodeDef.getDeclaringNodeType().getName() + ", but should be " + declName);
}
}
Name defaultPrimaryType = nodeDef.getDefaultPrimaryTypeName() == null ? null : resolver.getQName(nodeDef.getDefaultPrimaryTypeName());
Name[] requiredPrimaryTypes = getNames(nodeDef.getRequiredPrimaryTypeNames(), resolver);
declaredNodeDefs[i] = new QNodeDefinitionImpl(name, declName, nodeDef.isAutoCreated(), nodeDef.isMandatory(), nodeDef.getOnParentVersion(), nodeDef.isProtected(), defaultPrimaryType, requiredPrimaryTypes, nodeDef.allowsSameNameSiblings());
}
return declaredNodeDefs;
}
Aggregations