Search in sources :

Example 6 with ItemId

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

the class ItemInfoCacheImpl method put.

/**
 * This implementation cached the item by its id and if the id
 * is uuid based but has no path, also by its path.
 */
public void put(ItemInfo info, long generation) {
    ItemId id = info.getId();
    Entry<? extends ItemInfo> entry = info.denotesNode() ? new Entry<NodeInfo>((NodeInfo) info, generation) : new Entry<PropertyInfo>((PropertyInfo) info, generation);
    put(id, entry);
    if (id.getUniqueID() != null && id.getPath() == null) {
        put(info.getPath(), entry);
    }
}
Also used : NodeInfo(org.apache.jackrabbit.spi.NodeInfo) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) ItemId(org.apache.jackrabbit.spi.ItemId)

Example 7 with ItemId

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

the class JcrVersionManager method removeActivity.

/**
 * @see javax.jcr.version.VersionManager#removeActivity(Node)
 */
public void removeActivity(Node activityNode) throws UnsupportedRepositoryOperationException, RepositoryException {
    session.checkIsAlive();
    NodeImpl activity = getValidActivity(activityNode, "remove");
    NodeState nState = (NodeState) activity.getItemState();
    ItemId removeId = nState.getId();
    vMgr.removeActivity(nState);
    // setting on this session, that points to the removed activity.
    if (activityId != null && activityId.equals(removeId)) {
        activityId = null;
    }
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ItemId(org.apache.jackrabbit.spi.ItemId)

Example 8 with ItemId

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

the class SerializationTest method checkSerializable.

private void checkSerializable(ItemId id) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(out);
    oos.writeObject(id);
    oos.close();
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(in);
    ItemId clone = (ItemId) ois.readObject();
    assertEquals("Deserialized ItemId not equal to original", id, clone);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ItemId(org.apache.jackrabbit.spi.ItemId) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with ItemId

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

the class EventFactory method fromJCREvent.

public Event fromJCREvent(javax.jcr.observation.Event e) throws RepositoryException {
    Path p = e.getPath() != null ? resolver.getQPath(e.getPath()) : null;
    Path parent = p != null ? p.getAncestor(1) : null;
    int type = e.getType();
    NodeId parentId = parent != null ? idFactory.createNodeId((String) null, parent) : null;
    String identifier = e.getIdentifier();
    ItemId itemId;
    Node node = null;
    if (identifier != null) {
        itemId = idFactory.fromJcrIdentifier(e.getIdentifier());
        try {
            node = session.getItem(e.getPath()).getParent();
        } catch (RepositoryException re) {
        // ignore. TODO improve
        }
    } else {
        switch(type) {
            case Event.NODE_ADDED:
            case Event.NODE_MOVED:
                node = session.getItem(e.getPath()).getParent();
            case Event.NODE_REMOVED:
                itemId = idFactory.createNodeId((String) null, p);
                break;
            case Event.PROPERTY_ADDED:
            case Event.PROPERTY_CHANGED:
                node = session.getItem(e.getPath()).getParent();
            case Event.PROPERTY_REMOVED:
                itemId = idFactory.createPropertyId(parentId, p.getName());
                break;
            case Event.PERSIST:
            default:
                itemId = null;
        }
    }
    Name nodeTypeName = null;
    Name[] mixinTypes = Name.EMPTY_ARRAY;
    if (node != null) {
        try {
            parentId = idFactory.createNodeId(node.getUUID(), null);
        } catch (UnsupportedRepositoryOperationException ex) {
        // not referenceable
        }
        nodeTypeName = resolver.getQName(node.getPrimaryNodeType().getName());
        mixinTypes = getNodeTypeNames(node.getMixinNodeTypes(), resolver);
    }
    Map<Name, QValue> info = new HashMap<Name, QValue>();
    Map<String, Object> jcrInfo = e.getInfo();
    for (Map.Entry<String, Object> entry : jcrInfo.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        Name name = resolver.getQName(key);
        if (value != null) {
            // event information is generated for NODE_MOVED only in which
            // case all values are of type PATH.
            QValue v = ValueFormat.getQValue(value.toString(), PropertyType.PATH, resolver, qValueFactory);
            info.put(name, v);
        } else {
            info.put(name, null);
        }
    }
    return new EventImpl(e.getType(), p, itemId, parentId, nodeTypeName, mixinTypes, e.getUserID(), e.getUserData(), e.getDate(), info);
}
Also used : Path(org.apache.jackrabbit.spi.Path) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) QValue(org.apache.jackrabbit.spi.QValue) HashMap(java.util.HashMap) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) ItemId(org.apache.jackrabbit.spi.ItemId) Name(org.apache.jackrabbit.spi.Name) EventImpl(org.apache.jackrabbit.spi.commons.EventImpl) NodeId(org.apache.jackrabbit.spi.NodeId) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with ItemId

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

the class NodeEntryImpl method refresh.

/**
 * @see NodeEntry#refresh(Event)
 */
public void refresh(Event childEvent) {
    ItemId eventId = childEvent.getItemId();
    Path eventPath = childEvent.getPath();
    Name eventName = eventPath.getName();
    HierarchyEntry child = eventId == null ? null : lookupEntry(eventId, eventPath);
    switch(childEvent.getType()) {
        case Event.NODE_ADDED:
        case Event.PROPERTY_ADDED:
            if (child == null || child.getStatus() == Status.REMOVED) {
                // removed already -> add the new entry.
                if (childEvent.getType() == Event.NODE_ADDED) {
                    String uniqueChildID = (eventId.getPath() == null) ? eventId.getUniqueID() : null;
                    int index = eventPath.getNormalizedIndex();
                    internalAddNodeEntry(eventName, uniqueChildID, index);
                } else {
                    internalAddPropertyEntry(eventName, true);
                }
            } else {
                // item already present
                int status = child.getStatus();
                if (Status.NEW == status) {
                    // event conflicts with a transiently added item on this
                    // node entry -> mark the parent node (this) stale.
                    internalGetItemState().setStatus(Status.MODIFIED);
                }
            // else: child already added -> ignore
            }
            break;
        case Event.NODE_REMOVED:
        case Event.PROPERTY_REMOVED:
            if (child != null) {
                int status = child.getStatus();
                if (Status.EXISTING_REMOVED == status) {
                    // colliding item removal -> mark parent stale
                    internalGetItemState().setStatus(Status.MODIFIED);
                }
                child.remove();
            }
            // else: child-Entry has not been loaded yet -> ignore
            break;
        case Event.PROPERTY_CHANGED:
            if (child == null) {
                // prop-Entry has not been loaded yet -> add propEntry
                internalAddPropertyEntry(eventName, true);
            } else if (child.isAvailable()) {
                int status = child.getStatus();
                // modified and merge fails it must be marked STALE afterwards.
                if (Status.isStale(status)) {
                // ignore. nothing to do.
                } else if (Status.isTransient(child.getStatus())) {
                    // pending changes -> don't reload entry but rather
                    // mark it stale
                    ((HierarchyEntryImpl) child).internalGetItemState().setStatus(Status.MODIFIED);
                } else {
                    // no pending changes -> invalidate and force reload
                    // upon next access.
                    child.invalidate(false);
                    // parent (i.e. this NodeEntry)
                    if (StateUtility.isUuidOrMixin(eventName)) {
                        notifyUUIDorMIXINModified((PropertyEntry) child);
                    }
                }
            }
            // else: existing entry but state not yet built -> ignore 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");
        default:
            // ILLEGAL
            throw new IllegalArgumentException("Illegal event type " + childEvent.getType() + " for NodeState.");
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) ItemId(org.apache.jackrabbit.spi.ItemId) Name(org.apache.jackrabbit.spi.Name)

Aggregations

ItemId (org.apache.jackrabbit.spi.ItemId)12 RepositoryException (javax.jcr.RepositoryException)7 NodeId (org.apache.jackrabbit.spi.NodeId)5 Path (org.apache.jackrabbit.spi.Path)5 Name (org.apache.jackrabbit.spi.Name)4 IOException (java.io.IOException)2 ItemNotFoundException (javax.jcr.ItemNotFoundException)2 HttpResponse (org.apache.http.HttpResponse)2 Event (org.apache.jackrabbit.spi.Event)2 PropertyId (org.apache.jackrabbit.spi.PropertyId)2 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)2 DavException (org.apache.jackrabbit.webdav.DavException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1