/** {@inheritDoc} */ public boolean allowsSameNameSiblings() throws RemoteException { return def.allowsSameNameSiblings(); }
public NodeDefinitionValue(NodeDefinition nodeDefinition) { super(nodeDefinition); this.defaultNodeTypeName = ((NodeDefinitionImpl)nodeDefinition).getDefaultPrimaryTypeName(); this.requiredNodeTypeNames = Arrays.asList(((NodeDefinitionImpl)nodeDefinition).getRequiredPrimaryTypeNames()); this.sameNameSiblings = nodeDefinition.allowsSameNameSiblings(); }
/** * Tests the element test with a name test argument and a type argument that * matches only certain child nodes. Additonally this test requires that * testroot allows same name sibling child nodes. */ public void testElementTestNameTestSomeNTWithSNS() throws RepositoryException, NotExecutableException { Node n1 = testRootNode.addNode(nodeName1, testNodeType); if (!n1.getDefinition().allowsSameNameSiblings()) { throw new NotExecutableException("Node at " + testRoot + " does not allow same name siblings with name " + nodeName1); } testRootNode.addNode(nodeName1, simpleNodeType); Node n2 = testRootNode.addNode(nodeName1, testNodeType); testRootNode.addNode(nodeName2, simpleNodeType); testRootNode.addNode(nodeName3, testNodeType); testRootNode.getSession().save(); String query = "/" + jcrRoot + testRoot + "/element(" + nodeName1 + ", " + testNodeType + ")"; executeXPathQuery(superuser, query, new Node[]{n1, n2}); } }
private boolean allowsSNS(final String nodeType) throws RepositoryException { final NodeType nt = ntm.getNodeType(nodeType); for (final NodeDefinition nd : nt.getDeclaredChildNodeDefinitions()) { if (nd.allowsSameNameSiblings()) { return true; } } return false; }
private NodeDefinitionImpl(NodeDefinition definition) { super(definition); requiredPrimaryTypes = definition.getRequiredPrimaryTypes(); defaultPrimaryType = definition.getDefaultPrimaryType(); allowsSameNameSiblings = definition.allowsSameNameSiblings(); }
/** * Tests if same name siblings have equal names or if same name * siblings are not supported a ItemExistsException is thrown. */ public void testSameNameSiblings() throws RepositoryException { if (testRootNode.getDefinition().allowsSameNameSiblings()) { Node n1 = testRootNode.addNode(nodeName1, testNodeType); Node n2 = testRootNode.addNode(nodeName1, testNodeType); testRootNode.getSession().save(); assertEquals("Names of same name siblings are not equal.", n1.getName(), n2.getName()); } else { testRootNode.addNode(nodeName1, testNodeType); try { testRootNode.addNode(nodeName1, testNodeType); fail("Expected ItemExistsException."); } catch (ItemExistsException e) { // correct } } }
protected String createNodeName(final Node sourceNode) throws RepositoryException { final String name = sourceNode.getName(); if (sourceNode.getIndex() > 1) { return name + "[" + sourceNode.getIndex() + "]"; } else { if (sourceNode.getDefinition().allowsSameNameSiblings() && sourceNode.getParent().hasNode(name + "[2]")) { return name + "[1]"; } } return name; }
private void processChildNodeDefinition( Node nodeTypeNode, NodeDefinition childNodeDefinition ) throws RepositoryException { Node childNode = nodeTypeNode.addNode(CHILD_NODE_DEFINITION, CHILD_NODE_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(childNodeDefinition.getName())) { childNode.setProperty(NAME, childNodeDefinition.getName()); } childNode.setProperty(AUTO_CREATED, childNodeDefinition.isAutoCreated()); childNode.setProperty(MANDATORY, childNodeDefinition.isMandatory()); childNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(childNodeDefinition.getOnParentVersion())); childNode.setProperty(PROTECTED, childNodeDefinition.isProtected()); String[] requiredPrimaryTypeNames = childNodeDefinition.getRequiredPrimaryTypeNames(); childNode.setProperty(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeNames != null ? requiredPrimaryTypeNames : new String[0]); childNode.setProperty(SAME_NAME_SIBLINGS, childNodeDefinition.allowsSameNameSiblings()); childNode.setProperty(DEFAULT_PRIMARY_TYPE, childNodeDefinition.getDefaultPrimaryTypeName()); }
private void processChildNodeDefinition( Node nodeTypeNode, NodeDefinition childNodeDefinition ) throws RepositoryException { Node childNode = nodeTypeNode.addNode(CHILD_NODE_DEFINITION, CHILD_NODE_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(childNodeDefinition.getName())) { childNode.setProperty(NAME, childNodeDefinition.getName()); } childNode.setProperty(AUTO_CREATED, childNodeDefinition.isAutoCreated()); childNode.setProperty(MANDATORY, childNodeDefinition.isMandatory()); childNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(childNodeDefinition.getOnParentVersion())); childNode.setProperty(PROTECTED, childNodeDefinition.isProtected()); String[] requiredPrimaryTypeNames = childNodeDefinition.getRequiredPrimaryTypeNames(); childNode.setProperty(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeNames != null ? requiredPrimaryTypeNames : new String[0]); childNode.setProperty(SAME_NAME_SIBLINGS, childNodeDefinition.allowsSameNameSiblings()); childNode.setProperty(DEFAULT_PRIMARY_TYPE, childNodeDefinition.getDefaultPrimaryTypeName()); }
public NodeDefinitionTemplateImpl( NameMapper mapper, NodeDefinition definition) throws ConstraintViolationException { super(mapper, definition); setSameNameSiblings(definition.allowsSameNameSiblings()); setDefaultPrimaryTypeName(definition.getDefaultPrimaryTypeName()); setRequiredPrimaryTypeNames(definition.getRequiredPrimaryTypeNames()); }
public NodeDefinitionTemplateImpl( NameMapper mapper, NodeDefinition definition) throws ConstraintViolationException { super(mapper, definition); setSameNameSiblings(definition.allowsSameNameSiblings()); setDefaultPrimaryTypeName(definition.getDefaultPrimaryTypeName()); setRequiredPrimaryTypeNames(definition.getRequiredPrimaryTypeNames()); }
public NodeDefinitionTemplateImpl( NameMapper mapper, NodeDefinition definition) throws ConstraintViolationException { super(mapper, definition); setSameNameSiblings(definition.allowsSameNameSiblings()); setDefaultPrimaryTypeName(definition.getDefaultPrimaryTypeName()); setRequiredPrimaryTypeNames(definition.getRequiredPrimaryTypeNames()); }
@Override protected Item createRemoveItem() throws NotExecutableException, RepositoryException { if (testRootNode.hasNode(nodeName1)) { fail("Setup: Parent node must not yet contain a child node '" + nodeName1 + "'."); } firstSiblingNode = testRootNode.addNode(nodeName1, testNodeType); if (!firstSiblingNode.getDefinition().allowsSameNameSiblings()) { fail("Setup: RemoveSNSTest cannot be execute. Unable to create SameNameSiblings."); } firstSiblingPath = firstSiblingNode.getPath(); Node removeNode = testRootNode.addNode(nodeName1, testNodeType); // make sure the new node is persisted. testRootNode.save(); return removeNode; }
@Override protected void setUp() throws Exception { super.setUp(); if (destParentNode.hasNode(nodeName2)) { fail("Setup: Move destination already contains a child node with name " + nodeName2); } if (!moveNode.getDefinition().allowsSameNameSiblings()) { fail("Setup: Unable to create SNS-node for MoveSNSTest."); } sourceSibling = srcParentNode.addNode(nodeName2, testNodeType); destSibling = destParentNode.addNode(nodeName2, testNodeType); if (!destSibling.getDefinition().allowsSameNameSiblings()) { fail("Setup: Unable to create SNS-node at move destination."); } testRootNode.save(); }
public void insert(Object object) { String path = objectConverter.getPath(session, object); try { if (session.nodeExists(path)) { Node node = session.getNode(path); if (!node.getDefinition().allowsSameNameSiblings()) { throw new ObjectContentManagerException("Path already exists and it is not supporting the same name sibling : " + path); } } } catch (RepositoryException e) { throw new org.apache.jackrabbit.ocm.exception.RepositoryException("Impossible to insert the object at " + path, e); } objectConverter.insert(session, object); }
/** * 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()); } }
/** * 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()); } }
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)); } }
/** * 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()); }
public static void checkNodeType(String nodeTypeName, List<String> superTypes, NodeTypeManager nodeTypeManager) throws NoSuchNodeTypeException, RepositoryException { NodeType nodeTypeContent = nodeTypeManager.getNodeType(nodeTypeName); assertNotNull(nodeTypeContent); assertEquals("Should have only one generic child", 1, nodeTypeContent.getDeclaredChildNodeDefinitions().length); assertEquals("*", nodeTypeContent.getDeclaredChildNodeDefinitions()[0].getName()); assertEquals(false, nodeTypeContent.getDeclaredChildNodeDefinitions()[0].allowsSameNameSiblings()); assertEquals("Should have " + superTypes.size() + " supertype defined", superTypes.size(), nodeTypeContent.getDeclaredSupertypeNames().length); assertEquals("Should have 2 propertyDefinition defined", 2, nodeTypeContent.getDeclaredPropertyDefinitions().length); assertTrue("Should have all supertype declared", containsAllSupertypes(nodeTypeContent, superTypes)); }