Package org.apache.jackrabbit.core.nodetype

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


        }

        // now add new child node entry to parent
        parent.addChildNodeEntry(nodeName, id);

        EffectiveNodeType ent = getEffectiveNodeType(node);

        // check shareable
        if (ent.includesNodeType(NameConstants.MIX_SHAREABLE)) {
            node.addShare(parent.getNodeId());
        }

        if (!node.getMixinTypeNames().isEmpty()) {
            // create jcr:mixinTypes property
            QPropertyDefinition pd = ent.getApplicablePropertyDef(NameConstants.JCR_MIXINTYPES,
                    PropertyType.NAME, true);
            createPropertyState(node, pd.getName(), pd.getRequiredType(), pd);
        }

        // add 'auto-create' properties defined in node type
        for (QPropertyDefinition pd : ent.getAutoCreatePropDefs()) {
            createPropertyState(node, pd.getName(), pd.getRequiredType(), pd);
        }

        // recursively add 'auto-create' child nodes defined in node type
        for (QNodeDefinition nd : ent.getAutoCreateNodeDefs()) {
            createNodeState(node, nd.getName(), nd.getDefaultPrimaryType(),
                    null, null, nd);
        }

        // store node
View Full Code Here


            throws RepositoryException {

        NodeState newState;
        try {
            NodeId id;
            EffectiveNodeType ent = getEffectiveNodeType(srcState);
            boolean referenceable = ent.includesNodeType(NameConstants.MIX_REFERENCEABLE);
            boolean versionable = ent.includesNodeType(NameConstants.MIX_SIMPLE_VERSIONABLE);
            boolean fullVersionable = ent.includesNodeType(NameConstants.MIX_VERSIONABLE);
            boolean shareable = ent.includesNodeType(NameConstants.MIX_SHAREABLE);
            switch (flag) {
                case COPY:
                    /* if this node is shareable and another node in the same shared set
                     * has been already been copied and given a new uuid, use this one
                     * (see section 14.5 of the specification)
                     */
                    if (shareable && refTracker.getMappedId(srcState.getNodeId()) != null) {
                        NodeId newId = refTracker.getMappedId(srcState.getNodeId());
                        NodeState sharedState = (NodeState) stateMgr.getItemState(newId);
                        sharedState.addShare(destParentId);
                        return sharedState;
                    }
                    // always create new uuid
                    id = new NodeId();
                    if (referenceable) {
                        // remember uuid mapping
                        refTracker.mappedId(srcState.getNodeId(), id);
                    }
                    break;
                case CLONE:
                    if (!referenceable) {
                        // non-referenceable node: always create new uuid
                        id = new NodeId();
                        break;
                    }
                    // use same uuid as source node
                    id = srcState.getNodeId();

                    if (stateMgr.hasItemState(id)) {
                        if (shareable) {
                            NodeState sharedState = (NodeState) stateMgr.getItemState(id);
                            sharedState.addShare(destParentId);
                            return sharedState;
                        }
                        // node with this uuid already exists
                        throw new ItemExistsException(safeGetJCRPath(id));
                    }
                    break;
                case CLONE_REMOVE_EXISTING:
                    if (!referenceable) {
                        // non-referenceable node: always create new uuid
                        id = new NodeId();
                        break;
                    }
                    // use same uuid as source node
                    id = srcState.getNodeId();
                    if (stateMgr.hasItemState(id)) {
                        NodeState existingState = (NodeState) stateMgr.getItemState(id);
                        // make sure existing node is not the parent
                        // or an ancestor thereof
                        if (id.equals(destParentId)
                                || hierMgr.isAncestor(id, destParentId)) {
                            String msg =
                                "cannot remove node " + safeGetJCRPath(srcPath)
                                + " because it is an ancestor of the destination";
                            log.debug(msg);
                            throw new RepositoryException(msg);
                        }

                        // check if existing can be removed
                        // (access rights, locking & versioning status,
                        // node type constraints and retention/hold)
                        checkRemoveNode(existingState,
                                CHECK_ACCESS
                                | CHECK_LOCK
                                | CHECK_CHECKED_OUT
                                | CHECK_CONSTRAINTS
                                | CHECK_HOLD
                                | CHECK_RETENTION);
                        // do remove existing
                        removeNodeState(existingState);
                    }
                    break;
                default:
                    throw new IllegalArgumentException(
                            "unknown flag for copying node state: " + flag);
            }
            newState = stateMgr.createNew(id, srcState.getNodeTypeName(), destParentId);
            // copy node state
            newState.setMixinTypeNames(srcState.getMixinTypeNames());
            if (shareable) {
                // initialize shared set
                newState.addShare(destParentId);
            }
            // copy child nodes
            for (ChildNodeEntry entry : srcState.getChildNodeEntries()) {
                Path srcChildPath = PathFactoryImpl.getInstance().create(srcPath, entry.getName(), true);
                if (!srcAccessMgr.isGranted(srcChildPath, Permission.READ)) {
                    continue;
                }
                NodeId nodeId = entry.getId();
                NodeState srcChildState = (NodeState) srcStateMgr.getItemState(nodeId);

                /**
                 * special handling required for child nodes with special semantics
                 * (e.g. those defined by nt:version,  et.al.)
                 *
                 * todo FIXME delegate to 'node type instance handler'
                 */

                /**
                 * If child is shareble and its UUID has already been remapped,
                 * then simply add a reference to the state with that remapped
                 * UUID instead of copying the whole subtree.
                 */
                if (srcChildState.isShareable()) {
                    NodeId mappedId = refTracker.getMappedId(srcChildState.getNodeId());
                    if (mappedId != null) {
                        if (stateMgr.hasItemState(mappedId)) {
                            NodeState destState = (NodeState) stateMgr.getItemState(mappedId);
                            if (!destState.isShareable()) {
                                String msg =
                                    "Remapped child (" + safeGetJCRPath(srcPath)
                                    + ") is not shareable.";
                                throw new ItemStateException(msg);
                            }
                            if (!destState.addShare(id)) {
                                String msg = "Unable to add share to node: " + id;
                                throw new ItemStateException(msg);
                            }
                            stateMgr.store(destState);
                            newState.addChildNodeEntry(entry.getName(), mappedId);
                            continue;
                        }
                    }
                }

                // recursive copying of child node
                NodeState newChildState = copyNodeState(srcChildState, srcChildPath,
                        srcStateMgr, srcAccessMgr, id, flag, refTracker);
                // store new child node
                stateMgr.store(newChildState);
                // add new child node entry to new node
                newState.addChildNodeEntry(entry.getName(), newChildState.getNodeId());
            }
            // init version history if needed
            VersionHistoryInfo history = null;
            if (versionable && flag == COPY) {
                NodeId copiedFrom = null;
                if (fullVersionable) {
                    // base version of copied versionable node is reference value of
                    // the histories jcr:copiedFrom property
                    PropertyId propId = new PropertyId(srcState.getNodeId(), NameConstants.JCR_BASEVERSION);
                    PropertyState prop = (PropertyState) srcStateMgr.getItemState(propId);
                    copiedFrom = prop.getValues()[0].getNodeId();
                }
                InternalVersionManager manager = session.getInternalVersionManager();
                history = manager.getVersionHistory(session, newState, copiedFrom);
            }
            // copy properties
            for (Name propName : srcState.getPropertyNames()) {
                Path propPath = PathFactoryImpl.getInstance().create(srcPath, propName, true);               
                PropertyId propId = new PropertyId(srcState.getNodeId(), propName);
                if (!srcAccessMgr.canRead(propPath, propId)) {
                    continue;
                }
                PropertyState srcChildState =
                        (PropertyState) srcStateMgr.getItemState(propId);

                /**
                 * special handling required for properties with special semantics
                 * (e.g. those defined by mix:referenceable, mix:versionable,
                 * mix:lockable, et.al.)
                 *
                 * todo FIXME delegate to 'node type instance handler'
                 */
                QPropertyDefinition def = ent.getApplicablePropertyDef(
                        srcChildState.getName(), srcChildState.getType(),
                        srcChildState.isMultiValued());
                if (NameConstants.MIX_LOCKABLE.equals(def.getDeclaringNodeType())) {
                    // skip properties defined by mix:lockable
                    continue;
View Full Code Here

        if (mixins.contains(NameConstants.MIX_SHAREABLE)) {
            return true;
        }

        try {
            EffectiveNodeType type = ntReg.getEffectiveNodeType(primary, mixins);
            return type.includesNodeType(NameConstants.MIX_REFERENCEABLE);
        } catch (NodeTypeConflictException ntce) {
            String msg = "internal error: failed to build effective node type for node "
                    + state.getNodeId();
            log.debug(msg);
            throw new RepositoryException(msg, ntce);
View Full Code Here

                                        public boolean allowsSameNameSiblings(NodeId id) {
                                            try {
                                                NodeState ns = getNodeState(id);
                                                NodeState parent = getNodeState(ns.getParentId());
                                                Name name = parent.getChildNodeEntry(id).getName();
                                                EffectiveNodeType ent = ntReg.getEffectiveNodeType(
                                                        parent.getNodeTypeName(),
                                                        parent.getMixinTypeNames());
                                                QNodeDefinition def = ent.getApplicableChildNodeDef(name, ns.getNodeTypeName(), ntReg);
                                                return def != null ? def.allowsSameNameSiblings() : false;
                                            } catch (Exception e) {
                                                log.warn("Unable to get node definition", e);
                                                return false;
                                            }
View Full Code Here

                return true;
            }

            // build effective node type
            try {
                EffectiveNodeType type = ntReg.getEffectiveNodeType(primary, mixins);
                return type.includesNodeType(NameConstants.MIX_REFERENCEABLE);
            } catch (NodeTypeConflictException ntce) {
                String msg = "internal error: failed to build effective node type for node "
                        + state.getNodeId();
                log.debug(msg);
                throw new ItemStateException(msg, ntce);
View Full Code Here

            throw new RepositoryException(mixinName + ": already contained in primary node type");
        }

        // build effective node type of mixin's & primary type in order to detect conflicts
        NodeTypeRegistry ntReg = ntMgr.getNodeTypeRegistry();
        EffectiveNodeType entExisting;
        try {
            // existing mixin's
            HashSet set = new HashSet(((NodeState) state).getMixinTypeNames());
            // primary type
            set.add(primaryTypeName);
            // build effective node type representing primary type including existing mixin's
            entExisting = ntReg.getEffectiveNodeType((QName[]) set.toArray(new QName[set.size()]));
            if (entExisting.includesNodeType(mixinName)) {
                throw new RepositoryException(mixinName + ": already contained in mixin types");
            }
            // add new mixin
            set.add(mixinName);
            // try to build new effective node type (will throw in case of conflicts)
            ntReg.getEffectiveNodeType((QName[]) set.toArray(new QName[set.size()]));
        } catch (NodeTypeConflictException ntce) {
            throw new ConstraintViolationException(ntce.getMessage());
        }

        // do the actual modifications implied by the new mixin;
        // try to revert the changes in case an exception occurs
        try {
            // modify the state of this node
            NodeState thisState = (NodeState) getOrCreateTransientItemState();
            // add mixin name
            Set mixins = new HashSet(thisState.getMixinTypeNames());
            mixins.add(mixinName);
            thisState.setMixinTypeNames(mixins);

            // set jcr:mixinTypes property
            setMixinTypesProperty(mixins);

            // add 'auto-create' properties defined in mixin type
            PropertyDefinition[] pda = mixin.getAutoCreatedPropertyDefinitions();
            for (int i = 0; i < pda.length; i++) {
                PropertyDefinitionImpl pd = (PropertyDefinitionImpl) pda[i];
                // make sure that the property is not already defined by primary type
                // or existing mixin's
                NodeTypeImpl declaringNT = (NodeTypeImpl) pd.getDeclaringNodeType();
                if (!entExisting.includesNodeType(declaringNT.getQName())) {
                    createChildProperty(pd.getQName(), pd.getRequiredType(), pd);
                }
            }

            // recursively add 'auto-create' child nodes defined in mixin type
            NodeDefinition[] nda = mixin.getAutoCreatedNodeDefinitions();
            for (int i = 0; i < nda.length; i++) {
                NodeDefinitionImpl nd = (NodeDefinitionImpl) nda[i];
                // make sure that the child node is not already defined by primary type
                // or existing mixin's
                NodeTypeImpl declaringNT = (NodeTypeImpl) nd.getDeclaringNodeType();
                if (!entExisting.includesNodeType(declaringNT.getQName())) {
                    createChildNode(nd.getQName(), nd, (NodeTypeImpl) nd.getDefaultPrimaryType(), null);
                }
            }
        } catch (RepositoryException re) {
            // try to undo the modifications by removing the mixin
View Full Code Here

        // build effective node type of remaining mixin's & primary type
        Set remainingMixins = new HashSet(((NodeState) state).getMixinTypeNames());
        // remove name of target mixin
        remainingMixins.remove(mixinName);
        EffectiveNodeType entRemaining;
        try {
            // remaining mixin's
            HashSet set = new HashSet(remainingMixins);
            // primary type
            set.add(primaryTypeName);
            // build effective node type representing primary type including remaining mixin's
            entRemaining = ntReg.getEffectiveNodeType((QName[]) set.toArray(new QName[set.size()]));
        } catch (NodeTypeConflictException ntce) {
            throw new ConstraintViolationException(ntce.getMessage());
        }

        /**
         * mix:referenceable needs special handling because it has
         * special semantics:
         * it can only be removed if there no more references to this node
         */
        NodeTypeImpl mixin = ntMgr.getNodeType(mixinName);
        if ((QName.MIX_REFERENCEABLE.equals(mixinName)
                || mixin.isDerivedFrom(QName.MIX_REFERENCEABLE))
                && !entRemaining.includesNodeType(QName.MIX_REFERENCEABLE)) {
            // removing this mixin would effectively remove mix:referenceable:
            // make sure no references exist
            PropertyIterator iter = getReferences();
            if (iter.hasNext()) {
                throw new ConstraintViolationException(mixinName + " can not be removed: the node is being referenced"
                        + " through at least one property of type REFERENCE");
            }
        }

        // modify the state of this node
        NodeState thisState = (NodeState) getOrCreateTransientItemState();
        thisState.setMixinTypeNames(remainingMixins);

        // set jcr:mixinTypes property
        setMixinTypesProperty(remainingMixins);

        // shortcut
        if (mixin.getChildNodeDefinitions().length == 0
                && mixin.getPropertyDefinitions().length == 0) {
            // the node type has neither property nor child node definitions,
            // i.e. we're done
            return;
        }

        // walk through properties and child nodes and remove those that have been
        // defined by the specified mixin type

        // use temp set to avoid ConcurrentModificationException
        HashSet set = new HashSet(thisState.getPropertyNames());
        for (Iterator iter = set.iterator(); iter.hasNext();) {
            QName propName = (QName) iter.next();
            PropertyImpl prop = (PropertyImpl) itemMgr.getItem(
                    new PropertyId(thisState.getNodeId(), propName));
            // check if property has been defined by mixin type (or one of its supertypes)
            NodeTypeImpl declaringNT = (NodeTypeImpl) prop.getDefinition().getDeclaringNodeType();
            if (!entRemaining.includesNodeType(declaringNT.getQName())) {
                // the remaining effective node type doesn't include the
                // node type that declared this property, it is thus safe
                // to remove it
                removeChildProperty(propName);
            }
        }
        // use temp array to avoid ConcurrentModificationException
        ArrayList list = new ArrayList(thisState.getChildNodeEntries());
        // start from tail to avoid problems with same-name siblings
        for (int i = list.size() - 1; i >= 0; i--) {
            NodeState.ChildNodeEntry entry = (NodeState.ChildNodeEntry) list.get(i);
            NodeImpl node = (NodeImpl) itemMgr.getItem(entry.getId());
            // check if node has been defined by mixin type (or one of its supertypes)
            NodeTypeImpl declaringNT = (NodeTypeImpl) node.getDefinition().getDeclaringNodeType();
            if (!entRemaining.includesNodeType(declaringNT.getQName())) {
                // the remaining effective node type doesn't include the
                // node type that declared this child node, it is thus safe
                // to remove it
                removeChildNode(entry.getName(), entry.getIndex());
            }
View Full Code Here

        }

        // build effective node type of mixins & primary type
        // in order to detect conflicts
        NodeTypeRegistry ntReg = ntMgr.getNodeTypeRegistry();
        EffectiveNodeType entExisting;
        try {
            // existing mixin's
            HashSet set = new HashSet(((NodeState) state).getMixinTypeNames());
            // primary type
            set.add(primaryTypeName);
            // build effective node type representing primary type including existing mixin's
            entExisting = ntReg.getEffectiveNodeType((QName[]) set.toArray(new QName[set.size()]));
            if (entExisting.includesNodeType(ntName)) {
                return false;
            }
            // add new mixin
            set.add(ntName);
            // try to build new effective node type (will throw in case of conflicts)
View Full Code Here

                NodeImpl node = (NodeImpl) itemMgr.getItem(id);
                NodeDefinition def = node.getDefinition();
                // primary type
                NodeTypeImpl pnt = (NodeTypeImpl) node.getPrimaryNodeType();
                // effective node type (primary type incl. mixins)
                EffectiveNodeType ent = node.getEffectiveNodeType();
                /**
                 * if the transient node was added (i.e. if it is 'new'),
                 * check its node's node type against the required node type
                 * in its definition
                 */
                if (nodeState.getStatus() == ItemState.STATUS_NEW) {
                    NodeType[] nta = def.getRequiredPrimaryTypes();
                    for (int i = 0; i < nta.length; i++) {
                        NodeTypeImpl ntReq = (NodeTypeImpl) nta[i];
                        if (!(pnt.getQName().equals(ntReq.getQName())
                                || pnt.isDerivedFrom(ntReq.getQName()))) {
                            /**
                             * the transient node's primary node type does not
                             * satisfy the 'required primary types' constraint
                             */
                            String msg = node.safeGetJCRPath()
                                    + " must be of node type " + ntReq.getName();
                            log.debug(msg);
                            throw new ConstraintViolationException(msg);
                        }
                    }
                }

                // mandatory child properties
                PropDef[] pda = ent.getMandatoryPropDefs();
                for (int i = 0; i < pda.length; i++) {
                    PropDef pd = pda[i];
                    if (pd.getDeclaringNodeType().equals(QName.MIX_VERSIONABLE)) {
                        /**
                         * todo FIXME workaround for mix:versionable:
                         * the mandatory properties are initialized at a
                         * later stage and might not exist yet
                         */
                        continue;
                    }
                    if (!nodeState.hasPropertyName(pd.getName())) {
                        String msg = node.safeGetJCRPath()
                                + ": mandatory property " + pd.getName()
                                + " does not exist";
                        log.debug(msg);
                        throw new ConstraintViolationException(msg);
                    }
                }
                // mandatory child nodes
                NodeDef[] cnda = ent.getMandatoryNodeDefs();
                for (int i = 0; i < cnda.length; i++) {
                    NodeDef cnd = cnda[i];
                    if (!nodeState.hasChildNodeEntry(cnd.getName())) {
                        String msg = node.safeGetJCRPath()
                                + ": mandatory child node " + cnd.getName()
View Full Code Here

        PropDef propDef;
        // id of the jcr:system node's definition
        NodeDefId jcrSystemDefId;
        try {
            nodeDefId = ntReg.getRootNodeDef().getId();
            EffectiveNodeType ent = ntReg.getEffectiveNodeType(QName.REP_ROOT);
            propDef = ent.getApplicablePropertyDef(QName.JCR_PRIMARYTYPE,
                    PropertyType.NAME, false);
            jcrSystemDefId = ent.getApplicableChildNodeDef(QName.JCR_SYSTEM, QName.REP_SYSTEM, ntReg).getId();
        } catch (NoSuchNodeTypeException nsnte) {
            String msg = "internal error: failed to create root node";
            log.error(msg, nsnte);
            throw new ItemStateException(msg, nsnte);
        } catch (ConstraintViolationException cve) {
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.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.