use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class WorkspaceImporter method startNode.
/**
* {@inheritDoc}
*/
public void startNode(NodeInfo nodeInfo, List<PropInfo> propInfos) throws RepositoryException {
if (aborted) {
// the import has been aborted, get outta here...
return;
}
boolean succeeded = false;
NodeState parent;
try {
// check sanity of workspace/session first
wsp.sanityCheck();
parent = parents.peek();
// process node
NodeState node = null;
NodeId id = nodeInfo.getId();
Name nodeName = nodeInfo.getName();
Name ntName = nodeInfo.getNodeTypeName();
Name[] mixins = nodeInfo.getMixinNames();
if (parent == null) {
// parent node was skipped, skip this child node too
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping node " + nodeName);
return;
}
if (parent.hasChildNodeEntry(nodeName)) {
// a node with that name already exists...
ChildNodeEntry entry = parent.getChildNodeEntry(nodeName, 1);
NodeId idExisting = entry.getId();
NodeState existing = (NodeState) itemOps.getItemState(idExisting);
QNodeDefinition def = itemOps.findApplicableNodeDefinition(nodeName, existing.getNodeTypeName(), parent);
if (!def.allowsSameNameSiblings()) {
// existing doesn't allow same-name siblings,
// check for potential conflicts
EffectiveNodeType entExisting = itemOps.getEffectiveNodeType(existing);
if (def.isProtected() && entExisting.includesNodeType(ntName)) {
// skip protected node
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping protected node " + itemOps.safeGetJCRPath(existing.getNodeId()));
return;
}
if (def.isAutoCreated() && entExisting.includesNodeType(ntName)) {
// this node has already been auto-created,
// no need to create it
node = existing;
} else {
// (see http://issues.apache.org/jira/browse/JCR-1128)
if (!(idExisting.equals(id) && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))) {
throw new ItemExistsException(itemOps.safeGetJCRPath(existing.getNodeId()));
}
// fall through
}
}
}
if (node == null) {
// there's no node with that name...
if (id == null) {
// no potential uuid conflict, always create new node
QNodeDefinition def = itemOps.findApplicableNodeDefinition(nodeName, ntName, parent);
if (def.isProtected()) {
// skip protected node
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping protected node " + nodeName);
return;
}
// check if new node can be added (check access rights &
// node type constraints only, assume locking & versioning status
// and retention/hold has already been checked on ancestor)
itemOps.checkAddNode(parent, nodeName, ntName, BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_CONSTRAINTS);
// do create new node
node = itemOps.createNodeState(parent, nodeName, ntName, mixins, null, def);
} else {
// potential uuid conflict
try {
NodeState conflicting = itemOps.getNodeState(id);
// resolve uuid conflict
node = resolveUUIDConflict(parent, conflicting, nodeInfo);
if (node == null) {
// no new node has been created, so skip this node
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping existing node: " + nodeName);
return;
}
} catch (ItemNotFoundException e) {
// create new with given uuid
QNodeDefinition def = itemOps.findApplicableNodeDefinition(nodeName, ntName, parent);
if (def.isProtected()) {
// skip protected node
// push null onto stack for skipped node
parents.push(null);
succeeded = true;
log.debug("skipping protected node " + nodeName);
return;
}
// check if new node can be added (check access rights &
// node type constraints only, assume locking & versioning status
// and retention/hold has already been checked on ancestor)
itemOps.checkAddNode(parent, nodeName, ntName, BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_CONSTRAINTS);
// do create new node
node = itemOps.createNodeState(parent, nodeName, ntName, mixins, id, def);
}
}
}
// process properties
for (PropInfo propInfo : propInfos) {
processProperty(node, propInfo);
}
// store affected nodes
itemOps.store(node);
itemOps.store(parent);
// push current node onto stack of parents
parents.push(node);
succeeded = true;
} finally {
if (!succeeded) {
// update operation failed, cancel all modifications
aborted = true;
itemOps.cancel();
}
}
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class NodeStateEx method store.
/**
* stores the given persistent state recursively
*
* @param state node state to store
* @throws ItemStateException if an error occurs
*/
private void store(NodeState state, boolean recursively) throws ItemStateException {
if (state.getStatus() != ItemState.STATUS_EXISTING) {
// first store all transient properties
for (Name propName : state.getPropertyNames()) {
PropertyState pstate = (PropertyState) stateMgr.getItemState(new PropertyId(state.getNodeId(), propName));
if (pstate.getStatus() != ItemState.STATUS_EXISTING) {
stateMgr.store(pstate);
}
}
if (recursively) {
// now store all child node entries
for (ChildNodeEntry entry : state.getChildNodeEntries()) {
NodeState nstate = (NodeState) stateMgr.getItemState(entry.getId());
store(nstate, true);
}
}
// and store itself
stateMgr.store(state);
}
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class NodeStateEx method createChildNode.
/**
* creates a new child node
*
* @param name name
* @param nodeTypeName node type name
* @param id id
* @return the newly created node.
* @throws RepositoryException if an error occurs
*/
private NodeStateEx createChildNode(Name name, Name nodeTypeName, NodeId id) throws RepositoryException {
NodeId parentId = nodeState.getNodeId();
// create a new node state
NodeState state = stateMgr.createNew(id, nodeTypeName, parentId);
// create Node instance wrapping new node state
NodeStateEx node = new NodeStateEx(stateMgr, ntReg, state, name);
node.setPropertyValue(NameConstants.JCR_PRIMARYTYPE, InternalValue.create(nodeTypeName));
// add new child node entry
nodeState.addChildNodeEntry(name, state.getNodeId());
if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
}
return node;
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class NodeStateEx method reload.
/**
* reloads the given persistent state recursively
*
* @param state node state
* @throws ItemStateException if an error occurs
*/
private void reload(NodeState state) throws ItemStateException {
if (state.getStatus() != ItemState.STATUS_EXISTING) {
// first discard all all transient properties
for (Name propName : state.getPropertyNames()) {
PropertyState pstate = (PropertyState) stateMgr.getItemState(new PropertyId(state.getNodeId(), propName));
if (pstate.getStatus() != ItemState.STATUS_EXISTING) {
pstate.discard();
}
}
// now reload all child node entries
for (ChildNodeEntry entry : state.getChildNodeEntries()) {
NodeState nstate = (NodeState) stateMgr.getItemState(entry.getId());
reload(nstate);
}
// and reload itself
state.discard();
}
}
use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.
the class NodeStateEx method getChildNodes.
/**
* returns all child nodes
*
* @return the child nodes.
* @throws RepositoryException if an error occurs
*/
public NodeStateEx[] getChildNodes() throws RepositoryException {
try {
List<ChildNodeEntry> entries = nodeState.getChildNodeEntries();
NodeStateEx[] children = new NodeStateEx[entries.size()];
int i = 0;
for (ChildNodeEntry entry : entries) {
NodeState state = (NodeState) stateMgr.getItemState(entry.getId());
children[i++] = new NodeStateEx(stateMgr, ntReg, state, entry.getName());
}
return children;
} catch (ItemStateException e) {
throw new RepositoryException(e);
}
}
Aggregations