Package org.apache.jackrabbit.jcr2spi.nodetype

Examples of org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType


     * @throws RepositoryException          if another error occurs
     */
    public void validate(NodeState nodeState) throws ConstraintViolationException,
        RepositoryException {
        // effective primary node type
        EffectiveNodeType entPrimary = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeState.getNodeTypeName());
        QNodeDefinition def = nodeState.getDefinition();

        // check if primary type satisfies the 'required node types' constraint
        Name[] requiredPrimaryTypes = def.getRequiredPrimaryTypes();
        for (int i = 0; i < requiredPrimaryTypes.length; i++) {
            if (!entPrimary.includesNodeType(requiredPrimaryTypes[i])) {
                String msg = safeGetJCRPath(nodeState)
                        + ": missing required primary type "
                        + requiredPrimaryTypes[i];
                log.debug(msg);
                throw new ConstraintViolationException(msg);
            }
        }
        // mandatory properties
        // effective node type (primary type incl. mixins)
        Name[] ntNames = nodeState.getAllNodeTypeNames();
        EffectiveNodeType entPrimaryAndMixins = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
        QPropertyDefinition[] pda = entPrimaryAndMixins.getMandatoryQPropertyDefinitions();
        for (int i = 0; i < pda.length; i++) {
            QPropertyDefinition pd = pda[i];
            if (!nodeState.hasPropertyName(pd.getName())) {
                String msg = safeGetJCRPath(nodeState)
                        + ": mandatory property " + pd.getName()
                        + " does not exist";
                log.debug(msg);
                throw new ConstraintViolationException(msg);
            }
        }
        // mandatory child nodes
        QNodeDefinition[] cnda = entPrimaryAndMixins.getMandatoryQNodeDefinitions();
        for (int i = 0; i < cnda.length; i++) {
            QNodeDefinition cnd = cnda[i];
            if (!nodeState.getNodeEntry().hasNodeEntry(cnd.getName())) {
                String msg = safeGetJCRPath(nodeState)
                        + ": mandatory child node " + cnd.getName()
View Full Code Here


        }
        // node type constraints
        if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
            // make sure there's an applicable definition for new child node
            Name[] ntNames = parentState.getAllNodeTypeNames();
            EffectiveNodeType entParent = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
            entParent.checkAddNodeConstraints(nodeName, nodeTypeName, mgrProvider.getItemDefinitionProvider());
        }
        // collisions
        if ((options & CHECK_COLLISION) == CHECK_COLLISION) {
            checkCollision(parentState, nodeName, nodeTypeName);
        }
View Full Code Here

               QNodeDefinition def = existing.getDefinition();
               if (!def.allowsSameNameSiblings()) {
                   // existing doesn't allow same-name siblings, check for conflicts
                   EffectiveNodeTypeProvider provider = session.getEffectiveNodeTypeProvider();
                   Name[] ntNames = existing.getAllNodeTypeNames();
                   EffectiveNodeType entExisting = provider.getEffectiveNodeType(ntNames);
                   if (def.isProtected() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
                       // skip protected node
                       parents.push(null); // push null onto stack for skipped node
                       log.debug("skipping protected node " + LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
                       return;
                   }
                   if (def.isAutoCreated() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
                       // this node has already been auto-created, no need to create it
                       nodeState = existing;
                   } else {
                       throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getPathResolver()));
                   }
View Full Code Here

        if (l.contains(NameConstants.MIX_REFERENCEABLE)) {
            // shortcut
            return;
        }
        Name[] ntNames = (Name[]) l.toArray(new Name[l.size()]);
        EffectiveNodeType ent = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
        if (!ent.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
            throw new ConstraintViolationException("XML defines jcr:uuid without defining import node to be referenceable.");
        }
    }
View Full Code Here

        // check if add node is possible. note, that the options differ if
        // the 'addNode' is called from inside a regular add-node to create
        // autocreated child nodes that may be 'protected'.
        validator.checkAddNode(parent, nodeName, nodeTypeName, options);
        // a new NodeState doesn't have mixins defined yet -> ent is ent of primarytype
        EffectiveNodeType ent = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeTypeName);

        if (nodeTypeName == null) {
            // no primary node type specified,
            // try default primary type from definition
            nodeTypeName = definition.getDefaultPrimaryType();
            if (nodeTypeName == null) {
                String msg = "an applicable node type could not be determined for " + nodeName;
                log.debug(msg);
                throw new ConstraintViolationException(msg);
            }
        }

        List addedStates = new ArrayList();

        // create new nodeState. NOTE, that the uniqueID is not added to the
        // state for consistency between 'addNode' and importXML
        NodeState nodeState = transientStateMgr.createNewNodeState(nodeName, null, nodeTypeName, definition, parent);
        addedStates.add(nodeState);
        if (uuid != null) {
            QValue[] value = getQValues(uuid, qValueFactory);
            ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
            QPropertyDefinition pDef = defProvider.getQPropertyDefinition(NameConstants.MIX_REFERENCEABLE, NameConstants.JCR_UUID, PropertyType.STRING, false);
            addedStates.add(addPropertyState(nodeState, NameConstants.JCR_UUID, PropertyType.STRING, value, pDef, 0));
        }

        // add 'auto-create' properties defined in node type
        QPropertyDefinition[] pda = ent.getAutoCreateQPropertyDefinitions();
        for (int i = 0; i < pda.length; i++) {
            QPropertyDefinition pd = pda[i];
            if (!nodeState.hasPropertyName(pd.getName())) {
                QValue[] autoValue = computeSystemGeneratedPropertyValues(nodeState, pd);
                if (autoValue != null) {
                    int propOptions = ItemStateValidator.CHECK_NONE;
                    // execute 'addProperty' without adding operation.
                    addedStates.add(addPropertyState(nodeState, pd.getName(), pd.getRequiredType(), autoValue, pd, propOptions));
                }
            }
        }

        // recursively add 'auto-create' child nodes defined in node type
        QNodeDefinition[] nda = ent.getAutoCreateQNodeDefinitions();
        for (int i = 0; i < nda.length; i++) {
            QNodeDefinition nd = nda[i];
            // execute 'addNode' without adding the operation.
            int opt = ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_COLLISION;
            addedStates.addAll(addNodeState(nodeState, nd.getName(), nd.getDefaultPrimaryType(), null, nd, opt));
View Full Code Here

        NodeTypeImpl mixin = session.getNodeTypeManager().getNodeType(ntName);
        if (mixin.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
            // build effective node type of remaining mixin's & primary type
            Name[] allRemaining = (Name[]) mixinValue.toArray(new Name[mixinValue.size() + 1]);
            allRemaining[mixinValue.size()] = primaryTypeName;
            EffectiveNodeType entRemaining = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(allRemaining);

            if (!entRemaining.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
                PropertyIterator iter = getReferences();
                if (iter.hasNext()) {
                    throw new ConstraintViolationException("Mixin type " + mixinName + " can not be removed: the node is being referenced through at least one property of type REFERENCE");
                }
            }
View Full Code Here

            session.getNodeTypeManager().getNodeType(qName).isMixin()) {
            return false;
        }

        // check effective node type
        EffectiveNodeType effnt = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(getNodeState().getNodeTypeNames());
        return effnt.includesNodeType(qName);
    }
View Full Code Here

        }

        // get list of existing nodetypes
        Name[] existingNts = getNodeState().getNodeTypeNames();
        // build effective node type representing primary type including existing mixin's
        EffectiveNodeType entExisting = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(existingNts);

        // check if the base type supports adding this mixin
        if (!entExisting.supportsMixin(mixinName)) {
            log.debug(mixin.getName() + ": not supported on node type " + primaryTypeName);
            return false;
        }

        // check if adding new mixin conflicts with existing nodetypes
        if (entExisting.includesNodeType(mixinName)) {
            log.debug(mixin.getName() + ": already contained in mixin types");
            return false;
        }

        // second, build new effective node type for nts including the new mixin
View Full Code Here

        // mix:referenceable needs additional assertion: the mixin cannot be
        // removed, if any references are left to this node.
        NodeTypeImpl mixin = session.getNodeTypeManager().getNodeType(ntName);
        if (mixin.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
            EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
            if (!entRemaining.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
                PropertyIterator iter = getReferences();
                if (iter.hasNext()) {
                    throw new ConstraintViolationException("Mixin type " + mixinName + " can not be removed: the node is being referenced through at least one property of type REFERENCE");
                }
            }
        }

        /*
         * mix:lockable: the mixin cannot be removed if the node is currently
         * locked even if the editing session is the lock holder.
         */
        if (mixin.isNodeType((NameConstants.MIX_LOCKABLE))) {
            EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
            if (!entRemaining.includesNodeType(NameConstants.MIX_LOCKABLE) && isLocked()) {
                throw new ConstraintViolationException(mixinName + " can not be removed: the node is locked.");
            }
        }

        // delegate to operation
View Full Code Here

            session.getNodeTypeManager().getNodeType(qName).isMixin()) {
            return false;
        }

        // check effective node type
        EffectiveNodeType effnt = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(getNodeState().getNodeTypeNames());
        return effnt.includesNodeType(qName);
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType

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.