use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeTypeRegistry method internalUnregister.
private void internalUnregister(Name name) throws NoSuchNodeTypeException {
QNodeTypeDefinition ntd = registeredNTDefs.get(name);
if (ntd == null) {
throw new NoSuchNodeTypeException(name.toString());
}
registeredNTDefs.remove(name);
entCache.invalidate(name);
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeTypeRegistry method checkForCircularInheritance.
static void checkForCircularInheritance(Name[] supertypes, Stack<Name> inheritanceChain, Map<Name, QNodeTypeDefinition> ntDefCache) throws InvalidNodeTypeDefException, RepositoryException {
for (Name nt : supertypes) {
int pos = inheritanceChain.lastIndexOf(nt);
if (pos >= 0) {
StringBuilder buf = new StringBuilder();
for (int j = 0; j < inheritanceChain.size(); j++) {
if (j == pos) {
buf.append("--> ");
}
buf.append(inheritanceChain.get(j));
buf.append(" extends ");
}
buf.append("--> ");
buf.append(nt);
throw new InvalidNodeTypeDefException("circular inheritance detected: " + buf.toString());
}
try {
QNodeTypeDefinition ntd = ntDefCache.get(nt);
Name[] sta = ntd.getSupertypes();
if (sta.length > 0) {
// check recursively
inheritanceChain.push(nt);
checkForCircularInheritance(sta, inheritanceChain, ntDefCache);
inheritanceChain.pop();
}
} catch (NoSuchNodeTypeException nsnte) {
String msg = "unknown supertype: " + nt;
log.debug(msg);
throw new InvalidNodeTypeDefException(msg, nsnte);
}
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeTypeRegistry method getEffectiveNodeType.
/**
* Returns an effective node type representation of the given node types.
*
* @param ntNames array of node type names
* @param entCache cache of already-built effective node types
* @param ntdCache cache of node type definitions
* @return the desired effective node type
* @throws NodeTypeConflictException if the effective node type representation
* could not be built due to conflicting
* node type definitions.
* @throws NoSuchNodeTypeException if a node type reference (e.g. a supertype)
* could not be resolved.
*/
static EffectiveNodeType getEffectiveNodeType(Name[] ntNames, EffectiveNodeTypeCache entCache, Map<Name, QNodeTypeDefinition> ntdCache) throws NodeTypeConflictException, 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;
EffectiveNodeType 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) {
EffectiveNodeType ent = 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
*/
Name[] remainder = key.getNames();
for (Name aRemainder : remainder) {
QNodeTypeDefinition ntd = ntdCache.get(aRemainder);
EffectiveNodeType ent = EffectiveNodeType.create(ntd, entCache, ntdCache);
// store new effective node type
entCache.put(ent);
if (result == null) {
result = ent;
} else {
result = result.merge(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 PredefinedNodeTypeTest method testPredefinedNodeType.
/**
* Tests that the named node type matches the JSR 170 specification.
* The test is performed by genererating a node type definition spec
* string in the format used by the JSR 170 specification, and comparing
* the result with a static spec file extracted from the specification
* itself.
* <p>
* Note that the extracted spec files are not exact copies of the node
* type specification in the JSR 170 document. Some formatting and
* ordering changes have been made to simplify the test code, but the
* semantics remain the same.
*
* @param name node type name
* @param propsVariant whether the properties of this node type may
* have implementation variant autocreated and OPV flags.
* @throws NotExecutableException if the node type is not supported by
* this repository implementation.
*/
private void testPredefinedNodeType(String name, boolean propsVariant) throws NotExecutableException {
try {
StringBuffer spec = new StringBuffer();
String resource = "org/apache/jackrabbit/test/api/nodetype/spec/" + name.replace(':', '-') + ".txt";
Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(resource));
for (int ch = reader.read(); ch != -1; ch = reader.read()) {
spec.append((char) ch);
}
NodeType type = manager.getNodeType(name);
String current = getNodeTypeSpec(type, propsVariant).trim();
if (!System.getProperty("line.separator").equals("\n")) {
current = normalizeLineSeparators(current);
}
String expected = normalizeLineSeparators(spec.toString()).trim();
assertEquals("Predefined node type " + name, expected, current);
// check minimum declared supertypes
Set<String> declaredSupertypes = new HashSet<String>();
for (Iterator<NodeType> it = Arrays.asList(type.getDeclaredSupertypes()).iterator(); it.hasNext(); ) {
NodeType nt = it.next();
declaredSupertypes.add(nt.getName());
}
for (Iterator<String> it = Arrays.asList(SUPERTYPES.get(name)).iterator(); it.hasNext(); ) {
String supertype = it.next();
assertTrue("Predefined node type " + name + " does not " + "declare supertype " + supertype, declaredSupertypes.contains(supertype));
}
} catch (IOException e) {
fail(e.getMessage());
} catch (NoSuchNodeTypeException e) {
// only nt:base is strictly required
if ("nt:base".equals(name)) {
fail(e.getMessage());
} else {
throw new NotExecutableException("NodeType " + name + " not supported by this repository implementation.");
}
} catch (RepositoryException e) {
fail(e.getMessage());
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeTypeManagerTest method testGetNodeType.
/**
* Test if getNodeType(String nodeTypeName) returns the expected NodeType and
* if a NoSuchTypeException is thrown if no according node type is existing
*/
public void testGetNodeType() throws RepositoryException {
NodeType type = manager.getAllNodeTypes().nextNodeType();
assertEquals("getNodeType(String nodeTypeName) does not return correct " + "NodeType", manager.getNodeType(type.getName()).getName(), type.getName());
StringBuffer notExistingName = new StringBuffer("X");
NodeTypeIterator types = manager.getAllNodeTypes();
while (types.hasNext()) {
// build a name which is for sure not existing
// (":" of namespace prefix will be replaced later on)
notExistingName.append(types.nextNodeType().getName());
}
try {
manager.getNodeType(notExistingName.toString().replaceAll(":", ""));
fail("getNodeType(String nodeTypeName) must throw a " + "NoSuchNodeTypeException if no according NodeType " + "does exist");
} catch (NoSuchNodeTypeException e) {
// success
}
}
Aggregations