Here are the examples of the java api class javax.jcr.nodetype.NodeTypeDefinition taken from open source projects.
1. SystemContentTest#shouldReadNodeTypeDefinitionsFromSystemCatalog()
Project: modeshape
File: SystemContentTest.java
File: SystemContentTest.java
@Test public void shouldReadNodeTypeDefinitionsFromSystemCatalog() { NodeTypes nodeTypes = repository.nodeTypeManager().getNodeTypes(); Set<Name> builtInNodeTypes = new HashSet<Name>(nodeTypes.getAllNodeTypeNames()); for (NodeTypeDefinition type : system.readAllNodeTypes()) { Name name = name(type.getName()); JcrNodeType actual = nodeTypes.getNodeType(name); assertThat("Did not find actual node type for name \"" + type.getName() + "\"", actual, is(notNullValue())); assertThat(builtInNodeTypes.remove(name), is(true)); } assertThat(builtInNodeTypes.isEmpty(), is(true)); }
2. CndImporterTest#assertChild()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
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)); }
3. CndImporterTest#assertNodeType()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
protected void assertNodeType(String name, String[] superTypes, String primaryItemName, NodeOptions... nodeOptions) { Set<NodeOptions> options = new HashSet<NodeOptions>(); for (NodeOptions option : nodeOptions) options.add(option); NodeTypeDefinition defn = defn(name); assertThat(defn.getName(), is(name)); assertThat(defn.isAbstract(), is(options.contains(NodeOptions.Abstract))); assertThat(defn.hasOrderableChildNodes(), is(options.contains(NodeOptions.Ordered))); assertThat(defn.isMixin(), is(options.contains(NodeOptions.Mixin))); assertThat(defn.isQueryable(), is(options.contains(NodeOptions.Queryable))); assertThat(defn.getPrimaryItemName(), is(primaryItemName)); String[] supertypeNames = defn.getDeclaredSupertypeNames(); assertThat(supertypeNames, is(superTypes)); }
4. NodeTypeManagerImpl#registerNodeTypes()
Project: jackrabbit
File: NodeTypeManagerImpl.java
File: NodeTypeManagerImpl.java
/** * @see NodeTypeManager#registerNodeTypes(javax.jcr.nodetype.NodeTypeDefinition[], boolean) */ public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] ntds, boolean allowUpdate) throws RepositoryException { List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>(ntds.length); for (NodeTypeDefinition definition : ntds) { QNodeTypeDefinition qdef = new QNodeTypeDefinitionImpl(definition, getNamePathResolver(), mgrProvider.getQValueFactory()); if (!allowUpdate && hasNodeType(qdef.getName())) { throw new NodeTypeExistsException("NodeType " + definition.getName() + " already exists."); } defs.add(qdef); } getNodeTypeRegistry().registerNodeTypes(defs, allowUpdate); List<NodeType> nts = new ArrayList<NodeType>(); for (QNodeTypeDefinition def : defs) { nts.add(getNodeType(def.getName())); } return new NodeTypeIteratorAdapter(nts); }
5. CndImporterTest#defn()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
protected NodeTypeDefinition defn(String name) { NodeTypeDefinition result = null; for (NodeTypeDefinition defn : importer.getNodeTypeDefinitions()) { if (defn.getName().equals(name)) { result = defn; break; } } assertThat("Failed to find node type definition \"" + name + "\"", result, is(notNullValue())); return result; }
6. MultiUseAbstractTest#registerNodeTypes()
Project: modeshape
File: MultiUseAbstractTest.java
File: MultiUseAbstractTest.java
protected static void registerNodeTypes(List<? extends NodeTypeDefinition> nodeTypes) throws RepositoryException { Workspace workspace = session.getWorkspace(); org.modeshape.jcr.api.nodetype.NodeTypeManager ntMgr = (org.modeshape.jcr.api.nodetype.NodeTypeManager) workspace.getNodeTypeManager(); NodeTypeDefinition[] defns = nodeTypes.toArray(new NodeTypeDefinition[nodeTypes.size()]); ntMgr.registerNodeTypes(defns, true); }
7. CndImporterTest#assertProperty()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
protected void assertProperty(String nodeTypeName, String propertyName, String requiredType, String[] defaultValues, PropertyOptions[] propertyOptions, OnParentVersion onParentVersioning, String... valueConstraints) throws RepositoryException { Set<PropertyOptions> options = new HashSet<PropertyOptions>(); for (PropertyOptions option : propertyOptions) options.add(option); NodeTypeDefinition defn = defn(nodeTypeName); PropertyDefinition propDefn = propDefn(defn, propertyName); assertThat(propDefn.getName(), is(propertyName)); assertThat(propDefn.getRequiredType(), is(jcrPropertyType(requiredType))); assertThat(propDefn.isMandatory(), is(options.contains(PropertyOptions.Mandatory))); assertThat(propDefn.isAutoCreated(), is(options.contains(PropertyOptions.Autocreated))); assertThat(propDefn.isProtected(), is(options.contains(PropertyOptions.Protected))); assertThat(propDefn.isMultiple(), is(options.contains(PropertyOptions.Multiple))); assertThat(propDefn.isFullTextSearchable(), is(options.contains(PropertyOptions.FullTextSearchable))); assertThat(propDefn.isQueryOrderable(), is(options.contains(PropertyOptions.QueryOrderable))); int opv = opv(onParentVersioning); assertThat(propDefn.getOnParentVersion(), is(opv)); if (defaultValues == null || defaultValues.length == 0) { assertThat(propDefn.getDefaultValues(), is(nullValue())); } else { int i = 0; for (Value defaultValue : propDefn.getDefaultValues()) { assertThat(defaultValues[i++], is(defaultValue.getString())); } } if (valueConstraints == null || valueConstraints.length == 0) { assertThat(propDefn.getValueConstraints(), is(nullValue())); } else { assertThat(propDefn.getValueConstraints(), is(valueConstraints)); } }
8. CndImporterTest#shouldImportCndThatUsesExtensions()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
@Test public void shouldImportCndThatUsesExtensions() throws RepositoryException { // importer.setDebug(true); String cnd = "<ex = 'http://namespace.com/ns'>\n" + "[ex:NodeType] > ex:ParentType1, ex:ParentType2 abstract {mode:desc 'ex:NodeType description'} orderable mixin noquery primaryitem ex:property\n" + "- ex:property (STRING) = 'default1', 'default2' mandatory autocreated protected multiple VERSION\n" + " queryops '=, <>, <, <=, >, >=, LIKE' {mode:desc 'ex:property description'} {mode:altName Cool Property} nofulltext noqueryorder < 'constraint1', 'constraint2'" + "+ ex:node (ex:reqType1, ex:reqType2) = ex:defaultType {} mandatory autocreated protected sns version"; importer.importFrom(cnd, problems, "string"); // Check the namespace ... context.getNamespaceRegistry().register("ex", "http://namespace.com/ns"); assertThat(importer.getNamespaces().size(), is(1)); NamespaceRegistry.Namespace ns = importer.getNamespaces().iterator().next(); assertThat(ns.getNamespaceUri(), is("http://namespace.com/ns")); List<NodeTypeDefinition> defns = importer.getNodeTypeDefinitions(); assertThat(defns.size(), is(1)); NodeTypeDefinition defn = defns.get(0); assertThat(defn.getName(), is("ex:NodeType")); assertThat(defn.isAbstract(), is(true)); assertThat(defn.hasOrderableChildNodes(), is(true)); assertThat(defn.isMixin(), is(true)); assertThat(defn.isQueryable(), is(false)); assertThat(defn.getPrimaryItemName(), is("ex:property")); String[] supertypeNames = defn.getDeclaredSupertypeNames(); assertThat(supertypeNames[0], is("ex:ParentType1")); assertThat(supertypeNames[1], is("ex:ParentType2")); PropertyDefinition[] propDefns = defn.getDeclaredPropertyDefinitions(); assertThat(propDefns.length, is(1)); PropertyDefinition propDefn = propDefns[0]; assertThat(propDefn.getName(), is("ex:property")); assertThat(propDefn.getRequiredType(), is(PropertyType.STRING)); assertThat(propDefn.isMandatory(), is(true)); assertThat(propDefn.isAutoCreated(), is(true)); assertThat(propDefn.isProtected(), is(true)); assertThat(propDefn.isMultiple(), is(true)); assertThat(propDefn.getOnParentVersion(), is(OnParentVersionAction.VERSION)); assertThat(propDefn.isFullTextSearchable(), is(false)); assertThat(propDefn.isQueryOrderable(), is(false)); Value[] defaultValues = propDefn.getDefaultValues(); assertThat(defaultValues[0].getString(), is("default1")); assertThat(defaultValues[1].getString(), is("default2")); String[] queryOps = propDefn.getAvailableQueryOperators(); assertThat(queryOps[0], is("=")); assertThat(queryOps[1], is("<>")); assertThat(queryOps[2], is("<")); assertThat(queryOps[3], is("<=")); assertThat(queryOps[4], is(">")); assertThat(queryOps[5], is(">=")); assertThat(queryOps[6], is("LIKE")); String[] constraints = propDefn.getValueConstraints(); assertThat(constraints[0], is("constraint1")); assertThat(constraints[1], is("constraint2")); NodeDefinition[] childDefns = defn.getDeclaredChildNodeDefinitions(); assertThat(childDefns.length, is(1)); NodeDefinition childDefn = childDefns[0]; assertThat(childDefn.getName(), is("ex:node")); assertThat(childDefn.getDefaultPrimaryTypeName(), is("ex:defaultType")); assertThat(childDefn.isMandatory(), is(true)); assertThat(childDefn.isAutoCreated(), is(true)); assertThat(childDefn.isProtected(), is(true)); assertThat(childDefn.allowsSameNameSiblings(), is(true)); assertThat(childDefn.getOnParentVersion(), is(OnParentVersionAction.VERSION)); String[] requiredTypeNames = childDefn.getRequiredPrimaryTypeNames(); assertThat(requiredTypeNames[0], is("ex:reqType1")); assertThat(requiredTypeNames[1], is("ex:reqType2")); }
9. CndImporterTest#shouldImportCndThatUsesAllFeatures()
Project: modeshape
File: CndImporterTest.java
File: CndImporterTest.java
@Test public void shouldImportCndThatUsesAllFeatures() throws RepositoryException { // importer.setDebug(true); String cnd = "<ex = 'http://namespace.com/ns'>\n" + "[ex:NodeType] > ex:ParentType1, ex:ParentType2 abstract orderable mixin noquery primaryitem ex:property\n" + "- ex:property (STRING) = 'default1', 'default2' mandatory autocreated protected multiple VERSION\n" + " queryops '=, <>, <, <=, >, >=, LIKE' nofulltext noqueryorder < 'constraint1', 'constraint2'" + "+ ex:node (ex:reqType1, ex:reqType2) = ex:defaultType mandatory autocreated protected sns version"; importer.importFrom(cnd, problems, "string"); if (!problems.isEmpty()) printProblems(); // Check the namespace ... context.getNamespaceRegistry().register("ex", "http://namespace.com/ns"); assertThat(importer.getNamespaces().size(), is(1)); NamespaceRegistry.Namespace ns = importer.getNamespaces().iterator().next(); assertThat(ns.getNamespaceUri(), is("http://namespace.com/ns")); List<NodeTypeDefinition> defns = importer.getNodeTypeDefinitions(); assertThat(defns.size(), is(1)); NodeTypeDefinition defn = defns.get(0); assertThat(defn.getName(), is("ex:NodeType")); assertThat(defn.isAbstract(), is(true)); assertThat(defn.hasOrderableChildNodes(), is(true)); assertThat(defn.isMixin(), is(true)); assertThat(defn.isQueryable(), is(false)); assertThat(defn.getPrimaryItemName(), is("ex:property")); String[] supertypeNames = defn.getDeclaredSupertypeNames(); assertThat(supertypeNames[0], is("ex:ParentType1")); assertThat(supertypeNames[1], is("ex:ParentType2")); PropertyDefinition[] propDefns = defn.getDeclaredPropertyDefinitions(); assertThat(propDefns.length, is(1)); PropertyDefinition propDefn = propDefns[0]; assertThat(propDefn.getName(), is("ex:property")); assertThat(propDefn.getRequiredType(), is(PropertyType.STRING)); assertThat(propDefn.isMandatory(), is(true)); assertThat(propDefn.isAutoCreated(), is(true)); assertThat(propDefn.isProtected(), is(true)); assertThat(propDefn.isMultiple(), is(true)); assertThat(propDefn.getOnParentVersion(), is(OnParentVersionAction.VERSION)); assertThat(propDefn.isFullTextSearchable(), is(false)); assertThat(propDefn.isQueryOrderable(), is(false)); Value[] defaultValues = propDefn.getDefaultValues(); assertThat(defaultValues[0].getString(), is("default1")); assertThat(defaultValues[1].getString(), is("default2")); String[] queryOps = propDefn.getAvailableQueryOperators(); assertThat(queryOps[0], is("=")); assertThat(queryOps[1], is("<>")); assertThat(queryOps[2], is("<")); assertThat(queryOps[3], is("<=")); assertThat(queryOps[4], is(">")); assertThat(queryOps[5], is(">=")); assertThat(queryOps[6], is("LIKE")); String[] constraints = propDefn.getValueConstraints(); assertThat(constraints[0], is("constraint1")); assertThat(constraints[1], is("constraint2")); NodeDefinition[] childDefns = defn.getDeclaredChildNodeDefinitions(); assertThat(childDefns.length, is(1)); NodeDefinition childDefn = childDefns[0]; assertThat(childDefn.getName(), is("ex:node")); assertThat(childDefn.getDefaultPrimaryTypeName(), is("ex:defaultType")); assertThat(childDefn.isMandatory(), is(true)); assertThat(childDefn.isAutoCreated(), is(true)); assertThat(childDefn.isProtected(), is(true)); assertThat(childDefn.allowsSameNameSiblings(), is(true)); assertThat(childDefn.getOnParentVersion(), is(OnParentVersionAction.VERSION)); String[] requiredTypeNames = childDefn.getRequiredPrimaryTypeNames(); assertThat(requiredTypeNames[0], is("ex:reqType1")); assertThat(requiredTypeNames[1], is("ex:reqType2")); }
10. CndSequencer#processNodeTypeDefinitions()
Project: modeshape
File: CndSequencer.java
File: CndSequencer.java
private void processNodeTypeDefinitions(Node outputNode, CndImporter cndImporter) throws RepositoryException { List<NodeTypeDefinition> importedNodeTypes = cndImporter.getNodeTypeDefinitions(); for (NodeTypeDefinition nodeTypeDefinition : importedNodeTypes) { storeNodeTypeDefinition(outputNode, nodeTypeDefinition); } }
11. CmisConnector#registerRepositoryInfoType()
Project: modeshape
File: CmisConnector.java
File: CmisConnector.java
/** * Defines node type for the repository info. * * @param typeManager JCR node type manager. * @throws RepositoryException */ @SuppressWarnings("unchecked") private void registerRepositoryInfoType(NodeTypeManager typeManager) throws RepositoryException { // create node type template NodeTypeTemplate type = typeManager.createNodeTypeTemplate(); // convert CMIS type's attributes to node type template we have just created type.setName("cmis:repository"); type.setAbstract(false); type.setMixin(false); type.setOrderableChildNodes(true); type.setQueryable(true); type.setDeclaredSuperTypeNames(new String[] { JcrConstants.NT_FOLDER }); PropertyDefinitionTemplate vendorName = typeManager.createPropertyDefinitionTemplate(); vendorName.setAutoCreated(false); vendorName.setName("cmis:vendorName"); vendorName.setMandatory(false); type.getPropertyDefinitionTemplates().add(vendorName); PropertyDefinitionTemplate productName = typeManager.createPropertyDefinitionTemplate(); productName.setAutoCreated(false); productName.setName("cmis:productName"); productName.setMandatory(false); type.getPropertyDefinitionTemplates().add(productName); PropertyDefinitionTemplate productVersion = typeManager.createPropertyDefinitionTemplate(); productVersion.setAutoCreated(false); productVersion.setName("cmis:productVersion"); productVersion.setMandatory(false); type.getPropertyDefinitionTemplates().add(productVersion); // register type NodeTypeDefinition[] nodeDefs = new NodeTypeDefinition[] { type }; typeManager.registerNodeTypes(nodeDefs, true); }
12. CmisConnector#importType()
Project: modeshape
File: CmisConnector.java
File: CmisConnector.java
/** * Import given CMIS type to the JCR repository. * * @param cmisType cmis object type * @param typeManager JCR type manager/ * @param registry * @throws RepositoryException if there is a problem importing the types */ @SuppressWarnings("unchecked") public void importType(ObjectType cmisType, NodeTypeManager typeManager, NamespaceRegistry registry) throws RepositoryException { // TODO: get namespace information and register // registry.registerNamespace(cmisType.getLocalNamespace(), cmisType.getLocalNamespace()); // create node type template NodeTypeTemplate type = typeManager.createNodeTypeTemplate(); // convert CMIS type's attributes to node type template we have just created type.setName(cmisType.getId()); type.setAbstract(false); type.setMixin(false); type.setOrderableChildNodes(true); type.setQueryable(true); if (!cmisType.isBaseType()) { type.setDeclaredSuperTypeNames(superTypes(cmisType)); } Map<String, PropertyDefinition<?>> props = cmisType.getPropertyDefinitions(); Set<String> names = props.keySet(); // properties for (String name : names) { PropertyDefinition<?> pd = props.get(name); PropertyDefinitionTemplate pt = typeManager.createPropertyDefinitionTemplate(); pt.setRequiredType(properties.getJcrType(pd.getPropertyType())); pt.setAutoCreated(false); pt.setAvailableQueryOperators(new String[] {}); pt.setName(name); pt.setMandatory(pd.isRequired()); type.getPropertyDefinitionTemplates().add(pt); } // register type NodeTypeDefinition[] nodeDefs = new NodeTypeDefinition[] { type }; typeManager.registerNodeTypes(nodeDefs, true); }
13. NodeTypeTest#removeMandatoryPropertyFlag()
Project: jackrabbit-oak
File: NodeTypeTest.java
File: NodeTypeTest.java
@Test public void removeMandatoryPropertyFlag() throws Exception { Session session = getAdminSession(); Node root = session.getRootNode(); NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string) mandatory"; CndImporter.registerNodeTypes(new StringReader(cnd), session); Node n = root.addNode("test", "test:MyType"); n.setProperty("test:mandatory", "value"); session.save(); try { n.getProperty("test:mandatory").remove(); session.save(); fail("Must fail with ConstraintViolationException"); } catch (ConstraintViolationException e) { session.refresh(false); } // remove the mandatory property flag cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string)"; CndImporter.registerNodeTypes(new StringReader(cnd), session, true); // check node type NodeTypeDefinition ntd = manager.getNodeType("test:MyType"); assertEquals(1, ntd.getDeclaredPropertyDefinitions().length); assertFalse(ntd.getDeclaredPropertyDefinitions()[0].isMandatory()); // now we should be able to remove the property n.getProperty("test:mandatory").remove(); session.save(); }
14. NodeTypeTest#removeMandatoryProperty()
Project: jackrabbit-oak
File: NodeTypeTest.java
File: NodeTypeTest.java
@Test public void removeMandatoryProperty() throws Exception { Session session = getAdminSession(); Node root = session.getRootNode(); NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string) mandatory"; CndImporter.registerNodeTypes(new StringReader(cnd), session); Node n = root.addNode("test", "test:MyType"); n.setProperty("test:mandatory", "value"); session.save(); try { n.getProperty("test:mandatory").remove(); session.save(); fail("Must fail with ConstraintViolationException"); } catch (ConstraintViolationException e) { session.refresh(false); } // remove the mandatory property cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured"; CndImporter.registerNodeTypes(new StringReader(cnd), session, true); // check node type NodeTypeDefinition ntd = manager.getNodeType("test:MyType"); assertEquals(0, ntd.getDeclaredPropertyDefinitions().length); // now we should be able to remove the property n.getProperty("test:mandatory").remove(); session.save(); }
15. NodeTypeTest#updateNodeType()
Project: jackrabbit-oak
File: NodeTypeTest.java
File: NodeTypeTest.java
@Test public void updateNodeType() throws Exception { Session session = getAdminSession(); Node root = session.getRootNode(); ValueFactory vf = session.getValueFactory(); NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); Node n = root.addNode("q1", "nt:query"); n.setProperty("jcr:statement", vf.createValue("statement")); session.save(); NodeTypeDefinition ntd = manager.getNodeType("nt:query"); NodeTypeTemplate ntt = manager.createNodeTypeTemplate(ntd); try { manager.registerNodeType(ntt, true); // no changes to the type, so the registration should be a no-op } catch (ConstraintViolationException unexpected) { fail(); } // make the (still missing) jcr:language property mandatory @SuppressWarnings("unchecked") List<PropertyDefinitionTemplate> pdts = ntt.getPropertyDefinitionTemplates(); for (PropertyDefinitionTemplate pdt : pdts) { if ("jcr:language".equals(pdt.getName())) { pdt.setMandatory(true); } } try { manager.registerNodeType(ntt, true); fail(); } catch (ConstraintViolationException expected) { } // add the jcr:language property so it can be made mandatory n.setProperty("jcr:language", vf.createValue("language")); session.save(); try { manager.registerNodeType(ntt, true); // now the mandatory property exists, so the type change is OK } catch (ConstraintViolationException unexpected) { fail(); } }
16. RepositoryServiceImpl#registerNodeTypes()
Project: jackrabbit
File: RepositoryServiceImpl.java
File: RepositoryServiceImpl.java
/** * {@inheritDoc} */ public void registerNodeTypes(SessionInfo sessionInfo, QNodeTypeDefinition[] nodeTypeDefinitions, boolean allowUpdate) throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, RepositoryException { SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo); NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager(); NodeTypeDefinition[] defs = new NodeTypeDefinition[nodeTypeDefinitions.length]; for (int i = 0; i < nodeTypeDefinitions.length; i++) { defs[i] = new NodeTypeDefinitionImpl(nodeTypeDefinitions[i], sInfo.getNamePathResolver(), sInfo.getSession().getValueFactory()) { }; } ntMgr.registerNodeTypes(defs, allowUpdate); }
17. CompactNodeTypeDefWriter#write()
Project: jackrabbit
File: CompactNodeTypeDefWriter.java
File: CompactNodeTypeDefWriter.java
/** * Write one QNodeTypeDefinition to this writer * * @param ntd node type definition * @throws IOException if an I/O error occurs */ public void write(QNodeTypeDefinition ntd) throws IOException { NodeTypeDefinition def = new NodeTypeDefinitionImpl(ntd, npResolver, new ValueFactoryQImpl(QValueFactoryImpl.getInstance(), npResolver)); super.write(def); }
18. AbstractNodeTypeManager#registerNodeType()
Project: jackrabbit
File: AbstractNodeTypeManager.java
File: AbstractNodeTypeManager.java
/** * @see javax.jcr.nodetype.NodeTypeManager#registerNodeType(NodeTypeDefinition, boolean) */ public NodeType registerNodeType(NodeTypeDefinition ntd, boolean allowUpdate) throws RepositoryException { NodeTypeDefinition[] ntds = new NodeTypeDefinition[] { ntd }; return registerNodeTypes(ntds, allowUpdate).nextNodeType(); }
19. NodeTypeCreationTest#testRegisterNodeTypes()
Project: jackrabbit
File: NodeTypeCreationTest.java
File: NodeTypeCreationTest.java
public void testRegisterNodeTypes() throws Exception { NodeTypeDefinition[] defs = new NodeTypeDefinition[5]; for (int i = 0; i < defs.length; i++) { NodeTypeTemplate ntt = ntm.createNodeTypeTemplate(); ntt.setName("mix:foo" + i); ntt.setAbstract(false); ntt.setMixin(true); ntt.setOrderableChildNodes(false); ntt.setQueryable(false); PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate(); pdt.setAutoCreated(false); pdt.setName("foo" + i); pdt.setMultiple(false); pdt.setRequiredType(PropertyType.STRING); List pdefs = ntt.getPropertyDefinitionTemplates(); pdefs.add(pdt); defs[i] = ntt; } ntm.registerNodeTypes(defs, true); try { ntm.registerNodeTypes(defs, false); fail("NodeTypeExistsException expected."); } catch (NodeTypeExistsException e) { } }
20. NodeTypeCreationTest#testNonEmptyNodeTypeTemplate()
Project: jackrabbit
File: NodeTypeCreationTest.java
File: NodeTypeCreationTest.java
public void testNonEmptyNodeTypeTemplate() throws Exception { NodeTypeDefinition ntd = ntm.getNodeType("nt:address"); NodeTypeTemplate ntt = ntm.createNodeTypeTemplate(ntm.getNodeType("nt:address")); assertEquals(ntt.getName(), ntd.getName()); assertEquals(ntt.isMixin(), ntd.isMixin()); assertEquals(ntt.isAbstract(), ntd.isAbstract()); assertEquals(ntt.hasOrderableChildNodes(), ntd.hasOrderableChildNodes()); assertEquals(ntt.isQueryable(), ntd.isQueryable()); assertEquals(ntt.getPrimaryItemName(), ntd.getPrimaryItemName()); assertTrue(Arrays.equals(ntt.getDeclaredSupertypeNames(), ntd.getDeclaredSupertypeNames())); NodeDefinition[] nda = ntt.getDeclaredChildNodeDefinitions(); NodeDefinition[] nda1 = ntd.getDeclaredChildNodeDefinitions(); assertEquals(nda.length, nda1.length); for (int i = 0; i < nda.length; i++) { assertEquals(nda[i].getName(), nda1[i].getName()); assertEquals(nda[i].allowsSameNameSiblings(), nda1[i].allowsSameNameSiblings()); assertTrue(Arrays.equals(nda[i].getRequiredPrimaryTypeNames(), nda1[i].getRequiredPrimaryTypeNames())); assertEquals(nda[i].getDefaultPrimaryTypeName(), nda1[i].getDefaultPrimaryTypeName()); assertEquals(nda[i].getRequiredPrimaryTypeNames(), nda1[i].getRequiredPrimaryTypeNames()); } PropertyDefinition[] pda = ntt.getDeclaredPropertyDefinitions(); PropertyDefinition[] pda1 = ntd.getDeclaredPropertyDefinitions(); assertEquals(pda.length, pda1.length); for (int i = 0; i < pda.length; i++) { assertEquals(pda[i].getName(), pda1[i].getName()); assertEquals(pda[i].getRequiredType(), pda1[i].getRequiredType()); assertTrue(Arrays.equals(pda[i].getAvailableQueryOperators(), pda1[i].getAvailableQueryOperators())); assertTrue(Arrays.equals(pda[i].getValueConstraints(), pda1[i].getValueConstraints())); assertEquals(pda[i].isFullTextSearchable(), pda1[i].isFullTextSearchable()); assertEquals(pda[i].isMultiple(), pda1[i].isMultiple()); assertEquals(pda[i].isQueryOrderable(), pda1[i].isQueryOrderable()); } }
21. CompactNodeTypeDefWriter#write()
Project: jackrabbit
File: CompactNodeTypeDefWriter.java
File: CompactNodeTypeDefWriter.java
/** * Writes the given list of QNodeTypeDefinition to the output writer * including the used namespaces. * * @param defs collection of definitions * @param nsMapping the mapping from prefix to namespace URI. * @param out output writer * @throws java.io.IOException if an I/O error occurs */ public static void write(Collection<NodeTypeDefinition> defs, NamespaceMapping nsMapping, Writer out) throws IOException { CompactNodeTypeDefWriter w = new CompactNodeTypeDefWriter(out, nsMapping, true); for (NodeTypeDefinition def : defs) { w.write(def); } w.close(); }
22. CompactNodeTypeDefWriter#write()
Project: jackrabbit
File: CompactNodeTypeDefWriter.java
File: CompactNodeTypeDefWriter.java
/** * Writes the given list of QNodeTypeDefinition to the output writer including the * used namespaces. * * @param defs collection of definitions * @param session session * @param out output writer * @throws java.io.IOException if an I/O error occurs */ public static void write(Collection<NodeTypeDefinition> defs, Session session, Writer out) throws IOException { CompactNodeTypeDefWriter w = new CompactNodeTypeDefWriter(out, session, true); for (NodeTypeDefinition def : defs) { w.write(def); } w.close(); }
23. NodeTypeManagerImpl#registerNodeTypes()
Project: jackrabbit
File: NodeTypeManagerImpl.java
File: NodeTypeManagerImpl.java
//--------------------------------------------------< new JSR 283 methods > /** * Registers or updates the specified <code>Collection</code> of * <code>NodeTypeDefinition</code> objects. This method is used to register * or update a set of node types with mutual dependencies. Returns an * iterator over the resulting <code>NodeType</code> objects. * <p> * The effect of the method is "all or nothing"; if an error occurs, no node * types are registered or updated. * <p> * Throws an <code>InvalidNodeTypeDefinitionException</code> if a * <code>NodeTypeDefinition</code> within the <code>Collection</code> is * invalid or if the <code>Collection</code> contains an object of a type * other than <code>NodeTypeDefinition</code>. * <p> * Throws a <code>NodeTypeExistsException</code> if <code>allowUpdate</code> * is <code>false</code> and a <code>NodeTypeDefinition</code> within the * <code>Collection</code> specifies a node type name that is already * registered. * <p> * Throws an <code>UnsupportedRepositoryOperationException</code> if this * implementation does not support node type registration. * * @param definitions a collection of <code>NodeTypeDefinition</code>s * @param allowUpdate a boolean * @return the registered node types. * @throws InvalidNodeTypeDefinitionException if a * <code>NodeTypeDefinition</code> within the <code>Collection</code> is * invalid or if the <code>Collection</code> contains an object of a type * other than <code>NodeTypeDefinition</code>. * @throws NodeTypeExistsException if <code>allowUpdate</code> is * <code>false</code> and a <code>NodeTypeDefinition</code> within the * <code>Collection</code> specifies a node type name that is already * registered. * @throws UnsupportedRepositoryOperationException if this implementation * does not support node type registration. * @throws RepositoryException if another error occurs. * @since JCR 2.0 */ public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] definitions, boolean allowUpdate) throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, RepositoryException { // make sure the editing session is allowed to register node types. context.getAccessManager().checkRepositoryPermission(Permission.NODE_TYPE_DEF_MNGMT); NodeTypeRegistry registry = context.getNodeTypeRegistry(); // split the node types into new and already registered node types. // this way we can register new node types together with already // registered node types which make circular dependencies possible List<QNodeTypeDefinition> addedDefs = new ArrayList<QNodeTypeDefinition>(); List<QNodeTypeDefinition> modifiedDefs = new ArrayList<QNodeTypeDefinition>(); for (NodeTypeDefinition definition : definitions) { // convert to QNodeTypeDefinition QNodeTypeDefinition def = toNodeTypeDef(definition); if (registry.isRegistered(def.getName())) { if (allowUpdate) { modifiedDefs.add(def); } else { throw new NodeTypeExistsException(definition.getName()); } } else { addedDefs.add(def); } } try { ArrayList<NodeType> result = new ArrayList<NodeType>(); // register new node types result.addAll(registerNodeTypes(addedDefs)); // re-register already existing node types for (QNodeTypeDefinition nodeTypeDef : modifiedDefs) { registry.reregisterNodeType(nodeTypeDef); result.add(getNodeType(nodeTypeDef.getName())); } return new NodeTypeIteratorAdapter(result); } catch (InvalidNodeTypeDefException e) { throw new InvalidNodeTypeDefinitionException(e.getMessage(), e); } }