use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit-oak by apache.
the class NodeTypeUtils method createNodeDefTemplate.
/**
* Creates the node definition template.
*
* @param ntm the ntm
* @param types the types
* @return the node definition template
* @throws RepositoryException the repository exception
*/
private static NodeDefinitionTemplate createNodeDefTemplate(NodeTypeManager ntm, String[] types) throws RepositoryException {
NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
ndt.setOnParentVersion(OnParentVersionAction.IGNORE);
ndt.setRequiredPrimaryTypeNames(types);
ndt.setDefaultPrimaryTypeName(types[0]);
ndt.setName("*");
return ndt;
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit-oak by apache.
the class OpvAbortTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
vMgr = superuser.getWorkspace().getVersionManager();
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeDefinitionTemplate def = ntMgr.createNodeDefinitionTemplate();
def.setOnParentVersion(OnParentVersionAction.ABORT);
def.setName("child");
def.setRequiredPrimaryTypeNames(new String[] { NT_BASE });
NodeTypeTemplate tmpl = ntMgr.createNodeTypeTemplate();
tmpl.setName("OpvAbortTest");
tmpl.setMixin(true);
tmpl.getNodeDefinitionTemplates().add(def);
ntMgr.registerNodeType(tmpl, true);
testRootNode.addMixin(MIX_VERSIONABLE);
superuser.save();
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit-oak by apache.
the class RepositoryUpgrade method createNodeDefinitionTemplate.
private NodeDefinitionTemplate createNodeDefinitionTemplate(NodeTypeManager ntMgr, QNodeDefinition def) throws RepositoryException {
NodeDefinitionTemplate tmpl = ntMgr.createNodeDefinitionTemplate();
Name name = def.getName();
if (name != null) {
tmpl.setName(getOakName(name));
}
tmpl.setAutoCreated(def.isAutoCreated());
tmpl.setMandatory(def.isMandatory());
tmpl.setOnParentVersion(def.getOnParentVersion());
tmpl.setProtected(def.isProtected());
tmpl.setSameNameSiblings(def.allowsSameNameSiblings());
List<String> names = newArrayListWithCapacity(def.getRequiredPrimaryTypes().length);
for (Name type : def.getRequiredPrimaryTypes()) {
names.add(getOakName(type));
}
tmpl.setRequiredPrimaryTypeNames(names.toArray(new String[names.size()]));
Name type = def.getDefaultPrimaryType();
if (type != null) {
tmpl.setDefaultPrimaryTypeName(getOakName(type));
}
return tmpl;
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class NodeTypeCreationTest method testNewNodeTypeTemplate.
public void testNewNodeTypeTemplate() throws Exception {
String expandedName = "{" + NS_MIX_URI + "}" + "littlemixin";
String jcrName = superuser.getNamespacePrefix(NS_MIX_URI) + ":littlemixin";
NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
ntt.setName(expandedName);
assertEquals(jcrName, ntt.getName());
ntt.setName(jcrName);
assertEquals(jcrName, ntt.getName());
ntt.setAbstract(false);
assertFalse(ntt.isAbstract());
try {
ntt.setDeclaredSuperTypeNames(null);
fail("null isn't a valid array of jcr name");
} catch (ConstraintViolationException e) {
// success
}
assertNotNull(ntt.getDeclaredSupertypeNames());
assertEquals(0, ntt.getDeclaredSupertypeNames().length);
ntt.setDeclaredSuperTypeNames(new String[] { mixReferenceable });
assertNotNull(ntt.getDeclaredSupertypeNames());
assertEquals(1, ntt.getDeclaredSupertypeNames().length);
assertEquals(mixReferenceable, ntt.getDeclaredSupertypeNames()[0]);
ntt.setMixin(true);
assertTrue(ntt.isMixin());
ntt.setOrderableChildNodes(true);
assertTrue(ntt.hasOrderableChildNodes());
ntt.setQueryable(false);
assertFalse(ntt.isQueryable());
ntt.setPrimaryItemName(null);
assertNull(ntt.getPrimaryItemName());
ntt.setPrimaryItemName(jcrPrimaryType);
assertEquals(jcrPrimaryType, ntt.getPrimaryItemName());
PropertyDefinitionTemplate pdTemplate = createBooleanPropTemplate();
List pdefs = ntt.getPropertyDefinitionTemplates();
pdefs.add(pdTemplate);
assertNotNull(ntt.getDeclaredPropertyDefinitions());
assertEquals(1, ntt.getDeclaredPropertyDefinitions().length);
assertEquals(pdTemplate, ntt.getDeclaredPropertyDefinitions()[0]);
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());
assertEquals(1, ntt.getDeclaredChildNodeDefinitions().length);
assertEquals(ndTemplate, ntt.getDeclaredChildNodeDefinitions()[0]);
ndefs = ntt.getNodeDefinitionTemplates();
assertEquals(1, ndefs.size());
assertEquals(ndTemplate, ndefs.get(0));
}
use of javax.jcr.nodetype.NodeDefinitionTemplate in project jackrabbit by apache.
the class NodeTypeCreationTest method testResidualNames.
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());
}
Aggregations