Author: rhauch
Date: 2008-08-06 00:58:23 -0400 (Wed, 06 Aug 2008)
New Revision: 382
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83
Added new methods to the PathFactory that make it easier to create paths from segments.
(Also changed the signature of one of the ArgCheck methods to use
"Iterable<?>" rather than "Collection<?>".)
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-08-06
00:53:15 UTC (rev 381)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-08-06
04:58:23 UTC (rev 382)
@@ -631,7 +631,7 @@
* @param name The name of the argument
* @throws IllegalArgumentException If array is null or has null values
*/
- public static void containsNoNulls( Collection<?> argument,
+ public static void containsNoNulls( Iterable<?> argument,
String name ) {
isNotNull(argument, name);
int i = 0;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-08-06
00:53:15 UTC (rev 381)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-08-06
04:58:23 UTC (rev 382)
@@ -60,6 +60,16 @@
Path createAbsolutePath( Path.Segment... segments );
/**
+ * Create an absolute path with the supplied segments, in order. If no segments are
provided, the result will be the root
+ * path.
+ *
+ * @param segments the segments
+ * @return the new path
+ * @throws IllegalArgumentException if at least one segment is provided and if any of
the supplied segments are null
+ */
+ Path createAbsolutePath( Iterable<Path.Segment> segments );
+
+ /**
* Create an empty relative path (i.e., equivalent to {@link
#createRelativePath(Path.Segment...) createRelativePath}(
* {@link Path#SELF_SEGMENT})). Subsequent calls will always return the same
instance.
*
@@ -87,6 +97,15 @@
Path createRelativePath( Path.Segment... segments );
/**
+ * Create a relative path with the supplied segments, in order. If no segments are
provided, the result will be the root path.
+ *
+ * @param segments the segments
+ * @return the new path
+ * @throws IllegalArgumentException if at least one segment is provided and if any of
the supplied segments are null
+ */
+ Path createRelativePath( Iterable<Path.Segment> segments );
+
+ /**
* Create a path by appending the supplied relative path to the supplied parent path.
The resulting path will be
* {@link Path#isAbsolute() absolute} if the supplied parent path is absolute.
*
@@ -136,6 +155,18 @@
Path.Segment... segments );
/**
+ * Create a path by appending the supplied names to the parent path. If no names are
appended, the parent path is returned.
+ *
+ * @param parentPath the path that is to provide the basis for the new path
+ * @param segments the segments that are to be appended, in order, to the parent
path
+ * @return the new path
+ * @throws IllegalArgumentException if the parent path reference is null, or if at
least one segment name is provided and if
+ * any of the supplied segment names are null
+ */
+ Path create( Path parentPath,
+ Iterable<Path.Segment> segments );
+
+ /**
* Create a path by appending the supplied names to the parent path.
*
* @param parentPath the path that is to provide the basis for the new path
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-06
00:53:15 UTC (rev 381)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-08-06
04:58:23 UTC (rev 382)
@@ -53,7 +53,7 @@
public static final Path ROOT = new BasicPath(EMPTY_SEGMENTS, true);
- protected static final Path SELF_PATH = new
BasicPath(Collections.singletonList(Path.SELF_SEGMENT), false);
+ public static final Path SELF_PATH = new
BasicPath(Collections.singletonList(Path.SELF_SEGMENT), false);
private final List<Segment> segments;
private final boolean absolute;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-06
00:53:15 UTC (rev 381)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-08-06
04:58:23 UTC (rev 382)
@@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
@@ -281,6 +282,23 @@
}
/**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.PathFactory#createAbsolutePath(java.lang.Iterable)
+ */
+ public Path createAbsolutePath( Iterable<Segment> segments ) {
+ List<Segment> segmentsList = new LinkedList<Segment>();
+ for (Segment segment : segments) {
+ if (segment == null) {
+ ArgCheck.containsNoNulls(segments, "segments");
+ }
+ segmentsList.add(segment);
+ }
+ if (segmentsList.isEmpty()) return BasicPath.ROOT;
+ return new BasicPath(segmentsList, true);
+ }
+
+ /**
* <p>
* {@inheritDoc}
* </p>
@@ -295,7 +313,7 @@
* {@inheritDoc}
*/
public Path createRelativePath( Name... segmentNames ) {
- if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
+ if (segmentNames == null || segmentNames.length == 0) return
BasicPath.SELF_PATH;
List<Segment> segments = new
ArrayList<Segment>(segmentNames.length);
for (Name segmentName : segmentNames) {
if (segmentName == null) {
@@ -310,7 +328,7 @@
* {@inheritDoc}
*/
public Path createRelativePath( Segment... segments ) {
- if (segments == null || segments.length == 0) return BasicPath.ROOT;
+ if (segments == null || segments.length == 0) return BasicPath.SELF_PATH;
List<Segment> segmentsList = new
ArrayList<Segment>(segments.length);
for (Segment segment : segments) {
if (segment == null) {
@@ -324,6 +342,23 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.spi.graph.PathFactory#createRelativePath(java.lang.Iterable)
+ */
+ public Path createRelativePath( Iterable<Segment> segments ) {
+ List<Segment> segmentsList = new LinkedList<Segment>();
+ for (Segment segment : segments) {
+ if (segment == null) {
+ ArgCheck.containsNoNulls(segments, "segments");
+ }
+ segmentsList.add(segment);
+ }
+ if (segmentsList.isEmpty()) return BasicPath.SELF_PATH;
+ return new BasicPath(segmentsList, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.spi.graph.PathFactory#create(org.jboss.dna.spi.graph.Path,
org.jboss.dna.spi.graph.Path)
*/
public Path create( Path parentPath,
@@ -398,6 +433,27 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.spi.graph.PathFactory#create(org.jboss.dna.spi.graph.Path,
java.lang.Iterable)
+ */
+ public Path create( Path parentPath,
+ Iterable<Segment> segments ) {
+ ArgCheck.isNotNull(parentPath, "parent path");
+
+ List<Segment> segmentsList = new LinkedList<Segment>();
+ segmentsList.addAll(parentPath.getSegmentsList());
+ for (Segment segment : segments) {
+ if (segment == null) {
+ ArgCheck.containsNoNulls(segments, "segments");
+ }
+ segmentsList.add(segment);
+ }
+ if (segmentsList.isEmpty()) return BasicPath.ROOT;
+ return new BasicPath(segmentsList, parentPath.isAbsolute());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.spi.graph.PathFactory#create(org.jboss.dna.spi.graph.Path,
java.lang.String)
*/
public Path create( Path parentPath,