Package org.apache.jackrabbit.core

Examples of org.apache.jackrabbit.core.NodeId


        Name versionName = (Name) labelCache.get(label);
        if (versionName == null) {
            return null;
        }

        NodeId id = (NodeId) nameCache.get(versionName);
        InternalVersion v = (InternalVersion) versionCache.get(id);
        if (v == null) {
            v = createVersionInstance(versionName);
        }
        return v;
View Full Code Here


            Value[] preds = src.getProperty(NameConstants.JCR_PREDECESSORS).getValues();
            predecessors = new InternalValue[preds.length];
            for (int i = 0; i < preds.length; i++) {
                UUID predId = UUID.fromString(preds[i].getString());
                // check if version exist
                if (!nameCache.containsValue(new NodeId(predId))) {
                    throw new RepositoryException("invalid predecessor in source node");
                }
                predecessors[i] = InternalValue.create(predId);
            }
        } else {
            // with simple versioning, the node does not contain a predecessors
            // property and we just use the 'head' version as predecessor
            Iterator iter = nameCache.values().iterator();
            NodeId last = null;
            while (iter.hasNext()) {
                last = (NodeId) iter.next();
            }
            if (last == null) {
                // should never happen
                last = rootVersion.getId();
            }
            predecessors = new InternalValue[]{InternalValue.create(last.getUUID())};
        }

        NodeId versionId = new NodeId(UUID.randomUUID());
        NodeStateEx vNode = node.addNode(name, NameConstants.NT_VERSION, versionId, true);

        // initialize 'created', 'predecessors' and 'successors'
        if (cal == null) {
            cal = getCurrentTime();
View Full Code Here

    static NodeStateEx create(
            AbstractVersionManager vMgr, NodeStateEx parent, Name name,
            NodeState nodeState) throws RepositoryException {

        // create history node
        NodeId historyId = new NodeId(UUID.randomUUID());
        NodeStateEx pNode = parent.addNode(name, NameConstants.NT_VERSIONHISTORY, historyId, true);

        // set the versionable uuid
        String versionableUUID = nodeState.getNodeId().getUUID().toString();
        pNode.setPropertyValue(NameConstants.JCR_VERSIONABLEUUID, InternalValue.create(versionableUUID));

        // create label node
        pNode.addNode(NameConstants.JCR_VERSIONLABELS, NameConstants.NT_VERSIONLABELS, null, false);

        // create root version
        NodeId versionId = new NodeId(UUID.randomUUID());
        NodeStateEx vNode = pNode.addNode(NameConstants.JCR_ROOTVERSION, NameConstants.NT_VERSION, versionId, true);

        // initialize 'created' and 'predecessors'
        vNode.setPropertyValue(NameConstants.JCR_CREATED, InternalValue.create(getCurrentTime()));
        vNode.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
View Full Code Here

            // do create new node
            node = itemOps.createNodeState(parent, nodeInfo.getName(),
                    nodeInfo.getNodeTypeName(), nodeInfo.getMixinNames(),
                    nodeInfo.getId());
        } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING) {
            NodeId parentId = conflicting.getParentId();
            if (parentId == null) {
                String msg = "root node cannot be replaced";
                log.debug(msg);
                throw new RepositoryException(msg);
            }
View Full Code Here

            parent = (NodeState) parents.peek();

            // process node

            NodeState node = null;
            NodeId id = nodeInfo.getId();
            Name nodeName = nodeInfo.getName();
            Name ntName = nodeInfo.getNodeTypeName();
            Name[] mixins = nodeInfo.getMixinNames();

            if (parent == null) {
                // parent node was skipped, skip this child node too
                parents.push(null); // push null onto stack for skipped node
                succeeded = true;
                log.debug("skipping node " + nodeName);
                return;
            }
            if (parent.hasChildNodeEntry(nodeName)) {
                // a node with that name already exists...
                ChildNodeEntry entry =
                        parent.getChildNodeEntry(nodeName, 1);
                NodeId idExisting = entry.getId();
                NodeState existing = (NodeState) itemOps.getItemState(idExisting);
                NodeDef def = ntReg.getNodeDef(existing.getDefinitionId());

                if (!def.allowsSameNameSiblings()) {
                    // existing doesn't allow same-name siblings,
                    // check for potential conflicts
                    EffectiveNodeType entExisting =
                            itemOps.getEffectiveNodeType(existing);
                    if (def.isProtected() && entExisting.includesNodeType(ntName)) {
                        // skip protected node
                        parents.push(null); // push null onto stack for skipped node
                        succeeded = true;
                        log.debug("skipping protected node "
                                + itemOps.safeGetJCRPath(existing.getNodeId()));
                        return;
                    }
                    if (def.isAutoCreated() && entExisting.includesNodeType(ntName)) {
                        // this node has already been auto-created,
                        // no need to create it
                        node = existing;
                    } else {
                        // edge case: colliding node does have same uuid
                        // (see http://issues.apache.org/jira/browse/JCR-1128)
                        if (!(idExisting.equals(id)
                                && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
                                || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))) {
                            throw new ItemExistsException(itemOps.safeGetJCRPath(existing.getNodeId()));
                        }
                        // fall through
View Full Code Here

                // in case 8) parent of removed shareable node has removed child
                // node entry.
                NodeState n = (NodeState) state;

                if (n.hasOverlayedState()) {
                    NodeId oldParentId = n.getOverlayedState().getParentId();
                    NodeId newParentId = n.getParentId();
                    if (newParentId != null && !oldParentId.equals(newParentId) &&
                            !n.isShareable()) {
                       
                        // node moved
                        // generate node removed & node added event
                        NodeState oldParent;
                        try {
                            oldParent = (NodeState) changes.get(oldParentId);
                        } catch (NoSuchItemStateException e) {
                            // old parent has been deleted, retrieve from
                            // shared item state manager
                            oldParent = (NodeState) stateMgr.getItemState(oldParentId);
                        }

                        NodeTypeImpl oldParentNodeType = getNodeType(oldParent, session);
                        Set mixins = oldParent.getMixinTypeNames();
                        Path newPath = getPath(n.getNodeId(), hmgr);
                        Path oldPath = getZombiePath(n.getNodeId(), hmgr);
                        events.add(EventState.childNodeRemoved(oldParentId,
                                getParent(oldPath), n.getNodeId(),
                                oldPath.getNameElement(),
                                oldParentNodeType.getQName(),
                                mixins, session));

                        NodeState newParent = (NodeState) changes.get(newParentId);
                        NodeTypeImpl newParentNodeType = getNodeType(newParent, session);
                        mixins = newParent.getMixinTypeNames();
                        events.add(EventState.childNodeAdded(newParentId,
                                getParent(newPath), n.getNodeId(),
                                newPath.getNameElement(),
                                newParentNodeType.getQName(),
                                mixins, session));

                        events.add(EventState.nodeMoved(newParentId,
                                newPath, n.getNodeId(), oldPath,
                                newParentNodeType.getQName(), mixins,
                                session, false));
                    } else {
                        // a moved node always has a modified parent node
                        NodeState parent = null;
                        try {
                            // root node does not have a parent UUID
                            if (state.getParentId() != null) {
                                parent = (NodeState) changes.get(state.getParentId());
                            }
                        } catch (NoSuchItemStateException e) {
                            // should never happen actually. this would mean
                            // the parent of this modified node is deleted
                            String msg = "Parent of node " + state.getId() + " is deleted.";
                            log.error(msg);
                            throw new ItemStateException(msg, e);
                        }
                        if (parent != null) {
                            // check if node has been renamed
                            ChildNodeEntry moved = null;
                            for (Iterator removedNodes = parent.getRemovedChildNodeEntries().iterator(); removedNodes.hasNext();) {
                                ChildNodeEntry child = (ChildNodeEntry) removedNodes.next();
                                if (child.getId().equals(n.getNodeId())) {
                                    // found node re-added with different name
                                    moved = child;
                                }
                            }
                            if (moved != null) {
                                NodeTypeImpl nodeType = getNodeType(parent, session);
                                Set mixins = parent.getMixinTypeNames();
                                Path newPath = getPath(state.getId(), hmgr);
                                Path parentPath = getParent(newPath);
                                Path oldPath;
                                try {
                                    if (moved.getIndex() == 0) {
                                        oldPath = PathFactoryImpl.getInstance().create(parentPath, moved.getName(), false);
                                    } else {
                                        oldPath = PathFactoryImpl.getInstance().create(
                                                parentPath, moved.getName(), moved.getIndex(), false);
                                    }
                                } catch (RepositoryException e) {
                                    // should never happen actually
                                    String msg = "Malformed path for item: " + state.getId();
                                    log.error(msg);
                                    throw new ItemStateException(msg, e);
                                }
                                events.add(EventState.childNodeRemoved(
                                        parent.getNodeId(), parentPath,
                                        n.getNodeId(), oldPath.getNameElement(),
                                        nodeType.getQName(), mixins, session));

                                events.add(EventState.childNodeAdded(
                                        parent.getNodeId(), parentPath,
                                        n.getNodeId(), newPath.getNameElement(),
                                        nodeType.getQName(), mixins, session));

                                events.add(EventState.nodeMoved(
                                        parent.getNodeId(), newPath, n.getNodeId(),
                                        oldPath, nodeType.getQName(), mixins,
                                        session, false));
                            }
                        }
                    }
                }

                // check if child nodes of modified node state have been reordered
                List reordered = n.getReorderedChildNodeEntries();
                NodeTypeImpl nodeType = getNodeType(n, session);
                Set mixins = n.getMixinTypeNames();
                if (reordered.size() > 0) {
                    // create a node removed and a node added event for every
                    // reorder
                    for (Iterator ro = reordered.iterator(); ro.hasNext();) {
                        ChildNodeEntry child = (ChildNodeEntry) ro.next();
                        Path.Element addedElem = getPathElement(child);
                        Path parentPath = getPath(n.getNodeId(), hmgr);
                        // get removed index
                        NodeState overlayed = (NodeState) n.getOverlayedState();
                        ChildNodeEntry entry = overlayed.getChildNodeEntry(child.getId());
                        if (entry == null) {
                            throw new ItemStateException("Unable to retrieve old child index for item: " + child.getId());
                        }
                        Path.Element removedElem = getPathElement(entry);

                        events.add(EventState.childNodeRemoved(n.getNodeId(),
                                parentPath, child.getId(), removedElem,
                                nodeType.getQName(), mixins, session));

                        events.add(EventState.childNodeAdded(n.getNodeId(),
                                parentPath, child.getId(), addedElem,
                                nodeType.getQName(), mixins, session));

                        List cne = n.getChildNodeEntries();
                        // index of the child node entry before which this
                        // child node entry was reordered
                        int idx = cne.indexOf(child) + 1;
                        Path.Element beforeElem = null;
                        if (idx < cne.size()) {
                            beforeElem = getPathElement((ChildNodeEntry) cne.get(idx));
                        }

                        events.add(EventState.nodeReordered(n.getNodeId(),
                                parentPath, child.getId(), addedElem,
                                removedElem, beforeElem, nodeType.getQName(), mixins,
                                session, false));
                    }
                }

                // create events if n is shareable
                createShareableNodeEvents(n, changes, hmgr, stateMgr);
            } else {
                // property changed
                Path path = getPath(state.getId(), hmgr);
                NodeState parent = (NodeState) stateMgr.getItemState(state.getParentId());
                NodeTypeImpl nodeType = getNodeType(parent, session);
                Set mixins = parent.getMixinTypeNames();
                events.add(EventState.propertyChanged(state.getParentId(),
                        getParent(path), path.getNameElement(),
                        nodeType.getQName(), mixins, session));
            }
        }

        // 2. removed items

        for (Iterator it = changes.deletedStates(); it.hasNext();) {
            ItemState state = (ItemState) it.next();
            if (state.isNode()) {
                // node deleted
                NodeState n = (NodeState) state;
                NodeState parent = (NodeState) stateMgr.getItemState(n.getParentId());
                NodeTypeImpl nodeType = getNodeType(parent, session);
                Set mixins = parent.getMixinTypeNames();
                Path path = getZombiePath(state.getId(), hmgr);
                events.add(EventState.childNodeRemoved(n.getParentId(),
                        getParent(path),
                        n.getNodeId(),
                        path.getNameElement(),
                        nodeType.getQName(),
                        mixins,
                        session));

                // create events if n is shareable
                createShareableNodeEvents(n, changes, hmgr, stateMgr);
            } else {
                // property removed
                // only create an event if node still exists
                try {
                    NodeState n = (NodeState) changes.get(state.getParentId());
                    // node state exists -> only property removed
                    NodeTypeImpl nodeType = getNodeType(n, session);
                    Set mixins = n.getMixinTypeNames();
                    Path path = getZombiePath(state.getId(), hmgr);
                    events.add(EventState.propertyRemoved(state.getParentId(),
                            getParent(path),
                            path.getNameElement(),
                            nodeType.getQName(),
                            mixins,
                            session));
                } catch (NoSuchItemStateException e) {
                    // node removed as well -> do not create an event
                }
            }
        }

        // 3. added items

        for (Iterator it = changes.addedStates(); it.hasNext();) {
            ItemState state = (ItemState) it.next();
            if (state.isNode()) {
                // node created
                NodeState n = (NodeState) state;
                NodeId parentId = n.getParentId();
                // the parent of an added item is always modified or new
                NodeState parent = (NodeState) changes.get(parentId);
                NodeTypeImpl nodeType = getNodeType(parent, session);
                Set mixins = parent.getMixinTypeNames();
                Path path = getPath(n.getNodeId(), hmgr);
View Full Code Here

                                           ItemStateManager stateMgr)
            throws ItemStateException {
        if (n.isShareable()) {
            // check if a share was added or removed
            for (Iterator added = n.getAddedShares().iterator(); added.hasNext(); ) {
                NodeId parentId = (NodeId) added.next();
                // ignore primary parent id
                if (n.getParentId().equals(parentId)) {
                    continue;
                }
                NodeState parent = (NodeState) changes.get(parentId);
                if (parent == null) {
                    // happens when mix:shareable is added to an existing node
                    // usually the parent node state is in the change log
                    // when a node is added to a shared set -> new child node
                    // entry on parent node state.
                    parent = (NodeState) stateMgr.getItemState(parentId);
                }
                Name ntName = getNodeType(parent, session).getQName();
                EventState es = EventState.childNodeAdded(parentId,
                        getPath(parentId, hmgr),
                        n.getNodeId(),
                        getNameElement(n.getNodeId(), parentId, hmgr),
                        ntName,
                        parent.getMixinTypeNames(),
                        session);
                es.setShareableNode(true);
                events.add(es);
            }
            for (Iterator removed = n.getRemovedShares().iterator(); removed.hasNext(); ) {
                NodeId parentId = (NodeId) removed.next();
                // if this shareable node is removed, only create events for
                // parent ids that are not primary
                if (n.getParentId().equals(parentId)) {
                    continue;
                }
View Full Code Here

        }

        // create a new node state
        VirtualNodeState state;
        if (id == null) {
            id = new NodeId(UUID.randomUUID());
        }
        state = new VirtualNodeState(this, parent.getNodeId(), id, nodeTypeName, new Name[0]);
        state.setDefinitionId(def);

        cache(state);
View Full Code Here

                throw new RepositoryException("Unable to write lock properties.");
            }
            stateMgr.edit();
            try {
                // add properties to content
                NodeId nodeId = node.getNodeId();
                NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);

                PropertyState propState;
                if (!nodeState.hasPropertyName(NameConstants.JCR_LOCKOWNER)) {
                    PropDef def = helper.findApplicablePropertyDefinition(NameConstants.JCR_LOCKOWNER, PropertyType.STRING, false, nodeState);
View Full Code Here

        UpdatableItemStateManager stateMgr = wsp.getItemStateManager();

        synchronized (stateMgr) {
            try {
                // add properties to content
                NodeId nodeId = node.getNodeId();
                NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);

                if (stateMgr.inEditMode()) {
                    throw new RepositoryException("Unable to remove lock properties.");
                }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.NodeId

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.