Search in sources :

Example 41 with NodeType

use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.

the class CanAddChildNodeCallWithNodeTypeTest method testDefinedAndLegalType.

/**
     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
     * returns true if <code>childNodeName</code> and <code>nodeTypeName</code>
     * match the <code>NodeDef</code>.
     */
public void testDefinedAndLegalType() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
    if (nodeDef == null) {
        throw new NotExecutableException("No child node def with " + "defaultPrimaryType found");
    }
    NodeType nodeType = nodeDef.getDeclaringNodeType();
    String childNodeName = nodeDef.getName();
    String nodeTypeName = nodeDef.getRequiredPrimaryTypes()[0].getName();
    if (nodeTypeName.equals(ntBase)) {
        // nt:base is abstract and can never be added, upgrade for check below
        nodeTypeName = ntUnstructured;
    }
    assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return true if childNodeName and nodeTypeName match the " + "child node def of NodeType.", nodeType.canAddChildNode(childNodeName, nodeTypeName));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 42 with NodeType

use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.

the class CanAddChildNodeCallWithNodeTypeTest method testCanAddMixinType.

/**
     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
     * returns false if <code>nodeTypeName</code> represents a mixin.
     */
public void testCanAddMixinType() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
    if (nodeDef == null) {
        throw new NotExecutableException("No testable node type found.");
    }
    NodeType nodeType = nodeDef.getDeclaringNodeType();
    String childNodeName = nodeDef.getName();
    String mixinName;
    NodeTypeIterator it = manager.getMixinNodeTypes();
    if (it.hasNext()) {
        mixinName = it.nextNodeType().getName();
    } else {
        throw new NotExecutableException("No mixin type found.");
    }
    assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if nodeTypeName represents a mixin type.", nodeType.canAddChildNode(childNodeName, mixinName));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 43 with NodeType

use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.

the class CanAddChildNodeCallWithNodeTypeTest method testDefinedAndIllegalType.

/**
     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
     * returns false if <code>childNodeName</code> does and <code>nodeTypeName</code>
     * does not match the <code>NodeDef</code>.
     */
public void testDefinedAndIllegalType() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
    if (nodeDef == null) {
        throw new NotExecutableException("No testable node type found.");
    }
    NodeType nodeType = nodeDef.getDeclaringNodeType();
    String childNodeName = nodeDef.getName();
    String legalType = nodeDef.getRequiredPrimaryTypes()[0].getName();
    String illegalType = NodeTypeUtil.getIllegalChildNodeType(manager, legalType);
    if (illegalType == null) {
        throw new NotExecutableException("No illegal node type name found");
    }
    assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if childNodeName does and nodeTypeName does not " + "match the child node def of NodeType.", nodeType.canAddChildNode(childNodeName, illegalType));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 44 with NodeType

use of javax.jcr.nodetype.NodeType 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 45 with NodeType

use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.

the class NodeTypeManagerImpl method getPrimaryNodeTypes.

/**
     * {@inheritDoc}
     */
public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException {
    Name[] ntNames = ntReg.getRegisteredNodeTypes();
    ArrayList<NodeType> list = new ArrayList<NodeType>(ntNames.length);
    for (Name ntName : ntNames) {
        NodeType nt = getNodeType(ntName);
        if (!nt.isMixin()) {
            list.add(nt);
        }
    }
    return new NodeTypeIteratorAdapter(list);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter) Name(org.apache.jackrabbit.spi.Name)

Aggregations

NodeType (javax.jcr.nodetype.NodeType)258 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)84 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)79 Value (javax.jcr.Value)57 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)53 Node (javax.jcr.Node)52 NodeDefinition (javax.jcr.nodetype.NodeDefinition)44 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)41 RepositoryException (javax.jcr.RepositoryException)33 ArrayList (java.util.ArrayList)29 Test (org.junit.Test)27 Session (javax.jcr.Session)20 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)16 Name (org.apache.jackrabbit.spi.Name)15 HashSet (java.util.HashSet)14 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)13 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)11 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)6 InputStreamReader (java.io.InputStreamReader)5 NodeIterator (javax.jcr.NodeIterator)5