use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanAddChildNodeCallWithNodeTypeTest method testDefinedAndLegalType.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
* returns true if <code>childNodeName</code> and <code>nodeTypeName</code>
* match the <code>NodeDef</code>.
*/
public void testDefinedAndLegalType() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
if (nodeDef == null) {
throw new NotExecutableException("No child node def with " + "defaultPrimaryType found");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String childNodeName = nodeDef.getName();
String nodeTypeName = nodeDef.getRequiredPrimaryTypes()[0].getName();
if (nodeTypeName.equals(ntBase)) {
// nt:base is abstract and can never be added, upgrade for check below
nodeTypeName = ntUnstructured;
}
assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return true if childNodeName and nodeTypeName match the " + "child node def of NodeType.", nodeType.canAddChildNode(childNodeName, nodeTypeName));
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanAddChildNodeCallWithNodeTypeTest method testCanAddMixinType.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
* returns false if <code>nodeTypeName</code> represents a mixin.
*/
public void testCanAddMixinType() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
if (nodeDef == null) {
throw new NotExecutableException("No testable node type found.");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String childNodeName = nodeDef.getName();
String mixinName;
NodeTypeIterator it = manager.getMixinNodeTypes();
if (it.hasNext()) {
mixinName = it.nextNodeType().getName();
} else {
throw new NotExecutableException("No mixin type found.");
}
assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if nodeTypeName represents a mixin type.", nodeType.canAddChildNode(childNodeName, mixinName));
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanAddChildNodeCallWithNodeTypeTest method testDefinedAndIllegalType.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
* returns false if <code>childNodeName</code> does and <code>nodeTypeName</code>
* does not match the <code>NodeDef</code>.
*/
public void testDefinedAndIllegalType() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
if (nodeDef == null) {
throw new NotExecutableException("No testable node type found.");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String childNodeName = nodeDef.getName();
String legalType = nodeDef.getRequiredPrimaryTypes()[0].getName();
String illegalType = NodeTypeUtil.getIllegalChildNodeType(manager, legalType);
if (illegalType == null) {
throw new NotExecutableException("No illegal node type name found");
}
assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if childNodeName does and nodeTypeName does not " + "match the child node def of NodeType.", nodeType.canAddChildNode(childNodeName, illegalType));
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class NodeTypeManagerImpl method registerNodeTypes.
/**
* @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);
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class NodeTypeManagerImpl method getPrimaryNodeTypes.
/**
* {@inheritDoc}
*/
public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException {
Name[] ntNames = ntReg.getRegisteredNodeTypes();
ArrayList<NodeType> list = new ArrayList<NodeType>(ntNames.length);
for (Name ntName : ntNames) {
NodeType nt = getNodeType(ntName);
if (!nt.isMixin()) {
list.add(nt);
}
}
return new NodeTypeIteratorAdapter(list);
}
Aggregations