Package org.apache.jackrabbit.core.state

Examples of org.apache.jackrabbit.core.state.ChildNodeEntry


            throws ItemStateException, RepositoryException {
        doc.add(new Field(
                FieldNames.PARENT, parentId.toString(),
                Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
        NodeState parent = (NodeState) stateProvider.getItemState(parentId);
        ChildNodeEntry child = parent.getChildNodeEntry(node.getNodeId());
        if (child == null) {
            // this can only happen when jackrabbit
            // is running in a cluster.
            throw new RepositoryException(
                    "Missing child node entry for node with id: "
                    + node.getNodeId());
        }
        Name name = child.getName();
        addNodeName(doc, name.getNamespaceURI(), name.getLocalName());
    }
View Full Code Here


     *                             relative path
     */
    private NodeId getNodeId(Path p) throws RepositoryException {
        if (p.getLength() == 1 && p.denotesName()) {
            // check if node entry exists
            ChildNodeEntry cne = data.getNodeState().getChildNodeEntry(
                    p.getName(), p.getNormalizedIndex());
            if (cne != null) {
                return cne.getId();
            } else {
                return null; // there's no child node with that name
            }
        } else {
            // build and resolve absolute path
View Full Code Here

    }

    protected void removeChildNode(NodeId childId) throws RepositoryException {
        // modify the state of 'this', i.e. the parent node
        NodeState thisState = (NodeState) getOrCreateTransientItemState();
        ChildNodeEntry entry =
                thisState.getChildNodeEntry(childId);
        if (entry == null) {
            String msg = "failed to remove child " + childId + " of " + this;
            log.debug(msg);
            throw new RepositoryException(msg);
View Full Code Here

            // remove child nodes
            // use temp array to avoid ConcurrentModificationException
            ArrayList<ChildNodeEntry> tmp = new ArrayList<ChildNodeEntry>(thisState.getChildNodeEntries());
            // remove from tail to avoid problems with same-name siblings
            for (int i = tmp.size() - 1; i >= 0; i--) {
                ChildNodeEntry entry =
                        tmp.get(i);
                // recursively remove child node
                NodeId childId = entry.getId();
                //NodeImpl childNode = (NodeImpl) itemMgr.getItem(childId);
                try {
                    NodeImpl childNode = itemMgr.getNode(childId, getNodeId());
                    childNode.onRemove(thisState.getNodeId());
                    // remove the child node entry
                } catch (ItemNotFoundException e) {
                    boolean ignoreError = false;
                    if (parentId != null && sessionContext.getSessionImpl().autoFixCorruptions()) {
                        // it might be an access right problem
                        // we need to check if the item doesn't exist in the ism
                        ItemStateManager ism = sessionContext.getItemStateManager();
                        if (!ism.hasItemState(childId)) {
                            log.warn("Child named " + entry.getName() + " (index " + entry.getIndex() + ", " +
                                    "node id " + childId + ") " +
                                    "not found when trying to remove " + getPath() + " " +
                                    "(node id " + getNodeId() + ") - ignored", e);
                            ignoreError = true;
                        }
View Full Code Here

    public NodeImpl getNode(final Name name, final int index)
            throws ItemNotFoundException, RepositoryException {
        return perform(new SessionOperation<NodeImpl>() {
            public NodeImpl perform(SessionContext context)
                    throws RepositoryException {
                ChildNodeEntry cne = data.getNodeState().getChildNodeEntry(
                        name, index != 0 ? index : 1);
                if (cne != null) {
                    try {
                        return context.getItemManager().getNode(
                                cne.getId(), getNodeId());
                    } catch (AccessDeniedException e) {
                        throw new ItemNotFoundException();
                    }
                } else {
                    throw new ItemNotFoundException();
View Full Code Here

    public boolean hasNode(final Name name, final int index)
            throws RepositoryException {
        return perform(new SessionOperation<Boolean>() {
            public Boolean perform(SessionContext context)
                    throws RepositoryException {
                ChildNodeEntry cne = data.getNodeState().getChildNodeEntry(
                        name, index != 0 ? index : 1);
                return cne != null
                    && context.getItemManager().itemExists(cne.getId());
            }
            public String toString() {
                return "node.hasNode(" + name + "[" + index + "])";
            }
        });
View Full Code Here

            nt = (NodeTypeImpl) def.getDefaultPrimaryType();
        }

        // check for name collisions
        NodeState thisState = data.getNodeState();
        ChildNodeEntry cne = thisState.getChildNodeEntry(nodeName, 1);
        if (cne != null) {
            // there's already a child node entry with that name;
            // check same-name sibling setting of new node
            if (!def.allowsSameNameSiblings()) {
                throw new ItemExistsException(
                        "This node already exists: "
                        + itemMgr.safeGetJCRPath(nodePath));
            }
            // check same-name sibling setting of existing node
            NodeImpl existing = itemMgr.getNode(cne.getId(), getNodeId());
            if (!existing.getDefinition().allowsSameNameSiblings()) {
                throw new ItemExistsException(
                        "Same-name siblings not allowed for " + existing);
            }
        }
View Full Code Here

        }

        ArrayList<ChildNodeEntry> list = new ArrayList<ChildNodeEntry>(data.getNodeState().getChildNodeEntries());
        int srcInd = -1, destInd = -1;
        for (int i = 0; i < list.size(); i++) {
            ChildNodeEntry entry = list.get(i);
            if (srcInd == -1) {
                if (entry.getName().equals(srcName.getName())
                        && (entry.getIndex() == srcName.getIndex()
                        || srcName.getIndex() == 0 && entry.getIndex() == 1)) {
                    srcInd = i;
                }
            }
            if (destInd == -1 && dstName != null) {
                if (entry.getName().equals(dstName.getName())
                        && (entry.getIndex() == dstName.getIndex()
                        || dstName.getIndex() == 0 && entry.getIndex() == 1)) {
                    destInd = i;
                    if (srcInd != -1) {
                        break;
                    }
                }
View Full Code Here

        // this unfortunately changes the order of this node's
        // child node entries (JCR-1055);
        // => backup list of child node entries beforehand in order
        // to restore it afterwards
        NodeState state = data.getNodeState();
        ChildNodeEntry cneExisting = state.getChildNodeEntry(id);
        if (cneExisting == null) {
            throw new ItemNotFoundException(
                    this + ": no child node entry with id " + id);
        }
        List<ChildNodeEntry> cneList = new ArrayList<ChildNodeEntry>(state.getChildNodeEntries());

        // remove existing
        existing.remove();

        // create new child node
        NodeImpl node = addNode(nodeName, nodeTypeName, id);
        if (mixinNames != null) {
            for (Name mixinName : mixinNames) {
                node.addMixin(mixinName);
            }
        }

        // fetch <code>state</code> again, as it changed while removing child
        state = data.getNodeState();

        // restore list of child node entries (JCR-1055)
        if (cneExisting.getName().equals(nodeName)) {
            // restore original child node list
            state.setChildNodeEntries(cneList);
        } else {
            // replace child node entry with different name
            // but preserving original position
View Full Code Here

            String msg = "no definition found in parent node's node type for new node";
            log.debug(msg);
            throw new ConstraintViolationException(msg, re);
        }
        NodeState thisState = data.getNodeState();
        ChildNodeEntry cne = thisState.getChildNodeEntry(name, 1);
        if (cne != null) {
            // there's already a child node entry with that name;
            // check same-name sibling setting of new node
            if (!def.allowsSameNameSiblings()) {
                throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath));
            }
            // check same-name sibling setting of existing node
            NodeId newId = cne.getId();
            if (!((NodeImpl) itemMgr.getItem(newId)).getDefinition().allowsSameNameSiblings()) {
                throw new ItemExistsException(itemMgr.safeGetJCRPath(nodePath));
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.state.ChildNodeEntry

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.