Search in sources :

Example 26 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project jackrabbit-oak by apache.

the class NodeTypeImpl method getDeclaredNodeDefs.

private List<NodeDefinition> getDeclaredNodeDefs(Tree defs) {
    if (defs.exists()) {
        List<NodeDefinition> list = newArrayList();
        String typeName = getOakName();
        for (Tree def : defs.getChildren()) {
            String declaringTypeName = TreeUtil.getName(def, REP_DECLARING_NODE_TYPE);
            if (typeName.equals(declaringTypeName)) {
                list.add(new NodeDefinitionImpl(def, this, mapper));
            }
        }
        return list;
    } else {
        return emptyList();
    }
}
Also used : NodeDefinition(javax.jcr.nodetype.NodeDefinition) Tree(org.apache.jackrabbit.oak.api.Tree)

Example 27 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project jackrabbit-oak by apache.

the class RepositoryTest method testGetDefinitionWithSNS.

@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")) {
        // OAK-829
        NodeDefinition definition = child.getDefinition();
        // OAK-826
        definition.getDefaultPrimaryType();
        // OAK-826
        definition.getRequiredPrimaryTypes();
    }
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition) Session(javax.jcr.Session) Test(org.junit.Test)

Example 28 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project jackrabbit-oak by apache.

the class NodeDefinitionTest method testGetRequiredPrimaryTypes.

@Test
public void testGetRequiredPrimaryTypes() throws RepositoryException {
    for (String path : paths) {
        Node n = superuser.getNode(path);
        NodeDefinition def = n.getDefinition();
        def.getRequiredPrimaryTypes();
    }
}
Also used : Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition) Test(org.junit.Test) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest)

Example 29 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project jackrabbit-oak by apache.

the class NodeTypeDefinitionTest method testIndexedChildDefinition.

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));
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 30 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project jackrabbit-oak by apache.

the class NodeDefinitionTest method getAggregatedNodeDefinitions.

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()]);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Aggregations

NodeDefinition (javax.jcr.nodetype.NodeDefinition)77 NodeType (javax.jcr.nodetype.NodeType)44 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)29 Node (javax.jcr.Node)17 ItemExistsException (javax.jcr.ItemExistsException)14 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)13 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)13 Version (javax.jcr.version.Version)12 Test (org.junit.Test)11 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 RepositoryException (javax.jcr.RepositoryException)7 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 Name (org.apache.jackrabbit.spi.Name)5 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)5 NodeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl)5 ArrayList (java.util.ArrayList)4 NodeState (org.apache.jackrabbit.core.state.NodeState)4 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)4 Session (javax.jcr.Session)3