Search in sources :

Example 51 with NodeTypeIterator

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;
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 52 with NodeTypeIterator

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"));
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 53 with NodeTypeIterator

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
}
Also used : NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 54 with NodeTypeIterator

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);
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 55 with NodeTypeIterator

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);
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Aggregations

NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)65 NodeType (javax.jcr.nodetype.NodeType)53 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)28 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)15 NodeDefinition (javax.jcr.nodetype.NodeDefinition)13 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Node (javax.jcr.Node)9 RepositoryException (javax.jcr.RepositoryException)9 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)8 ArrayList (java.util.ArrayList)6 Session (javax.jcr.Session)6 HashSet (java.util.HashSet)4 Value (javax.jcr.Value)3 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)3 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Property (javax.jcr.Property)2