Search in sources :

Example 16 with NodeTypeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter in project jackrabbit by apache.

the class AbstractNodeType method getSubtypes.

//--------------------------------------------------------------------------
/**
     * Returns the node types derived from this node type.
     *
     * @param directOnly if <code>true</code> only direct subtypes will be considered
     *
     * @return an <code>NodeTypeIterator</code>.
     * @see NodeType#getSubtypes
     * @see NodeType#getDeclaredSubtypes
     */
public NodeTypeIterator getSubtypes(boolean directOnly) {
    NodeTypeIterator iter;
    try {
        iter = ntMgr.getAllNodeTypes();
    } catch (RepositoryException e) {
        // should never get here
        log.error("failed to retrieve registered node types", e);
        return NodeTypeIteratorAdapter.EMPTY;
    }
    ArrayList<NodeType> result = new ArrayList<NodeType>();
    String thisName = getName();
    while (iter.hasNext()) {
        NodeType nt = iter.nextNodeType();
        if (!nt.getName().equals(thisName)) {
            if (directOnly) {
                // direct subtypes only
                for (String name : nt.getDeclaredSupertypeNames()) {
                    if (name.equals(thisName)) {
                        result.add(nt);
                        break;
                    }
                }
            } else {
                // direct and indirect subtypes
                if (nt.isNodeType(thisName)) {
                    result.add(nt);
                }
            }
        }
    }
    return new NodeTypeIteratorAdapter(result);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) RepositoryException(javax.jcr.RepositoryException) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)

Aggregations

NodeType (javax.jcr.nodetype.NodeType)16 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)16 ArrayList (java.util.ArrayList)11 Name (org.apache.jackrabbit.spi.Name)6 Tree (org.apache.jackrabbit.oak.api.Tree)4 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)3 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)3 NodeTypeExistsException (javax.jcr.nodetype.NodeTypeExistsException)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)2 Set (java.util.Set)1 RepositoryException (javax.jcr.RepositoryException)1 InvalidNodeTypeDefinitionException (javax.jcr.nodetype.InvalidNodeTypeDefinitionException)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 Root (org.apache.jackrabbit.oak.api.Root)1 NamePathMapper (org.apache.jackrabbit.oak.namepath.NamePathMapper)1 QNodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)1 DavException (org.apache.jackrabbit.webdav.DavException)1 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)1