Skip to content

Commit

Permalink
1.6: Reimplemented most of the JCR-2170 changes in the 1.6 branch.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/branches/1.6@943301 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jukka committed May 11, 2010
1 parent 43a33ff commit d00e001
Show file tree
Hide file tree
Showing 36 changed files with 283 additions and 423 deletions.
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.jackrabbit.core;

import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeDefinition;
import org.apache.jackrabbit.core.state.NodeState;

Expand All @@ -31,10 +32,10 @@ public abstract class AbstractNodeData extends ItemData {
* Create a new instance of this class.
*
* @param state node state
* @param definition node definition
* @param itemMgr item manager
*/
protected AbstractNodeData(NodeState state, NodeDefinition definition) {
super(state, definition);
protected AbstractNodeData(NodeState state, ItemManager itemMgr) {
super(state, itemMgr);

if (state.isShareable()) {
this.primaryParentId = state.getParentId();
Expand Down Expand Up @@ -64,7 +65,7 @@ public NodeState getNodeState() {
*
* @return node definition
*/
public NodeDefinition getNodeDefinition() {
public NodeDefinition getNodeDefinition() throws RepositoryException {
return (NodeDefinition) getDefinition();
}

Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.apache.jackrabbit.core.nodetype.NodeTypeConflictException;
import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
import org.apache.jackrabbit.core.nodetype.PropDef;
import org.apache.jackrabbit.core.nodetype.PropDefId;
import org.apache.jackrabbit.core.security.AccessManager;
import org.apache.jackrabbit.core.security.authorization.Permission;
import org.apache.jackrabbit.core.state.ItemState;
Expand Down Expand Up @@ -104,7 +103,9 @@ public BatchedItemOperations(UpdatableItemStateManager stateMgr,
LockManager lockMgr,
SessionImpl session,
HierarchyManager hierMgr) throws RepositoryException {
super(ntReg, hierMgr, session, lockMgr, session.getAccessManager(), session.getRetentionRegistry());
super(ntReg, hierMgr, session, lockMgr,
session.getAccessManager(), session.getRetentionRegistry(),
session.getItemManager());
this.stateMgr = stateMgr;
this.session = session;
}
Expand Down Expand Up @@ -426,12 +427,6 @@ public NodeId copy(Path srcPath,
// add to new parent
destParentState.addChildNodeEntry(destName.getName(), newState.getNodeId());

// change definition (id) of new node
NodeDef newNodeDef =
findApplicableNodeDefinition(destName.getName(),
srcState.getNodeTypeName(), destParentState);
newState.setDefinitionId(newNodeDef.getId());

// adjust references that refer to uuid's which have been mapped to
// newly generated uuid's on copy/clone
Iterator iter = refTracker.getProcessedReferences();
Expand Down Expand Up @@ -584,12 +579,6 @@ public NodeId move(Path srcPath, Path destPath)
destParent.addChildNodeEntry(destName.getName(), target.getNodeId());
}

// change definition (id) of target node
NodeDef newTargetDef =
findApplicableNodeDefinition(destName.getName(),
target.getNodeTypeName(), destParent);
target.setDefinitionId(newTargetDef.getId());

// store states
stateMgr.store(target);
if (renameOnly) {
Expand Down Expand Up @@ -720,7 +709,7 @@ public void checkAddNode(NodeState parentState, Name nodeName,
// 4. node type constraints

if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
NodeDef parentDef = ntReg.getNodeDef(parentState.getDefinitionId());
NodeDef parentDef = itemMgr.getDefinition(parentState).unwrap();
// make sure parent node is not protected
if (parentDef.isProtected()) {
throw new ConstraintViolationException(
Expand Down Expand Up @@ -752,7 +741,7 @@ public void checkAddNode(NodeState parentState, Name nodeName,
throw new RepositoryException(msg, ise);
}
NodeDef conflictingTargetDef =
ntReg.getNodeDef(conflictingState.getDefinitionId());
itemMgr.getDefinition(conflictingState).unwrap();
// check same-name sibling setting of both target and existing node
if (!conflictingTargetDef.allowsSameNameSiblings()
|| !newNodeDef.allowsSameNameSiblings()) {
Expand Down Expand Up @@ -895,12 +884,12 @@ public void checkRemoveNode(NodeState targetState, NodeId parentId,
// 4. node type constraints

if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
NodeDef parentDef = ntReg.getNodeDef(parentState.getDefinitionId());
NodeDef parentDef = itemMgr.getDefinition(parentState).unwrap();
if (parentDef.isProtected()) {
throw new ConstraintViolationException(safeGetJCRPath(parentId)
+ ": cannot remove child node of protected parent node");
}
NodeDef targetDef = ntReg.getNodeDef(targetState.getDefinitionId());
NodeDef targetDef = itemMgr.getDefinition(targetState).unwrap();
if (targetDef.isMandatory()) {
throw new ConstraintViolationException(safeGetJCRPath(targetPath)
+ ": cannot remove mandatory node");
Expand Down Expand Up @@ -1123,7 +1112,6 @@ public NodeState createNodeState(NodeState parent,
if (mixinNames != null && mixinNames.length > 0) {
node.setMixinTypeNames(new HashSet(Arrays.asList(mixinNames)));
}
node.setDefinitionId(def.getId());

// now add new child node entry to parent
parent.addChildNodeEntry(nodeName, id);
Expand Down Expand Up @@ -1248,7 +1236,6 @@ public PropertyState createPropertyState(NodeState parent,
// create property
PropertyState prop = stateMgr.createNew(propName, parent.getNodeId());

prop.setDefinitionId(def.getId());
if (def.getRequiredType() != PropertyType.UNDEFINED) {
prop.setType(def.getRequiredType());
} else if (type != PropertyType.UNDEFINED) {
Expand Down Expand Up @@ -1441,7 +1428,7 @@ protected void verifyNotProtected(Path nodePath)
throws PathNotFoundException, ConstraintViolationException,
RepositoryException {
NodeState node = getNodeState(nodePath);
NodeDef parentDef = ntReg.getNodeDef(node.getDefinitionId());
NodeDef parentDef = itemMgr.getDefinition(node).unwrap();
if (parentDef.isProtected()) {
throw new ConstraintViolationException(safeGetJCRPath(nodePath)
+ ": node is protected");
Expand Down Expand Up @@ -1751,7 +1738,6 @@ private NodeState copyNodeState(NodeState srcState,
newState = stateMgr.createNew(id, srcState.getNodeTypeName(), destParentId);
// copy node state
newState.setMixinTypeNames(srcState.getMixinTypeNames());
newState.setDefinitionId(srcState.getDefinitionId());
if (shareable) {
// initialize shared set
newState.addShare(destParentId);
Expand Down Expand Up @@ -1829,15 +1815,16 @@ private NodeState copyNodeState(NodeState srcState,
*
* todo FIXME delegate to 'node type instance handler'
*/
PropDefId defId = srcChildState.getDefinitionId();
PropDef def = ntReg.getPropDef(defId);
PropDef def = ent.getApplicablePropertyDef(
srcChildState.getName(), srcChildState.getType(),
srcChildState.isMultiValued());
if (NameConstants.MIX_LOCKABLE.equals(def.getDeclaringNodeType())) {
// skip properties defined by mix:lockable
continue;
}

PropertyState newChildState =
copyPropertyState(srcChildState, id, propName);
copyPropertyState(srcChildState, id, propName, def);

if (versionable && flag == COPY) {
/**
Expand Down Expand Up @@ -1899,20 +1886,17 @@ private NodeState copyNodeState(NodeState srcState,
* @param srcState
* @param parentId
* @param propName
* @param def property definition
* @return
* @throws RepositoryException
*/
private PropertyState copyPropertyState(PropertyState srcState,
NodeId parentId,
Name propName)
Name propName,
PropDef def)
throws RepositoryException {

PropDefId defId = srcState.getDefinitionId();
PropDef def = ntReg.getPropDef(defId);

PropertyState newState = stateMgr.createNew(propName, parentId);

newState.setDefinitionId(defId);
newState.setType(srcState.getType());
newState.setMultiValued(srcState.isMultiValued());
InternalValue[] values = srcState.getValues();
Expand All @@ -1924,8 +1908,8 @@ private PropertyState copyPropertyState(PropertyState srcState,
*
* todo FIXME delegate to 'node type instance handler'
*/
if (def.getDeclaringNodeType().equals(NameConstants.MIX_REFERENCEABLE)
&& propName.equals(NameConstants.JCR_UUID)) {
if (propName.equals(NameConstants.JCR_UUID)
&& def.getDeclaringNodeType().equals(NameConstants.MIX_REFERENCEABLE)) {
// set correct value of jcr:uuid property
newState.setValues(new InternalValue[]{InternalValue.create(parentId.getUUID().toString())});
} else {
Expand Down
Expand Up @@ -16,8 +16,11 @@
*/
package org.apache.jackrabbit.core;

import javax.jcr.RepositoryException;
import javax.jcr.nodetype.ItemDefinition;
import org.apache.jackrabbit.core.state.ItemState;
import org.apache.jackrabbit.core.state.NodeState;
import org.apache.jackrabbit.core.state.PropertyState;

/**
* Data object referenced by different <code>ItemImpl</code> instances that
Expand All @@ -37,17 +40,20 @@ public abstract class ItemData {
/** Status */
private int status;

/** The item manager. */
private ItemManager itemMgr;

/**
* Create a new instance of this class.
*
* @param state item state
* @param definition item definition
* @param itemMgr item manager
*/
protected ItemData(ItemState state, ItemDefinition definition) {
protected ItemData(ItemState state, ItemManager itemMgr) {
this.id = state.getId();
this.state = state;
this.definition = definition;
this.status = ItemImpl.STATUS_NORMAL;
this.itemMgr = itemMgr;
}

/**
Expand Down Expand Up @@ -83,7 +89,14 @@ protected void setState(ItemState state) {
*
* @return item definition
*/
public ItemDefinition getDefinition() {
public ItemDefinition getDefinition() throws RepositoryException {
if (definition == null && itemMgr != null) {
if (isNode()) {
definition = itemMgr.getDefinition((NodeState) state);
} else {
definition = itemMgr.getDefinition((PropertyState) state);
}
}
return definition;
}

Expand Down
Expand Up @@ -371,9 +371,9 @@ private void validateTransientItems(Iterator dirtyIter, Iterator removedIter)
ItemState itemState = (ItemState) dirtyIter.next();
ItemDefinition def;
if (itemState.isNode()) {
def = ntMgr.getNodeDefinition(((NodeState) itemState).getDefinitionId());
def = itemMgr.getDefinition((NodeState) itemState);
} else {
def = ntMgr.getPropertyDefinition(((PropertyState) itemState).getDefinitionId());
def = itemMgr.getDefinition((PropertyState) itemState);
}
/* check permissions for non-protected items. protected items are
only added through API methods which need to assert that
Expand Down Expand Up @@ -572,9 +572,9 @@ private void validateTransientItems(Iterator dirtyIter, Iterator removedIter)
ItemState itemState = (ItemState) removedIter.next();
ItemDefinition def;
if (itemState.isNode()) {
def = ntMgr.getNodeDefinition(((NodeState) itemState).getDefinitionId());
def = itemMgr.getDefinition((NodeState) itemState);
} else {
def = ntMgr.getPropertyDefinition(((PropertyState) itemState).getDefinitionId());
def = itemMgr.getDefinition((PropertyState) itemState);
}
if (!def.isProtected()) {
Path path = stateMgr.getAtticAwareHierarchyMgr().getPath(itemState.getId());
Expand Down

0 comments on commit d00e001

Please sign in to comment.