Search in sources :

Example 1 with QNodeTypeDefinitionImpl

use of org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl 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);
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeExistsException(javax.jcr.nodetype.NodeTypeExistsException) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Example 2 with QNodeTypeDefinitionImpl

use of org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl in project jackrabbit by apache.

the class RepositoryServiceImpl method getQNodeTypeDefinitions.

/**
     * {@inheritDoc}
     */
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
    List<QNodeTypeDefinition> nodeTypes = new ArrayList<QNodeTypeDefinition>();
    try {
        for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) {
            NodeType nt = it.nextNodeType();
            nodeTypes.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
        }
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
    return nodeTypes.iterator();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) RepositoryException(javax.jcr.RepositoryException) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Example 3 with QNodeTypeDefinitionImpl

use of org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl in project jackrabbit by apache.

the class NodeTypeRegistry method checkNtBaseSubtyping.

/**
     * Checks if the given node type def has the correct supertypes in respect
     * to nt:base. all mixin nodetypes must not have a nt:base, the primary
     * ones only if they don't inherit it from another supertype.
     *
     * @param ntd the node type def to check
     * @param ntdCache cache for lookup
     * @return the node type definition that was given to check or a new
     *          instance if it had to be fixed up.
     */
private static QNodeTypeDefinition checkNtBaseSubtyping(QNodeTypeDefinition ntd, Map<Name, QNodeTypeDefinition> ntdCache) {
    if (NameConstants.NT_BASE.equals(ntd.getName())) {
        return ntd;
    }
    Set<Name> supertypes = new TreeSet<Name>(Arrays.asList(ntd.getSupertypes()));
    if (supertypes.isEmpty()) {
        return ntd;
    }
    boolean modified;
    if (ntd.isMixin()) {
        // if mixin, remove possible nt:base supertype
        modified = supertypes.remove(NameConstants.NT_BASE);
    } else {
        // check if all supertypes (except nt:base) are mixins
        boolean allMixins = true;
        for (Name name : supertypes) {
            if (!name.equals(NameConstants.NT_BASE)) {
                QNodeTypeDefinition def = ntdCache.get(name);
                if (def != null && !def.isMixin()) {
                    allMixins = false;
                    break;
                }
            }
        }
        if (allMixins) {
            // ntd is a primary node type and has only mixins as supertypes,
            // so it needs a nt:base
            modified = supertypes.add(NameConstants.NT_BASE);
        } else {
            // ntd is a primary node type and at least one of the supertypes
            // is too, so ensure that no nt:base is added. note that the
            // trivial case, where there would be no supertype left is handled
            // in the QNodeTypeDefinition directly
            modified = supertypes.remove(NameConstants.NT_BASE);
        }
    }
    if (modified) {
        ntd = new QNodeTypeDefinitionImpl(ntd.getName(), supertypes.toArray(new Name[supertypes.size()]), ntd.getSupportedMixinTypes(), ntd.isMixin(), ntd.isAbstract(), ntd.isQueryable(), ntd.hasOrderableChildNodes(), ntd.getPrimaryItemName(), ntd.getPropertyDefs(), ntd.getChildNodeDefs());
    }
    return ntd;
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) TreeSet(java.util.TreeSet) Name(org.apache.jackrabbit.spi.Name) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Example 4 with QNodeTypeDefinitionImpl

use of org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl in project jackrabbit by apache.

the class LostFromCacheIssueTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    Workspace workspace = superuser.getWorkspace();
    NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
    NodeTypeManager ntmgr = workspace.getNodeTypeManager();
    NodeTypeRegistry nodetypeRegistry = ((NodeTypeManagerImpl) ntmgr).getNodeTypeRegistry();
    try {
        namespaceRegistry.registerNamespace(NAMESPACE_PREFIX, NAMESPACE_URI);
    } catch (NamespaceException ignore) {
    //already exists
    }
    QNodeTypeDefinition nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_1), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
    try {
        nodetypeRegistry.registerNodeType(nodeTypeDefinition);
    } catch (InvalidNodeTypeDefException ignore) {
    //already exists
    }
    nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_2), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
    try {
        nodetypeRegistry.registerNodeType(nodeTypeDefinition);
    } catch (InvalidNodeTypeDefException ignore) {
    //already exists
    }
    getOrCreate(superuser.getRootNode(), TESTNODE_PATH);
    superuser.save();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NamespaceRegistry(javax.jcr.NamespaceRegistry) NamespaceException(javax.jcr.NamespaceException) NodeTypeRegistry(org.apache.jackrabbit.core.nodetype.NodeTypeRegistry) NodeTypeManagerImpl(org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl) Workspace(javax.jcr.Workspace) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Example 5 with QNodeTypeDefinitionImpl

use of org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl in project jackrabbit by apache.

the class RepositoryServiceImpl method getQNodeTypeDefinitions.

/**
     * {@inheritDoc}
     */
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames) throws RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
    List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
    for (Name nodetypeName : nodetypeNames) {
        try {
            String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
            NodeType nt = ntMgr.getNodeType(ntName);
            defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
            // in addition pack all supertypes into the return value
            NodeType[] supertypes = nt.getSupertypes();
            for (NodeType supertype : supertypes) {
                defs.add(new QNodeTypeDefinitionImpl(supertype, sInfo.getNamePathResolver(), getQValueFactory()));
            }
        } catch (NameException e) {
            throw new RepositoryException(e);
        }
    }
    return defs.iterator();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Aggregations

QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)5 QNodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)5 ArrayList (java.util.ArrayList)3 NodeType (javax.jcr.nodetype.NodeType)3 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)3 RepositoryException (javax.jcr.RepositoryException)2 Name (org.apache.jackrabbit.spi.Name)2 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)2 TreeSet (java.util.TreeSet)1 NamespaceException (javax.jcr.NamespaceException)1 NamespaceRegistry (javax.jcr.NamespaceRegistry)1 Workspace (javax.jcr.Workspace)1 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)1 NodeTypeExistsException (javax.jcr.nodetype.NodeTypeExistsException)1 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)1 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)1 InvalidNodeTypeDefException (org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException)1 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)1 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)1