Search in sources :

Example 1 with NodeId

use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.

the class NodeEntryImpl method getDeepPropertyEntry.

/**
 * @see NodeEntry#getDeepPropertyEntry(Path)
 */
public PropertyEntry getDeepPropertyEntry(Path path) throws PathNotFoundException, RepositoryException {
    NodeEntryImpl entry = this;
    Path.Element[] elems = path.getElements();
    int i = 0;
    for (; i < elems.length - 1; i++) {
        Path.Element elem = elems[i];
        if (elems[i].denotesRoot()) {
            if (entry.getParent() != null) {
                throw new RepositoryException("NodeEntry out of 'hierarchy' " + path.toString());
            }
            continue;
        }
        int index = elem.getNormalizedIndex();
        Name name = elem.getName();
        // first try to resolve to known node or property entry
        NodeEntry cne = entry.getNodeEntry(name, index, false);
        if (cne != null) {
            entry = (NodeEntryImpl) cne;
        } else {
            // on the persistent layer.
            if (entry.childNodeEntries.isComplete()) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // -> check for moved child entry in node-attic
            // -> check if child points to a removed/moved sns
            List<NodeEntry> siblings = entry.childNodeEntries.get(name);
            if (entry.containsAtticChild(siblings, name, index)) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // break out of the loop and start deep loading the property
            break;
        }
    }
    int st = entry.getStatus();
    PropertyEntry pe;
    if (i == elems.length - 1 && Status.INVALIDATED != st && Status._UNDEFINED_ != st) {
        // all node entries present in the hierarchy and the direct ancestor
        // has already been resolved and isn't invalidated -> no need to
        // retrieve property entry from SPI
        pe = entry.properties.get(path.getName());
    } else {
        /*
            * Unknown parent entry (not-existing or not yet loaded) or a parent
            * entry that has been invalidated:
            * Skip all intermediate entries and directly try to load the
            * PropertyState (including building the intermediate entries. If that
            * fails ItemNotFoundException is thrown.
            */
        PathBuilder pb = new PathBuilder(getPathFactory());
        for (int j = i; j < elems.length; j++) {
            pb.addLast(elems[j]);
        }
        Path remainingPath = pb.getPath();
        IdFactory idFactory = getIdFactory();
        NodeId parentId = entry.getWorkspaceId();
        if (remainingPath.getLength() != 1) {
            parentId = idFactory.createNodeId(parentId, remainingPath.getAncestor(1));
        }
        PropertyId propId = idFactory.createPropertyId(parentId, remainingPath.getName());
        pe = entry.loadPropertyEntry(propId);
    }
    if (pe == null) {
        throw new PathNotFoundException(factory.saveGetJCRPath(path));
    }
    return pe;
}
Also used : Path(org.apache.jackrabbit.spi.Path) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) IdFactory(org.apache.jackrabbit.spi.IdFactory) NodeId(org.apache.jackrabbit.spi.NodeId) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 2 with NodeId

use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.

the class LockManagerImpl method buildLockState.

private LockState buildLockState(NodeState nodeState) throws RepositoryException {
    NodeId nId = nodeState.getNodeId();
    NodeState lockHoldingState;
    LockInfo lockInfo = wspManager.getLockInfo(nId);
    if (lockInfo == null) {
        // no lock present
        return null;
    }
    NodeId lockNodeId = lockInfo.getNodeId();
    if (lockNodeId.equals(nId)) {
        lockHoldingState = nodeState;
    } else {
        NodeEntry lockedEntry = wspManager.getHierarchyManager().getNodeEntry(lockNodeId);
        try {
            lockHoldingState = lockedEntry.getNodeState();
        } catch (RepositoryException e) {
            log.warn("Cannot build LockState");
            throw new RepositoryException("Cannot build LockState", e);
        }
    }
    if (lockHoldingState == null) {
        return null;
    } else {
        return new LockState(lockHoldingState, lockInfo);
    }
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) NodeId(org.apache.jackrabbit.spi.NodeId) LockInfo(org.apache.jackrabbit.spi.LockInfo) RepositoryException(javax.jcr.RepositoryException)

Example 3 with NodeId

use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.

the class ChildNodeEntriesImpl method reload.

/**
 * @see ChildNodeEntries#reload()
 */
public synchronized void reload() throws ItemNotFoundException, RepositoryException {
    if (isComplete()) {
        // nothing to do
        return;
    }
    NodeId id = parent.getWorkspaceId();
    Iterator<ChildInfo> childNodeInfos = factory.getItemStateFactory().getChildNodeInfos(id);
    update(childNodeInfos);
}
Also used : NodeId(org.apache.jackrabbit.spi.NodeId) ChildInfo(org.apache.jackrabbit.spi.ChildInfo)

Example 4 with NodeId

use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.

the class HierarchyEventListener method pushEvents.

/**
 * Retrieve the workspace state(s) affected by the given event and refresh
 * them accordingly.
 *
 * @param events the events to process.
 */
private void pushEvents(Collection<Event> events) {
    if (events.isEmpty()) {
        log.debug("Empty event bundle");
        return;
    }
    // TODO: handle new 283 event types and clean add/remove that is also present as move-event.
    // collect set of removed node ids
    Set<ItemId> removedEvents = new HashSet<ItemId>();
    // separately collect the add events
    Set<Event> addEvents = new HashSet<Event>();
    for (Iterator<Event> it = events.iterator(); it.hasNext(); ) {
        Event event = it.next();
        int type = event.getType();
        if (type == Event.NODE_REMOVED) {
            // remember removed nodes separately for proper handling later on.
            removedEvents.add(event.getItemId());
        } else if (type == Event.NODE_ADDED || type == Event.PROPERTY_ADDED) {
            addEvents.add(event);
            it.remove();
        }
    }
    /* Process ADD-events.
           In case of persisting transients modifications, the event-set may
           still contain events that are not covered by the changeLog such as
           new version-history or other autocreated properties and nodes.

           Add events need to be processed hierarchically, since its not possible
           to add a new child reference to a state that is not yet present in
           the state manager.
           The 'progress' flag is used to make sure, that during each loop at
           least one event has been processed and removed from the iterator.
           If this is not the case, there are not parent states present in the
           state manager that need to be updated and the remaining events may
           be ignored.
         */
    boolean progress = true;
    while (!addEvents.isEmpty() && progress) {
        progress = false;
        for (Iterator<Event> it = addEvents.iterator(); it.hasNext(); ) {
            Event ev = it.next();
            NodeId parentId = ev.getParentId();
            HierarchyEntry parent = null;
            if (parentId != null) {
                parent = hierarchyMgr.lookup(parentId);
                if (parent == null && ev.getPath() != null && parentId.getUniqueID() != null) {
                    // the parent by path.
                    try {
                        Path parentPath = ev.getPath().getAncestor(1);
                        parent = hierarchyMgr.lookup(parentPath);
                    } catch (RepositoryException e) {
                        // should not occur
                        log.debug(e.getMessage());
                    }
                }
            }
            if (parent != null && parent.denotesNode()) {
                ((NodeEntry) parent).refresh(ev);
                it.remove();
                progress = true;
            }
        }
    }
    /* process all other events (removal, property changed) */
    for (Event event : events) {
        int type = event.getType();
        NodeId parentId = event.getParentId();
        NodeEntry parent = (parentId != null) ? (NodeEntry) hierarchyMgr.lookup(parentId) : null;
        switch(type) {
            case Event.NODE_REMOVED:
            case Event.PROPERTY_REMOVED:
                // only remove the parent an skip this event.
                if (parent != null && !removedEvents.contains(parentId)) {
                    parent.refresh(event);
                }
                break;
            case Event.PROPERTY_CHANGED:
                // not exist either -> no need to inform propEntry
                if (parent != null) {
                    parent.refresh(event);
                }
                break;
            case Event.NODE_MOVED:
                // TODO: implementation missing
                throw new UnsupportedOperationException("Implementation missing");
            // break;
            case Event.PERSIST:
                // TODO: implementation missing
                throw new UnsupportedOperationException("Implementation missing");
            // break;
            default:
                // should never occur
                throw new IllegalArgumentException("Invalid event type: " + event.getType());
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) RepositoryException(javax.jcr.RepositoryException) ItemId(org.apache.jackrabbit.spi.ItemId) NodeId(org.apache.jackrabbit.spi.NodeId) Event(org.apache.jackrabbit.spi.Event) HashSet(java.util.HashSet)

Example 5 with NodeId

use of org.apache.jackrabbit.spi.NodeId in project jackrabbit by apache.

the class VersionManagerImpl method getVersionHistoryEntry.

public NodeEntry getVersionHistoryEntry(NodeState versionableState) throws RepositoryException {
    PropertyState ps = versionableState.getPropertyState(NameConstants.JCR_VERSIONHISTORY);
    String uniqueID = ps.getValue().getString();
    NodeId vhId = workspaceManager.getIdFactory().createNodeId(uniqueID);
    return workspaceManager.getHierarchyManager().getNodeEntry(vhId);
}
Also used : NodeId(org.apache.jackrabbit.spi.NodeId) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState)

Aggregations

NodeId (org.apache.jackrabbit.spi.NodeId)80 Batch (org.apache.jackrabbit.spi.Batch)35 Name (org.apache.jackrabbit.spi.Name)32 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)23 RepositoryException (javax.jcr.RepositoryException)21 QValue (org.apache.jackrabbit.spi.QValue)21 PropertyId (org.apache.jackrabbit.spi.PropertyId)13 Path (org.apache.jackrabbit.spi.Path)11 NodeInfo (org.apache.jackrabbit.spi.NodeInfo)10 ArrayList (java.util.ArrayList)9 ItemNotFoundException (javax.jcr.ItemNotFoundException)9 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)9 IOException (java.io.IOException)6 Node (javax.jcr.Node)5 HttpResponse (org.apache.http.HttpResponse)5 ItemId (org.apache.jackrabbit.spi.ItemId)5 DavException (org.apache.jackrabbit.webdav.DavException)5 InputStream (java.io.InputStream)4 ChildInfo (org.apache.jackrabbit.spi.ChildInfo)4 PathNotFoundException (javax.jcr.PathNotFoundException)3