Here are the examples of the java api class javax.jcr.nodetype.NodeDefinition taken from open source projects.
1. ChildNodeDefGenerationTest#testResidualChildNodeDefinitions()
Project: sling
File: ChildNodeDefGenerationTest.java
File: ChildNodeDefGenerationTest.java
@Test public void testResidualChildNodeDefinitions() throws JSONException, ServletException, IOException { NodeType ntWithChildNOdeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs"); NodeDefinition childNodeDef1 = getSimpleChildNodeDef("*"); NodeDefinition childNodeDef2 = getSimpleChildNodeDef("*"); NodeDefinition childNodeDef3 = getSimpleChildNodeDef("childNodeDef"); NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2, childNodeDef3 }; when(ntWithChildNOdeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs); when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNOdeDefs); when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE); assertEqualsWithServletResult("testResidualChildNodeDefinitions"); }
2. ChildNodeDefGenerationTest#testCompleteChildNodeDefinitions()
Project: sling
File: ChildNodeDefGenerationTest.java
File: ChildNodeDefGenerationTest.java
@Test public void testCompleteChildNodeDefinitions() throws ServletException, IOException, JSONException { NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs"); NodeDefinition childNodeDef1 = getCompleteChildNodeDef("childNodeDef1"); NodeDefinition childNodeDef2 = getCompleteChildNodeDef("childNodeDef2"); NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2 }; when(ntWithChildNodeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs); when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs); when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE); assertEqualsWithServletResult("testCompleteChildNodeDefinitions"); }
3. ChildNodeDefGenerationTest#testSimpleChildNodeDefinitions()
Project: sling
File: ChildNodeDefGenerationTest.java
File: ChildNodeDefGenerationTest.java
@Test public void testSimpleChildNodeDefinitions() throws ServletException, IOException, JSONException { NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs"); NodeDefinition childNodeDef1 = getSimpleChildNodeDef("childNodeDef1"); NodeDefinition childNodeDef2 = getSimpleChildNodeDef("childNodeDef2"); NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2 }; when(ntWithChildNodeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs); when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs); when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE); assertEqualsWithServletResult("testSimpleChildNodeDefinitions"); }
4. MockNodeTypeGenerator#getCompleteChildNodeDef()
Project: sling
File: MockNodeTypeGenerator.java
File: MockNodeTypeGenerator.java
public NodeDefinition getCompleteChildNodeDef(String name) { NodeDefinition childNodeDef1 = mock(NodeDefinition.class); NodeType requiredPrimaryType1 = getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME1); NodeType requiredPrimaryType2 = getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME2); NodeType[] reqPrimaryTypes = { requiredPrimaryType1, requiredPrimaryType2 }; when(childNodeDef1.getRequiredPrimaryTypes()).thenReturn(reqPrimaryTypes); when(childNodeDef1.getName()).thenReturn(name); when(childNodeDef1.getOnParentVersion()).thenReturn(OnParentVersionAction.VERSION); when(childNodeDef1.getDefaultPrimaryType()).thenReturn(requiredPrimaryType1); when(childNodeDef1.allowsSameNameSiblings()).thenReturn(Boolean.TRUE); when(childNodeDef1.isAutoCreated()).thenReturn(Boolean.TRUE); when(childNodeDef1.isMandatory()).thenReturn(Boolean.TRUE); when(childNodeDef1.isProtected()).thenReturn(Boolean.TRUE); return childNodeDef1; }
5. ChildNodeDefGenerationTest#testOneSimpleChildNodeDefinition()
Project: sling
File: ChildNodeDefGenerationTest.java
File: ChildNodeDefGenerationTest.java
@Test public void testOneSimpleChildNodeDefinition() throws ServletException, IOException, JSONException { NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs"); NodeDefinition[] childNodeDefs = { getSimpleChildNodeDef("childNodeDef1") }; when(ntWithChildNodeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs); when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs); when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE); assertEqualsWithServletResult("testOneSimpleChildNodeDefinition"); }
6. NodeTypeAssertion#compareTemplateToNodeType()
Project: modeshape
File: NodeTypeAssertion.java
File: NodeTypeAssertion.java
@SuppressWarnings("unchecked") public static void compareTemplateToNodeType(NodeTypeTemplate template, NodeType nodeType) { compareNodeTypeDefinitions(template, nodeType); PropertyDefinition[] propertyDefs = nodeType.getDeclaredPropertyDefinitions(); List<PropertyDefinitionTemplate> propertyTemplates = template.getPropertyDefinitionTemplates(); comparePropertyDefinitions(propertyDefs, propertyTemplates); NodeDefinition[] childNodeDefs = nodeType.getDeclaredChildNodeDefinitions(); List<NodeDefinitionTemplate> childNodeTemplates = template.getNodeDefinitionTemplates(); compareChildNodeDefinitions(childNodeDefs, childNodeTemplates); }
7. CndImporterTest#assertChild()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
protected void assertChild(String nodeTypeName, String childName, String[] requiredTypes, String defaultPrimaryType, ChildOptions[] childOptions, OnParentVersion onParentVersioning) { Set<ChildOptions> options = new HashSet<ChildOptions>(); for (ChildOptions option : childOptions) options.add(option); NodeTypeDefinition defn = defn(nodeTypeName); NodeDefinition childDefn = childDefn(defn, childName); assertThat(childDefn.getName(), is(childName)); assertThat(childDefn.getDefaultPrimaryTypeName(), is(defaultPrimaryType)); assertThat(childDefn.isMandatory(), is(options.contains(ChildOptions.Mandatory))); assertThat(childDefn.isAutoCreated(), is(options.contains(ChildOptions.Autocreated))); assertThat(childDefn.isProtected(), is(options.contains(ChildOptions.Protected))); assertThat(childDefn.allowsSameNameSiblings(), is(options.contains(ChildOptions.Sns))); assertThat(childDefn.getOnParentVersion(), is(opv(onParentVersioning))); assertThat(childDefn.getRequiredPrimaryTypeNames(), is(requiredTypes)); }
8. CndSequencer#storeNodeTypeDefinition()
Project: modeshape
File: CndSequencer.java
File: CndSequencer.java
private void storeNodeTypeDefinition(Node outputNode, NodeTypeDefinition nodeTypeDefinition) throws RepositoryException { Node nodeTypeNode = processNodeTypeDefinition(outputNode, nodeTypeDefinition); PropertyDefinition[] declaredPropertyDefinitions = nodeTypeDefinition.getDeclaredPropertyDefinitions(); if (declaredPropertyDefinitions != null) { for (PropertyDefinition propertyDefinition : declaredPropertyDefinitions) { processPropertyDefinition(nodeTypeNode, propertyDefinition); } } NodeDefinition[] declaredChildNodeDefinitions = nodeTypeDefinition.getDeclaredChildNodeDefinitions(); if (declaredChildNodeDefinitions != null) { for (NodeDefinition childNodeDefinition : declaredChildNodeDefinitions) { processChildNodeDefinition(nodeTypeNode, childNodeDefinition); } } }
9. NodeTypeManagerImplTest#getChildNodeDefinition()
Project: jackrabbit-ocm
File: NodeTypeManagerImplTest.java
File: NodeTypeManagerImplTest.java
/** Returns a property defintion identified by its name. * * @param childNodeDefs Child nodes of a node type * @param childNodeName Name of child node to find * @return found */ protected NodeDefinition getChildNodeDefinition(NodeDefinition[] childNodeDefs, String childNodeName) { NodeDefinition found = null; for (int i = 0; i < childNodeDefs.length; i++) { if (childNodeDefs[i].getName().equals(childNodeName)) { found = childNodeDefs[i]; break; } } return found; }
10. CopyNodeTypesUpgradeTest#customNodeTypesAreRegistered()
Project: jackrabbit-oak
File: CopyNodeTypesUpgradeTest.java
File: CopyNodeTypesUpgradeTest.java
@Test public void customNodeTypesAreRegistered() throws RepositoryException { final JackrabbitSession adminSession = createAdminSession(); final NodeTypeManager nodeTypeManager = adminSession.getWorkspace().getNodeTypeManager(); final NodeType testFolderNodeType = nodeTypeManager.getNodeType("test:Folder"); final NodeDefinition[] cnd = testFolderNodeType.getChildNodeDefinitions(); final PropertyDefinition[] pd = testFolderNodeType.getPropertyDefinitions(); assertEquals("More than one child node definition", 1, cnd.length); assertEquals("Incorrect default primary type", "test:Folder", cnd[0].getDefaultPrimaryTypeName()); assertEquals("More than two property definitions", 4, pd.length); adminSession.logout(); }
11. NodeTypeDefinitionTest#testIndexedChildDefinition()
Project: jackrabbit-oak
File: NodeTypeDefinitionTest.java
File: NodeTypeDefinitionTest.java
public void testIndexedChildDefinition() throws Exception { String ntPath = NodeTypeConstants.NODE_TYPES_PATH + '/' + NodeTypeConstants.NT_VERSIONHISTORY; assertTrue(superuser.nodeExists(ntPath + "/jcr:childNodeDefinition")); assertTrue(superuser.nodeExists(ntPath + "/jcr:childNodeDefinition[1]")); Node cdNode = superuser.getNode(ntPath + "/jcr:childNodeDefinition[1]"); assertEquals(ntPath + "/jcr:childNodeDefinition", cdNode.getPath()); List<String> defNames = new ArrayList(); NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(NodeTypeConstants.NT_VERSIONHISTORY); for (NodeDefinition nd : nt.getDeclaredChildNodeDefinitions()) { defNames.add(nd.getName()); } Node ntNode = superuser.getNode(ntPath); NodeIterator it = ntNode.getNodes("jcr:childNodeDefinition*"); while (it.hasNext()) { Node def = it.nextNode(); int index = getIndex(def); String name = (def.hasProperty(NodeTypeConstants.JCR_NAME)) ? def.getProperty(NodeTypeConstants.JCR_NAME).getString() : NodeTypeConstants.RESIDUAL_NAME; assertEquals(name, defNames.get(index - 1)); } }
12. UserProviderTest#assertAutoCreatedItems()
Project: jackrabbit-oak
File: UserProviderTest.java
File: UserProviderTest.java
private static void assertAutoCreatedItems(@Nonnull Tree authorizableTree, @Nonnull String ntName, @Nonnull Root root) throws Exception { NodeType repUser = ReadOnlyNodeTypeManager.getInstance(root, NamePathMapper.DEFAULT).getNodeType(ntName); for (NodeDefinition cnd : repUser.getChildNodeDefinitions()) { if (cnd.isAutoCreated()) { assertTrue(authorizableTree.hasChild(cnd.getName())); } } for (PropertyDefinition pd : repUser.getPropertyDefinitions()) { if (pd.isAutoCreated()) { assertTrue(authorizableTree.hasProperty(pd.getName())); } } }
13. NodeTypeDefDiff#collectChildNodeDefs()
Project: jackrabbit-oak
File: NodeTypeDefDiff.java
File: NodeTypeDefDiff.java
private Map<NodeDefinitionId, List<NodeDefinition>> collectChildNodeDefs(final NodeDefinition[] cnda1) { Map<NodeDefinitionId, List<NodeDefinition>> defs1 = new HashMap<NodeDefinitionId, List<NodeDefinition>>(); for (NodeDefinition def1 : cnda1) { final NodeDefinitionId def1Id = new NodeDefinitionId(def1); List<NodeDefinition> list = defs1.get(def1Id); if (list == null) { list = new ArrayList<NodeDefinition>(); defs1.put(def1Id, list); } list.add(def1); } return defs1; }
14. MandatoryItemTest#setUp()
Project: jackrabbit
File: MandatoryItemTest.java
File: MandatoryItemTest.java
@Override protected void setUp() throws Exception { super.setUp(); NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(testNodeType); NodeDefinition[] ndefs = nt.getChildNodeDefinitions(); for (int i = 0; i < ndefs.length; i++) { if (ndefs[i].isMandatory() && !ndefs[i].isProtected() && !ndefs[i].isAutoCreated()) { childNodeDef = ndefs[i]; break; } } PropertyDefinition[] pdefs = nt.getPropertyDefinitions(); for (int i = 0; i < pdefs.length; i++) { if (pdefs[i].isMandatory() && !pdefs[i].isProtected() && !pdefs[i].isAutoCreated()) { childPropDef = pdefs[i]; break; } } if (childPropDef == null && childNodeDef == null) { cleanUp(); throw new NotExecutableException(); } }
15. NodeTypeUtil#getUndefinedChildNodeName()
Project: jackrabbit
File: NodeTypeUtil.java
File: NodeTypeUtil.java
/** * Returns a name that is not defined by the nodeType's child node def */ public static String getUndefinedChildNodeName(NodeType nodeType) { NodeDefinition nodeDefs[] = nodeType.getChildNodeDefinitions(); StringBuffer s = new StringBuffer("X"); for (int i = 0; i < nodeDefs.length; i++) { s.append(nodeDefs[i].getName()); } String undefinedName = s.toString(); undefinedName = undefinedName.replaceAll("\\*", ""); undefinedName = undefinedName.replaceAll(":", ""); return undefinedName; }
16. NodeDefTest#checkMandatoryConstraint()
Project: jackrabbit
File: NodeDefTest.java
File: NodeDefTest.java
/** * Checks if mandatory node definitions are respected. */ private void checkMandatoryConstraint(Node node, NodeType type) throws RepositoryException { // test if node contains all mandatory nodes of current type NodeDefinition nodeDefs[] = type.getChildNodeDefinitions(); for (int i = 0; i < nodeDefs.length; i++) { NodeDefinition nodeDef = nodeDefs[i]; if (nodeDef.isMandatory()) { foundMandatoryNode = true; try { node.getNode(nodeDef.getName()); } catch (PathNotFoundException e) { fail("Mandatory child " + nodeDef.getName() + " for " + node.getPath() + " does not exist."); } } } }
17. CanRemoveItemTest#testMandatoryChildNode()
Project: jackrabbit
File: CanRemoveItemTest.java
File: CanRemoveItemTest.java
/** * Tests if {@link NodeType#canRemoveItem(String)} and * {@link NodeType#canRemoveNode(String)} return * false if the specified node is a mandatory child node. */ public void testMandatoryChildNode() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false); if (nodeDef == null) { throw new NotExecutableException("No mandatory property def found."); } NodeType type = nodeDef.getDeclaringNodeType(); assertFalse("NodeType.canRemoveItem(String itemName) must return false " + "if itemName is a mandatory child node def.", type.canRemoveItem(nodeDef.getName())); assertFalse("NodeType.canRemoveNode(String nodeName) must return false " + "if nodeName is a mandatory child node def.", type.canRemoveNode(nodeDef.getName())); }
18. CanRemoveItemTest#testProtectedChildNode()
Project: jackrabbit
File: CanRemoveItemTest.java
File: CanRemoveItemTest.java
/** * Tests if {@link NodeType#canRemoveItem(String)} and * {@link NodeType#canRemoveNode(String)} return * false if the specified node is a protected child node. */ public void testProtectedChildNode() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false); if (nodeDef == null) { throw new NotExecutableException("No mandatory property def found."); } NodeType type = nodeDef.getDeclaringNodeType(); assertFalse("NodeType.canRemoveItem(String itemName) must return false " + "if itemName is a protected child node def.", type.canRemoveItem(nodeDef.getName())); assertFalse("NodeType.canRemoveNode(String nodeName) must return false " + "if nodeName is a protected child node def.", type.canRemoveNode(nodeDef.getName())); }
19. CanRemoveItemTest#testRemovableChildNode()
Project: jackrabbit
File: CanRemoveItemTest.java
File: CanRemoveItemTest.java
/** * Tests if {@link NodeType#canRemoveItem(String)} and * {@link NodeType#canRemoveNode(String)} return true * if the specified node is not a protected nor a mandatory * child node. */ public void testRemovableChildNode() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false); if (nodeDef == null) { throw new NotExecutableException("No mandatory property def found."); } NodeType type = nodeDef.getDeclaringNodeType(); assertTrue("NodeType.canRemoveItem(String itemName) must return true " + "if itemName is not a protected nor a mandatory child node def.", type.canRemoveItem(nodeDef.getName())); assertTrue("NodeType.canRemoveNode(String nodeName) must return true " + "if nodeName is not a protected nor a mandatory child node def.", type.canRemoveNode(nodeDef.getName())); }
20. CanAddChildNodeCallWithoutNodeTypeTest#testResidualWithoutDefault()
Project: jackrabbit
File: CanAddChildNodeCallWithoutNodeTypeTest.java
File: CanAddChildNodeCallWithoutNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns * true if <code>NodeType</code> contains a residual <code>NodeDef</code> * without a default primary type. */ public void testResidualWithoutDefault() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false, true); if (nodeDef == null) { throw new NotExecutableException("No residual child node def " + "with a defaultPrimaryType found."); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType); assertFalse("NodeType.canAddChildNode(String childNodeName) must return " + "false for a not defiend childNodeName if NodeType has a " + "residual child node definition without a defaultPrimaryType", nodeType.canAddChildNode(undefinedName)); }
21. CanAddChildNodeCallWithoutNodeTypeTest#testResidualWithDefault()
Project: jackrabbit
File: CanAddChildNodeCallWithoutNodeTypeTest.java
File: CanAddChildNodeCallWithoutNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns * true if <code>NodeType</code> contains a residual <code>NodeDef</code> * with a default primary type. */ public void testResidualWithDefault() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, true, true); if (nodeDef == null) { throw new NotExecutableException("No residual child node def " + "without a defaultPrimaryType found."); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType); assertTrue("NodeType.canAddChildNode(String childNodeName) must return " + "true for a not defined childNodeName if NodeType has a residual child node " + "definition with a defaultPrimaryType", nodeType.canAddChildNode(undefinedName)); }
22. CanAddChildNodeCallWithoutNodeTypeTest#testUndefined()
Project: jackrabbit
File: CanAddChildNodeCallWithoutNodeTypeTest.java
File: CanAddChildNodeCallWithoutNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns * true if <code>NodeType</code> nor does contain a <code>NodeDef</code> named * <code>childNodeName</code> nor a residual definition. */ public void testUndefined() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, true, false); if (nodeDef == null) { throw new NotExecutableException("No testable node type found."); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType); assertFalse("NodeType.canAddChildNode(String childNodeName) must return " + "false if 'childNodeName' is a undefined child node def", nodeType.canAddChildNode(undefinedName)); }
23. CanAddChildNodeCallWithoutNodeTypeTest#testDefinedWithoutDefault()
Project: jackrabbit
File: CanAddChildNodeCallWithoutNodeTypeTest.java
File: CanAddChildNodeCallWithoutNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns * true if <code>NodeType</code> contains a <code>NodeDef</code> named * <code>childNodeName</code> without a default primary type. */ public void testDefinedWithoutDefault() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false, false); if (nodeDef == null) { throw new NotExecutableException("No child node def without " + "defaultPrimaryType found"); } NodeType nodeType = nodeDef.getDeclaringNodeType(); assertFalse("NodeType.canAddChildNode(String childNodeName) must return false " + "if child node def 'childNodeName' does not define a defaultPrimaryType.", nodeType.canAddChildNode(nodeDef.getName())); }
24. CanAddChildNodeCallWithoutNodeTypeTest#testDefinedWithDefault()
Project: jackrabbit
File: CanAddChildNodeCallWithoutNodeTypeTest.java
File: CanAddChildNodeCallWithoutNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns * true if <code>NodeType</code> contains a <code>NodeDef</code> named * <code>childNodeName</code> with a default primary type. */ public void testDefinedWithDefault() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, true, false); if (nodeDef == null) { throw new NotExecutableException("No child node def with " + "defaultPrimaryType found"); } NodeType nodeType = nodeDef.getDeclaringNodeType(); assertTrue("NodeType.canAddChildNode(String childNodeName) must return " + "true if child node def 'childNodeName' defines a defaultPrimaryType.", nodeType.canAddChildNode(nodeDef.getName())); }
25. CanAddChildNodeCallWithNodeTypeTest#testResidualAndIllegalType()
Project: jackrabbit
File: CanAddChildNodeCallWithNodeTypeTest.java
File: CanAddChildNodeCallWithNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns false if <code>childNodeName</code> does not match the <code>NodeDef</code> * and <code>nodeTypeName</code> does not matches the node type of a residual * <code>NodeDef</code>. */ public void testResidualAndIllegalType() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, true); if (nodeDef == null) { throw new NotExecutableException("No testable residual child node def."); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType); String legalType = nodeDef.getRequiredPrimaryTypes()[0].getName(); String illegalType = NodeTypeUtil.getIllegalChildNodeType(manager, legalType); if (illegalType == null) { throw new NotExecutableException("No illegal node type name found"); } assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false for a not defined childNodeName if nodeTypeName " + "does not matches the type of a residual child node def", nodeType.canAddChildNode(undefinedName, illegalType)); }
26. CanAddChildNodeCallWithNodeTypeTest#testUndefined()
Project: jackrabbit
File: CanAddChildNodeCallWithNodeTypeTest.java
File: CanAddChildNodeCallWithNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns false if <code>childNodeName</code> does not match the <code>NodeDef</code>. */ public void testUndefined() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, true, false); if (nodeDef == null) { throw new NotExecutableException("No testable node type found."); } String type = nodeDef.getRequiredPrimaryTypes()[0].getName(); NodeType nodeType = nodeDef.getDeclaringNodeType(); String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType); assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if childNodeName does not match the " + "child node def of NodeType.", nodeType.canAddChildNode(undefinedName, type)); }
27. CanAddChildNodeCallWithNodeTypeTest#testCanAddMixinType()
Project: jackrabbit
File: CanAddChildNodeCallWithNodeTypeTest.java
File: CanAddChildNodeCallWithNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns false if <code>nodeTypeName</code> represents a mixin. */ public void testCanAddMixinType() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false); if (nodeDef == null) { throw new NotExecutableException("No testable node type found."); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String childNodeName = nodeDef.getName(); String mixinName; NodeTypeIterator it = manager.getMixinNodeTypes(); if (it.hasNext()) { mixinName = it.nextNodeType().getName(); } else { throw new NotExecutableException("No mixin type found."); } assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if nodeTypeName represents a mixin type.", nodeType.canAddChildNode(childNodeName, mixinName)); }
28. CanAddChildNodeCallWithNodeTypeTest#testDefinedAndIllegalType()
Project: jackrabbit
File: CanAddChildNodeCallWithNodeTypeTest.java
File: CanAddChildNodeCallWithNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns false if <code>childNodeName</code> does and <code>nodeTypeName</code> * does not match the <code>NodeDef</code>. */ public void testDefinedAndIllegalType() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false); if (nodeDef == null) { throw new NotExecutableException("No testable node type found."); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String childNodeName = nodeDef.getName(); String legalType = nodeDef.getRequiredPrimaryTypes()[0].getName(); String illegalType = NodeTypeUtil.getIllegalChildNodeType(manager, legalType); if (illegalType == null) { throw new NotExecutableException("No illegal node type name found"); } assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if childNodeName does and nodeTypeName does not " + "match the child node def of NodeType.", nodeType.canAddChildNode(childNodeName, illegalType)); }
29. CanAddChildNodeCallWithNodeTypeTest#testDefinedAndLegalType()
Project: jackrabbit
File: CanAddChildNodeCallWithNodeTypeTest.java
File: CanAddChildNodeCallWithNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns true if <code>childNodeName</code> and <code>nodeTypeName</code> * match the <code>NodeDef</code>. */ public void testDefinedAndLegalType() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false); if (nodeDef == null) { throw new NotExecutableException("No child node def with " + "defaultPrimaryType found"); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String childNodeName = nodeDef.getName(); String nodeTypeName = nodeDef.getRequiredPrimaryTypes()[0].getName(); if (nodeTypeName.equals(ntBase)) { // nt:base is abstract and can never be added, upgrade for check below nodeTypeName = ntUnstructured; } assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return true if childNodeName and nodeTypeName match the " + "child node def of NodeType.", nodeType.canAddChildNode(childNodeName, nodeTypeName)); }
30. CompactNodeTypeDefWriter#write()
Project: jackrabbit
File: CompactNodeTypeDefWriter.java
File: CompactNodeTypeDefWriter.java
/** * Write one NodeTypeDefinition to this writer * * @param ntd node type definition * @throws IOException if an I/O error occurs */ public void write(NodeTypeDefinition ntd) throws IOException { writeName(ntd); writeSupertypes(ntd); writeOptions(ntd); PropertyDefinition[] pdefs = ntd.getDeclaredPropertyDefinitions(); if (pdefs != null) { for (PropertyDefinition pd : pdefs) { writePropDef(pd); } } NodeDefinition[] ndefs = ntd.getDeclaredChildNodeDefinitions(); if (ndefs != null) { for (NodeDefinition nd : ndefs) { writeNodeDef(nd); } } out.write("\n\n"); }
31. NodeTypeGenerationTest#testCompleteNodeTypes()
Project: sling
File: NodeTypeGenerationTest.java
File: NodeTypeGenerationTest.java
@Test public void testCompleteNodeTypes() throws JSONException, ServletException, IOException, ValueFormatException, IllegalStateException, RepositoryException { NodeType nt1 = getSimpleNodeTypeWithName("testNodeType"); NodeType[] superTypes = { getSimpleNodeTypeWithName("superType1"), getSimpleNodeTypeWithName("superType2"), getSimpleNodeTypeWithName("superType3") }; NodeType nt2 = getSimpleNodeTypeWithName(null); when(nt1.getDeclaredSupertypes()).thenReturn(superTypes); when(nodeTypeIterator.nextNodeType()).thenReturn(nt1, nt2); when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE); NodeDefinition childNodeDef1 = getCompleteChildNodeDef("childNodeDef1"); NodeDefinition childNodeDef2 = getCompleteChildNodeDef("childNodeDef2"); NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2 }; when(nt1.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs); String propertyName = "stringPropertyDef"; PropertyDefinition propertyDef = mock(PropertyDefinition.class); when(propertyDef.getOnParentVersion()).thenReturn(OnParentVersionAction.VERSION); when(propertyDef.getName()).thenReturn(propertyName); when(propertyDef.getRequiredType()).thenReturn(PropertyType.STRING); when(propertyDef.getValueConstraints()).thenReturn(new String[] { GenerationConstants.CONSTRAINT_STRING }); when(propertyDef.isMultiple()).thenReturn(Boolean.TRUE); when(propertyDef.isProtected()).thenReturn(Boolean.TRUE); Value defaultValue = mock(Value.class); when(defaultValue.getType()).thenReturn(PropertyType.STRING); when(defaultValue.getString()).thenReturn(GenerationConstants.DEFAULT_VALUE_STRING); when(propertyDef.getDefaultValues()).thenReturn(new Value[] { defaultValue }); when(propertyDef.isAutoCreated()).thenReturn(Boolean.TRUE); when(propertyDef.isMandatory()).thenReturn(Boolean.TRUE); when(nt1.getDeclaredPropertyDefinitions()).thenReturn(new PropertyDefinition[] { propertyDef }); assertEqualsWithServletResult("testCompleteNodeTypes"); }
32. DefaultNodeTypeTest#testIfDefaultsAreOmittedWithServlet()
Project: sling
File: DefaultNodeTypeTest.java
File: DefaultNodeTypeTest.java
/** * Simulates a node type in the repository that has only default values and checks if they are omitted in the generated * JSON file. */ @Test public void testIfDefaultsAreOmittedWithServlet() throws JSONException, ServletException, IOException, ValueFormatException, IllegalStateException, RepositoryException { NodeType nt1 = getSimpleNodeTypeWithName("testNodeType"); when(nodeTypeIterator.nextNodeType()).thenReturn(nt1); when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE); NodeType ntBase = mock(NodeType.class); when(ntBase.getName()).thenReturn("nt:base"); NodeDefinition childNodeDef1 = mock(NodeDefinition.class); NodeType[] reqPrimaryTypes = { ntBase }; when(childNodeDef1.getRequiredPrimaryTypes()).thenReturn(reqPrimaryTypes); when(childNodeDef1.getName()).thenReturn("childNodeDef"); NodeDefinition[] childNodeDefs = { childNodeDef1 }; when(nt1.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs); String propertyName = "stringPropertyDef"; PropertyDefinition propertyDef = mock(PropertyDefinition.class); when(propertyDef.getRequiredType()).thenReturn(PropertyType.STRING); when(propertyDef.getName()).thenReturn(propertyName); when(nt1.getDeclaredPropertyDefinitions()).thenReturn(new PropertyDefinition[] { propertyDef }); assertEqualsWithServletResult("testIfDefaultsAreOmittedWithServlet"); }
33. CndImporterTest#shouldImportCndThatUsesExtensions()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
@Test public void shouldImportCndThatUsesExtensions() throws RepositoryException { // importer.setDebug(true); String cnd = "<ex = 'http://namespace.com/ns'>\n" + "[ex:NodeType] > ex:ParentType1, ex:ParentType2 abstract {mode:desc 'ex:NodeType description'} orderable mixin noquery primaryitem ex:property\n" + "- ex:property (STRING) = 'default1', 'default2' mandatory autocreated protected multiple VERSION\n" + " queryops '=, <>, <, <=, >, >=, LIKE' {mode:desc 'ex:property description'} {mode:altName Cool Property} nofulltext noqueryorder < 'constraint1', 'constraint2'" + "+ ex:node (ex:reqType1, ex:reqType2) = ex:defaultType {} mandatory autocreated protected sns version"; importer.importFrom(cnd, problems, "string"); // Check the namespace ... context.getNamespaceRegistry().register("ex", "http://namespace.com/ns"); assertThat(importer.getNamespaces().size(), is(1)); NamespaceRegistry.Namespace ns = importer.getNamespaces().iterator().next(); assertThat(ns.getNamespaceUri(), is("http://namespace.com/ns")); List<NodeTypeDefinition> defns = importer.getNodeTypeDefinitions(); assertThat(defns.size(), is(1)); NodeTypeDefinition defn = defns.get(0); assertThat(defn.getName(), is("ex:NodeType")); assertThat(defn.isAbstract(), is(true)); assertThat(defn.hasOrderableChildNodes(), is(true)); assertThat(defn.isMixin(), is(true)); assertThat(defn.isQueryable(), is(false)); assertThat(defn.getPrimaryItemName(), is("ex:property")); String[] supertypeNames = defn.getDeclaredSupertypeNames(); assertThat(supertypeNames[0], is("ex:ParentType1")); assertThat(supertypeNames[1], is("ex:ParentType2")); PropertyDefinition[] propDefns = defn.getDeclaredPropertyDefinitions(); assertThat(propDefns.length, is(1)); PropertyDefinition propDefn = propDefns[0]; assertThat(propDefn.getName(), is("ex:property")); assertThat(propDefn.getRequiredType(), is(PropertyType.STRING)); assertThat(propDefn.isMandatory(), is(true)); assertThat(propDefn.isAutoCreated(), is(true)); assertThat(propDefn.isProtected(), is(true)); assertThat(propDefn.isMultiple(), is(true)); assertThat(propDefn.getOnParentVersion(), is(OnParentVersionAction.VERSION)); assertThat(propDefn.isFullTextSearchable(), is(false)); assertThat(propDefn.isQueryOrderable(), is(false)); Value[] defaultValues = propDefn.getDefaultValues(); assertThat(defaultValues[0].getString(), is("default1")); assertThat(defaultValues[1].getString(), is("default2")); String[] queryOps = propDefn.getAvailableQueryOperators(); assertThat(queryOps[0], is("=")); assertThat(queryOps[1], is("<>")); assertThat(queryOps[2], is("<")); assertThat(queryOps[3], is("<=")); assertThat(queryOps[4], is(">")); assertThat(queryOps[5], is(">=")); assertThat(queryOps[6], is("LIKE")); String[] constraints = propDefn.getValueConstraints(); assertThat(constraints[0], is("constraint1")); assertThat(constraints[1], is("constraint2")); NodeDefinition[] childDefns = defn.getDeclaredChildNodeDefinitions(); assertThat(childDefns.length, is(1)); NodeDefinition childDefn = childDefns[0]; assertThat(childDefn.getName(), is("ex:node")); assertThat(childDefn.getDefaultPrimaryTypeName(), is("ex:defaultType")); assertThat(childDefn.isMandatory(), is(true)); assertThat(childDefn.isAutoCreated(), is(true)); assertThat(childDefn.isProtected(), is(true)); assertThat(childDefn.allowsSameNameSiblings(), is(true)); assertThat(childDefn.getOnParentVersion(), is(OnParentVersionAction.VERSION)); String[] requiredTypeNames = childDefn.getRequiredPrimaryTypeNames(); assertThat(requiredTypeNames[0], is("ex:reqType1")); assertThat(requiredTypeNames[1], is("ex:reqType2")); }
34. CndImporterTest#shouldImportCndThatUsesAllFeatures()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
@Test public void shouldImportCndThatUsesAllFeatures() throws RepositoryException { // importer.setDebug(true); String cnd = "<ex = 'http://namespace.com/ns'>\n" + "[ex:NodeType] > ex:ParentType1, ex:ParentType2 abstract orderable mixin noquery primaryitem ex:property\n" + "- ex:property (STRING) = 'default1', 'default2' mandatory autocreated protected multiple VERSION\n" + " queryops '=, <>, <, <=, >, >=, LIKE' nofulltext noqueryorder < 'constraint1', 'constraint2'" + "+ ex:node (ex:reqType1, ex:reqType2) = ex:defaultType mandatory autocreated protected sns version"; importer.importFrom(cnd, problems, "string"); if (!problems.isEmpty()) printProblems(); // Check the namespace ... context.getNamespaceRegistry().register("ex", "http://namespace.com/ns"); assertThat(importer.getNamespaces().size(), is(1)); NamespaceRegistry.Namespace ns = importer.getNamespaces().iterator().next(); assertThat(ns.getNamespaceUri(), is("http://namespace.com/ns")); List<NodeTypeDefinition> defns = importer.getNodeTypeDefinitions(); assertThat(defns.size(), is(1)); NodeTypeDefinition defn = defns.get(0); assertThat(defn.getName(), is("ex:NodeType")); assertThat(defn.isAbstract(), is(true)); assertThat(defn.hasOrderableChildNodes(), is(true)); assertThat(defn.isMixin(), is(true)); assertThat(defn.isQueryable(), is(false)); assertThat(defn.getPrimaryItemName(), is("ex:property")); String[] supertypeNames = defn.getDeclaredSupertypeNames(); assertThat(supertypeNames[0], is("ex:ParentType1")); assertThat(supertypeNames[1], is("ex:ParentType2")); PropertyDefinition[] propDefns = defn.getDeclaredPropertyDefinitions(); assertThat(propDefns.length, is(1)); PropertyDefinition propDefn = propDefns[0]; assertThat(propDefn.getName(), is("ex:property")); assertThat(propDefn.getRequiredType(), is(PropertyType.STRING)); assertThat(propDefn.isMandatory(), is(true)); assertThat(propDefn.isAutoCreated(), is(true)); assertThat(propDefn.isProtected(), is(true)); assertThat(propDefn.isMultiple(), is(true)); assertThat(propDefn.getOnParentVersion(), is(OnParentVersionAction.VERSION)); assertThat(propDefn.isFullTextSearchable(), is(false)); assertThat(propDefn.isQueryOrderable(), is(false)); Value[] defaultValues = propDefn.getDefaultValues(); assertThat(defaultValues[0].getString(), is("default1")); assertThat(defaultValues[1].getString(), is("default2")); String[] queryOps = propDefn.getAvailableQueryOperators(); assertThat(queryOps[0], is("=")); assertThat(queryOps[1], is("<>")); assertThat(queryOps[2], is("<")); assertThat(queryOps[3], is("<=")); assertThat(queryOps[4], is(">")); assertThat(queryOps[5], is(">=")); assertThat(queryOps[6], is("LIKE")); String[] constraints = propDefn.getValueConstraints(); assertThat(constraints[0], is("constraint1")); assertThat(constraints[1], is("constraint2")); NodeDefinition[] childDefns = defn.getDeclaredChildNodeDefinitions(); assertThat(childDefns.length, is(1)); NodeDefinition childDefn = childDefns[0]; assertThat(childDefn.getName(), is("ex:node")); assertThat(childDefn.getDefaultPrimaryTypeName(), is("ex:defaultType")); assertThat(childDefn.isMandatory(), is(true)); assertThat(childDefn.isAutoCreated(), is(true)); assertThat(childDefn.isProtected(), is(true)); assertThat(childDefn.allowsSameNameSiblings(), is(true)); assertThat(childDefn.getOnParentVersion(), is(OnParentVersionAction.VERSION)); String[] requiredTypeNames = childDefn.getRequiredPrimaryTypeNames(); assertThat(requiredTypeNames[0], is("ex:reqType1")); assertThat(requiredTypeNames[1], is("ex:reqType2")); }
35. ImporterImpl#startNode()
Project: jackrabbit-oak
File: ImporterImpl.java
File: ImporterImpl.java
@Override public void startNode(NodeInfo nodeInfo, List<PropInfo> propInfos) throws RepositoryException { Tree parent = parents.peek(); Tree tree = null; String id = nodeInfo.getUUID(); String nodeName = nodeInfo.getName(); String ntName = nodeInfo.getPrimaryTypeName(); if (parent == null) { log.debug("Skipping node: {}", nodeName); // parent node was skipped, skip this child node too // push null onto stack for skipped node parents.push(null); // notify the p-i-importer if (pnImporter != null) { pnImporter.startChildInfo(nodeInfo, propInfos); } return; } NodeDefinition parentDef = getDefinition(parent); if (parentDef.isProtected()) { // skip protected node parents.push(null); log.debug("Skipping protected node: {}", nodeName); if (pnImporter != null) { // pnImporter was already started (current nodeInfo is a sibling) // notify it about this child node. pnImporter.startChildInfo(nodeInfo, propInfos); } else { // potentially is able to deal with it, notify it about the child node. for (ProtectedNodeImporter pni : getNodeImporters()) { if (pni.start(parent)) { log.debug("Protected node -> delegated to ProtectedNodeImporter"); pnImporter = pni; pnImporter.startChildInfo(nodeInfo, propInfos); break; } /* else: p-i-Importer isn't able to deal with the protected tree. try next. and if none can handle the passed parent the tree below will be skipped */ } } return; } if (parent.hasChild(nodeName)) { // a node with that name already exists... Tree existing = parent.getChild(nodeName); NodeDefinition def = getDefinition(existing); if (!def.allowsSameNameSiblings()) { // check for potential conflicts if (def.isProtected() && isNodeType(existing, ntName)) { /* use the existing node as parent for the possible subsequent import of a protected tree, that the protected node importer may or may not be able to deal with. -> upon the next 'startNode' the check for the parent being protected will notify the protected node importer. -> if the importer is able to deal with that node it needs to care of the complete subtree until it is notified during the 'endNode' call. -> if the import can't deal with that node or if that node is the a leaf in the tree to be imported 'end' will not have an effect on the importer, that was never started. */ log.debug("Skipping protected node: {}", existing); parents.push(existing); /** * let ProtectedPropertyImporters handle the properties * associated with the imported node. this may include overwriting, * merging or just adding missing properties. */ importProperties(existing, propInfos, true); return; } if (def.isAutoCreated() && isNodeType(existing, ntName)) { // this node has already been auto-created, no need to create it tree = existing; } else { // edge case: colliding node does have same uuid // (see http://issues.apache.org/jira/browse/JCR-1128) String existingIdentifier = IdentifierManager.getIdentifier(existing); if (!(existingIdentifier.equals(id) && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))) { throw new ItemExistsException("Node with the same UUID exists:" + existing); } // fall through } } } if (tree == null) { // create node if (id == null) { // no potential uuid conflict, always add new node tree = createTree(parent, nodeInfo, null); } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW) { // always create a new UUID even if no // conflicting node exists. see OAK-1244 tree = createTree(parent, nodeInfo, UUID.randomUUID().toString()); // remember uuid mapping if (isNodeType(tree, JcrConstants.MIX_REFERENCEABLE)) { refTracker.put(nodeInfo.getUUID(), TreeUtil.getString(tree, JcrConstants.JCR_UUID)); } } else { Tree conflicting = idLookup.getConflictingTree(id); if (conflicting != null && conflicting.exists()) { // resolve uuid conflict tree = resolveUUIDConflict(parent, conflicting, id, nodeInfo); if (tree == null) { // no new node has been created, so skip this node // push null onto stack for skipped node parents.push(null); log.debug("Skipping existing node {}", nodeInfo.getName()); return; } } else { // create new with given uuid tree = createTree(parent, nodeInfo, id); } } } // process properties importProperties(tree, propInfos, false); if (tree.exists()) { parents.push(tree); } }
36. EffectiveNodeType#getNodeDefinition()
Project: jackrabbit-oak
File: EffectiveNodeType.java
File: EffectiveNodeType.java
/** * * @param childName The internal oak name of the target node. * @param childEffective * @return the node definition * @throws ConstraintViolationException */ public NodeDefinition getNodeDefinition(String childName, EffectiveNodeType childEffective) throws ConstraintViolationException { for (NodeDefinition def : getNamedNodeDefinitions(childName)) { boolean match = true; if (childEffective != null && !childEffective.includesNodeTypes(def.getRequiredPrimaryTypeNames())) { match = false; } if (match) { return def; } } for (NodeDefinition def : getResidualNodeDefinitions()) { boolean match = true; if (childEffective != null && !childEffective.includesNodeTypes(def.getRequiredPrimaryTypeNames())) { match = false; } if (match) { return def; } } throw new ConstraintViolationException("No matching node definition found for " + childName); }
37. NodeTypeCreationTest#testNonEmptyNodeTypeTemplate()
Project: jackrabbit
File: NodeTypeCreationTest.java
File: NodeTypeCreationTest.java
public void testNonEmptyNodeTypeTemplate() throws Exception { NodeTypeDefinition ntd = ntm.getNodeType("nt:address"); NodeTypeTemplate ntt = ntm.createNodeTypeTemplate(ntm.getNodeType("nt:address")); assertEquals(ntt.getName(), ntd.getName()); assertEquals(ntt.isMixin(), ntd.isMixin()); assertEquals(ntt.isAbstract(), ntd.isAbstract()); assertEquals(ntt.hasOrderableChildNodes(), ntd.hasOrderableChildNodes()); assertEquals(ntt.isQueryable(), ntd.isQueryable()); assertEquals(ntt.getPrimaryItemName(), ntd.getPrimaryItemName()); assertTrue(Arrays.equals(ntt.getDeclaredSupertypeNames(), ntd.getDeclaredSupertypeNames())); NodeDefinition[] nda = ntt.getDeclaredChildNodeDefinitions(); NodeDefinition[] nda1 = ntd.getDeclaredChildNodeDefinitions(); assertEquals(nda.length, nda1.length); for (int i = 0; i < nda.length; i++) { assertEquals(nda[i].getName(), nda1[i].getName()); assertEquals(nda[i].allowsSameNameSiblings(), nda1[i].allowsSameNameSiblings()); assertTrue(Arrays.equals(nda[i].getRequiredPrimaryTypeNames(), nda1[i].getRequiredPrimaryTypeNames())); assertEquals(nda[i].getDefaultPrimaryTypeName(), nda1[i].getDefaultPrimaryTypeName()); assertEquals(nda[i].getRequiredPrimaryTypeNames(), nda1[i].getRequiredPrimaryTypeNames()); } PropertyDefinition[] pda = ntt.getDeclaredPropertyDefinitions(); PropertyDefinition[] pda1 = ntd.getDeclaredPropertyDefinitions(); assertEquals(pda.length, pda1.length); for (int i = 0; i < pda.length; i++) { assertEquals(pda[i].getName(), pda1[i].getName()); assertEquals(pda[i].getRequiredType(), pda1[i].getRequiredType()); assertTrue(Arrays.equals(pda[i].getAvailableQueryOperators(), pda1[i].getAvailableQueryOperators())); assertTrue(Arrays.equals(pda[i].getValueConstraints(), pda1[i].getValueConstraints())); assertEquals(pda[i].isFullTextSearchable(), pda1[i].isFullTextSearchable()); assertEquals(pda[i].isMultiple(), pda1[i].isMultiple()); assertEquals(pda[i].isQueryOrderable(), pda1[i].isQueryOrderable()); } }
38. VltNodeTypeFactory#initAllowedPrimaryChildNodeTypes()
Project: sling
File: VltNodeTypeFactory.java
File: VltNodeTypeFactory.java
private void initAllowedPrimaryChildNodeTypes(VltNodeType nt0) throws RepositoryException { NodeDefinition[] declaredCihldNodeDefinitions = nt0.getDeclaredChildNodeDefinitions(); Set<String> allowedChildNodeTypes = new HashSet<>(); if (declaredCihldNodeDefinitions != null) { for (int i = 0; i < declaredCihldNodeDefinitions.length; i++) { NodeDefinition nodeDefinition = declaredCihldNodeDefinitions[i]; NodeType[] requiredPrimaryTypes = nodeDefinition.getRequiredPrimaryTypes(); if (requiredPrimaryTypes != null) { for (int j = 0; j < requiredPrimaryTypes.length; j++) { VltNodeType aRequiredPrimaryType = (VltNodeType) requiredPrimaryTypes[j]; if (aRequiredPrimaryType == null) { System.out.println("this can not be"); } Set<VltNodeType> allKnownChildTypes = aRequiredPrimaryType.getAllKnownChildTypes(); for (Iterator<VltNodeType> it = allKnownChildTypes.iterator(); it.hasNext(); ) { VltNodeType aChildType = it.next(); VltNodeType nt2 = getNodeType(aChildType.getName()); if (!nt2.isMixin()) { // mixins cannot be primary node types! allowedChildNodeTypes.add(nt2.getName()); } } } } } } nt0.setAllowedPrimaryChildNodeTypes(allowedChildNodeTypes); }
39. MockNodeTypeGenerator#getSimpleChildNodeDef()
Project: sling
File: MockNodeTypeGenerator.java
File: MockNodeTypeGenerator.java
public NodeDefinition getSimpleChildNodeDef(String name) { NodeDefinition childNodeDef1 = mock(NodeDefinition.class); NodeType[] reqPrimaryTypes = { getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME1), getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME2) }; when(childNodeDef1.getRequiredPrimaryTypes()).thenReturn(reqPrimaryTypes); when(childNodeDef1.getName()).thenReturn(name); when(childNodeDef1.getOnParentVersion()).thenReturn(OnParentVersionAction.COPY); return childNodeDef1; }
40. CndImporterTest#childDefn()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
protected NodeDefinition childDefn(NodeTypeDefinition nodeType, String name) { for (NodeDefinition defn : nodeType.getDeclaredChildNodeDefinitions()) { if (defn.getName().equals(name)) return defn; } assertThat("Failed to find child node definition \"" + name + "\"", false, is(true)); return null; }
41. RepositoryNodeTypeManager#nodeTypeFrom()
Project: modeshape
File: RepositoryNodeTypeManager.java
File: RepositoryNodeTypeManager.java
private JcrNodeType nodeTypeFrom(NodeTypeDefinition nodeType, List<JcrNodeType> supertypes) throws RepositoryException { PropertyDefinition[] propDefns = nodeType.getDeclaredPropertyDefinitions(); NodeDefinition[] childDefns = nodeType.getDeclaredChildNodeDefinitions(); List<JcrPropertyDefinition> properties = new ArrayList<JcrPropertyDefinition>(); List<JcrNodeDefinition> childNodes = new ArrayList<JcrNodeDefinition>(); if (propDefns != null) { for (PropertyDefinition propDefn : propDefns) { properties.add(propertyDefinitionFrom(propDefn)); } } if (childDefns != null) { for (NodeDefinition childNodeDefn : childDefns) { childNodes.add(childNodeDefinitionFrom(childNodeDefn)); } } Name name = nameFactory.create(nodeType.getName()); Name primaryItemName = nameFactory.create(nodeType.getPrimaryItemName()); boolean mixin = nodeType.isMixin(); boolean isAbstract = nodeType.isAbstract(); boolean queryable = nodeType.isQueryable(); boolean orderableChildNodes = nodeType.hasOrderableChildNodes(); NodeKey prototypeKey = repository.repositoryCache().getSystemKey(); return new JcrNodeType(prototypeKey, this.context, null, this, name, supertypes, primaryItemName, childNodes, properties, mixin, isAbstract, queryable, orderableChildNodes); }
42. JcrNodeTypeManager#getRootNodeDefinition()
Project: modeshape
File: JcrNodeTypeManager.java
File: JcrNodeTypeManager.java
/** * Get the {@link NodeDefinition} for the root node. * * @return the definition; never null * @throws RepositoryException * @throws NoSuchNodeTypeException */ JcrNodeDefinition getRootNodeDefinition() throws NoSuchNodeTypeException, RepositoryException { NodeTypes nodeTypes = nodeTypes(); for (NodeDefinition definition : nodeTypes.getNodeType(ModeShapeLexicon.ROOT).getChildNodeDefinitions()) { if (definition.getName().equals(JcrNodeType.RESIDUAL_ITEM_NAME)) return (JcrNodeDefinition) definition; } // should not get here assert false; return null; }
43. NodeTypeManagerImplTest#testCreateSingleNodeTypeWithChildNodeForBean()
Project: jackrabbit-ocm
File: NodeTypeManagerImplTest.java
File: NodeTypeManagerImplTest.java
public void testCreateSingleNodeTypeWithChildNodeForBean() throws Exception { ClassDescriptor classDescriptor = new ClassDescriptor(); classDescriptor.setClassName("test.Test12Class"); classDescriptor.setJcrType("ocm:test12"); classDescriptor.setJcrSuperTypes("nt:base"); BeanDescriptor bean1 = new BeanDescriptor(); bean1.setFieldName("a"); bean1.setJcrName("b"); bean1.setJcrType("nt:unstructured"); classDescriptor.addBeanDescriptor(bean1); nodeTypeManagerImpl.createSingleNodeType(getSession(), classDescriptor); NodeType test12 = getSession().getWorkspace().getNodeTypeManager().getNodeType("ocm:test12"); assertNotNull(test12); // not check node type definition, assuming other tests have done that // assert property definition a NodeDefinition nodeDef = getChildNodeDefinition(test12.getChildNodeDefinitions(), "b"); assertNotNull(nodeDef); assertNotNull(nodeDef.getRequiredPrimaryTypes()); assertEquals(nodeDef.getRequiredPrimaryTypes().length, 1); assertEquals(nodeDef.getRequiredPrimaryTypes()[0].getName(), "nt:unstructured"); }
44. NodeTypeManagerImplTest#testCreateSingleNodeTypeWithChildNodeForCollection()
Project: jackrabbit-ocm
File: NodeTypeManagerImplTest.java
File: NodeTypeManagerImplTest.java
public void testCreateSingleNodeTypeWithChildNodeForCollection() throws Exception { ClassDescriptor classDescriptor = new ClassDescriptor(); classDescriptor.setClassName("test.Test11Class"); classDescriptor.setJcrType("ocm:test11"); classDescriptor.setJcrSuperTypes("nt:base"); CollectionDescriptor collection1 = new CollectionDescriptor(); collection1.setFieldName("a"); collection1.setJcrName("b"); collection1.setJcrType("nt:unstructured"); classDescriptor.addCollectionDescriptor(collection1); nodeTypeManagerImpl.createSingleNodeType(getSession(), classDescriptor); NodeType test11 = getSession().getWorkspace().getNodeTypeManager().getNodeType("ocm:test11"); assertNotNull(test11); // not check node type definition, assuming other tests have done that // assert child node definition a NodeDefinition nodeDef = getChildNodeDefinition(test11.getChildNodeDefinitions(), "b"); assertNotNull(nodeDef); assertNotNull(nodeDef.getRequiredPrimaryTypes()); assertEquals(nodeDef.getRequiredPrimaryTypes().length, 1); assertEquals(nodeDef.getRequiredPrimaryTypes()[0].getName(), "nt:unstructured"); }
45. NodeDefinitionTest#getAggregatedNodeDefinitions()
Project: jackrabbit-oak
File: NodeDefinitionTest.java
File: NodeDefinitionTest.java
private static NodeDefinition[] getAggregatedNodeDefinitions(Node node) throws RepositoryException { Set<NodeDefinition> cDefs = newHashSet(); NodeDefinition[] nd = node.getPrimaryNodeType().getChildNodeDefinitions(); cDefs.addAll(Arrays.asList(nd)); NodeType[] mixins = node.getMixinNodeTypes(); for (NodeType mixin : mixins) { nd = mixin.getChildNodeDefinitions(); cDefs.addAll(Arrays.asList(nd)); } return cDefs.toArray(new NodeDefinition[cDefs.size()]); }
46. NodeTypeImpl#canAddChildNode()
Project: jackrabbit-oak
File: NodeTypeImpl.java
File: NodeTypeImpl.java
@Override public boolean canAddChildNode(String childNodeName, String nodeTypeName) { NodeType type; try { type = getManager().getNodeType(nodeTypeName); if (type.isAbstract()) { return false; } } catch (NoSuchNodeTypeException e) { return false; } catch (RepositoryException e) { log.warn("Unable to access node type " + nodeTypeName, e); return false; } // FIXME: properly calculate matching definition for (NodeDefinition definition : getChildNodeDefinitions()) { String name = definition.getName(); if (matches(childNodeName, name) || RESIDUAL_NAME.equals(name)) { if (definition.isProtected()) { return false; } for (String required : definition.getRequiredPrimaryTypeNames()) { if (type.isNodeType(required)) { return true; } } } } return false; }
47. NodeTypeImpl#canAddChildNode()
Project: jackrabbit-oak
File: NodeTypeImpl.java
File: NodeTypeImpl.java
@Override public boolean canAddChildNode(String childNodeName) { // FIXME: properly calculate matching definition for (NodeDefinition definition : getChildNodeDefinitions()) { String name = definition.getName(); if (matches(childNodeName, name) || RESIDUAL_NAME.equals(name)) { return !definition.isProtected() && definition.getDefaultPrimaryType() != null; } } return false; }
48. NodeTypeDefinitionImpl#getDeclaredChildNodeDefinitions()
Project: jackrabbit
File: NodeTypeDefinitionImpl.java
File: NodeTypeDefinitionImpl.java
/** * @see javax.jcr.nodetype.NodeTypeDefinition#getDeclaredChildNodeDefinitions() */ public NodeDefinition[] getDeclaredChildNodeDefinitions() { QNodeDefinition[] cnda = ntd.getChildNodeDefs(); NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length]; for (int i = 0; i < cnda.length; i++) { nodeDefs[i] = new NodeDefinitionImpl(cnda[i], resolver); } return nodeDefs; }
49. AbstractNodeType#getDeclaredChildNodeDefinitions()
Project: jackrabbit
File: AbstractNodeType.java
File: AbstractNodeType.java
/** * {@inheritDoc} */ public NodeDefinition[] getDeclaredChildNodeDefinitions() { QNodeDefinition[] cnda = ntd.getChildNodeDefs(); NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length]; for (int i = 0; i < cnda.length; i++) { nodeDefs[i] = ntMgr.getNodeDefinition(cnda[i]); } return nodeDefs; }
50. NodeTypeImpl#getChildNodeDefinitions()
Project: jackrabbit
File: NodeTypeImpl.java
File: NodeTypeImpl.java
/** * @see javax.jcr.nodetype.NodeType#getChildNodeDefinitions() */ public NodeDefinition[] getChildNodeDefinitions() { QNodeDefinition[] cnda = ent.getAllQNodeDefinitions(); NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length]; for (int i = 0; i < cnda.length; i++) { nodeDefs[i] = ntMgr.getNodeDefinition(cnda[i]); } return nodeDefs; }
51. PredefinedNodeTypeTest#getNodeTypeSpec()
Project: jackrabbit
File: PredefinedNodeTypeTest.java
File: PredefinedNodeTypeTest.java
/** * Creates and returns a spec string for the given node type definition. * The returned spec string follows the node type definition format * used in the JSR 170 specification. * * @param type node type definition * @param propsVariant whether the properties of this node type may * have implementation variant autocreated and OPV flags. * @return spec string * @throws RepositoryException on repository errors */ private static String getNodeTypeSpec(NodeType type, boolean propsVariant) throws RepositoryException { String typeName = type.getName(); StringWriter buffer = new StringWriter(); PrintWriter writer = new PrintWriter(buffer); writer.println("NodeTypeName"); writer.println(" " + typeName); writer.println("IsMixin"); writer.println(" " + type.isMixin()); writer.println("HasOrderableChildNodes"); writer.println(" " + type.hasOrderableChildNodes()); writer.println("PrimaryItemName"); writer.println(" " + type.getPrimaryItemName()); NodeDefinition[] nodes = type.getDeclaredChildNodeDefinitions(); Arrays.sort(nodes, NODE_DEF_COMPARATOR); for (int i = 0; i < nodes.length; i++) { writer.print(getChildNodeDefSpec(nodes[i])); } PropertyDefinition[] properties = type.getDeclaredPropertyDefinitions(); Arrays.sort(properties, PROPERTY_DEF_COMPARATOR); for (int i = 0; i < properties.length; i++) { writer.print(getPropertyDefSpec(properties[i], propsVariant)); } return buffer.toString(); }
52. CanAddChildNodeCallWithNodeTypeTest#testResidualAndLegalType()
Project: jackrabbit
File: CanAddChildNodeCallWithNodeTypeTest.java
File: CanAddChildNodeCallWithNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns true if <code>childNodeName</code> does not match the <code>NodeDef</code> * but <code>nodeTypeName</code> matches the node type of a residual <code>NodeDef</code>. */ public void testResidualAndLegalType() throws NotExecutableException, RepositoryException { String type = null; NodeType nodeType = null; for (NodeDefinition nodeDef : NodeTypeUtil.locateAllChildNodeDef(session, false, false, true)) { for (NodeType nt : nodeDef.getRequiredPrimaryTypes()) { if (!nt.isAbstract()) { nodeType = nodeDef.getDeclaringNodeType(); type = nt.getName(); } } } if (nodeType == null || type == null) { throw new NotExecutableException("No testable residual child node def."); } String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType); assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return true for a not defined childNodeName if nodeTypeName " + "matches the type of a residual child node def", nodeType.canAddChildNode(undefinedName, type)); }
53. CanAddChildNodeCallWithNodeTypeTest#testCanAddAbstractType()
Project: jackrabbit
File: CanAddChildNodeCallWithNodeTypeTest.java
File: CanAddChildNodeCallWithNodeTypeTest.java
/** * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code> * returns false if <code>nodeTypeName</code> represents an abstract node type. */ public void testCanAddAbstractType() throws NotExecutableException, RepositoryException { NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false); if (nodeDef == null) { throw new NotExecutableException("No testable node type found."); } NodeType nodeType = nodeDef.getDeclaringNodeType(); String childNodeName = nodeDef.getName(); String abstractName = null; NodeTypeIterator it = manager.getPrimaryNodeTypes(); while (it.hasNext() && abstractName == null) { NodeType nt = it.nextNodeType(); if (nt.isAbstract()) { abstractName = nt.getName(); } } if (abstractName == null) { throw new NotExecutableException("No abstract type found."); } assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if nodeTypeName represents an abstract node type.", nodeType.canAddChildNode(childNodeName, abstractName)); }
54. NodeTypeImpl#getChildNodeDefinitions()
Project: jackrabbit
File: NodeTypeImpl.java
File: NodeTypeImpl.java
/** * {@inheritDoc} */ public NodeDefinition[] getChildNodeDefinitions() { QNodeDefinition[] cnda = ent.getAllNodeDefs(); NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length]; for (int i = 0; i < cnda.length; i++) { nodeDefs[i] = ntMgr.getNodeDefinition(cnda[i]); } return nodeDefs; }
55. NodeTypeImpl#getMandatoryNodeDefinitions()
Project: jackrabbit
File: NodeTypeImpl.java
File: NodeTypeImpl.java
/** * Returns an array containing only those child node definitions of this * node type (including the child node definitions inherited from supertypes * of this node type) where <code>{@link NodeDefinition#isMandatory()}</code> * returns <code>true</code>. * * @return an array of child node definitions. * @see NodeDefinition#isMandatory */ public NodeDefinition[] getMandatoryNodeDefinitions() { QNodeDefinition[] cnda = ent.getMandatoryNodeDefs(); NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length]; for (int i = 0; i < cnda.length; i++) { nodeDefs[i] = ntMgr.getNodeDefinition(cnda[i]); } return nodeDefs; }
56. NodeTypeImpl#getAutoCreatedNodeDefinitions()
Project: jackrabbit
File: NodeTypeImpl.java
File: NodeTypeImpl.java
/** * Returns an array containing only those child node definitions of this * node type (including the child node definitions inherited from supertypes * of this node type) where <code>{@link NodeDefinition#isAutoCreated()}</code> * returns <code>true</code>. * * @return an array of child node definitions. * @see NodeDefinition#isAutoCreated */ public NodeDefinition[] getAutoCreatedNodeDefinitions() { QNodeDefinition[] cnda = ent.getAutoCreateNodeDefs(); NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length]; for (int i = 0; i < cnda.length; i++) { nodeDefs[i] = ntMgr.getNodeDefinition(cnda[i]); } return nodeDefs; }
57. NodeTypeDefinitionImpl#getDeclaredChildNodeDefinitions()
Project: jackrabbit
File: NodeTypeDefinitionImpl.java
File: NodeTypeDefinitionImpl.java
/** * {@inheritDoc} */ public NodeDefinition[] getDeclaredChildNodeDefinitions() { QItemDefinition[] cnda = ntd.getChildNodeDefs(); NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length]; for (int i = 0; i < cnda.length; i++) { nodeDefs[i] = new NodeDefinitionImpl(cnda[i], null, resolver); } return nodeDefs; }
58. NodeImpl#createChildNode()
Project: jackrabbit
File: NodeImpl.java
File: NodeImpl.java
protected synchronized NodeImpl createChildNode(Name name, NodeTypeImpl nodeType, NodeId id) throws RepositoryException { // create a new node state NodeState nodeState = stateMgr.createTransientNodeState(id, nodeType.getQName(), getNodeId(), ItemState.STATUS_NEW); // create Node instance wrapping new node state NodeImpl node; try { // NOTE: since the node is not yet connected to its parent, avoid // calling ItemManager#getItem(ItemId) which may include a permission // check (with subsequent usage of the hierarachy-mgr -> error). // just let the mgr create the new node that is known to exist and // which has not been accessed before. node = (NodeImpl) itemMgr.createItemInstance(nodeState); } catch (RepositoryException re) { stateMgr.disposeTransientItemState(nodeState); throw re; } // modify the state of 'this', i.e. the parent node NodeState thisState = (NodeState) getOrCreateTransientItemState(); // add new child node entry thisState.addChildNodeEntry(name, nodeState.getNodeId()); // add 'auto-create' properties defined in node type for (PropertyDefinition aPda : nodeType.getAutoCreatedPropertyDefinitions()) { PropertyDefinitionImpl pd = (PropertyDefinitionImpl) aPda; node.createChildProperty(pd.unwrap().getName(), pd.getRequiredType(), pd); } // recursively add 'auto-create' child nodes defined in node type for (NodeDefinition aNda : nodeType.getAutoCreatedNodeDefinitions()) { NodeDefinitionImpl nd = (NodeDefinitionImpl) aNda; node.createChildNode(nd.unwrap().getName(), (NodeTypeImpl) nd.getDefaultPrimaryType(), null); } return node; }