/** {@inheritDoc} */ public RemoteNodeType[] getRequiredPrimaryTypes() throws RemoteException { return getRemoteNodeTypeArray(def.getRequiredPrimaryTypes()); }
private NodeDefinitionImpl(NodeDefinition definition) { super(definition); requiredPrimaryTypes = definition.getRequiredPrimaryTypes(); defaultPrimaryType = definition.getDefaultPrimaryType(); allowsSameNameSiblings = definition.allowsSameNameSiblings(); }
/** * Tests that the information from getRequiredPrimaryTypeNames() * matches getRequiredPrimaryTypes(). * * @since JCR 2.0 */ public void testGetRequiredPrimaryTypeNames() throws RepositoryException { // loop all node types for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) { NodeType type = types.nextNodeType(); NodeDefinition defs[] = type.getChildNodeDefinitions(); for (int i = 0; i < defs.length; i++) { NodeType requiredPrimaryTypes[] = defs[i].getRequiredPrimaryTypes(); Set<String> rptnames = new HashSet<String>(); for (int j = 0; j < requiredPrimaryTypes.length; j++) { rptnames.add(requiredPrimaryTypes[j].getName()); } Set<String> rptnames2 = new HashSet<String>(Arrays.asList(defs[i].getRequiredPrimaryTypeNames())); assertEquals("names returned from getRequiredPrimaryTypeNames should match types returned from getRequiredPrimaryTypes", rptnames, rptnames2); } } }
static ITypeDescriptor getType(ITypeLocator locator, ItemDefinition def, ITypeDescriptor containingType) throws StoreException { String type; if (def instanceof NodeDefinition) { NodeDefinition ntDef = (NodeDefinition) def; NodeType[] types = ntDef.getRequiredPrimaryTypes(); if (types.length == 0) { type = "nt:base"; } else { type = types[0].getName(); if (types.length > 1) { log.warn("multiple primary types specified; this is not supported. Only the first one is used."); } } } else { type = PropertyType.nameFromValue(((PropertyDefinition) def).getRequiredType()); } if (type.equals(containingType.getType())) { return containingType; } return locator.locate(type); } }
private void writeNodeType(NodeType nt, CNDWriter w, Set<String> written) throws IOException, RepositoryException { if (nt != null && !written.contains(nt.getName())) { written.add(nt.getName()); w.write(nt); for (NodeType s: nt.getSupertypes()) { writeNodeType(s, w, written); } for (NodeDefinition n: nt.getChildNodeDefinitions()) { writeNodeType(n.getDefaultPrimaryType(), w, written); if (n.getRequiredPrimaryTypes() != null) { for (NodeType r: n.getRequiredPrimaryTypes()) { writeNodeType(r, w, written); } } } } }
private void visit(String namespacePrefix, NodeType nt, HashSet<String> visited, LinkedHashSet<QNodeTypeDefinition> result) { if (visited.contains(nt.getName())) { return; } visited.add(nt.getName()); for (NodeType superType : nt.getSupertypes()) { visit(namespacePrefix, superType, visited, result); } for (NodeDefinition nd : nt.getChildNodeDefinitions()) { for (NodeType childType : nd.getRequiredPrimaryTypes()) { visit(namespacePrefix, childType, visited, result); } NodeType defaultPriType = nd.getDefaultPrimaryType(); if (defaultPriType != null) { visit(namespacePrefix, defaultPriType, visited, result); } } if (nt.getName().startsWith(namespacePrefix + ":")) { result.add(((AbstractNodeType)nt).getDefinition()); } }
/** * Tests if getRequiredPrimaryTypes() does not return an empty array. Test * runs for all existing node types. */ public void testGetRequiredPrimaryTypes() throws RepositoryException { // loop all node types for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) { NodeType type = types.nextNodeType(); NodeDefinition defs[] = type.getChildNodeDefinitions(); for (int i = 0; i < defs.length; i++) { assertTrue("getRequiredPrimaryTypes() must never return an " + "empty array.", defs[i].getRequiredPrimaryTypes().length > 0); } } }
@Test public void testGetRequiredPrimaryTypes() throws RepositoryException { for (String path : paths) { Node n = superuser.getNode(path); NodeDefinition def = n.getDefinition(); def.getRequiredPrimaryTypes(); } }
/** * 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)); }
@Test public void testGetRequiredPrimaryTypes2() throws RepositoryException { for (String path : paths) { Node n = superuser.getNode(path); for (NodeDefinition nd : getAggregatedNodeDefinitions(n)) { nd.getRequiredPrimaryTypes(); } } }
/** * Package private constructor * * @param def * @param resolver * @throws javax.jcr.nodetype.ConstraintViolationException */ NodeDefinitionTemplateImpl(NodeDefinition def, NamePathResolver resolver) throws ConstraintViolationException { super(def, resolver); requiredPrimaryTypes = def.getRequiredPrimaryTypes(); allowSameNameSiblings = def.allowsSameNameSiblings(); if (def instanceof NodeDefinitionImpl) { QNodeDefinition qDef = (QNodeDefinition) ((NodeDefinitionImpl) def).itemDef; requiredPrimaryTypeNames = qDef.getRequiredPrimaryTypes(); defaultPrimaryTypeName = qDef.getDefaultPrimaryType(); } else { setRequiredPrimaryTypeNames(def.getRequiredPrimaryTypeNames()); setDefaultPrimaryTypeName(def.getDefaultPrimaryTypeName()); } }
/** * 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)); }
/** * Package private constructor * * @param def * @param resolver * @throws javax.jcr.nodetype.ConstraintViolationException */ NodeDefinitionTemplateImpl(NodeDefinition def, NamePathResolver resolver) throws ConstraintViolationException { super(def, resolver); requiredPrimaryTypes = def.getRequiredPrimaryTypes(); allowSameNameSiblings = def.allowsSameNameSiblings(); if (def instanceof NodeDefinitionImpl) { QNodeDefinition qDef = (QNodeDefinition) ((NodeDefinitionImpl) def).itemDef; requiredPrimaryTypeNames = qDef.getRequiredPrimaryTypes(); defaultPrimaryTypeName = qDef.getDefaultPrimaryType(); } else { setRequiredPrimaryTypeNames(def.getRequiredPrimaryTypeNames()); setDefaultPrimaryTypeName(def.getDefaultPrimaryTypeName()); } }
private void loadChildNodeDefinitions(NodeType nodeType, EffectiveNodeTypeImpl ent) throws RepositoryException { for (NodeDefinition nd : nodeType.getChildNodeDefinitions()) { EffectiveNodeTypeChildImpl child = // ensure child definition declaring type is also loaded new EffectiveNodeTypeChildImpl(nd.getName(), loadEffectiveNodeType(nd.getDeclaringNodeType()).getName()); for (NodeType childType : nd.getRequiredPrimaryTypes()) { // ensure all possible child types are also loaded child.getRequiredPrimaryTypes().add(loadEffectiveNodeType(childType).getName()); } if (nd.getDefaultPrimaryType() != null) { // ensure possible primary type is also loaded child.setDefaultPrimaryType(loadEffectiveNodeType(nd.getDefaultPrimaryType()).getName()); } child.setMandatory(nd.isMandatory()); child.setAutoCreated(nd.isAutoCreated()); child.setMultiple(nd.allowsSameNameSiblings()); child.setProtected(nd.isProtected()); // each child definition is maintained in a list by name List<EffectiveNodeTypeChild> childList = ent.getChildren().get(child.getName()); if (childList == null) { childList = new ArrayList<EffectiveNodeTypeChild>(); ent.getChildren().put(child.getName(), childList); } childList.add(child); } }
/** * 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)); }
@Test public void testGetDefinitionWithSNS() throws RepositoryException, IOException { Session session = getAdminSession(); Node node = session.getNode("/jcr:system/jcr:nodeTypes/nt:file"); // TODO: use getNode("jcr:childNodeDefinition[1]") once that works for (Node child : getChildNodes(node, "jcr:childNodeDefinition")) { NodeDefinition definition = child.getDefinition(); // OAK-829 definition.getDefaultPrimaryType(); // OAK-826 definition.getRequiredPrimaryTypes(); // OAK-826 } }
/** * 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)); }
/** * 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)); } }
/** * Creates a new node definition based on a JCR <code>NodeDefinition</code>. * * @param nodeDef the node definition. * @param resolver the name/path resolver of the session that provided the * node definition * @throws NameException if <code>nodeDef</code> contains an illegal * name. * @throws NamespaceException if <code>nodeDef</code> contains a name with * an namespace prefix that is unknown to * <code>resolver</code>. */ public QNodeDefinitionImpl(NodeDefinition nodeDef, NamePathResolver resolver) throws NameException, NamespaceException { this(nodeDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(nodeDef.getName()), nodeDef.getDeclaringNodeType() != null ? resolver.getQName(nodeDef.getDeclaringNodeType().getName()) : null, nodeDef.isAutoCreated(), nodeDef.isMandatory(), nodeDef.getOnParentVersion(), nodeDef.isProtected(), nodeDef.getDefaultPrimaryType() != null ? resolver.getQName(nodeDef.getDefaultPrimaryType().getName()) : null, getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), resolver), nodeDef.allowsSameNameSiblings()); }
/** * Creates a new node definition based on a JCR <code>NodeDefinition</code>. * * @param nodeDef the node definition. * @param resolver the name/path resolver of the session that provided the * node definition * @throws NameException if <code>nodeDef</code> contains an illegal * name. * @throws NamespaceException if <code>nodeDef</code> contains a name with * an namespace prefix that is unknown to * <code>resolver</code>. */ public QNodeDefinitionImpl(NodeDefinition nodeDef, NamePathResolver resolver) throws NameException, NamespaceException { this(nodeDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(nodeDef.getName()), nodeDef.getDeclaringNodeType() != null ? resolver.getQName(nodeDef.getDeclaringNodeType().getName()) : null, nodeDef.isAutoCreated(), nodeDef.isMandatory(), nodeDef.getOnParentVersion(), nodeDef.isProtected(), nodeDef.getDefaultPrimaryType() != null ? resolver.getQName(nodeDef.getDefaultPrimaryType().getName()) : null, getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), resolver), nodeDef.allowsSameNameSiblings()); }