use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit-oak by apache.
the class TypeEditorProvider method isTrivialChange.
private boolean isTrivialChange(ReadOnlyNodeTypeManager ntBefore, ReadOnlyNodeTypeManager ntAfter, String nodeType) {
NodeType nb, na;
try {
nb = ntBefore.getNodeType(nodeType);
} catch (NoSuchNodeTypeException ex) {
LOG.info(nodeType + " not present in 'before' state");
return true;
} catch (RepositoryException ex) {
LOG.info("getting node type", ex);
return false;
}
try {
na = ntAfter.getNodeType(nodeType);
} catch (NoSuchNodeTypeException ex) {
LOG.info(nodeType + " was removed");
return false;
} catch (RepositoryException ex) {
LOG.info("getting node type", ex);
return false;
}
NodeTypeDefDiff diff = NodeTypeDefDiff.create(nb, na);
if (!diff.isModified()) {
LOG.info("Node type " + nodeType + " was not changed");
return true;
} else if (diff.isTrivial()) {
LOG.info("Node type change for " + nodeType + " appears to be trivial");
return true;
} else {
LOG.info("Node type change for " + nodeType + " requires repository scan: " + diff);
return false;
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit-oak by apache.
the class ReadWriteNodeTypeManager method unregisterNodeType.
@Override
public void unregisterNodeType(String name) throws RepositoryException {
Root root = getWriteRoot();
Tree type = root.getTree(NODE_TYPES_PATH).getChild(getOakName(name));
if (!type.exists()) {
throw new NoSuchNodeTypeException("Node type " + name + " can not be unregistered.");
}
try {
type.remove();
root.commit();
refresh();
} catch (CommitFailedException e) {
String message = "Failed to unregister node type " + name;
throw e.asRepositoryException(message);
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit-oak by apache.
the class NodeDelegate method removeMixin.
public void removeMixin(String typeName) throws RepositoryException {
Tree tree = getTree();
Set<String> mixins = newLinkedHashSet(getNames(tree, JCR_MIXINTYPES));
if (!mixins.remove(typeName)) {
throw new NoSuchNodeTypeException("Mixin " + typeName + " not contained in " + getPath());
}
updateMixins(mixins, Collections.singleton(typeName));
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit-oak by apache.
the class MixinTest method testRemoveInheritedMixin.
public void testRemoveInheritedMixin() throws Exception {
Node node = testRootNode.addNode("testRemoveInheritedMixin", NT_UNSTRUCTURED);
node.addMixin(JcrConstants.MIX_VERSIONABLE);
superuser.save();
try {
node.removeMixin(JcrConstants.MIX_REFERENCEABLE);
fail();
} catch (NoSuchNodeTypeException e) {
// success
} finally {
node.remove();
superuser.save();
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class GQL method collectNodeTypes.
/**
* Resolves and collects all node types that match <code>ntName</code>.
*
* @param ntName the name of a node type (optionally without prefix).
* @throws RepositoryException if an error occurs while reading from the
* node type manager.
*/
private void collectNodeTypes(String ntName) throws RepositoryException {
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
String[] resolvedNames = resolveNodeTypeName(ntName);
// now resolve node type hierarchy
for (String resolvedName : resolvedNames) {
try {
NodeType base = ntMgr.getNodeType(resolvedName);
if (base.isMixin()) {
// search for nodes where jcr:mixinTypes is set to this mixin
addTypeConstraint(new MixinComparision(resolvedName));
} else {
// search for nodes where jcr:primaryType is set to this type
addTypeConstraint(new PrimaryTypeComparision(resolvedName));
}
// now search for all node types that are derived from base
NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
while (allTypes.hasNext()) {
NodeType nt = allTypes.nextNodeType();
NodeType[] superTypes = nt.getSupertypes();
if (Arrays.asList(superTypes).contains(base)) {
if (nt.isMixin()) {
addTypeConstraint(new MixinComparision(nt.getName()));
} else {
addTypeConstraint(new PrimaryTypeComparision(nt.getName()));
}
}
}
} catch (NoSuchNodeTypeException e) {
// add anyway -> will not match anything
addTypeConstraint(new PrimaryTypeComparision(resolvedName));
}
}
}
Aggregations