List<NodeDefinitionValue> nodes = new ArrayList<NodeDefinitionValue>();
List<String> requeredPrimaryType = new ArrayList<String>();
requeredPrimaryType.add("nt:hierarchyNode");
nodes
.add(new NodeDefinitionValue("child", false, false, 1, false, "nt:hierarchyNode", requeredPrimaryType, false));
testNValue.setDeclaredChildNodeDefinitionValues(nodes);
nodeTypeManager.registerNodeType(testNValue, ExtendedNodeTypeManager.FAIL_IF_EXISTS);
testNValue = nodeTypeManager.getNodeTypeValue(testNValue.getName());
Node testNode = root.addNode("testNode", testNValue.getName());
session.save();
try
{
testNode.addNode("wrongchild", "nt:unstructured");
fail();
}
catch (ConstraintViolationException e)
{
// ok
}
Node child = testNode.addNode("child", "nt:file");
Node cont = child.addNode("jcr:content", "nt:resource");
cont.setProperty("jcr:mimeType", "text");
cont.setProperty("jcr:lastModified", new GregorianCalendar(2011, 3, 4));
cont.setProperty("jcr:data", "test text");
session.save();
nodes = new ArrayList<NodeDefinitionValue>();
requeredPrimaryType = new ArrayList<String>();
requeredPrimaryType.add("nt:folder");
nodes
.add(new NodeDefinitionValue("child", false, false, 1, false, "nt:hierarchyNode", requeredPrimaryType, false));
testNValue.setDeclaredChildNodeDefinitionValues(nodes);
try
{
nodeTypeManager.registerNodeType(testNValue, ExtendedNodeTypeManager.REPLACE_IF_EXISTS);