use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeTypeUtil method getIllegalChildNodeType.
/**
* Returns a node type that is nor legalType nor a sub type of of
*/
public static String getIllegalChildNodeType(NodeTypeManager manager, String legalType) throws RepositoryException {
NodeTypeIterator types = manager.getAllNodeTypes();
while (types.hasNext()) {
NodeType type = types.nextNodeType();
if (!type.getName().equals(legalType)) {
NodeType[] superTypes = type.getSupertypes();
boolean isSubType = false;
for (int i = 0; i < superTypes.length; i++) {
String name = superTypes[i].getName();
if (name.equals(legalType)) {
isSubType = true;
break;
}
}
if (!isSubType) {
return type.getName();
}
}
}
return null;
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class PredefinedNodeTypeTest method testIfPrimaryNodeTypesAreSubtypesOfNTBase.
/**
* Tests if all primary node types are subtypes of node type <code>nt:base</code>
*/
public void testIfPrimaryNodeTypesAreSubtypesOfNTBase() throws RepositoryException {
NodeTypeIterator types = manager.getPrimaryNodeTypes();
while (types.hasNext()) {
NodeType type = types.nextNodeType();
assertTrue("Primary node type " + type.getName() + " must inherit nt:base", type.isNodeType("nt:base"));
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeTypeTest method testIsMixin.
/**
* Test if isMixin() returns false if applied on a primary node type and true
* on a mixin node type.
*/
public void testIsMixin() throws RepositoryException {
NodeTypeIterator primaryTypes = manager.getPrimaryNodeTypes();
assertFalse("testIsMixin() must return false if applied on a " + "primary node type", primaryTypes.nextNodeType().isMixin());
// if a mixin node type exist, test if isMixin() returns true
NodeTypeIterator mixinTypes = manager.getMixinNodeTypes();
if (getSize(mixinTypes) > 0) {
// need to re-aquire iterator {@link #getSize} may consume iterator
mixinTypes = manager.getMixinNodeTypes();
assertTrue("testIsMixin() must return true if applied on a " + "mixin node type", mixinTypes.nextNodeType().isMixin());
}
// else skip the test for mixin node types
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeDefTest method testGetDeclaringNodeType.
/**
* Test getDeclaringNodeType() returns the node type which is defining the
* requested child node def. Test runs for all existing node types.
*/
public void testGetDeclaringNodeType() throws RepositoryException {
NodeTypeIterator types = manager.getAllNodeTypes();
// loop all node types
while (types.hasNext()) {
NodeType currentType = types.nextNodeType();
NodeDefinition[] defsOfCurrentType = currentType.getChildNodeDefinitions();
// loop all child node defs of each node type
for (int i = 0; i < defsOfCurrentType.length; i++) {
NodeDefinition def = defsOfCurrentType[i];
NodeType type = def.getDeclaringNodeType();
// check if def is part of the child node defs of the
// declaring node type
NodeDefinition[] defs = type.getChildNodeDefinitions();
boolean hasType = false;
for (int j = 0; j < defs.length; j++) {
if (defs[j].getName().equals(def.getName())) {
hasType = true;
break;
}
}
assertTrue("getDeclaringNodeType() must return the node " + "which defines the corresponding child node def.", hasType);
}
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeDefTest method testGetRequiredPrimaryTypes.
/**
* Tests if getRequiredPrimaryTypes() does not return an empty array. Test
* runs for all existing node types.
*/
public void testGetRequiredPrimaryTypes() throws RepositoryException {
// loop all node types
for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
NodeType type = types.nextNodeType();
NodeDefinition[] defs = type.getChildNodeDefinitions();
for (int i = 0; i < defs.length; i++) {
assertTrue("getRequiredPrimaryTypes() must never return an " + "empty array.", defs[i].getRequiredPrimaryTypes().length > 0);
}
}
}
Aggregations