Search in sources :

Example 41 with QNodeTypeDefinition

use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.

the class NodeTypeImpl method canAddChildNode.

/**
     * @see javax.jcr.nodetype.NodeType#canAddChildNode(String, String)
     */
public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
    try {
        Name ntName = resolver().getQName(nodeTypeName);
        QNodeTypeDefinition def = ntMgr.getNodeTypeDefinition(ntName);
        ent.checkAddNodeConstraints(resolver().getQName(childNodeName), def, definitionProvider());
        return true;
    } catch (NameException be) {
    // implementation specific exception, fall through
    } catch (RepositoryException re) {
    // fall through
    }
    return false;
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 42 with QNodeTypeDefinition

use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.

the class WorkspaceManager method createNodeTypeRegistry.

/**
     * @param nsRegistry The namespace registry.
     * @return an instance of <code>NodeTypeRegistryImpl</code>.
     */
private NodeTypeRegistryImpl createNodeTypeRegistry(NamespaceRegistry nsRegistry) {
    NodeTypeStorage ntst = new NodeTypeStorage() {

        public Iterator<QNodeTypeDefinition> getAllDefinitions() throws RepositoryException {
            return service.getQNodeTypeDefinitions(sessionInfo);
        }

        public Iterator<QNodeTypeDefinition> getDefinitions(Name[] nodeTypeNames) throws NoSuchNodeTypeException, RepositoryException {
            return service.getQNodeTypeDefinitions(sessionInfo, nodeTypeNames);
        }

        public void registerNodeTypes(QNodeTypeDefinition[] nodeTypeDefs, boolean allowUpdate) throws RepositoryException {
            service.registerNodeTypes(sessionInfo, nodeTypeDefs, allowUpdate);
        }

        public void unregisterNodeTypes(Name[] nodeTypeNames) throws NoSuchNodeTypeException, RepositoryException {
            service.unregisterNodeTypes(sessionInfo, nodeTypeNames);
        }
    };
    NodeTypeCache ntCache = NodeTypeCache.getInstance(service, sessionInfo.getUserID());
    ntst = ntCache.wrap(ntst);
    return NodeTypeRegistryImpl.create(ntst, nsRegistry);
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeCache(org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeCache) NodeTypeStorage(org.apache.jackrabbit.spi.commons.nodetype.NodeTypeStorage)

Example 43 with QNodeTypeDefinition

use of org.apache.jackrabbit.spi.QNodeTypeDefinition 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)

Example 44 with QNodeTypeDefinition

use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.

the class ClusterRecordTest method testNodeTypeRegistration.

/**
     * Test producing and consuming a node type registration.
     * @throws Exception
     */
public void testNodeTypeRegistration() throws Exception {
    QNodeTypeDefinitionBuilder ntd = new QNodeTypeDefinitionBuilder();
    ntd.setName(NameFactoryImpl.getInstance().create("", "test"));
    ntd.setSupertypes(new Name[] { NameConstants.NT_BASE });
    ArrayList<QNodeTypeDefinition> list = new ArrayList<QNodeTypeDefinition>();
    list.add(ntd.build());
    NodeTypeEvent event = new NodeTypeEvent(NodeTypeEvent.REGISTER, list);
    master.registered(event.getCollection());
    SimpleEventListener listener = new SimpleEventListener();
    slave.setListener((NodeTypeEventListener) listener);
    slave.sync();
    assertEquals(1, listener.getClusterEvents().size());
    assertEquals(listener.getClusterEvents().get(0), event);
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeEvent(org.apache.jackrabbit.core.cluster.SimpleEventListener.NodeTypeEvent) ArrayList(java.util.ArrayList) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)

Example 45 with QNodeTypeDefinition

use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.

the class CyclicNodeTypeRegistrationTest method testRegisterSimpleMissingNodeTypes.

/**
     * A simple check, if a missing node type is found
     */
public void testRegisterSimpleMissingNodeTypes() {
    /**
         * Constructs node types with the following structure:
         * [foo]
         * + myNTInFoo (I_am_an_invalid_required_primary_type)
         *
         */
    final QNodeTypeDefinitionBuilder foo = new QNodeTypeDefinitionBuilder();
    foo.setName(nameFactory.create("", "foo"));
    foo.setSupertypes(new Name[] { NameConstants.NT_BASE });
    QNodeDefinitionBuilder myBarInFoo = new QNodeDefinitionBuilder();
    myBarInFoo.setRequiredPrimaryTypes(new Name[] { nameFactory.create("", "I_am_an_invalid_required_primary_type") });
    myBarInFoo.setName(nameFactory.create("", "myNTInFoo"));
    myBarInFoo.setDeclaringNodeType(foo.getName());
    foo.setChildNodeDefs(new QNodeDefinition[] { myBarInFoo.build() });
    ntDefCollection = new LinkedList<QNodeTypeDefinition>();
    ntDefCollection.add(foo.build());
    try {
        ntreg.registerNodeTypes(ntDefCollection);
        assertFalse("Missing node type not found", true);
    } catch (InvalidNodeTypeDefException e) {
        assertTrue(true);
    } catch (RepositoryException e) {
        assertFalse("Wrong Exception thrown on missing node type.", true);
        e.printStackTrace();
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QNodeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder) RepositoryException(javax.jcr.RepositoryException) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)

Aggregations

QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)57 Name (org.apache.jackrabbit.spi.Name)21 ArrayList (java.util.ArrayList)13 RepositoryException (javax.jcr.RepositoryException)11 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)9 NodeType (javax.jcr.nodetype.NodeType)6 QNodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)6 HashMap (java.util.HashMap)5 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)5 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)4 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)4 InvalidNodeTypeDefException (org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException)4 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4 QNodeTypeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)4 CompactNodeTypeDefReader (org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader)3 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)3 NamespaceMapping (org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping)3 QDefinitionBuilderFactory (org.apache.jackrabbit.spi.commons.nodetype.QDefinitionBuilderFactory)3 QNodeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder)3