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);
}
}
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;
}
}
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);
}
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);
}
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.");
}
}
Aggregations