use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeSetPrimaryTypeTest method testAddNonExisting.
/**
* Tests if <code>Node.setPrimaryType(String)</code> throws a
* <code>NoSuchNodeTypeException</code> if the
* name of an existing node type is passed.
*/
public void testAddNonExisting() throws RepositoryException {
Session session = testRootNode.getSession();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
String nonExistingMixinName = "abc";
while (manager.hasNodeType(nonExistingMixinName)) {
nonExistingMixinName += "_";
}
Node node = testRootNode.addNode(nodeName1, testNodeType);
try {
node.setPrimaryType(nonExistingMixinName);
// ev. only detected upon save
superuser.save();
fail("Node.setPrimaryType(String) must throw a NoSuchNodeTypeException if no nodetype exists with the given name.");
} catch (NoSuchNodeTypeException e) {
// success
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class AbstractWorkspaceSameNameSibsTest method setUp.
protected void setUp() throws Exception {
super.setUp();
// we assume sameNameSibs is supported by repository
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
// make sure 'sameNameSibsTrue' nodetype is properly defined
try {
sameNameSibsTrueNodeType = ntMgr.getNodeType(getProperty(PROP_SAME_NAME_SIBS_TRUE_NODE_TYPE));
NodeDefinition[] childNodeDefs = sameNameSibsTrueNodeType.getDeclaredChildNodeDefinitions();
boolean isSameNameSibs = false;
for (int i = 0; i < childNodeDefs.length; i++) {
if (childNodeDefs[i].allowsSameNameSiblings()) {
isSameNameSibs = true;
break;
}
}
if (!isSameNameSibs) {
throw new NotExecutableException("Property 'sameNameSibsTrueNodeType' does not define a nodetype where sameNameSibs are allowed: '" + sameNameSibsTrueNodeType.getName() + "'");
}
} catch (NoSuchNodeTypeException e) {
fail("Property 'sameNameSibsTrueNodeType' does not define an existing nodetype: '" + sameNameSibsTrueNodeType + "'");
}
// make sure 'sameNameSibsFalse' nodetype is properly defined
try {
sameNameSibsFalseNodeType = ntMgr.getNodeType(getProperty(PROP_SAME_NAME_SIBS_FALSE_NODE_TYPE));
NodeDefinition[] childNodeDefs = sameNameSibsFalseNodeType.getDeclaredChildNodeDefinitions();
boolean isSameNameSibs = true;
for (int i = 0; i < childNodeDefs.length; i++) {
if (!childNodeDefs[i].allowsSameNameSiblings()) {
isSameNameSibs = false;
break;
}
}
if (isSameNameSibs) {
fail("Property 'sameNameSibsFalseNodeType' does define a nodetype where sameNameSibs are not allowed: '" + sameNameSibsFalseNodeType.getName() + "'");
}
} catch (NoSuchNodeTypeException e) {
fail("Property 'sameNameSibsFalseNodeType' does not define an existing nodetype: '" + sameNameSibsFalseNodeType + "'");
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeCanAddMixinTest method testNonExisting.
/**
* Tests if <code>Node.canAddMixin(String mixinName)</code> throws a
* <code>NoSuchNodeTypeException</code> if <code>mixinName</code> is not the
* name of an existing mixin node type
*/
public void testNonExisting() throws RepositoryException {
Session session = testRootNode.getSession();
String nonExistingMixinName = NodeMixinUtil.getNonExistingMixinName(session);
Node node = testRootNode.addNode(nodeName1, testNodeType);
try {
node.canAddMixin(nonExistingMixinName);
fail("Node.canAddMixin(String mixinName) must throw a " + "NoSuchNodeTypeException if mixinName is an unknown mixin type");
} catch (NoSuchNodeTypeException e) {
// success
}
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeTypeImpl method getInheritedSupertypes.
/**
* Returns all <i>inherited</i> supertypes of this node type.
*
* @return an array of <code>NodeType</code> objects.
* @see #getSupertypes
* @see #getDeclaredSupertypes
*/
public NodeType[] getInheritedSupertypes() {
// declared supertypes
Name[] ntNames = ntd.getSupertypes();
Set<Name> declared = new HashSet<Name>();
for (Name ntName : ntNames) {
declared.add(ntName);
}
// all supertypes
ntNames = ent.getInheritedNodeTypes();
// filter from all supertypes those that are not declared
List<NodeType> inherited = new ArrayList<NodeType>();
for (Name ntName : ntNames) {
if (!declared.contains(ntName)) {
try {
inherited.add(ntMgr.getNodeType(ntName));
} catch (NoSuchNodeTypeException e) {
// should never get here
log.error("undefined supertype", e);
return new NodeType[0];
}
}
}
return inherited.toArray(new NodeType[inherited.size()]);
}
use of javax.jcr.nodetype.NoSuchNodeTypeException in project jackrabbit by apache.
the class NodeTypeRegistry method reregisterNodeType.
/**
* Internal implementation of {@link #reregisterNodeType(QNodeTypeDefinition)}.
*
* @param ntd node type definition
* @param external whether this invocation should be considered external
* @return the new effective node type
* @throws NoSuchNodeTypeException if <code>ntd</code> refers to an
* unknown node type
* @throws InvalidNodeTypeDefException if the node type definition
* is invalid
* @throws RepositoryException if another error occurs
*/
private EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd, boolean external) throws NoSuchNodeTypeException, InvalidNodeTypeDefException, RepositoryException {
EffectiveNodeType entNew;
synchronized (this) {
Name name = ntd.getName();
if (!registeredNTDefs.containsKey(name)) {
throw new NoSuchNodeTypeException(name.toString());
}
if (builtInNTDefs.contains(name)) {
throw new RepositoryException(name.toString() + ": can't reregister built-in node type.");
}
/**
* validate new node type definition
*/
ntd = checkNtBaseSubtyping(ntd, registeredNTDefs);
validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
/**
* build diff of current and new definition and determine type of change
*/
QNodeTypeDefinition ntdOld = registeredNTDefs.get(name);
NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
if (!diff.isModified()) {
// the definition has not been modified, there's nothing to do here...
return getEffectiveNodeType(name);
}
// make sure existing content would not conflict
// with new node type definition
checkForConflictingContent(ntd, diff);
/**
* re-register node type definition and update caches &
* notify listeners on re-registration
*/
internalUnregister(name);
// remove old node type definition from store
customNTDefs.remove(name);
entNew = internalRegister(ntd);
// add new node type definition to store
customNTDefs.add(ntd);
// persist node type definitions
persistCustomNodeTypeDefs(customNTDefs);
// notify listeners
notifyReRegistered(name);
}
// inform cluster if this is not an external invocation
if (!external && eventChannel != null) {
eventChannel.reregistered(ntd);
}
return entNew;
}
Aggregations