Package javax.jcr.nodetype

Examples of javax.jcr.nodetype.NodeDefinitionTemplate


    return t;
  }

  private NodeDefinitionTemplate getInternalFolderNode( final NodeTypeManager ntMgr, final ValueFactory vFac )
    throws RepositoryException {
    NodeDefinitionTemplate t = ntMgr.createNodeDefinitionTemplate();
    t.setName( "*" ); //$NON-NLS-1$
    t.setRequiredPrimaryTypeNames( new String[] { PHO_NT + "pentahoInternalFolder" } ); //$NON-NLS-1$
    t.setOnParentVersion( OnParentVersionAction.IGNORE );
    return t;
  }
View Full Code Here


    return t;
  }

  private NodeDefinitionTemplate getLocaleNode( final NodeTypeManager ntMgr, final String localeName )
    throws RepositoryException {
    NodeDefinitionTemplate t = ntMgr.createNodeDefinitionTemplate();
    t.setName( localeName ); //$NON-NLS-1$
    t.setRequiredPrimaryTypeNames( new String[] { NT + "unstructured" } ); //$NON-NLS-1$
    t.setOnParentVersion( OnParentVersionAction.COPY );
    t.setSameNameSiblings( false );
    return t;
  }
View Full Code Here

        pdefs = ntt.getPropertyDefinitionTemplates();
        assertEquals(1, pdefs.size());
        assertEquals(pdTemplate, pdefs.get(0));

        NodeDefinitionTemplate ndTemplate = ntm.createNodeDefinitionTemplate();

        List ndefs = ntt.getNodeDefinitionTemplates();
        ndefs.add(ndTemplate);

        assertNotNull(ntt.getDeclaredChildNodeDefinitions());
View Full Code Here

        // TODO: PropertyDefinitionTemplate: test setting name/path constraints
        // see  https://jsr-283.dev.java.net/issues/show_bug.cgi?id=794
    }

    public void testEmptyNodeDefinitionTemplate() throws Exception {
        NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();

        assertNull(ndt.getName());
        assertFalse(ndt.isAutoCreated());
        assertFalse(ndt.isMandatory());
        assertFalse(ndt.isProtected());
        assertEquals(OnParentVersionAction.COPY, ndt.getOnParentVersion());
        assertNull(ndt.getDeclaringNodeType());

        assertNull(ndt.getRequiredPrimaryTypes());
        assertNull(ndt.getRequiredPrimaryTypeNames());
        assertNull(ndt.getDefaultPrimaryType());
        assertNull(ndt.getDefaultPrimaryTypeName());
        assertFalse(ndt.allowsSameNameSiblings());
    }
View Full Code Here

        assertNull(ndt.getDefaultPrimaryTypeName());
        assertFalse(ndt.allowsSameNameSiblings());
    }

    public void testNodeDefinitionTemplate() throws Exception {
        NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();

        try {
            ndt.setName(null);
            fail("null isn't a valid JCR name");
        } catch (ConstraintViolationException e) {
            // success
        }

        String expandedName = "{" + NS_JCR_URI + "}" + "content";
        String jcrName = superuser.getNamespacePrefix(NS_JCR_URI) + ":content";
        ndt.setName(expandedName);
        assertEquals(jcrName, ndt.getName());
        ndt.setName(jcrName);
        assertEquals(jcrName, ndt.getName());

        ndt.setSameNameSiblings(true);
        assertTrue(ndt.allowsSameNameSiblings());

        ndt.setAutoCreated(true);
        assertTrue(ndt.isAutoCreated());

        ndt.setMandatory(true);
        assertTrue(ndt.isMandatory());

        ndt.setProtected(true);
        assertTrue(ndt.isProtected());

        ndt.setOnParentVersion(OnParentVersionAction.VERSION);
        assertEquals(OnParentVersionAction.VERSION, ndt.getOnParentVersion());

        expandedName = "{" + NS_NT_URI + "}" + "folder";
        jcrName = superuser.getNamespacePrefix(NS_NT_URI) + ":folder";
        ndt.setDefaultPrimaryTypeName(expandedName);
        assertEquals(jcrName, ndt.getDefaultPrimaryTypeName());

        try {
            ndt.setDefaultPrimaryTypeName(null);
            fail("null isn't a valid jcr name");
        } catch (ConstraintViolationException e) {
            // success
        }

        ndt.setRequiredPrimaryTypeNames(new String[] {expandedName});
        assertNotNull(ndt.getRequiredPrimaryTypeNames());
        assertEquals(1, ndt.getRequiredPrimaryTypeNames().length);
        assertEquals(jcrName, ndt.getRequiredPrimaryTypeNames()[0]);

        try {
            ndt.setRequiredPrimaryTypeNames(null);
            fail("null isn't a valid array of jcr name");
        } catch (ConstraintViolationException e) {
            // success
        }
    }
View Full Code Here

    }

    public void testResidualNames() throws Exception {
        String residualName = "*";

        NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
        ndt.setName(residualName);
        assertEquals(residualName, ndt.getName());

        PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
        pdt.setName(residualName);
        assertEquals(residualName, pdt.getName());
    }
View Full Code Here

        } catch (ConstraintViolationException e) {
            // success
        }

        // invalid name(s) passed to NodeDefinitionTemplate
        NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
        try {
            ndt.setName(invalidName);
            fail("ConstraintViolationException expected. Name is invalid");
        } catch (ConstraintViolationException e) {
            // success
        }
        try {
            ndt.setRequiredPrimaryTypeNames(new String[] {"{" + NS_MIX_URI + "}" + "littlemixin", invalidName});
            fail("ConstraintViolationException expected. One of the required primary type names is invalid");
        } catch (ConstraintViolationException e) {
            // success
        }
        try {
            ndt.setDefaultPrimaryTypeName(invalidName);
            fail("ConstraintViolationException expected. Default primary type name is invalid");
        } catch (ConstraintViolationException e) {
            // success
        }
View Full Code Here

        // node type with default child-node type of to nt:base
        String ntName = "test";
        NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
        NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
        ntt.setName(ntName);
        NodeDefinitionTemplate child = ntm.createNodeDefinitionTemplate();
        child.setName("*");
        child.setDefaultPrimaryTypeName("nt:base");
        child.setRequiredPrimaryTypeNames(new String[] {"nt:base"});
        List<NodeDefinition> children = ntt.getNodeDefinitionTemplates();
        children.add(child);
        ntm.registerNodeType(ntt, true);

        // try to create a node with the default nt:base
View Full Code Here

        return defn;
    }

    protected NodeDefinition readChildNodeDefinition( CachedNode childDefn ) throws ConstraintViolationException {
        NodeDefinitionTemplate defn = new JcrNodeDefinitionTemplate(context());
        defn.setName(strings.create(first(childDefn, JcrLexicon.NAME, JcrNodeType.RESIDUAL_ITEM_NAME)));
        defn.setAutoCreated(booleans.create(first(childDefn, JcrLexicon.AUTO_CREATED)));
        defn.setMandatory(booleans.create(first(childDefn, JcrLexicon.MANDATORY)));
        defn.setSameNameSiblings(booleans.create(first(childDefn, JcrLexicon.SAME_NAME_SIBLINGS)));
        defn.setProtected(booleans.create(first(childDefn, JcrLexicon.PROTECTED)));
        defn.setOnParentVersion(OnParentVersionAction.valueFromName(strings.create(first(childDefn, JcrLexicon.ON_PARENT_VERSION))));

        String defaultPrimaryType = strings.create(first(childDefn, JcrLexicon.DEFAULT_PRIMARY_TYPE));
        if (defaultPrimaryType != null) defn.setDefaultPrimaryTypeName(defaultPrimaryType);

        Property requiredPrimaryTypes = childDefn.getProperty(JcrLexicon.REQUIRED_PRIMARY_TYPES, system);
        if (requiredPrimaryTypes != null && !requiredPrimaryTypes.isEmpty()) {
            String[] values = new String[requiredPrimaryTypes.size()];
            int i = 0;
            for (Object op : requiredPrimaryTypes) {
                values[i++] = strings.create(op);
            }
            defn.setRequiredPrimaryTypeNames(values);
        }

        return defn;
    }
View Full Code Here

    private NodeTypeTemplate createMixinWithAutoChild( NodeTypeManager mgr ) throws RepositoryException {
        NodeTypeTemplate mixinTypeWithAutoChild = mgr.createNodeTypeTemplate();
        mixinTypeWithAutoChild.setName("mixinTypeWithAutoCreatedChildNode");
        mixinTypeWithAutoChild.setMixin(true);

        NodeDefinitionTemplate childNodeB = mgr.createNodeDefinitionTemplate();
        childNodeB.setName(CHILD_NODE_B);
        childNodeB.setOnParentVersion(OnParentVersionAction.IGNORE);
        childNodeB.setMandatory(true);
        childNodeB.setAutoCreated(true);
        childNodeB.setDefaultPrimaryTypeName("nt:unstructured");
        childNodeB.setRequiredPrimaryTypeNames(new String[] {"nt:unstructured"});
        mixinTypeWithAutoChild.getNodeDefinitionTemplates().add(childNodeB);
        return mixinTypeWithAutoChild;
    }
View Full Code Here

TOP

Related Classes of javax.jcr.nodetype.NodeDefinitionTemplate

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.