* @param includeInvalidNodes
* @return a node, if found, or null if not.
*/
private WorkspaceNode fetchWorkspaceNode(InvocationContext ctx, Fqn fqn, TransactionWorkspace workspace, boolean undeleteIfNecessary, boolean includeInvalidNodes)
{
WorkspaceNode workspaceNode = workspace.getNode(fqn);
// if we do not have the node then we need to add it to the workspace
if (workspaceNode == null)
{
NodeSPI node = dataContainer.peek(fqn, true, includeInvalidNodes);
if (node == null) return null;
GlobalTransaction gtx = ctx.getGlobalTransaction();
workspaceNode = lockAndCreateWorkspaceNode(nodeFactory, node, workspace, gtx, lockAcquisitionTimeout);
// and add the node to the workspace.
workspace.addNode(workspaceNode);
}
// Check that the workspace node has been marked as deleted.
if (workspaceNode.isDeleted())
{
if (trace) log.trace("Node " + fqn + " has been deleted in the workspace.");
if (undeleteIfNecessary)
{
undeleteWorkspaceNode(workspaceNode, fetchWorkspaceNode(ctx, fqn.getParent(), workspace, undeleteIfNecessary, includeInvalidNodes));
}
else if (!includeInvalidNodes)
{
// don't return deleted nodes if undeleteIfNecessary is false!
workspaceNode = null;
}
}
// set implicit node versioning flag.
if (workspaceNode != null && !(workspaceNode.getVersion() instanceof DefaultDataVersion))
{
workspaceNode.setVersioningImplicit(false);
}
// now make sure all parents are in the wsp as well
if (workspaceNode != null && !fqn.isRoot())
fetchWorkspaceNode(ctx, fqn.getParent(), workspace, false, includeInvalidNodes);