Package org.modeshape.jcr.NodeTypes

Examples of org.modeshape.jcr.NodeTypes.NodeDefinitionSet


                    // There is at least one persisted child with the same name, and we're adding a new child
                    // or renaming an existing child to this name. Therefore, we have to find a child node definition
                    // that allows SNS. Look for one ignoring the child node type (this is faster than finding the
                    // child node primary types) ...
                    NodeDefinitionSet childDefns = nodeTypeCapabilities.findChildNodeDefinitions(primaryType, mixinTypes);
                    JcrNodeDefinition childNodeDefinition = childDefns.findBestDefinitionForChild(childName, null, true,
                                                                                                  siblingCounter);
                    if (childNodeDefinition != null) {
                        // found the one child node definition that applies, so it's okay ...
                        continue;
                    }

                    // We were NOT able to find a definition that allows SNS for this name, but we need to make sure that
                    // the node that already exists (persisted) isn't the one that's being changed
                    NodeKey persistedChildKey = persistedChildReferences.getChild(childName).getKey();
                    if (appendedChildren.containsKey(persistedChildKey) || renamedChildren.containsKey(persistedChildKey)) {
                        // The persisted node is being changed, so it's okay ...
                        continue;
                    }

                    // We still were NOT able to find a definition that allows SNS for this name WITHOUT considering the
                    // specific child node type. This likely means there is either 0 or more than 1 (possibly residual)
                    // child node definitions. We need to find all of the added/renamed child nodes and use their specific
                    // primary types. The first to fail will result in an exception ...
                    final SessionCache session = cache();
                    for (NodeKey appendedOrRenamedKey : appendedOrRenamedChildrenByName.get(childName)) {
                        MutableCachedNode appendedOrRenamedChild = session.mutable(appendedOrRenamedKey);
                        if (appendedOrRenamedChild == null) continue;
                        Name childPrimaryType = appendedOrRenamedChild.getPrimaryType(session);
                        childDefns = nodeTypeCapabilities.findChildNodeDefinitions(primaryType, mixinTypes);
                        childNodeDefinition = childDefns.findBestDefinitionForChild(childName, childPrimaryType, true,
                                                                                    siblingCounter);
                        if (childNodeDefinition == null) {
                            // Could not find a valid child node definition that allows SNS given the child's primary type and
                            // name plus the parent's primary type and mixin types.
                            throw new ItemExistsException(JcrI18n.noSnsDefinitionForNode.text(childName, workspaceName()));
View Full Code Here


                I18n msg = JcrI18n.primaryTypeCannotBeAbstract;
                throw new ConstraintViolationException(msg.text(primaryType.getName()));
            }
        }

        NodeDefinitionSet childDefns = nodeTypes.findChildNodeDefinitions(primaryTypeName, mixins);
        JcrNodeDefinition childDefn = childDefns.findBestDefinitionForChild(childName, childPrimaryNodeTypeName, skipProtected,
                                                                            siblingCounter);
        if (childDefn == null) {
            // Failed to find an appropriate child node definition. Throw an exception with the appropriate message...
            String repoName = session.repository().repositoryName();
            String workspaceName = workspaceName();
            childDefns.determineReasonForMismatch(childName, childPrimaryNodeTypeName, skipProtected, siblingCounter,
                                                  primaryTypeName, mixins, path(), workspaceName, repoName, context());
        }
        assert childDefn != null;

        if (childPrimaryNodeTypeName == null && childDefn.getDefaultPrimaryType() == null) {
View Full Code Here

        Name primaryType = parent.getPrimaryType(cache);
        Set<Name> mixins = parent.getMixinTypes(cache);
        // The node is already a child, so create a counter that returns the count as if it were not a child ...
        SiblingCounter siblingCounter = SiblingCounter.alter(SiblingCounter.create(parent, cache), -1);
        boolean skipProtected = true;
        NodeDefinitionSet childDefns = nodeTypes.findChildNodeDefinitions(primaryType, mixins);
        JcrNodeDefinition childDefn = childDefns.findBestDefinitionForChild(nodeName, newPrimaryTypeName, skipProtected,
                                                                            siblingCounter);
        if (childDefn == null) {
            String ptype = readable(primaryType);
            String mtypes = readable(parent.getMixinTypes(cache));
            I18n msg = JcrI18n.unableToChangePrimaryTypeDueToParentsChildDefinition;
View Full Code Here

                if (mixinType.isNodeType(childDeclaredNodeType)) {
                    // Only the residual definition would work - if there were any other definition for this name,
                    // the mixin type would not have been added due to the conflict
                    boolean skipProtected = true;
                    NodeDefinitionSet childDefns = nodeTypes.findChildNodeDefinitions(primaryTypeName, newMixinNames);
                    JcrNodeDefinition match = childDefns.findBestDefinitionForChild(JcrNodeType.RESIDUAL_NAME,
                                                                                    child.getPrimaryNodeType().getInternalName(),
                                                                                    skipProtected, siblingCounter);
                    if (match == null) {
                        throw new ConstraintViolationException(JcrI18n.cannotRemoveMixinNoChildNodeDefinition.text(
                                mixinName,
View Full Code Here

                while (iter.hasNext()) {
                    ChildReference ref = iter.next();
                    CachedNode child = cache.getNode(ref);
                    Name childPrimaryType = child.getPrimaryType(cache);
                    boolean skipProtected = true;
                    NodeDefinitionSet childDefns = nodeTypes.findChildNodeDefinitions(mixinType.getInternalName(), null);
                    JcrNodeDefinition childDefn = childDefns.findBestDefinitionForChild(nodeName, childPrimaryType,
                                                                                        skipProtected, siblingCounter);
                    if (childDefn == null) {
                        return false;
                    }
                }
View Full Code Here

            Name primaryType = node().getPrimaryType(cache);
            Name parentPrimaryType = parent.getPrimaryType(cache);
            Set<Name> parentMixins = parent.getMixinTypes(cache);
            SiblingCounter siblingCounter = SiblingCounter.create(parent, cache);
            boolean skipProtected = true;
            NodeDefinitionSet childDefns = nodeTypes.findChildNodeDefinitions(parentPrimaryType, parentMixins);
            JcrNodeDefinition childDefn = childDefns.findBestDefinitionForChild(nodeName, primaryType, skipProtected,
                                                                                siblingCounter);
            if (childDefn == null) {
                throw new ConstraintViolationException(JcrI18n.noChildNodeDefinition.text(nodeName, getParent().location(),
                                                                                          readable(parentPrimaryType),
                                                                                          readable(parentMixins)));
View Full Code Here

            Name parentPrimaryType = parent.getPrimaryType(cache);
            Set<Name> parentMixins = parent.getMixinTypes(cache);
            // The node is already a child, so create a counter that returns the count as if it were not a child ...
            SiblingCounter siblingCounter = SiblingCounter.alter(SiblingCounter.create(parent, cache), -1);
            boolean skipProtected = false;
            NodeDefinitionSet childDefns = nodeTypes.findChildNodeDefinitions(parentPrimaryType, parentMixins);
            JcrNodeDefinition childDefn = childDefns.findBestDefinitionForChild(nodeName, primaryType, skipProtected,
                                                                                siblingCounter);
            if (childDefn == null) {
                throw new ConstraintViolationException(JcrI18n.noChildNodeDefinition.text(nodeName, getParent().location(),
                                                                                          readable(parentPrimaryType),
                                                                                          readable(parentMixins)));
View Full Code Here

    @Override
    public boolean canAddChildNode( String childNodeName ) {
        CheckArg.isNotNull(childNodeName, "childNodeName");
        Name childName = context.getValueFactories().getNameFactory().create(childNodeName);
        boolean skipProtected = true;
        NodeDefinitionSet childDefns = nodeTypes().findChildNodeDefinitions(this.name, null);
        JcrNodeDefinition childNodeDefinition = childDefns.findBestDefinitionForChild(childName, null, skipProtected,
                                                                                      SiblingCounter.constant(0));
        // No primary node type was given, which means the child node definition (if found) must have a default type ...
        return childNodeDefinition != null && childNodeDefinition.getDefaultPrimaryType() != null;
    }
View Full Code Here

        Name childName = context.getValueFactories().getNameFactory().create(childNodeName);
        Name childPrimaryTypeName = context.getValueFactories().getNameFactory().create(primaryNodeTypeName);

        NodeTypes nodeTypes = nodeTypes();
        boolean skipProtected = true;
        NodeDefinitionSet childDefns = nodeTypes.findChildNodeDefinitions(this.name, null);
        JcrNodeDefinition childNodeDefinition = childDefns.findBestDefinitionForChild(childName, childPrimaryTypeName,
                                                                                      skipProtected, SiblingCounter.constant(0));
        if (childNodeDefinition == null) {
            // We found no valid child node definition ...
            return false;
        }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.NodeTypes.NodeDefinitionSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.