pnever 2003/10/10 04:31:10
Modified: src/share/org/apache/slide/common Uri.java
src/share/org/apache/slide/structure Structure.java
StructureImpl.java
Log:
Moved isStoreRoot from StructureImpl to Uri and added getParents() to Structure
Revision Changes Path
1.13 +13 -4 jakarta-slide/src/share/org/apache/slide/common/Uri.java
Index: Uri.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Uri.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Uri.java 25 Apr 2002 21:15:10 -0000 1.12
+++ Uri.java 10 Oct 2003 11:31:09 -0000 1.13
@@ -279,6 +279,15 @@
return (uri.substring(scope.toString().length()));
}
+ /**
+ * Test whether this Uri is equivalent to its scope
+ * @return a boolean
+ */
+ public boolean isStoreRoot() {
+ UriPath thisPath = new UriPath(uri);
+ UriPath scopePath = new UriPath(scope.toString());
+ return thisPath.equals(scopePath);
+ }
// --------------------------------------------------------- Object Methods
1.13 +38 -13
jakarta-slide/src/share/org/apache/slide/structure/Structure.java
Index: Structure.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/structure/Structure.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Structure.java 8 Sep 2003 15:50:30 -0000 1.12
+++ Structure.java 10 Oct 2003 11:31:09 -0000 1.13
@@ -63,16 +63,12 @@
package org.apache.slide.structure;
-import java.io.*;
import java.util.Enumeration;
-import java.util.Stack;
-import java.util.Vector;
-import java.util.Hashtable;
-import java.util.Date;
-import org.apache.slide.common.*;
-import org.apache.slide.lock.*;
-import org.apache.slide.security.*;
-import org.apache.slide.authenticate.CredentialsToken;
+import java.util.List;
+import org.apache.slide.common.ServiceAccessException;
+import org.apache.slide.common.SlideToken;
+import org.apache.slide.lock.ObjectLockedException;
+import org.apache.slide.security.AccessDeniedException;
/**
* Structure helper.
@@ -131,6 +127,35 @@
throws ServiceAccessException, ObjectNotFoundException,
LinkedObjectNotFoundException, AccessDeniedException;
+ /**
+ * Return all parents of this object node. If pathOnly=true, only parents
+ * on the path of the specified ObjectNode are returned, all parents (binding!)
+ * otherwise. If storeOnly=true, only parents within the scope of the store
+ * in charge of the specified ObjectNode are returned, parents up to the root
+ * ObjectNode (uri="/") otherwise.
+ *
+ * @param token a SlideToken
+ * @param object an ObjectNode
+ * @param pathOnly if true, only parents on the path of the
specified
+ * ObjectNode are returned, all parents (binding!)
+ * otherwise
+ * @param storeOnly if true, only parents within the scope of the
store
+ * in charge of the specified ObjectNode are
returned,
+ * parents up to the root ObjectNode (uri="/")
otherwise
+ * @param includeSelf if true, the ObjectNode specified by object is
included,
+ * otherwise, it is excluded
+ *
+ * @return a List of ObjectNode instances
+ *
+ * @throws ServiceAccessException
+ * @throws ObjectNotFoundException
+ * @throws LinkedObjectNotFoundException
+ * @throws AccessDeniedException
+ *
+ */
+ List getParents(SlideToken token, ObjectNode object, boolean pathOnly, boolean
storeOnly, boolean includeSelf)
+ throws ServiceAccessException, ObjectNotFoundException,
+ LinkedObjectNotFoundException, AccessDeniedException;
/**
* Retrieves a node by URI, following any links.
1.32 +75 -23
jakarta-slide/src/share/org/apache/slide/structure/StructureImpl.java
Index: StructureImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/structure/StructureImpl.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- StructureImpl.java 18 Sep 2003 11:01:43 -0000 1.31
+++ StructureImpl.java 10 Oct 2003 11:31:09 -0000 1.32
@@ -63,15 +63,19 @@
package org.apache.slide.structure;
+import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
+import java.util.List;
import java.util.Vector;
import org.apache.slide.common.Domain;
import org.apache.slide.common.Namespace;
import org.apache.slide.common.NamespaceConfig;
import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.common.SlideToken;
+import org.apache.slide.common.SlideTokenWrapper;
import org.apache.slide.common.Uri;
+import org.apache.slide.common.UriPath;
import org.apache.slide.common.UriTokenizer;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionNumber;
@@ -436,7 +440,7 @@
ObjectNode oldChild = null;
// we can check the parentUri, it's in the same store as
newObject
if (Configuration.useBinding(parentUri.getStore())) {
- String bindingName = newObject.lastUriSegment();
+ String bindingName = newObject.getPath().lastSegment();
if (parentObject.hasBinding(bindingName)) {
oldChild = retrieve(token,
parentObject.getUri()+"/"+bindingName, false);
parentObject.removeChild(oldChild);
@@ -496,7 +500,7 @@
}
if (alreadyExists) {
- if (isStoreRoot(courUri)) {
+ if (courUri.isStoreRoot()) {
// if the object already exists map it anyway into
// the node hierarchy, to prevent loose of nodes
// during start up
@@ -509,22 +513,6 @@
}
}
- // TODO: move into Uri class?
- private static boolean isStoreRoot(Uri uri) {
- return ("".equals(uri.getRelative()) || "/".equals(uri.getRelative()));
- }
-
- // TODO: move somewhere else?
- private boolean isSameStore(SlideToken token, String leftUri, String rightUri) {
- Store leftStore = namespace.getUri(token, leftUri).getStore();
- Store rightStore = namespace.getUri(token, rightUri).getStore();
- if (leftStore == null || rightStore == null) {
- throw new IllegalStateException("Got null store:
leftStore="+leftStore+", rightStore="+rightStore);
- }
- return leftStore == rightStore;
- }
-
-
public void createLink(SlideToken token, LinkNode link,
String linkUri, ObjectNode linkedObject)
throws ServiceAccessException, ObjectAlreadyExistsException,
@@ -654,8 +642,10 @@
if (Configuration.useBinding(namespace.getUri(token,
collectionNode.getUri()).getStore())) {
collectionNode = retrieve(token, collectionNode.getUri(), false);
sourceNode = retrieve(token, sourceNode.getUri(), false);
+ Uri collectionUri = namespace.getUri(token, collectionNode.getUri());
+ Uri sourceUri = namespace.getUri(token, sourceNode.getUri());
- if (!isSameStore(token, collectionNode.getUri(), sourceNode.getUri())) {
+ if (collectionUri.getStore() != sourceUri.getStore()) {
throw new CrossServerBindingException(collectionNode.getUri(),
sourceNode.getUri());
}
@@ -709,4 +699,66 @@
store( token, collectionNode, true );
}
}
+
+
+ /**
+ * Return all parents of this object node. If pathOnly=true, only parents
+ * on the path of the specified ObjectNode are returned, all parents (binding!)
+ * otherwise. If storeOnly=true, only parents within the scope of the store
+ * in charge of the specified ObjectNode are returned, parents up to the root
+ * ObjectNode (uri="/") otherwise.
+ *
+ * @param token a SlideToken
+ * @param object an ObjectNode
+ * @param pathOnly if true, only parents on the path of the
specified
+ * ObjectNode are returned, all parents (binding!)
+ * otherwise
+ * @param storeOnly if true, only parents within the scope of the
store
+ * in charge of the specified ObjectNode are
returned,
+ * parents up to the root ObjectNode (uri="/")
otherwise
+ * @param includeSelf if true, the ObjectNode specified by object is
included,
+ * otherwise, it is excluded
+ *
+ * @return a List of ObjectNode instances
+ *
+ * @throws ServiceAccessException
+ * @throws ObjectNotFoundException
+ * @throws LinkedObjectNotFoundException
+ * @throws AccessDeniedException
+ *
+ */
+ public List getParents(SlideToken token, ObjectNode object, boolean pathOnly,
boolean storeOnly, boolean includeSelf) throws ServiceAccessException,
ObjectNotFoundException, LinkedObjectNotFoundException, AccessDeniedException {
+ List result = new ArrayList();
+ if (token.isForceStoreEnlistment()) {
+ // get read-only token
+ token = new SlideTokenWrapper(token, false);
+ }
+
+ if (pathOnly) {
+ String[] uriTokens = object.getPath().tokens();
+ UriPath path = new UriPath("/");
+ Uri currentUri = namespace.getUri(token, path.toString());
+ Uri objectUri = namespace.getUri(token, object.getUri());
+ if (!storeOnly || currentUri.getStore() == objectUri.getStore()) {
+ result.add( retrieve(token, path.toString()) );
+ }
+
+ for (int i = 0; i < uriTokens.length; i++) {
+ path = path.child( uriTokens[i] );
+ currentUri = namespace.getUri(token, path.toString());
+ if (i == uriTokens.length - 1 && !includeSelf) {
+ break;
+ }
+ if (!storeOnly || currentUri.getStore() == objectUri.getStore()) {
+ result.add( retrieve(token, path.toString()) );
+ }
+ }
}
+ else {
+ // TODO
+ }
+
+ return result;
+ }
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]