You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by md...@apache.org on 2011/10/14 13:49:40 UTC
svn commit: r1183317 - in
/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state:
ItemStateValidator.java NodeState.java Status.java TransientISFactory.java
WorkspaceItemStateFactory.java
Author: mduerig
Date: Fri Oct 14 11:49:39 2011
New Revision: 1183317
URL: http://svn.apache.org/viewvc?rev=1183317&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
clean up
Modified:
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java?rev=1183317&r1=1183316&r2=1183317&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java Fri Oct 14 11:49:39 2011
@@ -48,12 +48,10 @@ import javax.jcr.version.VersionExceptio
* specified by its definition.
*/
public class ItemStateValidator {
-
- /**
- * Logger instance for this class
- */
private static final Logger log = LoggerFactory.getLogger(ItemStateValidator.class);
+ public static final int CHECK_NONE = 0;
+
/**
* option for {@code }{@link #checkAddNode}</code> and
* {@code }{@link #checkRemoveItem}</code> methods:<p/>
@@ -87,8 +85,6 @@ public class ItemStateValidator {
* check that target node is not being referenced
*/
public static final int CHECK_COLLISION = 32;
-
- public static final int CHECK_NONE = 0;
public static final int CHECK_ALL = CHECK_ACCESS | CHECK_LOCK | CHECK_VERSIONING | CHECK_CONSTRAINTS | CHECK_COLLISION;
/**
@@ -105,20 +101,6 @@ public class ItemStateValidator {
this.mgrProvider = mgrProvider;
}
- //-------------------------------------------------< misc. helper methods >
-
- /**
- * Fail safe translation of internal {@code ItemState} to JCR path for use
- * in error messages etc.
- *
- * @param itemState
- * @return JCR path
- * @see LogUtil#safeGetJCRPath(ItemState, org.apache.jackrabbit.spi.commons.conversion.PathResolver)
- */
- private String safeGetJCRPath(ItemState<?> itemState) {
- return LogUtil.safeGetJCRPath(itemState, mgrProvider.getNamePathResolver());
- }
-
//------------------------------------------------------< check methods >---
/**
@@ -133,7 +115,6 @@ public class ItemStateValidator {
* @throws RepositoryException
*/
public void checkIsWritable(NodeState parentState, int options) throws RepositoryException {
-
if ((options & CHECK_ACCESS) == CHECK_ACCESS) {
// make sure current session is granted read access on parent node
if (!mgrProvider.getAccessManager().canRead(parentState)) {
@@ -247,7 +228,7 @@ public class ItemStateValidator {
checkIsWritable(parentState, options);
- // access restriction on prop.
+ // access restriction on property
if ((options & CHECK_ACCESS) == CHECK_ACCESS) {
// make sure current session is granted write access on new prop
Path relPath = mgrProvider.getPathFactory().create(propertyName);
@@ -304,8 +285,7 @@ public class ItemStateValidator {
* @throws RepositoryException
*/
public void checkAddNode(NodeState parentState, Name nodeName, Name nodeTypeName, int options)
- throws
- RepositoryException {
+ throws RepositoryException {
checkIsWritable(parentState, options);
@@ -318,6 +298,7 @@ public class ItemStateValidator {
": not allowed to add child node '" + nodeName + '\'');
}
}
+
// node type constraints
if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
// make sure there's an applicable definition for new child node
@@ -326,6 +307,7 @@ public class ItemStateValidator {
QNodeTypeDefinition def = mgrProvider.getNodeTypeDefinitionProvider().getNodeTypeDefinition(nodeTypeName);
entParent.checkAddNodeConstraints(nodeName, def, mgrProvider.getItemDefinitionProvider());
}
+
// collisions
if ((options & CHECK_COLLISION) == CHECK_COLLISION) {
checkCollision(parentState, nodeName, nodeTypeName);
@@ -362,6 +344,7 @@ public class ItemStateValidator {
// root node
throw new ConstraintViolationException("Cannot remove root node.");
}
+
// check parent
checkIsWritable(targetState.getParent(), options);
@@ -386,6 +369,20 @@ public class ItemStateValidator {
}
}
+ //------------------------------------------< private >---
+
+ /**
+ * Fail safe translation of internal {@code ItemState} to JCR path for use
+ * in error messages etc.
+ *
+ * @param itemState
+ * @return JCR path
+ * @see LogUtil#safeGetJCRPath(ItemState, org.apache.jackrabbit.spi.commons.conversion.PathResolver)
+ */
+ private String safeGetJCRPath(ItemState<?> itemState) {
+ return LogUtil.safeGetJCRPath(itemState, mgrProvider.getNamePathResolver());
+ }
+
/**
* Verifies that the item represented by the given state is checked-out;
* throws a {@code VersionException} if that's not the case.
@@ -479,10 +476,6 @@ public class ItemStateValidator {
*/
private static void checkCollision(NodeState parentState, Name propertyName) throws RepositoryException {
NodeEntry parentEntry = parentState.getHierarchyEntry();
- // NOTE: check for name collisions with existing child node has been
- // removed as with JSR 283 having same-named node and property can be
- // allowed. thus delegate the corresponding validation to the underlying
- // SPI implementation.
// check for name collisions with an existing property
PropertyEntry pe = parentEntry.getPropertyEntry(propertyName);
@@ -507,11 +500,6 @@ public class ItemStateValidator {
* @throws NoSuchNodeTypeException
*/
private void checkCollision(NodeState parentState, Name nodeName, Name nodeTypeName) throws RepositoryException {
- // NOTE: check for name collisions with existing child property has been
- // removed as with JSR 283 having same-named node and property may be
- // allowed. thus delegate the corresponding validation to the underlying
- // SPI implementation.
-
// check for conflict with existing same-name sibling node.
if (parentState.hasChildNodeEntry(nodeName, Path.INDEX_DEFAULT)) {
// retrieve the existing node state that ev. conflicts with the new one.
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=1183317&r1=1183316&r2=1183317&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java Fri Oct 14 11:49:39 2011
@@ -220,7 +220,7 @@ public class NodeState extends ItemState
*
* @return array of NodeType names
*/
- public synchronized Name[] getNodeTypeNames() {
+ public Name[] getNodeTypeNames() {
// mixin types
Name[] mixinNames = getMixinTypeNames();
Name[] types = new Name[mixinNames.length + 1];
@@ -231,13 +231,12 @@ public class NodeState extends ItemState
}
/**
- * TODO: clarify usage
* In case the status of the given node state is not {@link Status#EXISTING}
* the transiently added mixin types are taken into account as well.
*
- * @return
+ * @return array of NodeType names
*/
- public synchronized Name[] getAllNodeTypeNames() {
+ public Name[] getAllNodeTypeNames() {
Name[] allNtNames;
if (getStatus() == Status.EXISTING) {
allNtNames = getNodeTypeNames();
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java?rev=1183317&r1=1183316&r2=1183317&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/Status.java Fri Oct 14 11:49:39 2011
@@ -159,19 +159,14 @@ public enum Status {
|| oldStatus == EXISTING_REMOVED
|| oldStatus == STALE_MODIFIED;
break;
- case REMOVED:
- // removal always possible -> getNewStatus(int, int)
+ case REMOVED: // removal always possible -> getNewStatus(int, int)
isValid = true;
break;
- case MODIFIED:
- // except for NEW states an external modification is always valid
+ case MODIFIED: // except for NEW states an external modification is always valid
isValid = oldStatus != NEW;
break;
- case NEW:
- // default: NEW cannot change state to NEW -> false
- break;
- case _UNDEFINED_:
- // false
+ case NEW: // cannot change state to NEW -> false
+ case _UNDEFINED_: // cannot change state to _UNDEFINED_ -> false
break;
}
return isValid;
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java?rev=1183317&r1=1183316&r2=1183317&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java Fri Oct 14 11:49:39 2011
@@ -41,15 +41,14 @@ public final class TransientISFactory ex
private static final Logger log = LoggerFactory.getLogger(TransientISFactory.class);
- private final ItemStateFactory workspaceStateFactory;
+ private final WorkspaceItemStateFactory workspaceStateFactory;
private final ItemDefinitionProvider defProvider;
- public TransientISFactory(AbstractItemStateFactory workspaceStateFactory, ItemDefinitionProvider defProvider) {
+ public TransientISFactory(WorkspaceItemStateFactory workspaceStateFactory, ItemDefinitionProvider defProvider) {
this.workspaceStateFactory = workspaceStateFactory;
this.defProvider = defProvider;
- // start listening to 'creations' on the workspaceStateFactory (and
- // consequently skip an extra notification if the has been built by the
- // workspaceStateFactory.
+ // start listening to 'creations' on the workspaceStateFactory (and consequently skip an extra
+ // notification if the has been built by the workspaceStateFactory.
workspaceStateFactory.addCreationListener(this);
}
@@ -61,7 +60,6 @@ public final class TransientISFactory ex
// notify listeners that a node state has been created
notifyCreated(nodeState);
-
return nodeState;
}
@@ -70,6 +68,7 @@ public final class TransientISFactory ex
int propertyType) throws RepositoryException {
PropertyState propState = new PropertyState(entry, this, definition, defProvider, values, propertyType);
+
// notify listeners that a property state has been created
notifyCreated(propState);
return propState;
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?rev=1183317&r1=1183316&r2=1183317&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java Fri Oct 14 11:49:39 2011
@@ -21,14 +21,12 @@ import org.apache.jackrabbit.jcr2spi.hie
import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
import org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProvider;
import org.apache.jackrabbit.spi.ChildInfo;
-import org.apache.jackrabbit.spi.IdFactory;
import org.apache.jackrabbit.spi.ItemInfo;
import org.apache.jackrabbit.spi.ItemInfoCache;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.NodeId;
import org.apache.jackrabbit.spi.NodeInfo;
import org.apache.jackrabbit.spi.Path;
-import org.apache.jackrabbit.spi.PathFactory;
import org.apache.jackrabbit.spi.PropertyId;
import org.apache.jackrabbit.spi.PropertyInfo;
import org.apache.jackrabbit.spi.RepositoryService;
@@ -69,10 +67,9 @@ public class WorkspaceItemStateFactory e
@Override
public NodeState createRootState(NodeEntry entry) throws RepositoryException {
- IdFactory idFactory = service.getIdFactory();
- PathFactory pf = service.getPathFactory();
-
- return createNodeState(idFactory.createNodeId((String) null, pf.getRootPath()), entry);
+ Path rootPath = service.getPathFactory().getRootPath();
+ NodeId nodeId = service.getIdFactory().createNodeId((String) null, rootPath);
+ return createNodeState(nodeId, entry);
}
/**
@@ -281,8 +278,7 @@ public class WorkspaceItemStateFactory e
List<Name> propNames = new ArrayList<Name>();
for (Iterator<PropertyId> it = info.getPropertyIds(); it.hasNext(); ) {
PropertyId pId = it.next();
- Name propertyName = pId.getName();
- propNames.add(propertyName);
+ propNames.add(pId.getName());
}
entry.setPropertyEntries(propNames);
@@ -334,8 +330,7 @@ public class WorkspaceItemStateFactory e
}
// now build or update the node state itself
- PropertyState tmp = new PropertyState(entry, info, this, definitionProvider);
- entry.setItemState(tmp);
+ entry.setItemState(new PropertyState(entry, info, this, definitionProvider));
PropertyState pState = entry.getPropertyState();
if (previousStatus == Status._UNDEFINED_) {
@@ -431,11 +426,13 @@ public class WorkspaceItemStateFactory e
parent = parent.getParent();
degree--;
}
- if (degree != 0) {
+
+ if (degree == 0) {
+ return parent;
+ } else {
IllegalArgumentException e = new IllegalArgumentException("Parent of degree " + degree + " does not exist.");
log.error(e.getMessage(), e);
throw e;
}
- return parent;
}
}