use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeTypeRegistryImpl method getEffectiveNodeType.
/**
* @param ntNames
* @param entCache
* @param ntdCache
* @return
* @throws ConstraintViolationException
* @throws NoSuchNodeTypeException
*/
private EffectiveNodeType getEffectiveNodeType(Name[] ntNames, EffectiveNodeTypeCache entCache, Map<Name, QNodeTypeDefinition> ntdCache) throws ConstraintViolationException, NoSuchNodeTypeException {
EffectiveNodeTypeCache.Key key = entCache.getKey(ntNames);
// 1. check if aggregate has already been built
if (entCache.contains(key)) {
return entCache.get(key);
}
// 2. make sure we've got the definitions of the specified node types
for (Name ntName : ntNames) {
if (!ntdCache.containsKey(ntName)) {
throw new NoSuchNodeTypeException(ntName.toString());
}
}
// 3. build aggregate
EffectiveNodeTypeCache.Key requested = key;
EffectiveNodeTypeImpl result = null;
synchronized (entCache) {
// build list of 'best' existing sub-aggregates
while (key.getNames().length > 0) {
// find the (sub) key that matches the current key the best
EffectiveNodeTypeCache.Key subKey = entCache.findBest(key);
if (subKey != null) {
EffectiveNodeTypeImpl ent = (EffectiveNodeTypeImpl) entCache.get(subKey);
if (result == null) {
result = ent;
} else {
result = result.merge(ent);
// store intermediate result
entCache.put(result);
}
// subtract the result from the temporary key
key = key.subtract(subKey);
} else {
/**
* no matching sub-aggregates found:
* build aggregate of remaining node types through iteration
*/
for (Name remainder : key.getNames()) {
QNodeTypeDefinition ntd = ntdCache.get(remainder);
EffectiveNodeType ent = getEffectiveNodeType(ntd, ntdCache);
// store new effective node type
entCache.put(ent);
if (result == null) {
result = (EffectiveNodeTypeImpl) ent;
} else {
result = result.merge((EffectiveNodeTypeImpl) ent);
// store intermediate result (sub-aggregate)
entCache.put(result);
}
}
break;
}
}
}
// the redundant nodetypes
if (!entCache.contains(requested)) {
entCache.put(requested, result);
}
// we're done
return result;
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeTypeManagerImplTest method testUnregisterNodeTypes.
public void testUnregisterNodeTypes() throws RepositoryException {
NodeTypeTemplate test = ntMgr.createNodeTypeTemplate();
test.setName("testNodeType2");
ntMgr.registerNodeType(test, true);
NodeType nt = ntMgr.getNodeType("testNodeType2");
assertNotNull(nt);
assertEquals("testNodeType2", nt.getName());
boolean supported = false;
try {
ntMgr.unregisterNodeType(test.getName());
supported = true;
} catch (UnsupportedRepositoryOperationException e) {
// ok
} catch (RepositoryException e) {
// TODO improve
if (e.getMessage().contains("not yet implemented")) {
// ok (original message in jr-core)
} else {
throw e;
}
}
if (supported) {
try {
ntMgr.getNodeType("testNodeType2");
fail("should not be available any more");
} catch (NoSuchNodeTypeException e) {
// success
}
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class AbstractVersionTest method setUp.
protected void setUp() throws Exception {
super.setUp();
super.checkSupportedOption(Repository.OPTION_VERSIONING_SUPPORTED);
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
// assert that this repository support versioning
try {
NodeType versionableNt = ntMgr.getNodeType(mixVersionable);
if (versionableNt == null) {
fail("Repository does not support Versioning: mixin nodetype 'mix:versionable' is missing.");
}
} catch (NoSuchNodeTypeException e) {
fail("Repository does not support Versioning: mixin nodetype 'mix:versionable' is missing.");
}
// retrieve versionable nodetype
String versionableNodeTypeName = getProperty("versionableNodeType");
try {
versionableNodeType = ntMgr.getNodeType(versionableNodeTypeName);
if (versionableNodeType == null) {
fail("Property 'versionableNodeType' does not define a valid nodetype: '" + versionableNodeTypeName + "'");
}
} catch (NoSuchNodeTypeException e) {
fail("Property 'versionableNodeType' does not define an existing nodetype: '" + versionableNodeTypeName + "'");
}
// make sure 'non-versionable' nodetype is properly defined
try {
nonVersionableNodeType = ntMgr.getNodeType(testNodeType);
if (nonVersionableNodeType == null || nonVersionableNodeType.isNodeType(mixVersionable)) {
fail("Property 'testNodeType' does define a versionable nodetype: '" + testNodeType + "'");
}
} catch (NoSuchNodeTypeException e) {
fail("Property 'testNodeType' does not define an existing nodetype: '" + testNodeType + "'");
}
// build persistent versionable and non-versionable nodes
try {
versionableNode = createVersionableNode(testRootNode, nodeName1, versionableNodeType);
} catch (RepositoryException e) {
fail("Failed to create versionable test node." + e.getMessage());
}
try {
nonVersionableNode = testRootNode.addNode(nodeName3, nonVersionableNodeType.getName());
testRootNode.getSession().save();
} catch (RepositoryException e) {
fail("Failed to create non-versionable test node." + e.getMessage());
}
propertyValue = getProperty("propertyValue");
if (propertyValue == null) {
fail("Property 'propertyValue' is not defined.");
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project kylo by Teradata.
the class JcrExtensibleTypeProvider method getType.
@Override
public ExtensibleType getType(final ID id) {
final JcrExtensibleType.TypeId typeId = (JcrExtensibleType.TypeId) id;
final Session session = getSession();
try {
final Node typeNode = session.getNodeByIdentifier(typeId.getIdValue());
final NodeType nodeType = session.getWorkspace().getNodeTypeManager().getNodeType(typeNode.getName());
return new JcrExtensibleType(typeNode, nodeType);
} catch (ItemNotFoundException e) {
return null;
} catch (NoSuchNodeTypeException | PathNotFoundException e) {
return null;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failure retriving exstenible type with ID: " + id, e);
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project kylo by Teradata.
the class JcrExtensibleTypeProvider method getType.
@Override
public ExtensibleType getType(final String name) {
final Session session = getSession();
final String typeName = ensureTypeName(name);
try {
final NodeType nodeType = session.getWorkspace().getNodeTypeManager().getNodeType(typeName);
final Node typeNode = session.getRootNode().getNode(ExtensionsConstants.TYPES + "/" + typeName);
return new JcrExtensibleType(typeNode, nodeType);
} catch (NoSuchNodeTypeException | PathNotFoundException e) {
return null;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to lookup extensible type: " + name, e);
}
}
Aggregations