use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class BatchedItemOperations method recursiveRemoveNodeState.
//------------------------------------------------------< private methods >
/**
* Recursively removes the given node state including its properties and
* child nodes.
* <p>
* The removal of child nodes is subject to the following checks:
* access rights, locking & versioning status. Referential integrity
* (references) is checked on commit.
* <p>
* Note that the child node entry refering to <code>targetState</code> is
* <b><i>not</i></b> automatically removed from <code>targetState</code>'s
* parent.
*
* @param targetState
* @throws RepositoryException if an error occurs
*/
private void recursiveRemoveNodeState(NodeState targetState) throws RepositoryException {
if (targetState.hasChildNodeEntries()) {
// remove child nodes
// use temp array to avoid ConcurrentModificationException
ArrayList<ChildNodeEntry> tmp = new ArrayList<ChildNodeEntry>(targetState.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);
NodeId nodeId = entry.getId();
try {
NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
// check if child node can be removed
// (access rights, locking & versioning status as well
// as retention and hold);
// referential integrity (references) is checked
// on commit
checkRemoveNode(nodeState, targetState.getNodeId(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_HOLD | CHECK_RETENTION);
// remove child node
recursiveRemoveNodeState(nodeState);
} catch (ItemStateException ise) {
String msg = "internal error: failed to retrieve state of " + nodeId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
// remove child node entry
targetState.removeChildNodeEntry(entry.getName(), entry.getIndex());
}
}
// remove properties
// use temp set to avoid ConcurrentModificationException
HashSet<Name> tmp = new HashSet<Name>(targetState.getPropertyNames());
for (Name propName : tmp) {
PropertyId propId = new PropertyId(targetState.getNodeId(), propName);
try {
PropertyState propState = (PropertyState) stateMgr.getItemState(propId);
// remove property entry
targetState.removePropertyName(propId.getName());
// destroy property state
stateMgr.destroy(propState);
} catch (ItemStateException ise) {
String msg = "internal error: failed to retrieve state of " + propId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
// now actually do unlink target state
targetState.setParentId(null);
// destroy target state (pass overlayed state since target state
// might have been modified during unlinking)
stateMgr.destroy(targetState.getOverlayedState());
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class HierarchyManagerImpl method getName.
/**
* {@inheritDoc}
*/
public Name getName(NodeId id, NodeId parentId) throws ItemNotFoundException, RepositoryException {
NodeState parentState;
try {
parentState = (NodeState) getItemState(parentId);
} catch (NoSuchItemStateException nsis) {
String msg = "failed to resolve name of " + id;
log.debug(msg);
throw new ItemNotFoundException(id.toString());
} catch (ItemStateException ise) {
String msg = "failed to resolve name of " + id;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
ChildNodeEntry entry = getChildNodeEntry(parentState, id);
if (entry == null) {
String msg = "failed to resolve name of " + id;
log.debug(msg);
throw new ItemNotFoundException(msg);
}
return entry.getName();
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class HierarchyManagerImpl method getName.
/**
* {@inheritDoc}
*/
public Name getName(ItemId itemId) throws ItemNotFoundException, RepositoryException {
if (itemId.denotesNode()) {
NodeId nodeId = (NodeId) itemId;
try {
NodeState nodeState = (NodeState) getItemState(nodeId);
NodeId parentId = getParentId(nodeState);
if (parentId == null) {
// FIXME
return EMPTY_NAME;
}
return getName(nodeId, parentId);
} catch (NoSuchItemStateException nsis) {
String msg = "failed to resolve name of " + nodeId;
log.debug(msg);
throw new ItemNotFoundException(nodeId.toString());
} catch (ItemStateException ise) {
String msg = "failed to resolve name of " + nodeId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
} else {
return ((PropertyId) itemId).getName();
}
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class ItemSaveOperation method processShareableNodes.
/**
* Process all items given in iterator and check whether <code>mix:shareable</code>
* or (some derived node type) has been added or removed:
* <ul>
* <li>If the mixin <code>mix:shareable</code> (or some derived node type),
* then initialize the shared set inside the state.</li>
* <li>If the mixin <code>mix:shareable</code> (or some derived node type)
* has been removed, throw.</li>
* </ul>
*/
private void processShareableNodes(NodeTypeRegistry registry, Iterable<ItemState> states) throws RepositoryException {
for (ItemState is : states) {
if (is.isNode()) {
NodeState ns = (NodeState) is;
boolean wasShareable = false;
if (ns.hasOverlayedState()) {
NodeState old = (NodeState) ns.getOverlayedState();
EffectiveNodeType ntOld = getEffectiveNodeType(registry, old);
wasShareable = ntOld.includesNodeType(NameConstants.MIX_SHAREABLE);
}
EffectiveNodeType ntNew = getEffectiveNodeType(registry, ns);
boolean isShareable = ntNew.includesNodeType(NameConstants.MIX_SHAREABLE);
if (!wasShareable && isShareable) {
// mix:shareable has been added
ns.addShare(ns.getParentId());
} else if (wasShareable && !isShareable) {
// mix:shareable has been removed: not supported
String msg = "Removing mix:shareable is not supported.";
log.debug(msg);
throw new UnsupportedRepositoryOperationException(msg);
}
}
}
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class ItemSaveOperation method initVersionHistories.
/**
* Initialises the version history of all new nodes of node type
* <code>mix:versionable</code>.
*
* @param states
* @return true if this call generated new transient state; otherwise false
* @throws RepositoryException
*/
private boolean initVersionHistories(SessionContext context, Iterable<ItemState> states) throws RepositoryException {
SessionImpl session = context.getSessionImpl();
ItemManager itemMgr = context.getItemManager();
// walk through list of transient items and search for new versionable nodes
boolean createdTransientState = false;
for (ItemState itemState : states) {
if (itemState.isNode()) {
NodeState nodeState = (NodeState) itemState;
EffectiveNodeType nt = getEffectiveNodeType(context.getRepositoryContext().getNodeTypeRegistry(), nodeState);
if (nt.includesNodeType(NameConstants.MIX_VERSIONABLE)) {
if (!nodeState.hasPropertyName(NameConstants.JCR_VERSIONHISTORY)) {
NodeImpl node = (NodeImpl) itemMgr.getItem(itemState.getId(), false);
InternalVersionManager vMgr = session.getInternalVersionManager();
/**
* check if there's already a version history for that
* node; this would e.g. be the case if a versionable
* node had been exported, removed and re-imported with
* either IMPORT_UUID_COLLISION_REMOVE_EXISTING or
* IMPORT_UUID_COLLISION_REPLACE_EXISTING;
* otherwise create a new version history
*/
VersionHistoryInfo history = vMgr.getVersionHistory(session, nodeState, null);
InternalValue historyId = InternalValue.create(history.getVersionHistoryId());
InternalValue versionId = InternalValue.create(history.getRootVersionId());
node.internalSetProperty(NameConstants.JCR_VERSIONHISTORY, historyId);
node.internalSetProperty(NameConstants.JCR_BASEVERSION, versionId);
node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
node.internalSetProperty(NameConstants.JCR_PREDECESSORS, new InternalValue[] { versionId });
createdTransientState = true;
}
} else if (nt.includesNodeType(NameConstants.MIX_SIMPLE_VERSIONABLE)) {
// we need to check the version manager for an existing
// version history, since simple versioning does not
// expose it's reference in a property
InternalVersionManager vMgr = session.getInternalVersionManager();
vMgr.getVersionHistory(session, nodeState, null);
// create isCheckedOutProperty if not already exists
NodeImpl node = (NodeImpl) itemMgr.getItem(itemState.getId(), false);
if (!nodeState.hasPropertyName(NameConstants.JCR_ISCHECKEDOUT)) {
node.internalSetProperty(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(true));
createdTransientState = true;
}
}
}
}
return createdTransientState;
}
Aggregations