Search in sources :

Example 11 with NoSuchNodeTypeException

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

the class NodeSetPrimaryTypeTest method testAddNonExisting.

/**
 * Tests if <code>Node.setPrimaryType(String)</code> throws a
 * <code>NoSuchNodeTypeException</code> if the
 * name of an existing node type is passed.
 */
public void testAddNonExisting() throws RepositoryException {
    Session session = testRootNode.getSession();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    String nonExistingMixinName = "abc";
    while (manager.hasNodeType(nonExistingMixinName)) {
        nonExistingMixinName += "_";
    }
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    try {
        node.setPrimaryType(nonExistingMixinName);
        // ev. only detected upon save
        superuser.save();
        fail("Node.setPrimaryType(String) must throw a NoSuchNodeTypeException if no nodetype exists with the given name.");
    } catch (NoSuchNodeTypeException e) {
    // success
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) Node(javax.jcr.Node) Session(javax.jcr.Session) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 12 with NoSuchNodeTypeException

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

the class AbstractWorkspaceSameNameSibsTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    // we assume sameNameSibs is supported by repository
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    // make sure 'sameNameSibsTrue' nodetype is properly defined
    try {
        sameNameSibsTrueNodeType = ntMgr.getNodeType(getProperty(PROP_SAME_NAME_SIBS_TRUE_NODE_TYPE));
        NodeDefinition[] childNodeDefs = sameNameSibsTrueNodeType.getDeclaredChildNodeDefinitions();
        boolean isSameNameSibs = false;
        for (int i = 0; i < childNodeDefs.length; i++) {
            if (childNodeDefs[i].allowsSameNameSiblings()) {
                isSameNameSibs = true;
                break;
            }
        }
        if (!isSameNameSibs) {
            throw new NotExecutableException("Property 'sameNameSibsTrueNodeType' does not define a nodetype where sameNameSibs are allowed: '" + sameNameSibsTrueNodeType.getName() + "'");
        }
    } catch (NoSuchNodeTypeException e) {
        fail("Property 'sameNameSibsTrueNodeType' does not define an existing nodetype: '" + sameNameSibsTrueNodeType + "'");
    }
    // make sure 'sameNameSibsFalse' nodetype is properly defined
    try {
        sameNameSibsFalseNodeType = ntMgr.getNodeType(getProperty(PROP_SAME_NAME_SIBS_FALSE_NODE_TYPE));
        NodeDefinition[] childNodeDefs = sameNameSibsFalseNodeType.getDeclaredChildNodeDefinitions();
        boolean isSameNameSibs = true;
        for (int i = 0; i < childNodeDefs.length; i++) {
            if (!childNodeDefs[i].allowsSameNameSiblings()) {
                isSameNameSibs = false;
                break;
            }
        }
        if (isSameNameSibs) {
            fail("Property 'sameNameSibsFalseNodeType' does define a nodetype where sameNameSibs are not allowed: '" + sameNameSibsFalseNodeType.getName() + "'");
        }
    } catch (NoSuchNodeTypeException e) {
        fail("Property 'sameNameSibsFalseNodeType' does not define an existing nodetype: '" + sameNameSibsFalseNodeType + "'");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 13 with NoSuchNodeTypeException

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

the class NodeCanAddMixinTest method testNonExisting.

/**
 * Tests if <code>Node.canAddMixin(String mixinName)</code> throws a
 * <code>NoSuchNodeTypeException</code> if <code>mixinName</code> is not the
 * name of an existing mixin node type
 */
public void testNonExisting() throws RepositoryException {
    Session session = testRootNode.getSession();
    String nonExistingMixinName = NodeMixinUtil.getNonExistingMixinName(session);
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    try {
        node.canAddMixin(nonExistingMixinName);
        fail("Node.canAddMixin(String mixinName) must throw a " + "NoSuchNodeTypeException if mixinName is an unknown mixin type");
    } catch (NoSuchNodeTypeException e) {
    // success
    }
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 14 with NoSuchNodeTypeException

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

the class NodeTypeImpl method getInheritedSupertypes.

/**
 * Returns all <i>inherited</i> supertypes of this node type.
 *
 * @return an array of <code>NodeType</code> objects.
 * @see #getSupertypes
 * @see #getDeclaredSupertypes
 */
public NodeType[] getInheritedSupertypes() {
    // declared supertypes
    Name[] ntNames = ntd.getSupertypes();
    Set<Name> declared = new HashSet<Name>();
    for (Name ntName : ntNames) {
        declared.add(ntName);
    }
    // all supertypes
    ntNames = ent.getInheritedNodeTypes();
    // filter from all supertypes those that are not declared
    List<NodeType> inherited = new ArrayList<NodeType>();
    for (Name ntName : ntNames) {
        if (!declared.contains(ntName)) {
            try {
                inherited.add(ntMgr.getNodeType(ntName));
            } catch (NoSuchNodeTypeException e) {
                // should never get here
                log.error("undefined supertype", e);
                return new NodeType[0];
            }
        }
    }
    return inherited.toArray(new NodeType[inherited.size()]);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) AbstractNodeType(org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeType) ArrayList(java.util.ArrayList) Name(org.apache.jackrabbit.spi.Name) HashSet(java.util.HashSet) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 15 with NoSuchNodeTypeException

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

the class NodeTypeRegistry method reregisterNodeType.

/**
 * Internal implementation of {@link #reregisterNodeType(QNodeTypeDefinition)}.
 *
 * @param ntd node type definition
 * @param external whether this invocation should be considered external
 * @return the new effective node type
 * @throws NoSuchNodeTypeException if <code>ntd</code> refers to an
 *                                 unknown node type
 * @throws InvalidNodeTypeDefException if the node type definition
 *                                     is invalid
 * @throws RepositoryException if another error occurs
 */
private EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd, boolean external) throws NoSuchNodeTypeException, InvalidNodeTypeDefException, RepositoryException {
    EffectiveNodeType entNew;
    synchronized (this) {
        Name name = ntd.getName();
        if (!registeredNTDefs.containsKey(name)) {
            throw new NoSuchNodeTypeException(name.toString());
        }
        if (builtInNTDefs.contains(name)) {
            throw new RepositoryException(name.toString() + ": can't reregister built-in node type.");
        }
        /**
         * validate new node type definition
         */
        ntd = checkNtBaseSubtyping(ntd, registeredNTDefs);
        validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
        /**
         * build diff of current and new definition and determine type of change
         */
        QNodeTypeDefinition ntdOld = registeredNTDefs.get(name);
        NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
        if (!diff.isModified()) {
            // the definition has not been modified, there's nothing to do here...
            return getEffectiveNodeType(name);
        }
        // make sure existing content would not conflict
        // with new node type definition
        checkForConflictingContent(ntd, diff);
        /**
         * re-register node type definition and update caches &
         * notify listeners on re-registration
         */
        internalUnregister(name);
        // remove old node type definition from store
        customNTDefs.remove(name);
        entNew = internalRegister(ntd);
        // add new node type definition to store
        customNTDefs.add(ntd);
        // persist node type definitions
        persistCustomNodeTypeDefs(customNTDefs);
        // notify listeners
        notifyReRegistered(name);
    }
    // inform cluster if this is not an external invocation
    if (!external && eventChannel != null) {
        eventChannel.reregistered(ntd);
    }
    return entNew;
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException) NodeTypeDefDiff(org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefDiff)

Aggregations

NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)47 Name (org.apache.jackrabbit.spi.Name)16 NodeType (javax.jcr.nodetype.NodeType)15 RepositoryException (javax.jcr.RepositoryException)11 Node (javax.jcr.Node)10 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)9 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 Session (javax.jcr.Session)7 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)7 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)7 HashSet (java.util.HashSet)5 Tree (org.apache.jackrabbit.oak.api.Tree)4 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)4 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)4 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)3 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)3 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)3 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 Stack (java.util.Stack)2