Package javax.jcr.nodetype

Examples of javax.jcr.nodetype.NodeTypeTemplate


    public void testUnRegisterNodeType() throws Exception {
        assertDefaultPrivileges(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT);
        assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);

        NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
        NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
        ntd.setName("testNodeType");
        ntd.setMixin(true);
        ntm.registerNodeType(ntd, true);

        Workspace testWsp = getTestWorkspace();
        try {
            try {
                NodeTypeManager testNtm = testWsp.getNodeTypeManager();
                testNtm.unregisterNodeType(ntd.getName());
                fail("Namespace unregistration should be denied.");
            } catch (AccessDeniedException e) {
                // success
            }
            try {
                NodeTypeManager testNtm = testWsp.getNodeTypeManager();
                testNtm.unregisterNodeTypes(new String[] {ntd.getName()});
                fail("Namespace unregistration should be denied.");
            } catch (AccessDeniedException e) {
                // success
            }
        } finally {
            // clean up (not supported by jackrabbit-core)
            try {
                ntm.unregisterNodeType(ntd.getName());
            } catch (Exception e) {
                // ns unregistration is not supported by jackrabbit-core.
            }
        }
View Full Code Here


    @Test
    public void nodeTypeRegistry() throws RepositoryException {
        NodeTypeManager ntMgr = getSession().getWorkspace().getNodeTypeManager();
        assertFalse(ntMgr.hasNodeType("foo"));

        NodeTypeTemplate ntd = ntMgr.createNodeTypeTemplate();
        ntd.setName("foo");
        ntMgr.registerNodeType(ntd, false);
        assertTrue(ntMgr.hasNodeType("foo"));

        ntMgr.unregisterNodeType("foo");
        assertFalse(ntMgr.hasNodeType("foo"));
View Full Code Here

    }

    @Test
    public void mixin() throws RepositoryException {
        NodeTypeManager ntMgr = getSession().getWorkspace().getNodeTypeManager();
        NodeTypeTemplate mixTest = ntMgr.createNodeTypeTemplate();
        mixTest.setName("mix:test");
        mixTest.setMixin(true);
        ntMgr.registerNodeType(mixTest, false);

        Node testNode = getNode(TEST_PATH);
        NodeType[] mix = testNode.getMixinNodeTypes();
        assertEquals(0, mix.length);
View Full Code Here

        String nt;
        do {
            nt = baseName + "_" + i++;
        } while (ntMgr.hasNodeType(nt));
        // register node type
        NodeTypeTemplate ntTemplate = ntMgr.createNodeTypeTemplate();
        ntTemplate.setName(nt);
        ntTemplate.setDeclaredSuperTypeNames(new String[]{ntUnstructured});
        ntMgr.registerNodeType(ntTemplate, false);
        // create node
        Node n = testRootNode.addNode(nodeName2, nt);
        session.save();
        // get state
View Full Code Here

                    session.getWorkspace().getNamespaceRegistry();
                registry.registerNamespace("test", "http://www.example.org/");

                NodeTypeManager manager =
                    session.getWorkspace().getNodeTypeManager();
                NodeTypeTemplate template = manager.createNodeTypeTemplate();
                template.setName("test:unstructured");
                template.setDeclaredSuperTypeNames(
                        new String[] { "nt:unstructured" });
                manager.registerNodeType(template, false);

                Node root = session.getRootNode();
View Full Code Here

        String nt;
        do {
            nt = baseName + "_" + i++;
        } while (ntMgr.hasNodeType(nt));
        // register node type
        NodeTypeTemplate ntTemplate = ntMgr.createNodeTypeTemplate();
        ntTemplate.setName(nt);
        ntTemplate.setDeclaredSuperTypeNames(new String[]{ntUnstructured});
        ntMgr.registerNodeType(ntTemplate, false);
        // create node
        Node n = testRootNode.addNode(nodeName2, nt);
        superuser.save();
        // get state
View Full Code Here

        assertDefaultPrivileges(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT);
        assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);

        Workspace testWsp = getTestWorkspace();
        NodeTypeManager ntm = testWsp.getNodeTypeManager();
        NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
        ntd.setName("testNodeType");
        ntd.setMixin(true);

        try {
            ntm.registerNodeType(ntd, true);
            fail("Node type registration should be denied.");
        } catch (AccessDeniedException e) {
View Full Code Here

        assertPermission(Permission.NODE_TYPE_DEF_MNGMT, true);

        try {
            Workspace testWsp = getTestWorkspace();
            NodeTypeManager ntm = testWsp.getNodeTypeManager();
            NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
            ntd.setName("testNodeType");
            ntd.setMixin(true);
            ntm.registerNodeType(ntd, true);

            NodeTypeTemplate[] ntds = new NodeTypeTemplate[2];
            ntds[0] = ntd;
            ntds[1] = ntm.createNodeTypeTemplate();
View Full Code Here

    public void testUnRegisterNodeType() throws Exception {
        assertDefaultPrivileges(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT);
        assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);

        NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
        NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
        ntd.setName("testNodeType");
        ntd.setMixin(true);
        ntm.registerNodeType(ntd, true);

        Workspace testWsp = getTestWorkspace();
        try {
            try {
                NodeTypeManager testNtm = testWsp.getNodeTypeManager();
                testNtm.unregisterNodeType(ntd.getName());
                fail("Namespace unregistration should be denied.");
            } catch (AccessDeniedException e) {
                // success
            }
            try {
                NodeTypeManager testNtm = testWsp.getNodeTypeManager();
                testNtm.unregisterNodeTypes(new String[] {ntd.getName()});
                fail("Namespace unregistration should be denied.");
            } catch (AccessDeniedException e) {
                // success
            }
        } finally {
            // clean up (not supported by jackrabbit-core)
            try {
                ntm.unregisterNodeType(ntd.getName());
            } catch (Exception e) {
                // ns unregistration is not supported by jackrabbit-core.
            }
        }
View Full Code Here

            if (checkSuperTypes(session.getWorkspace().getNodeTypeManager(),
                    classDescriptor.getJcrSuperTypes())) {

                javax.jcr.nodetype.NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
                final NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();

                if (classDescriptor.getJcrType() == null) {
                    ntt.setName(classDescriptor.getClassName());
                } else {
                    ntt.setName(classDescriptor.getJcrType());
                }
                ntt.setAbstract(classDescriptor.isAbstract());
                if (classDescriptor.getJcrSuperTypes() != null && classDescriptor.getJcrSuperTypes().length() > 0) {
                    String[] superTypesArray = classDescriptor.getJcrSuperTypes().split(",");
                    //TODO  combine the mixins here as well as supertypes
                    // Add classDescriptor.getJcrMixinTypes() to superTypesArray
                    for (String s : classDescriptor.getJcrMixinTypes()) {
                        System.out.println(s);
                    }
                    ntt.setDeclaredSuperTypeNames(superTypesArray);
                }
                // should we also support mixins to be created?
                ntt.setMixin(false);
                ntt.setQueryable(true);
                ntt.setOrderableChildNodes(true);

                final List nodeDefinitionTemplates = ntt.getNodeDefinitionTemplates();
                final List propertyDefinitionTemplates = ntt.getPropertyDefinitionTemplates();

                if (classDescriptor.getFieldDescriptors() != null) {
                    Iterator fieldIterator = classDescriptor.getFieldDescriptors().iterator();
                    while (fieldIterator.hasNext()) {
                        FieldDescriptor field = (FieldDescriptor) fieldIterator.next();
                        if (!field.isPath()) {
                            final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm, session.getValueFactory(), field);
                            // add the just created pdt to the nodetypetemplate
                            propertyDefinitionTemplates.add(pdt);
                        }
                    }

                    if (classDescriptor.getBeanDescriptors() != null) {
                        Iterator beanIterator = classDescriptor.getBeanDescriptors().iterator();
                        while (beanIterator.hasNext()) {
                            BeanDescriptor field = (BeanDescriptor) beanIterator.next();
                            if (this.isPropertyType(field.getJcrType())) {
                                final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm, session.getValueFactory(), field);
                                // add the just created pdt to the nodetypetemplate
                                propertyDefinitionTemplates.add(pdt);
                            } else {
                                final NodeDefinitionTemplate ndt = getNodeDefinition(ntm, session.getValueFactory(), field);
                                // add the just created pdt to the nodetypetemplate
                                nodeDefinitionTemplates.add(ndt);
                            }
                        }
                    }

                    if (classDescriptor.getCollectionDescriptors() != null) {
                        Iterator collectionIterator = classDescriptor.getCollectionDescriptors().iterator();
                        while (collectionIterator.hasNext()) {
                            CollectionDescriptor field = (CollectionDescriptor) collectionIterator.next();
                            if (this.isPropertyType(field.getJcrType())) {
                                final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm, session.getValueFactory(), field);
                                // add the just created pdt to the nodetypetemplate
                                propertyDefinitionTemplates.add(pdt);
                            } else {
                                final NodeDefinitionTemplate ndt = getNodeDefinition(ntm, session.getValueFactory(), field);
                                // add the just created pdt to the nodetypetemplate
                                nodeDefinitionTemplates.add(ndt);
                            }
                        }
                    }
                    ntm.registerNodeType(ntt, false);
                    log.info("Registered JCR node type '" + ntt.getName() +
                            "' for class '" + classDescriptor.getClassName() + "'");
                }
            } else {
                throw new NodeTypeCreationException("JCR supertypes could not be resolved.");
            }
View Full Code Here

TOP

Related Classes of javax.jcr.nodetype.NodeTypeTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.