Author: rhauch
Date: 2008-06-03 13:32:57 -0400 (Tue, 03 Jun 2008)
New Revision: 235
Added:
trunk/dna-common/src/main/java/org/jboss/dna/common/text/TextDecoder.java
Modified:
trunk/dna-common/src/main/java/org/jboss/dna/common/text/Jsr283Encoder.java
trunk/dna-common/src/main/java/org/jboss/dna/common/text/NoOpEncoder.java
trunk/dna-common/src/main/java/org/jboss/dna/common/text/TextEncoder.java
trunk/dna-common/src/main/java/org/jboss/dna/common/text/UrlEncoder.java
trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/MavenUrl.java
trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/spi/JcrMavenUrlProvider.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.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/ValueComparators.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
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/StandardValueFactories.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java
Log:
DNA-82: Break TextEncoder interface into two interfaces: one for encoding and one for
decoding
http://jira.jboss.org/jira/browse/DNA-82
Broke into separate interfaces, and changed all uses. Some places did require references
to both a TextEncoder and TextDecoder, but most only required a single reference. It also
made some of the uses of a decoder more clear (than calling it a "decoder" but
having the type be TextEncoder, as it was previously.)
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/text/Jsr283Encoder.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/text/Jsr283Encoder.java 2008-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/text/Jsr283Encoder.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -57,9 +57,10 @@
* </tr>
* </table>
* </p>
+ *
* @author Randall Hauch
*/
-public class Jsr283Encoder implements TextEncoder {
+public class Jsr283Encoder implements TextEncoder, TextDecoder {
/**
* {@inheritDoc}
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/text/NoOpEncoder.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/text/NoOpEncoder.java 2008-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/text/NoOpEncoder.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -24,9 +24,10 @@
/**
* An encoder implementation that does nothing. This is useful when a {@link TextEncoder
encoder} is optional but the code is
* easier to write when there is always an encoder.
+ *
* @author Randall Hauch
*/
-public class NoOpEncoder implements TextEncoder {
+public class NoOpEncoder implements TextEncoder, TextDecoder {
private static final NoOpEncoder INSTANCE = new NoOpEncoder();
Added: trunk/dna-common/src/main/java/org/jboss/dna/common/text/TextDecoder.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/text/TextDecoder.java
(rev 0)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/text/TextDecoder.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.common.text;
+
+/**
+ * Interface for components that can decode text. This is the counterpart to {@link
TextEncoder}.
+ *
+ * @author Randall Hauch
+ * @see TextEncoder
+ */
+public interface TextDecoder {
+
+ /**
+ * Return the decoded version of an encoded string
+ *
+ * @param encodedText the encoded text
+ * @return the unecoded form of the text, or null if the supplied node name is also
null
+ * @see TextEncoder#encode(String)
+ */
+ public String decode( String encodedText );
+
+}
Property changes on:
trunk/dna-common/src/main/java/org/jboss/dna/common/text/TextDecoder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/text/TextEncoder.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/text/TextEncoder.java 2008-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/text/TextEncoder.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -22,25 +22,20 @@
package org.jboss.dna.common.text;
/**
- * Interface for components that can encode and unencode text.
+ * Interface for components that can encode text. This is the counterpart to {@link
TextDecoder}.
+ *
* @author Randall Hauch
+ * @see TextDecoder
*/
public interface TextEncoder {
/**
* Returns the encoded version of a string.
+ *
* @param text the text with characters that are to be encoded.
* @return the text with the characters encoded as required, or null if the supplied
text is null
- * @see #decode(String)
+ * @see TextDecoder#decode(String)
*/
public String encode( String text );
- /**
- * Return the decoded version of an encoded string
- * @param encodedText the encoded text
- * @return the unecoded form of the text, or null if the supplied node name is also
null
- * @see #encode(String)
- */
- public String decode( String encodedText );
-
}
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/text/UrlEncoder.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/text/UrlEncoder.java 2008-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/text/UrlEncoder.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,9 +29,10 @@
* An encoder useful for converting text to be used within a URL, as defined by Section
2.3 of <a
*
href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>. Note that
this class does not encode a complete URL ({@link java.net.URLEncoder}
* and {@link java.net.URLDecoder} should be used for such purposes).
+ *
* @author Randall Hauch
*/
-public class UrlEncoder implements TextEncoder {
+public class UrlEncoder implements TextEncoder, TextDecoder {
/**
* Data characters that are allowed in a URI but do not have a reserved purpose are
called unreserved. These include upper and
Modified: trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/MavenUrl.java
===================================================================
--- trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/MavenUrl.java 2008-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/MavenUrl.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -26,11 +26,13 @@
import java.net.URLStreamHandler;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.text.UrlEncoder;
/**
* Wrapper for a URL that uses a format for referencing JCR nodes and content.
+ *
* @author Randall Hauch
*/
public class MavenUrl {
@@ -46,6 +48,7 @@
/**
* Get the host name
+ *
* @return the host name
*/
public String getHostname() {
@@ -62,6 +65,7 @@
/**
* Get the port. This method returns {@link #NO_PORT} if the port has not been
specified.
+ *
* @return the port
*/
public int getPort() {
@@ -90,6 +94,7 @@
/**
* Set the name of the workspace.
+ *
* @param workspaceName the name of the workspace
*/
public void setWorkspaceName( String workspaceName ) {
@@ -123,6 +128,7 @@
/**
* Get a URL that corresponds to the information in this object.
+ *
* @param handler the URL stream handler that will be used to handle obtaining an
input stream or an output stream on the
* resulting URL
* @param encoder an encoder that will be used to escape any characters that are not
allowed in URLs; {@link UrlEncoder} will
@@ -196,11 +202,13 @@
* <li><b>path/to/node</b> is the path of the node or property that
is to be referenced</li>
* </ul>
* </p>
+ *
* @param url the URL to be parsed
* @param decoder the text encoder that should be used to decode the URL; may be null
if no decoding should be done
* @return the object representing the JCR information contained in the URL
+ * @see #parse(URL, TextDecoder)
*/
- public static MavenUrl parse( String url, TextEncoder decoder ) {
+ public static MavenUrl parse( String url, TextDecoder decoder ) {
if (decoder == null) decoder = new UrlEncoder();
// This regular expression has the following groups:
// 1) //hostname:port
@@ -231,12 +239,13 @@
/**
* Parse the supplied URL and determine if the URL fits the JCR URL format. If it
does, return a {@link MavenUrl} instance;
* otherwise return null. If the URL is malformed or otherwise invalid, this method
also returns null.
+ *
* @param url the URL to be parsed
* @param decoder the text encoder that should be used to decode the URL; may be null
if no decoding should be done
* @return the object representing the JCR information contained in the URL
- * @see #parse(String,TextEncoder)
+ * @see #parse(String,TextDecoder)
*/
- public static MavenUrl parse( URL url, TextEncoder decoder ) {
+ public static MavenUrl parse( URL url, TextDecoder decoder ) {
if (url == null) return null;
return parse(url.toExternalForm(), decoder);
}
Modified:
trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/spi/JcrMavenUrlProvider.java
===================================================================
---
trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/spi/JcrMavenUrlProvider.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-maven-classloader/src/main/java/org/jboss/dna/maven/spi/JcrMavenUrlProvider.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -52,6 +52,7 @@
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.version.VersionException;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.text.UrlEncoder;
import org.jboss.dna.common.util.Logger;
@@ -96,7 +97,8 @@
public static final String CONTENT_PROPERTY_NAME = "jcr:data";
private final URLStreamHandler urlStreamHandler = new JcrUrlStreamHandler();
- private final TextEncoder urlEncoder = new UrlEncoder().setSlashEncoded(false);
+ private final TextEncoder urlEncoder;
+ private final TextDecoder urlDecoder;
private Repository repository;
private String workspaceName;
private Credentials credentials;
@@ -104,6 +106,15 @@
private final Logger logger = Logger.getLogger(JcrMavenUrlProvider.class);
/**
+ *
+ */
+ public JcrMavenUrlProvider() {
+ UrlEncoder encoder = new UrlEncoder().setSlashEncoded(false);
+ this.urlEncoder = encoder;
+ this.urlDecoder = encoder;
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -163,6 +174,7 @@
/**
* Get the JCR repository used by this provider
+ *
* @return the repository instance
*/
public Repository getRepository() {
@@ -267,6 +279,7 @@
/**
* Get the JRC path to the node in this repository and it's workspace that
represents the artifact with the given type in the
* supplied Maven project.
+ *
* @param mavenId the ID of the Maven project; may not be null
* @param artifactType the type of artifact; may be null
* @param signatureType the type of signature; may be null if the signature file is
not desired
@@ -302,6 +315,10 @@
return this.urlEncoder;
}
+ protected TextDecoder getUrlDecoder() {
+ return this.urlDecoder;
+ }
+
protected Session createSession() throws LoginException, NoSuchWorkspaceException,
RepositoryException {
if (this.workspaceName != null) {
if (this.credentials != null) {
@@ -319,6 +336,7 @@
* Obtain an input stream to the existing content at the location given by the
supplied {@link MavenUrl}. The Maven URL
* should have a path that points to the node where the content is stored in the
* {@link #getContentProperty() content property}.
+ *
* @param mavenUrl the Maven URL to the content; may not be null
* @return the input stream to the content, or null if there is no existing content
* @throws IOException
@@ -354,6 +372,7 @@
* Obtain an output stream to the existing content at the location given by the
supplied {@link MavenUrl}. The Maven URL
* should have a path that points to the property or to the node where the content is
stored in the
* {@link #getContentProperty() content property}.
+ *
* @param mavenUrl the Maven URL to the content; may not be null
* @return the input stream to the content, or null if there is no existing content
* @throws IOException
@@ -513,6 +532,7 @@
/**
* This {@link URLStreamHandler} specialization understands {@link URL URLs} that
point to content in the JCR repository used
* by this Maven repository.
+ *
* @author Randall Hauch
*/
protected class JcrUrlStreamHandler extends URLStreamHandler {
@@ -535,6 +555,7 @@
* Each JcrUrlConnection is used to make a single request to read or write the
<code>jcr:content</code> property value on
* the {@link javax.jcr.Node node} that corresponds to the given URL. The node must
already exist.
* </p>
+ *
* @author Randall Hauch
*/
protected class MavenUrlConnection extends URLConnection {
@@ -548,7 +569,7 @@
*/
protected MavenUrlConnection( URL url ) {
super(url);
- this.mavenUrl = MavenUrl.parse(url,
JcrMavenUrlProvider.this.getUrlEncoder());
+ this.mavenUrl = MavenUrl.parse(url,
JcrMavenUrlProvider.this.getUrlDecoder());
}
/**
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -21,48 +21,45 @@
*/
package org.jboss.dna.spi.graph;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
/**
* A factory for creating {@link Name names}.
- *
+ *
* @author Randall Hauch
*/
public interface NameFactory extends ValueFactory<Name> {
- String JCR_PRIMARY_TYPE = "jcr:primaryType";
+ String JCR_PRIMARY_TYPE = "jcr:primaryType";
- /**
- * Create a name from the given namespace URI and local name.
- * <p>
- * This method is equivalent to calling {@link #create(String, String, TextEncoder)}
with a null encoder.
- * </p>
- *
- * @param namespaceUri the namespace URI
- * @param localName the local name
- * @return the new name
- * @throws IllegalArgumentException if the local name is <code>null</code>
or empty
- */
- Name create( String namespaceUri,
- String localName );
+ /**
+ * Create a name from the given namespace URI and local name.
+ * <p>
+ * This method is equivalent to calling {@link #create(String, String, TextDecoder)}
with a null encoder.
+ * </p>
+ *
+ * @param namespaceUri the namespace URI
+ * @param localName the local name
+ * @return the new name
+ * @throws IllegalArgumentException if the local name is
<code>null</code> or empty
+ */
+ Name create( String namespaceUri, String localName );
- /**
- * Create a name from the given namespace URI and local name.
- *
- * @param namespaceUri the namespace URI
- * @param localName the local name
- * @param encoder the encoder that should be used to decode the qualified name
- * @return the new name
- * @throws IllegalArgumentException if the local name is <code>null</code>
or empty
- */
- Name create( String namespaceUri,
- String localName,
- TextEncoder encoder );
+ /**
+ * Create a name from the given namespace URI and local name.
+ *
+ * @param namespaceUri the namespace URI
+ * @param localName the local name
+ * @param decoder the decoder that should be used to decode the qualified name
+ * @return the new name
+ * @throws IllegalArgumentException if the local name is
<code>null</code> or empty
+ */
+ Name create( String namespaceUri, String localName, TextDecoder decoder );
- /**
- * Get the namespace registry.
- *
- * @return the namespace registry; never <code>null</code>
- */
- NamespaceRegistry getNamespaceRegistry();
+ /**
+ * Get the namespace registry.
+ *
+ * @return the namespace registry; never <code>null</code>
+ */
+ NamespaceRegistry getNamespaceRegistry();
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-06-02 20:19:51 UTC
(rev 234)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-06-03 17:32:57 UTC
(rev 235)
@@ -27,6 +27,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.Jsr283Encoder;
import org.jboss.dna.common.text.NoOpEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.text.UrlEncoder;
import org.jboss.dna.spi.graph.impl.BasicName;
@@ -73,409 +74,425 @@
@Immutable
public interface Path extends Comparable<Path>, Iterable<Path.Segment>,
Serializable {
- /**
- * The text encoder that does nothing.
- */
- public static final TextEncoder NO_OP_ENCODER = new NoOpEncoder();
+ /**
+ * The text encoder that does nothing.
+ */
+ public static final TextEncoder NO_OP_ENCODER = new NoOpEncoder();
- /**
- * The text encoder that encodes and decodes according to JSR-283.
- */
- public static final TextEncoder JSR283_ENCODER = new Jsr283Encoder();
+ /**
+ * The text encoder that encodes according to JSR-283.
+ */
+ public static final TextEncoder JSR283_ENCODER = new Jsr283Encoder();
- /**
- * The text encoder that encodes and decodes text according to the rules of <a
href="http://www.ietf.org/rfc/rfc2396.txt">RFC
- * 2396</a>.
- */
- public static final TextEncoder URL_ENCODER = new UrlEncoder().setSlashEncoded(true);
+ /**
+ * The text encoder that encodes text according to the rules of <a
href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>.
+ */
+ public static final TextEncoder URL_ENCODER = new
UrlEncoder().setSlashEncoded(true);
- /**
- * The default text encoder to be used when none is otherwise specified. This is
currently the
- * {@link #JSR283_ENCODER JSR-283 encoder}.
- */
- public static final TextEncoder DEFAULT_ENCODER = JSR283_ENCODER;
+ /**
+ * The text decoder that does nothing.
+ */
+ public static final TextDecoder NO_OP_DECODER = new NoOpEncoder();
- /**
- * The delimiter character used to separate segments within a path.
- */
- public static final char DELIMITER = '/';
+ /**
+ * The text decoder that decodes according to JSR-283.
+ */
+ public static final TextDecoder JSR283_DECODER = new Jsr283Encoder();
- /**
- * String form of the delimiter used to separate segments within a path.
- */
- public static final String DELIMITER_STR = new String(new char[] {DELIMITER});
+ /**
+ * The text decoder that decodes text according to the rules of <a
href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>.
+ */
+ public static final TextDecoder URL_DECODER = new
UrlEncoder().setSlashEncoded(true);
- /**
- * String representation of the segment that references a parent.
- */
- public static final String PARENT = "..";
+ /**
+ * The default text encoder to be used when none is otherwise specified. This is
currently the
+ * {@link #JSR283_ENCODER JSR-283 encoder}.
+ */
+ public static final TextEncoder DEFAULT_ENCODER = JSR283_ENCODER;
- /**
- * String representation of the segment that references the same segment.
- */
- public static final String SELF = ".";
+ /**
+ * The default text decoder to be used when none is otherwise specified. This is
currently the
+ * {@link #JSR283_ENCODER JSR-283 encoder}.
+ */
+ public static final TextDecoder DEFAULT_DECODER = JSR283_DECODER;
- /**
- * The index that will be returned for a {@link Segment} that {@link Segment#hasIndex()
has no index}.
- */
- public static final int NO_INDEX = -1;
+ /**
+ * The delimiter character used to separate segments within a path.
+ */
+ public static final char DELIMITER = '/';
- /**
- * Representation of the segments that occur within a path.
- *
- * @author Randall Hauch
- */
- @Immutable
- public static interface Segment extends Cloneable, Comparable<Segment>,
Serializable {
+ /**
+ * String form of the delimiter used to separate segments within a path.
+ */
+ public static final String DELIMITER_STR = new String(new char[] {DELIMITER});
- /**
- * Get the name component of this segment.
- *
- * @return the segment's name
- */
- public Name getName();
+ /**
+ * String representation of the segment that references a parent.
+ */
+ public static final String PARENT = "..";
- /**
- * Get the index for this segment, which will be {@link Path#NO_INDEX 0} if this
segment has no specific index.
- *
- * @return the index
- */
- public int getIndex();
+ /**
+ * String representation of the segment that references the same segment.
+ */
+ public static final String SELF = ".";
- /**
- * Return whether this segment has an index.
- *
- * @return true if this segment has an index, or false otherwise.
- */
- public boolean hasIndex();
+ /**
+ * The index that will be returned for a {@link Segment} that {@link
Segment#hasIndex() has no index}.
+ */
+ public static final int NO_INDEX = -1;
- /**
- * Return whether this segment is a self-reference.
- *
- * @return true if the segment is a self-reference, or false otherwise.
- */
- public boolean isSelfReference();
+ /**
+ * Representation of the segments that occur within a path.
+ *
+ * @author Randall Hauch
+ */
+ @Immutable
+ public static interface Segment extends Cloneable, Comparable<Segment>,
Serializable {
- /**
- * Return whether this segment is a reference to a parent.
- *
- * @return true if the segment is a parent-reference, or false otherwise.
- */
- public boolean isParentReference();
+ /**
+ * Get the name component of this segment.
+ *
+ * @return the segment's name
+ */
+ public Name getName();
- /**
- * Get the string form of the segment. The {@link #DEFAULT_ENCODER default encoder} is
used to encode characters in each
- * of the path segments.
- *
- * @return the encoded string
- * @see #getString(TextEncoder)
- */
- public String getString();
+ /**
+ * Get the index for this segment, which will be {@link Path#NO_INDEX 0} if this
segment has no specific index.
+ *
+ * @return the index
+ */
+ public int getIndex();
- /**
- * Get the encoded string form of the segment, using the supplied encoder to encode
characters in each of the path
- * segments.
- *
- * @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER default
encoder} should be used
- * @return the encoded string
- * @see #getString()
- */
- public String getString( TextEncoder encoder );
+ /**
+ * Return whether this segment has an index.
+ *
+ * @return true if this segment has an index, or false otherwise.
+ */
+ public boolean hasIndex();
- /**
- * Get the string form of the segment, using the supplied namespace registry to convert
the name's namespace URI to a
- * prefix. The {@link #DEFAULT_ENCODER default encoder} is used to encode characters in
each of the path segments.
- *
- * @param namespaceRegistry the namespace registry that should be used to obtain the
prefix for the
- * {@link Name#getNamespaceUri() namespace URI} in the segment's {@link
#getName() name}
- * @return the encoded string
- * @throws IllegalArgumentException if the namespace registry is null
- * @see #getString(NamespaceRegistry,TextEncoder)
- */
- public String getString( NamespaceRegistry namespaceRegistry );
+ /**
+ * Return whether this segment is a self-reference.
+ *
+ * @return true if the segment is a self-reference, or false otherwise.
+ */
+ public boolean isSelfReference();
- /**
- * Get the encoded string form of the segment, using the supplied namespace registry to
convert the name's namespace URI
- * to a prefix and the supplied encoder to encode characters in each of the path
segments.
- *
- * @param namespaceRegistry the namespace registry that should be used to obtain the
prefix for the
- * {@link Name#getNamespaceUri() namespace URI} in the segment's {@link
#getName() name}
- * @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER default
encoder} should be used
- * @return the encoded string
- * @throws IllegalArgumentException if the namespace registry is null
- * @see #getString(NamespaceRegistry)
- */
- public String getString( NamespaceRegistry namespaceRegistry,
- TextEncoder encoder );
- }
+ /**
+ * Return whether this segment is a reference to a parent.
+ *
+ * @return true if the segment is a parent-reference, or false otherwise.
+ */
+ public boolean isParentReference();
- /**
- * Singleton instance of the name referencing a self, provided as a convenience.
- */
- public static final Name SELF_NAME = new BasicName(null, SELF);
+ /**
+ * Get the string form of the segment. The {@link #DEFAULT_ENCODER default
encoder} is used to encode characters in each
+ * of the path segments.
+ *
+ * @return the encoded string
+ * @see #getString(TextEncoder)
+ */
+ public String getString();
- /**
- * Singleton instance of the name referencing a parent, provided as a convenience.
- */
- public static final Name PARENT_NAME = new BasicName(null, PARENT);
+ /**
+ * Get the encoded string form of the segment, using the supplied encoder to
encode characters in each of the path
+ * segments.
+ *
+ * @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER
default encoder} should be used
+ * @return the encoded string
+ * @see #getString()
+ */
+ public String getString( TextEncoder encoder );
- /**
- * Singleton instance of the path segment referencing a parent, provided as a
convenience.
- */
- public static final Path.Segment SELF_SEGMENT = new BasicPathSegment(SELF_NAME);
+ /**
+ * Get the string form of the segment, using the supplied namespace registry to
convert the name's namespace URI to a
+ * prefix. The {@link #DEFAULT_ENCODER default encoder} is used to encode
characters in each of the path segments.
+ *
+ * @param namespaceRegistry the namespace registry that should be used to obtain
the prefix for the
+ * {@link Name#getNamespaceUri() namespace URI} in the segment's {@link
#getName() name}
+ * @return the encoded string
+ * @throws IllegalArgumentException if the namespace registry is null
+ * @see #getString(NamespaceRegistry,TextEncoder)
+ */
+ public String getString( NamespaceRegistry namespaceRegistry );
- /**
- * Singleton instance of the path segment referencing a parent, provided as a
convenience.
- */
- public static final Path.Segment PARENT_SEGMENT = new BasicPathSegment(PARENT_NAME);
+ /**
+ * Get the encoded string form of the segment, using the supplied namespace
registry to convert the name's namespace URI
+ * to a prefix and the supplied encoder to encode characters in each of the path
segments.
+ *
+ * @param namespaceRegistry the namespace registry that should be used to obtain
the prefix for the
+ * {@link Name#getNamespaceUri() namespace URI} in the segment's {@link
#getName() name}
+ * @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER
default encoder} should be used
+ * @return the encoded string
+ * @throws IllegalArgumentException if the namespace registry is null
+ * @see #getString(NamespaceRegistry)
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder
);
+ }
- /**
- * Return the number of segments in this path.
- *
- * @return the number of path segments
- */
- public int size();
+ /**
+ * Singleton instance of the name referencing a self, provided as a convenience.
+ */
+ public static final Name SELF_NAME = new BasicName(null, SELF);
- /**
- * Return whether this path represents the root path.
- *
- * @return true if this path is the root path, or false otherwise
- */
- public boolean isRoot();
+ /**
+ * Singleton instance of the name referencing a parent, provided as a convenience.
+ */
+ public static final Name PARENT_NAME = new BasicName(null, PARENT);
- /**
- * Determine whether this path represents the same as the supplied path. This is
equivalent to calling
- * <code>this.compareTo(other) == 0 </code>.
- *
- * @param other the other path to compare with this path
- * @return true if the paths are equivalent, or false otherwise
- */
- public boolean isSame( Path other );
+ /**
+ * Singleton instance of the path segment referencing a parent, provided as a
convenience.
+ */
+ public static final Path.Segment SELF_SEGMENT = new BasicPathSegment(SELF_NAME);
- /**
- * Determine whether this path is an ancestor of the supplied path. A path is considered
an ancestor of another path if the
- * the ancestor path appears in its entirety at the beginning of the decendant path, and
where the decendant path contains at
- * least one additional segment.
- *
- * @param decendant the path that may be the decendant
- * @return true if this path is an ancestor of the supplied path, or false otherwise
- */
- public boolean isAncestorOf( Path decendant );
+ /**
+ * Singleton instance of the path segment referencing a parent, provided as a
convenience.
+ */
+ public static final Path.Segment PARENT_SEGMENT = new BasicPathSegment(PARENT_NAME);
- /**
- * Determine whether this path is an decendant of the supplied path. A path is
considered a decendant of another path if the
- * the decendant path starts exactly with the entire ancestor path but contains at least
one additional segment.
- *
- * @param ancestor the path that may be the ancestor
- * @return true if this path is an decendant of the supplied path, or false otherwise
- */
- public boolean isDecendantOf( Path ancestor );
+ /**
+ * Return the number of segments in this path.
+ *
+ * @return the number of path segments
+ */
+ public int size();
- /**
- * Return whether this path is an absolute path. A path is either relative or {@link
#isAbsolute() absolute}. An absolute
- * path starts with a "/".
- *
- * @return true if the path is absolute, or false otherwise
- */
- public boolean isAbsolute();
+ /**
+ * Return whether this path represents the root path.
+ *
+ * @return true if this path is the root path, or false otherwise
+ */
+ public boolean isRoot();
- /**
- * Return whether this path is normalized and contains no "." segments and as
few ".." segments as possible. For example, the
- * path "../a" is normalized, while "/a/b/c/../d" is not
normalized.
- *
- * @return true if this path is normalized, or false otherwise
- */
- public boolean isNormalized();
+ /**
+ * Determine whether this path represents the same as the supplied path. This is
equivalent to calling
+ * <code>this.compareTo(other) == 0 </code>.
+ *
+ * @param other the other path to compare with this path
+ * @return true if the paths are equivalent, or false otherwise
+ */
+ public boolean isSame( Path other );
- /**
- * Get a normalized path with as many ".." segments and all "."
resolved.
- *
- * @return the normalized path, or this object if this path is already normalized
- * @throws InvalidPathException if the normalized form would result in a path with
negative length (e.g., "/a/../../..")
- */
- public Path getNormalizedPath();
+ /**
+ * Determine whether this path is an ancestor of the supplied path. A path is
considered an ancestor of another path if the
+ * the ancestor path appears in its entirety at the beginning of the decendant path,
and where the decendant path contains at
+ * least one additional segment.
+ *
+ * @param decendant the path that may be the decendant
+ * @return true if this path is an ancestor of the supplied path, or false otherwise
+ */
+ public boolean isAncestorOf( Path decendant );
- /**
- * Get the canonical form of this path. A canonical path has is {@link #isAbsolute()
absolute} and {@link #isNormalized()}.
- *
- * @return the canonical path, or this object if it is already in its canonical form
- * @throws InvalidPathException if the path is not absolute and cannot be canonicalized
- */
- public Path getCanonicalPath();
+ /**
+ * Determine whether this path is an decendant of the supplied path. A path is
considered a decendant of another path if the
+ * the decendant path starts exactly with the entire ancestor path but contains at
least one additional segment.
+ *
+ * @param ancestor the path that may be the ancestor
+ * @return true if this path is an decendant of the supplied path, or false
otherwise
+ */
+ public boolean isDecendantOf( Path ancestor );
- /**
- * Get a relative path from the supplied path to this path.
- *
- * @param startingPath the path specifying the starting point for the new relative path;
may not be null
- * @return the relative path
- * @throws IllegalArgumentException if the supplied path is null
- * @throws PathNotFoundException if both this path and the supplied path are not
absolute
- */
- public Path relativeTo( Path startingPath );
+ /**
+ * Return whether this path is an absolute path. A path is either relative or {@link
#isAbsolute() absolute}. An absolute
+ * path starts with a "/".
+ *
+ * @return true if the path is absolute, or false otherwise
+ */
+ public boolean isAbsolute();
- /**
- * Get the absolute path by resolving the supplied relative (non-absolute) path against
this absolute path.
- *
- * @param relativePath the relative path that is to be resolved against this path
- * @return the absolute and normalized path resolved from this path and the supplied
absolute path
- * @throws IllegalArgumentException if the supplied path is null
- * @throws InvalidPathException if the this path is not absolute or if the supplied path
is not relative.
- */
- public Path resolve( Path relativePath );
+ /**
+ * Return whether this path is normalized and contains no "." segments and
as few ".." segments as possible. For example, the
+ * path "../a" is normalized, while "/a/b/c/../d" is not
normalized.
+ *
+ * @return true if this path is normalized, or false otherwise
+ */
+ public boolean isNormalized();
- /**
- * Get the absolute path by resolving this relative (non-absolute) path against the
supplied absolute path.
- *
- * @param absolutePath the absolute path to which this relative path should be resolve
- * @return the absolute path resolved from this path and the supplied absolute path
- * @throws IllegalArgumentException if the supplied path is null
- * @throws InvalidPathException if the supplied path is not absolute or if this path is
not relative.
- */
- public Path resolveAgainst( Path absolutePath );
+ /**
+ * Get a normalized path with as many ".." segments and all "."
resolved.
+ *
+ * @return the normalized path, or this object if this path is already normalized
+ * @throws InvalidPathException if the normalized form would result in a path with
negative length (e.g., "/a/../../..")
+ */
+ public Path getNormalizedPath();
- /**
- * Return the path to the parent, or this path if it is the {@link #isRoot() root}. This
is an efficient operation that does
- * not require copying any data.
- *
- * @return the parent path, or this path if it is already the root
- */
- public Path getAncestor();
+ /**
+ * Get the canonical form of this path. A canonical path has is {@link #isAbsolute()
absolute} and {@link #isNormalized()}.
+ *
+ * @return the canonical path, or this object if it is already in its canonical form
+ * @throws InvalidPathException if the path is not absolute and cannot be
canonicalized
+ */
+ public Path getCanonicalPath();
- /**
- * Return the path to the ancestor of the supplied degree. An ancestor of degree
<code>x</code> is the path that is
- * <code>x</code> levels up along the path. For example, <code>degree
= 0</code> returns this path, while
- * <code>degree = 1</code> returns the parent of this path,
<code>degree = 2</code> returns the grandparent of this path,
- * and so on. Note that the result may be unexpected if this path is not {@link
#isNormalized() normalized}, as a
- * non-normalized path contains ".." and "." segments.
- *
- * @param degree
- * @return the ancestor of the supplied degree
- * @throws IllegalArgumentException if the degree is negative
- * @throws PathNotFoundException if the degree is greater than the {@link #size()
length} of this path
- */
- public Path getAncestor( int degree );
+ /**
+ * Get a relative path from the supplied path to this path.
+ *
+ * @param startingPath the path specifying the starting point for the new relative
path; may not be null
+ * @return the relative path
+ * @throws IllegalArgumentException if the supplied path is null
+ * @throws PathNotFoundException if both this path and the supplied path are not
absolute
+ */
+ public Path relativeTo( Path startingPath );
- /**
- * Determine whether this path and the supplied path have the same immediate ancestor.
In other words, this method determines
- * whether the node represented by this path is a sibling of the node represented by the
supplied path.
- *
- * @param that the other path
- * @return true if this path and the supplied path have the same immediate ancestor.
- * @throws IllegalArgumentException if the supplied path is null
- */
- public boolean hasSameAncestor( Path that );
+ /**
+ * Get the absolute path by resolving the supplied relative (non-absolute) path
against this absolute path.
+ *
+ * @param relativePath the relative path that is to be resolved against this path
+ * @return the absolute and normalized path resolved from this path and the supplied
absolute path
+ * @throws IllegalArgumentException if the supplied path is null
+ * @throws InvalidPathException if the this path is not absolute or if the supplied
path is not relative.
+ */
+ public Path resolve( Path relativePath );
- /**
- * Find the lowest common ancestor of this path and the supplied path.
- *
- * @param that the other path
- * @return the lowest common ancestor, which may be the root path if there is no other.
- * @throws IllegalArgumentException if the supplied path is null
- */
- public Path getCommonAncestor( Path that );
+ /**
+ * Get the absolute path by resolving this relative (non-absolute) path against the
supplied absolute path.
+ *
+ * @param absolutePath the absolute path to which this relative path should be
resolve
+ * @return the absolute path resolved from this path and the supplied absolute path
+ * @throws IllegalArgumentException if the supplied path is null
+ * @throws InvalidPathException if the supplied path is not absolute or if this path
is not relative.
+ */
+ public Path resolveAgainst( Path absolutePath );
- /**
- * Get the last segment in this path.
- *
- * @return the last segment, or null if the path is empty
- */
- public Segment getLastSegment();
+ /**
+ * Return the path to the parent, or this path if it is the {@link #isRoot() root}.
This is an efficient operation that does
+ * not require copying any data.
+ *
+ * @return the parent path, or this path if it is already the root
+ */
+ public Path getAncestor();
- /**
- * Get the segment at the supplied index.
- *
- * @param index the index
- * @return the segment
- * @throws IndexOutOfBoundsException if the index is out of bounds
- */
- public Segment getSegment( int index );
+ /**
+ * Return the path to the ancestor of the supplied degree. An ancestor of degree
<code>x</code> is the path that is
+ * <code>x</code> levels up along the path. For example,
<code>degree = 0</code> returns this path, while
+ * <code>degree = 1</code> returns the parent of this path,
<code>degree = 2</code> returns the grandparent of this path,
+ * and so on. Note that the result may be unexpected if this path is not {@link
#isNormalized() normalized}, as a
+ * non-normalized path contains ".." and "." segments.
+ *
+ * @param degree
+ * @return the ancestor of the supplied degree
+ * @throws IllegalArgumentException if the degree is negative
+ * @throws PathNotFoundException if the degree is greater than the {@link #size()
length} of this path
+ */
+ public Path getAncestor( int degree );
- /**
- * Return a new path consisting of the segments starting at
<code>beginIndex</code> index (inclusive). This is equivalent to
- * calling <code>path.subpath(beginIndex,path.size()-1)</code>.
- *
- * @param beginIndex the beginning index, inclusive.
- * @return the specified subpath
- * @exception IndexOutOfBoundsException if the <code>beginIndex</code> is
negative or larger than the length of this
- * <code>Path</code> object
- */
- public Path subpath( int beginIndex );
+ /**
+ * Determine whether this path and the supplied path have the same immediate
ancestor. In other words, this method determines
+ * whether the node represented by this path is a sibling of the node represented by
the supplied path.
+ *
+ * @param that the other path
+ * @return true if this path and the supplied path have the same immediate ancestor.
+ * @throws IllegalArgumentException if the supplied path is null
+ */
+ public boolean hasSameAncestor( Path that );
- /**
- * Return a new path consisting of the segments between the
<code>beginIndex</code> index (inclusive) and the
- * <code>endIndex</code> index (exclusive).
- *
- * @param beginIndex the beginning index, inclusive.
- * @param endIndex the ending index, exclusive.
- * @return the specified subpath
- * @exception IndexOutOfBoundsException if the <code>beginIndex</code> is
negative, or <code>endIndex</code> is larger
- * than the length of this <code>Path</code> object, or
<code>beginIndex</code> is larger than
- * <code>endIndex</code>.
- */
- public Path subpath( int beginIndex,
- int endIndex );
+ /**
+ * Find the lowest common ancestor of this path and the supplied path.
+ *
+ * @param that the other path
+ * @return the lowest common ancestor, which may be the root path if there is no
other.
+ * @throws IllegalArgumentException if the supplied path is null
+ */
+ public Path getCommonAncestor( Path that );
- /**
- * {@inheritDoc}
- */
- public Iterator<Segment> iterator();
+ /**
+ * Get the last segment in this path.
+ *
+ * @return the last segment, or null if the path is empty
+ */
+ public Segment getLastSegment();
- /**
- * Obtain a copy of the segments in this path. None of the segments are encoded.
- *
- * @return the array of segments as a copy
- */
- public Segment[] getSegmentsArray();
+ /**
+ * Get the segment at the supplied index.
+ *
+ * @param index the index
+ * @return the segment
+ * @throws IndexOutOfBoundsException if the index is out of bounds
+ */
+ public Segment getSegment( int index );
- /**
- * Get an unmodifiable list of the path segments.
- *
- * @return the unmodifiable list of path segments; never null
- */
- public List<Segment> getSegmentsList();
+ /**
+ * Return a new path consisting of the segments starting at
<code>beginIndex</code> index (inclusive). This is equivalent to
+ * calling <code>path.subpath(beginIndex,path.size()-1)</code>.
+ *
+ * @param beginIndex the beginning index, inclusive.
+ * @return the specified subpath
+ * @exception IndexOutOfBoundsException if the <code>beginIndex</code> is
negative or larger than the length of this
+ * <code>Path</code> object
+ */
+ public Path subpath( int beginIndex );
- /**
- * Get the string form of the path. The {@link #DEFAULT_ENCODER default encoder} is used
to encode characters in each of the
- * path segments.
- *
- * @return the encoded string
- * @see #getString(TextEncoder)
- */
- public String getString();
+ /**
+ * Return a new path consisting of the segments between the
<code>beginIndex</code> index (inclusive) and the
+ * <code>endIndex</code> index (exclusive).
+ *
+ * @param beginIndex the beginning index, inclusive.
+ * @param endIndex the ending index, exclusive.
+ * @return the specified subpath
+ * @exception IndexOutOfBoundsException if the <code>beginIndex</code> is
negative, or <code>endIndex</code> is larger
+ * than the length of this <code>Path</code> object, or
<code>beginIndex</code> is larger than <code>endIndex</code>.
+ */
+ public Path subpath( int beginIndex, int endIndex );
- /**
- * Get the encoded string form of the path, using the supplied encoder to encode
characters in each of the path segments.
- *
- * @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER default
encoder} should be used
- * @return the encoded string
- * @see #getString()
- */
- public String getString( TextEncoder encoder );
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Segment> iterator();
- /**
- * Get the string form of the path, using the supplied namespace registry to convert the
names' namespace URIs to prefixes.
- * The {@link #DEFAULT_ENCODER default encoder} is used to encode characters in each of
the path segments.
- *
- * @param namespaceRegistry the namespace registry that should be used to obtain the
prefix for the
- * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link
Segment#getName() names}
- * @return the encoded string
- * @throws IllegalArgumentException if the namespace registry is null
- * @see #getString(NamespaceRegistry,TextEncoder)
- */
- public String getString( NamespaceRegistry namespaceRegistry );
+ /**
+ * Obtain a copy of the segments in this path. None of the segments are encoded.
+ *
+ * @return the array of segments as a copy
+ */
+ public Segment[] getSegmentsArray();
- /**
- * Get the encoded string form of the path, using the supplied namespace registry to
convert the names' namespace URIs to
- * prefixes and the supplied encoder to encode characters in each of the path segments.
- *
- * @param namespaceRegistry the namespace registry that should be used to obtain the
prefix for the
- * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link
Segment#getName() names}
- * @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER default
encoder} should be used
- * @return the encoded string
- * @throws IllegalArgumentException if the namespace registry is null
- * @see #getString(NamespaceRegistry)
- */
- public String getString( NamespaceRegistry namespaceRegistry,
- TextEncoder encoder );
+ /**
+ * Get an unmodifiable list of the path segments.
+ *
+ * @return the unmodifiable list of path segments; never null
+ */
+ public List<Segment> getSegmentsList();
+ /**
+ * Get the string form of the path. The {@link #DEFAULT_ENCODER default encoder} is
used to encode characters in each of the
+ * path segments.
+ *
+ * @return the encoded string
+ * @see #getString(TextEncoder)
+ */
+ public String getString();
+
+ /**
+ * Get the encoded string form of the path, using the supplied encoder to encode
characters in each of the path segments.
+ *
+ * @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER default
encoder} should be used
+ * @return the encoded string
+ * @see #getString()
+ */
+ public String getString( TextEncoder encoder );
+
+ /**
+ * Get the string form of the path, using the supplied namespace registry to convert
the names' namespace URIs to prefixes.
+ * The {@link #DEFAULT_ENCODER default encoder} is used to encode characters in each
of the path segments.
+ *
+ * @param namespaceRegistry the namespace registry that should be used to obtain the
prefix for the
+ * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link
Segment#getName() names}
+ * @return the encoded string
+ * @throws IllegalArgumentException if the namespace registry is null
+ * @see #getString(NamespaceRegistry,TextEncoder)
+ */
+ public String getString( NamespaceRegistry namespaceRegistry );
+
+ /**
+ * Get the encoded string form of the path, using the supplied namespace registry to
convert the names' namespace URIs to
+ * prefixes and the supplied encoder to encode characters in each of the path
segments.
+ *
+ * @param namespaceRegistry the namespace registry that should be used to obtain the
prefix for the
+ * {@link Name#getNamespaceUri() namespace URIs} in the segment {@link
Segment#getName() names}
+ * @param encoder the encoder to use, or null if the {@link #DEFAULT_ENCODER default
encoder} should be used
+ * @return the encoded string
+ * @throws IllegalArgumentException if the namespace registry is null
+ * @see #getString(NamespaceRegistry)
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder );
+
}
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-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -21,7 +21,7 @@
*/
package org.jboss.dna.spi.graph;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
/**
* A factory for creating {@link Path paths}. This interface extends the {@link
ValueFactory} generic interface and adds specific
@@ -32,148 +32,141 @@
*/
public interface PathFactory extends ValueFactory<Path> {
- /**
- * Create an absolute root path. Subsequent calls will always return the same instance.
- *
- * @return the new path
- */
- Path create();
+ /**
+ * Create an absolute root path. Subsequent calls will always return the same
instance.
+ *
+ * @return the new path
+ */
+ Path create();
- /**
- * Create an absolute path with the supplied segment names, in order. If no segments are
provided, the result will be the root
- * path.
- *
- * @param segmentNames the names of the segments
- * @return the new path
- * @throws IllegalArgumentException if at least one segment name is provided and if any
of the supplied segment names are null
- */
- Path create( Name... segmentNames );
+ /**
+ * Create an absolute path with the supplied segment names, in order. If no segments
are provided, the result will be the root
+ * path.
+ *
+ * @param segmentNames the names of the segments
+ * @return the new path
+ * @throws IllegalArgumentException if at least one segment name is provided and if
any of the supplied segment names are null
+ */
+ Path create( Name... segmentNames );
- /**
- * 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 create( 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 create( 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.
- *
- * @return the new path
- */
- Path createRelativePath();
+ /**
+ * 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.
+ *
+ * @return the new path
+ */
+ Path createRelativePath();
- /**
- * Create a relative path with the supplied segment names, in order. If no segments are
provided, the result will be the root
- * path.
- *
- * @param segmentNames the names of the segments
- * @return the new path
- * @throws IllegalArgumentException if at least one segment name is provided and if any
of the supplied segment names are null
- */
- Path createRelativePath( Name... segmentNames );
+ /**
+ * Create a relative path with the supplied segment names, in order. If no segments
are provided, the result will be the root
+ * path.
+ *
+ * @param segmentNames the names of the segments
+ * @return the new path
+ * @throws IllegalArgumentException if at least one segment name is provided and if
any of the supplied segment names are null
+ */
+ Path createRelativePath( Name... segmentNames );
- /**
- * 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( 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( 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
- * @param segmentName the name of the segment to be appended to the parent path
- * @param index the index for the new segment
- * @return the new path
- * @throws IllegalArgumentException if the parent path reference or the segment name is
null, or if the index is invalid
- */
- Path create( Path parentPath,
- Name segmentName,
- int index );
+ /**
+ * 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
+ * @param segmentName the name of the segment to be appended to the parent path
+ * @param index the index for the new segment
+ * @return the new path
+ * @throws IllegalArgumentException if the parent path reference or the segment name
is null, or if the index is invalid
+ */
+ Path create( Path parentPath, Name segmentName, int index );
- /**
- * 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 segmentNames the names of 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,
- Name... segmentNames );
+ /**
+ * 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 segmentNames the names of 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, Name... segmentNames );
- /**
- * 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,
- 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, Path.Segment... segments );
- /**
- * Create a path segment given the supplied segment name. The resulting segment will
have no index.
- *
- * @param segmentName the name of the segment
- * @return the segment
- * @throws IllegalArgumentException if the segment name reference is
<code>null</code> or the value could not be created
- * from the supplied string
- */
- Path.Segment createSegment( String segmentName );
+ /**
+ * Create a path segment given the supplied segment name. The resulting segment will
have no index.
+ *
+ * @param segmentName the name of the segment
+ * @return the segment
+ * @throws IllegalArgumentException if the segment name reference is
<code>null</code> or the value could not be created
+ * from the supplied string
+ */
+ Path.Segment createSegment( String segmentName );
- /**
- * Create a path segment given the supplied segment name. The resulting segment will
have no index.
- *
- * @param segmentName the name of the segment
- * @param encoder the encoder that should be used to decode the qualified name
- * @return the segment
- * @throws IllegalArgumentException if the segment name reference is
<code>null</code> or the value could not be created
- * from the supplied string
- */
- Path.Segment createSegment( String segmentName,
- TextEncoder encoder );
+ /**
+ * Create a path segment given the supplied segment name. The resulting segment will
have no index.
+ *
+ * @param segmentName the name of the segment
+ * @param decoder the decoder that should be used to decode the qualified name
+ * @return the segment
+ * @throws IllegalArgumentException if the segment name reference is
<code>null</code> or the value could not be created
+ * from the supplied string
+ */
+ Path.Segment createSegment( String segmentName, TextDecoder decoder );
- /**
- * Create a path segment given the supplied segment name and index.
- *
- * @param segmentName the name of the new segment
- * @param index the index of the new segment
- * @return the segment
- * @throws IllegalArgumentException if the segment name reference is
<code>null</code> or if the index is invalid
- */
- Path.Segment createSegment( String segmentName,
- int index );
+ /**
+ * Create a path segment given the supplied segment name and index.
+ *
+ * @param segmentName the name of the new segment
+ * @param index the index of the new segment
+ * @return the segment
+ * @throws IllegalArgumentException if the segment name reference is
<code>null</code> or if the index is invalid
+ */
+ Path.Segment createSegment( String segmentName, int index );
- /**
- * Create a path segment given the supplied segment name. The resulting segment will
have no index.
- *
- * @param segmentName the name of the segment
- * @return the segment
- * @throws IllegalArgumentException if the segment name reference is null
- */
- Path.Segment createSegment( Name segmentName );
+ /**
+ * Create a path segment given the supplied segment name. The resulting segment will
have no index.
+ *
+ * @param segmentName the name of the segment
+ * @return the segment
+ * @throws IllegalArgumentException if the segment name reference is null
+ */
+ Path.Segment createSegment( Name segmentName );
- /**
- * Create a path segment given the supplied segment name and index.
- *
- * @param segmentName the name of the new segment
- * @param index the index of the new segment
- * @return the segment
- * @throws IllegalArgumentException if the segment name reference is null or if the
index is invalid
- */
- Path.Segment createSegment( Name segmentName,
- int index );
+ /**
+ * Create a path segment given the supplied segment name and index.
+ *
+ * @param segmentName the name of the new segment
+ * @param index the index of the new segment
+ * @return the segment
+ * @throws IllegalArgumentException if the segment name reference is null or if the
index is invalid
+ */
+ Path.Segment createSegment( Name segmentName, int index );
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -284,7 +284,7 @@
protected static final ValueFactory<String> getStringValueFactory() {
// No locking is required, because it doesn't matter if we create several
instances during initialization ...
if (STRING_VALUE_FACTORY == null) {
- STRING_VALUE_FACTORY = new StringValueFactory(Path.NO_OP_ENCODER);
+ STRING_VALUE_FACTORY = new StringValueFactory(Path.NO_OP_DECODER,
Path.NO_OP_ENCODER);
}
return STRING_VALUE_FACTORY;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -28,45 +28,52 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
/**
* A factory for {@link Property} values. Some of the methods may throw a {@link
ValueFormatException} if the parameter supplied
* to the <code>create(...)</code> method cannot be converted to the {@link
#getPropertyType() factory's type}.
+ *
* @author Randall Hauch
* @param <T> the type of value to create
*/
public interface ValueFactory<T> {
+ static final TextDecoder DEFAULT_DECODER = Path.NO_OP_DECODER;
static final TextEncoder DEFAULT_ENCODER = Path.NO_OP_ENCODER;
/**
* Get the {@link PropertyType type} of values created by this factory.
+ *
* @return the value type; never null
*/
PropertyType getPropertyType();
/**
* Create a value from a string, using no decoding.
+ *
* @param value the string from which the value is to be created
* @return the value, or null if the supplied string is null
* @throws ValueFormatException if the value could not be created from the supplied
string
- * @see #create(String, TextEncoder)
+ * @see #create(String, TextDecoder)
*/
T create( String value ) throws ValueFormatException;
/**
* Create a value from a string, using the supplied decoder.
+ *
* @param value the string from which the value is to be created
- * @param decoder the decoder that should be used; if null, the {@link
#DEFAULT_ENCODER default decoder} is used
+ * @param decoder the decoder that should be used; if null, the {@link
#DEFAULT_DECODER default decoder} is used
* @return the value, or null if the supplied string is null
* @throws ValueFormatException if the value could not be created from the supplied
string
* @see #create(String)
*/
- T create( String value, TextEncoder decoder ) throws ValueFormatException;
+ T create( String value, TextDecoder decoder ) throws ValueFormatException;
/**
* Create a value from an integer.
+ *
* @param value the integer from which the value is to be created
* @return the value; never null
* @throws ValueFormatException if the value could not be created from the supplied
integer
@@ -75,6 +82,7 @@
/**
* Create a long from a string.
+ *
* @param value the string from which the long is to be created
* @return the value; never null
* @throws ValueFormatException if the value could not be created from the supplied
long
@@ -83,6 +91,7 @@
/**
* Create a boolean from a string.
+ *
* @param value the boolean from which the value is to be created
* @return the value; never null
* @throws ValueFormatException if the value could not be created from the supplied
boolean
@@ -91,6 +100,7 @@
/**
* Create a value from a float.
+ *
* @param value the float from which the value is to be created
* @return the value; never null
* @throws ValueFormatException if the value could not be created from the supplied
float
@@ -99,6 +109,7 @@
/**
* Create a value from a double.
+ *
* @param value the double from which the value is to be created
* @return the value; never null
* @throws ValueFormatException if the value could not be created from the supplied
double
@@ -107,6 +118,7 @@
/**
* Create a value from a decimal.
+ *
* @param value the decimal from which the value is to be created
* @return the value, or null if the supplied decimal is null
* @throws ValueFormatException if the value could not be created from the supplied
decimal
@@ -115,6 +127,7 @@
/**
* Create a value from a Calendar instance.
+ *
* @param value the Calendar instance from which the value is to be created
* @return the value, or null if the supplied Calendar is null
* @throws ValueFormatException if the value could not be created from the supplied
Calendar object
@@ -123,6 +136,7 @@
/**
* Create a value from a date.
+ *
* @param value the date from which the value is to be created
* @return the value, or null if the supplied date is null
* @throws ValueFormatException if the value could not be created from the supplied
date
@@ -131,6 +145,7 @@
/**
* Create a value from a name.
+ *
* @param value the name from which the value is to be created
* @return the value, or null if the supplied name is null
* @throws ValueFormatException if the value could not be created from the supplied
name
@@ -139,6 +154,7 @@
/**
* Create a value from a path.
+ *
* @param value the path from which the value is to be created
* @return the value, or null if the supplied path is null
* @throws ValueFormatException if the value could not be created from the supplied
path
@@ -147,6 +163,7 @@
/**
* Create a value from a reference.
+ *
* @param value the reference from which the value is to be created
* @return the value, or null if the supplied reference is null
* @throws ValueFormatException if the value could not be created from the supplied
reference
@@ -155,6 +172,7 @@
/**
* Create a value from a URI.
+ *
* @param value the URI from which the value is to be created
* @return the value, or null if the supplied URI is null
* @throws ValueFormatException if the value could not be created from the supplied
URI
@@ -163,6 +181,7 @@
/**
* Create a value from the binary content given by the supplied array.
+ *
* @param value the content to be used to create the value
* @return the value, or null if the supplied stream is null
* @throws ValueFormatException if the value could not be created from the supplied
byte array
@@ -171,6 +190,7 @@
/**
* Create a value from the binary content given by the supplied stream.
+ *
* @param stream the stream containing the content to be used to create the value
* @param approximateLength the approximate length of the content (in bytes)
* @return the value, or null if the supplied stream is null
@@ -181,6 +201,7 @@
/**
* Create a value from a the binary content given by the supplied reader.
+ *
* @param reader the reader containing the content to be used to create the value
* @param approximateLength the approximate length of the content (in bytes)
* @return the value, or null if the supplied string is null
@@ -192,7 +213,8 @@
/**
* Create a value from the specified information by determining which other
<code>create</code> method applies and
* delegating to that method. Note that this method only will call
<code>create</code> methods that take a single parameter;
- * so this excludes {@link #create(InputStream, int)}, {@link #create(Reader, int)}
and {@link #create(String, TextEncoder)}.
+ * so this excludes {@link #create(InputStream, int)}, {@link #create(Reader, int)}
and {@link #create(String, TextDecoder)}.
+ *
* @param value the value
* @return the new value, or null if the supplied parameter is null
* @throws ValueFormatException if the value could not be created from the supplied
stream
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,7 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -40,20 +40,21 @@
/**
* Abstract {@link ValueFactory}.
+ *
* @author Randall Hauch
* @param <T> the property type
*/
@Immutable
public abstract class AbstractValueFactory<T> implements ValueFactory<T> {
- private final TextEncoder encoder;
+ private final TextDecoder decoder;
private final PropertyType propertyType;
private final ValueFactory<String> stringValueFactory;
- protected AbstractValueFactory( PropertyType type, TextEncoder encoder,
ValueFactory<String> stringValueFactory ) {
+ protected AbstractValueFactory( PropertyType type, TextDecoder decoder,
ValueFactory<String> stringValueFactory ) {
ArgCheck.isNotNull(type, "type");
this.propertyType = type;
- this.encoder = encoder != null ? encoder : DEFAULT_ENCODER;
+ this.decoder = decoder != null ? decoder : DEFAULT_DECODER;
this.stringValueFactory = stringValueFactory;
}
@@ -65,20 +66,22 @@
}
/**
- * Get the text encoder/decoder.
- * @return encoder/decoder
+ * Get the text decoder.
+ *
+ * @return the decoder
*/
- public TextEncoder getEncoder() {
- return this.encoder;
+ public TextDecoder getDecoder() {
+ return this.decoder;
}
/**
- * Utility method to obtain either the supplied encoder (if not null) or this
factory's {@link #getEncoder() encoder}.
- * @param encoder the encoder, which may be null if this factory's {@link
#getEncoder() is to be used}
- * @return the encoder; never null
+ * Utility method to obtain either the supplied decoder (if not null) or this
factory's {@link #getDecoder() decoder}.
+ *
+ * @param decoder the decoder, which may be null if this factory's {@link
#getDecoder() is to be used}
+ * @return the decoder; never null
*/
- protected TextEncoder getEncoder( TextEncoder encoder ) {
- return encoder != null ? encoder : this.getEncoder();
+ protected TextDecoder getDecoder( TextDecoder decoder ) {
+ return decoder != null ? decoder : this.getDecoder();
}
/**
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,7 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -40,13 +40,14 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#BOOLEAN} values.
+ *
* @author Randall Hauch
*/
@Immutable
public class BooleanValueFactory extends AbstractValueFactory<Boolean> {
- public BooleanValueFactory( TextEncoder encoder, ValueFactory<String>
stringValueFactory ) {
- super(PropertyType.BOOLEAN, encoder, stringValueFactory);
+ public BooleanValueFactory( TextDecoder decoder, ValueFactory<String>
stringValueFactory ) {
+ super(PropertyType.BOOLEAN, decoder, stringValueFactory);
}
/**
@@ -60,9 +61,9 @@
/**
* {@inheritDoc}
*/
- public Boolean create( String value, TextEncoder decoder ) {
+ public Boolean create( String value, TextDecoder decoder ) {
// this probably doesn't really need to call the decoder, but by doing so
then we don't care at all what the decoder does
- return create(getEncoder(decoder).decode(value));
+ return create(getDecoder(decoder).decode(value));
}
/**
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,7 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -40,13 +40,14 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#DECIMAL} values.
+ *
* @author Randall Hauch
*/
@Immutable
public class DecimalValueFactory extends AbstractValueFactory<BigDecimal> {
- public DecimalValueFactory( TextEncoder encoder, ValueFactory<String>
stringValueFactory ) {
- super(PropertyType.DECIMAL, encoder, stringValueFactory);
+ public DecimalValueFactory( TextDecoder decoder, ValueFactory<String>
stringValueFactory ) {
+ super(PropertyType.DECIMAL, decoder, stringValueFactory);
}
/**
@@ -64,9 +65,9 @@
/**
* {@inheritDoc}
*/
- public BigDecimal create( String value, TextEncoder decoder ) {
+ public BigDecimal create( String value, TextDecoder decoder ) {
// this probably doesn't really need to call the decoder, but by doing so
then we don't care at all what the decoder does
- return create(getEncoder(decoder).decode(value.trim()));
+ return create(getDecoder(decoder).decode(value.trim()));
}
/**
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,7 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -40,13 +40,14 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#DOUBLE} values.
+ *
* @author Randall Hauch
*/
@Immutable
public class DoubleValueFactory extends AbstractValueFactory<Double> {
- public DoubleValueFactory( TextEncoder encoder, ValueFactory<String>
stringValueFactory ) {
- super(PropertyType.DOUBLE, encoder, stringValueFactory);
+ public DoubleValueFactory( TextDecoder decoder, ValueFactory<String>
stringValueFactory ) {
+ super(PropertyType.DOUBLE, decoder, stringValueFactory);
}
/**
@@ -64,9 +65,9 @@
/**
* {@inheritDoc}
*/
- public Double create( String value, TextEncoder decoder ) {
+ public Double create( String value, TextDecoder decoder ) {
// this probably doesn't really need to call the decoder, but by doing so
then we don't care at all what the decoder does
- return create(getEncoder(decoder).decode(value));
+ return create(getDecoder(decoder).decode(value));
}
/**
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -30,7 +30,7 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.IoUtil;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Binary;
@@ -43,6 +43,7 @@
/**
* Teh standard {@link ValueFactory} for {@link PropertyType#BINARY} values.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -50,8 +51,8 @@
private static final String CHAR_SET_NAME = "UTF-8";
- public InMemoryBinaryValueFactory( TextEncoder encoder, ValueFactory<String>
stringValueFactory ) {
- super(PropertyType.BINARY, encoder, stringValueFactory);
+ public InMemoryBinaryValueFactory( TextDecoder decoder, ValueFactory<String>
stringValueFactory ) {
+ super(PropertyType.BINARY, decoder, stringValueFactory);
}
/**
@@ -69,9 +70,9 @@
/**
* {@inheritDoc}
*/
- public Binary create( String value, TextEncoder decoder ) throws ValueFormatException
{
+ public Binary create( String value, TextDecoder decoder ) throws ValueFormatException
{
if (value == null) return null;
- return create(getEncoder(decoder).decode(value));
+ return create(getDecoder(decoder).decode(value));
}
/**
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,7 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.DateTimeFactory;
@@ -42,13 +42,14 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#DATE} values.
+ *
* @author Randall Hauch
*/
@Immutable
public class JodaDateTimeValueFactory extends AbstractValueFactory<DateTime>
implements DateTimeFactory {
- public JodaDateTimeValueFactory( TextEncoder encoder, ValueFactory<String>
stringValueFactory ) {
- super(PropertyType.DATE, encoder, stringValueFactory);
+ public JodaDateTimeValueFactory( TextDecoder decoder, ValueFactory<String>
stringValueFactory ) {
+ super(PropertyType.DATE, decoder, stringValueFactory);
}
/**
@@ -66,9 +67,9 @@
/**
* {@inheritDoc}
*/
- public DateTime create( String value, TextEncoder decoder ) {
+ public DateTime create( String value, TextDecoder decoder ) {
// this probably doesn't really need to call the decoder, but by doing so
then we don't care at all what the decoder does
- return create(getEncoder(decoder).decode(value));
+ return create(getDecoder(decoder).decode(value));
}
/**
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,7 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -40,13 +40,14 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#LONG} values.
+ *
* @author Randall Hauch
*/
@Immutable
public class LongValueFactory extends AbstractValueFactory<Long> {
- public LongValueFactory( TextEncoder encoder, ValueFactory<String>
stringValueFactory ) {
- super(PropertyType.LONG, encoder, stringValueFactory);
+ public LongValueFactory( TextDecoder decoder, ValueFactory<String>
stringValueFactory ) {
+ super(PropertyType.LONG, decoder, stringValueFactory);
}
/**
@@ -64,9 +65,9 @@
/**
* {@inheritDoc}
*/
- public Long create( String value, TextEncoder decoder ) {
+ public Long create( String value, TextDecoder decoder ) {
// this probably doesn't really need to call the decoder, but by doing so
then we don't care at all what the decoder does
- return create(getEncoder(decoder).decode(value));
+ return create(getDecoder(decoder).decode(value));
}
/**
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -31,7 +31,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
@@ -46,256 +46,222 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#NAME} values.
- *
+ *
* @author Randall Hauch
*/
@Immutable
public class NameValueFactory extends AbstractValueFactory<Name> implements
NameFactory {
- // Non-escaped pattern: (\{([^}]*)\})?(.*)
- protected static final String FULLY_QUALFIED_NAME_PATTERN_STRING =
"\\{([^}]*)\\}(.*)";
- protected static final Pattern FULLY_QUALIFIED_NAME_PATTERN =
Pattern.compile(FULLY_QUALFIED_NAME_PATTERN_STRING);
+ // Non-escaped pattern: (\{([^}]*)\})?(.*)
+ protected static final String FULLY_QUALFIED_NAME_PATTERN_STRING =
"\\{([^}]*)\\}(.*)";
+ protected static final Pattern FULLY_QUALIFIED_NAME_PATTERN =
Pattern.compile(FULLY_QUALFIED_NAME_PATTERN_STRING);
- // Original pattern: (([^:/]*):)?(.*)
- private static final String PREFIXED_NAME_PATTERN_STRING =
"(([^:/]*):)?(.*)";
- private static final Pattern PREFIXED_NAME_PATTERN =
Pattern.compile(PREFIXED_NAME_PATTERN_STRING);
+ // Original pattern: (([^:/]*):)?(.*)
+ private static final String PREFIXED_NAME_PATTERN_STRING =
"(([^:/]*):)?(.*)";
+ private static final Pattern PREFIXED_NAME_PATTERN =
Pattern.compile(PREFIXED_NAME_PATTERN_STRING);
- private final NamespaceRegistry namespaceRegistry;
+ private final NamespaceRegistry namespaceRegistry;
- public NameValueFactory( NamespaceRegistry namespaceRegistry,
- TextEncoder encoder,
- ValueFactory<String> stringValueFactory ) {
- super(PropertyType.NAME, encoder, stringValueFactory);
- ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
- this.namespaceRegistry = namespaceRegistry;
- }
+ public NameValueFactory( NamespaceRegistry namespaceRegistry, TextDecoder decoder,
ValueFactory<String> stringValueFactory ) {
+ super(PropertyType.NAME, decoder, stringValueFactory);
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ this.namespaceRegistry = namespaceRegistry;
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( String value ) {
- return create(value, getEncoder());
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( String value ) {
+ return create(value, getDecoder());
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( String value,
- TextEncoder decoder ) throws ValueFormatException {
- if (value == null) return null;
- if (decoder == null) decoder = getEncoder();
- try {
- // First see whether the value fits the internal pattern ...
- Matcher matcher = FULLY_QUALIFIED_NAME_PATTERN.matcher(value);
- if (matcher.matches()) {
- String namespaceUri = matcher.group(1);
- String localName = matcher.group(2);
- // Decode the parts ...
- namespaceUri = decoder.decode(namespaceUri);
- localName = decoder.decode(localName);
- return new BasicName(namespaceUri, localName);
- }
- // Second, see whether the value fits the prefixed name pattern ...
- matcher = PREFIXED_NAME_PATTERN.matcher(value);
- if (matcher.matches()) {
- String prefix = matcher.group(2);
- String localName = matcher.group(3);
- // Decode the parts ...
- prefix = prefix == null ? "" : decoder.decode(prefix);
- localName = decoder.decode(localName);
- // Look for a namespace match ...
- String namespaceUri = this.namespaceRegistry.getNamespaceForPrefix(prefix);
- // Fail if no namespace is found ...
- if (namespaceUri == null) {
- throw new NamespaceException(SpiI18n.noNamespaceRegisteredForPrefix.text(prefix));
- }
- return new BasicName(namespaceUri, localName);
- }
- } catch (Throwable t) {
- throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
-
String.class.getSimpleName(),
- value), t);
- }
- throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
-
String.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( String value, TextDecoder decoder ) throws ValueFormatException
{
+ if (value == null) return null;
+ if (decoder == null) decoder = getDecoder();
+ try {
+ // First see whether the value fits the internal pattern ...
+ Matcher matcher = FULLY_QUALIFIED_NAME_PATTERN.matcher(value);
+ if (matcher.matches()) {
+ String namespaceUri = matcher.group(1);
+ String localName = matcher.group(2);
+ // Decode the parts ...
+ namespaceUri = decoder.decode(namespaceUri);
+ localName = decoder.decode(localName);
+ return new BasicName(namespaceUri, localName);
+ }
+ // Second, see whether the value fits the prefixed name pattern ...
+ matcher = PREFIXED_NAME_PATTERN.matcher(value);
+ if (matcher.matches()) {
+ String prefix = matcher.group(2);
+ String localName = matcher.group(3);
+ // Decode the parts ...
+ prefix = prefix == null ? "" : decoder.decode(prefix);
+ localName = decoder.decode(localName);
+ // Look for a namespace match ...
+ String namespaceUri =
this.namespaceRegistry.getNamespaceForPrefix(prefix);
+ // Fail if no namespace is found ...
+ if (namespaceUri == null) {
+ throw new
NamespaceException(SpiI18n.noNamespaceRegisteredForPrefix.text(prefix));
+ }
+ return new BasicName(namespaceUri, localName);
+ }
+ } catch (Throwable t) {
+ throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
String.class.getSimpleName(), value), t);
+ }
+ throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
String.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( String namespaceUri,
- String localName ) {
- return create(namespaceUri, localName, getEncoder());
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( String namespaceUri, String localName ) {
+ return create(namespaceUri, localName, getDecoder());
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( String namespaceUri,
- String localName,
- TextEncoder decoder ) {
- ArgCheck.isNotEmpty(localName, "localName");
- if (decoder == null) decoder = getEncoder();
- namespaceUri = namespaceUri != null ? decoder.decode(namespaceUri.trim()) : null;
- localName = decoder.decode(localName.trim());
- return new BasicName(namespaceUri, localName);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( String namespaceUri, String localName, TextDecoder decoder ) {
+ ArgCheck.isNotEmpty(localName, "localName");
+ if (decoder == null) decoder = getDecoder();
+ namespaceUri = namespaceUri != null ? decoder.decode(namespaceUri.trim()) :
null;
+ localName = decoder.decode(localName.trim());
+ return new BasicName(namespaceUri, localName);
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( int value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( int value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( long value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( long value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( boolean value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( boolean value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( float value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( float value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( double value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( double value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( BigDecimal value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( BigDecimal value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( Calendar value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( Calendar value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( Date value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( Date value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( Name value ) {
- return value;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( Name value ) {
+ return value;
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( Path value ) throws ValueFormatException {
- if (value == null) return null;
- if (!value.isAbsolute() && value.size() == 1) {
- // A relative name of length 1 is converted to a name
- return value.getSegment(0).getName();
- }
- throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
-
Path.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( Path value ) throws ValueFormatException {
+ if (value == null) return null;
+ if (!value.isAbsolute() && value.size() == 1) {
+ // A relative name of length 1 is converted to a name
+ return value.getSegment(0).getName();
+ }
+ throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
Path.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( Reference value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Reference.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( Reference value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Reference.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( URI value ) throws ValueFormatException {
- if (value == null) return null;
- String asciiString = value.toASCIIString();
- // Remove any leading "./" ...
- if (asciiString.startsWith("./") && asciiString.length() > 2) {
- asciiString = asciiString.substring(2);
- }
- if (asciiString.indexOf('/') == -1) {
- return create(asciiString);
- }
- throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
-
Path.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( URI value ) throws ValueFormatException {
+ if (value == null) return null;
+ String asciiString = value.toASCIIString();
+ // Remove any leading "./" ...
+ if (asciiString.startsWith("./") && asciiString.length() >
2) {
+ asciiString = asciiString.substring(2);
+ }
+ if (asciiString.indexOf('/') == -1) {
+ return create(asciiString);
+ }
+ throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
Path.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( byte[] value ) throws ValueFormatException {
- // First attempt to create a string from the value, then a long from the string ...
- return create(getStringValueFactory().create(value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( byte[] value ) throws ValueFormatException {
+ // First attempt to create a string from the value, then a long from the string
...
+ return create(getStringValueFactory().create(value));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( InputStream stream,
- int approximateLength ) throws IOException, ValueFormatException {
- // First attempt to create a string from the value, then a double from the string ...
- return create(getStringValueFactory().create(stream, approximateLength));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( InputStream stream, int approximateLength ) throws IOException,
ValueFormatException {
+ // First attempt to create a string from the value, then a double from the string
...
+ return create(getStringValueFactory().create(stream, approximateLength));
+ }
- /**
- * {@inheritDoc}
- */
- public Name create( Reader reader,
- int approximateLength ) throws IOException, ValueFormatException {
- // First attempt to create a string from the value, then a double from the string ...
- return create(getStringValueFactory().create(reader, approximateLength));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( Reader reader, int approximateLength ) throws IOException,
ValueFormatException {
+ // First attempt to create a string from the value, then a double from the string
...
+ return create(getStringValueFactory().create(reader, approximateLength));
+ }
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
- * @see org.jboss.dna.spi.graph.NameFactory#getNamespaceRegistry()
- */
- public NamespaceRegistry getNamespaceRegistry() {
- return namespaceRegistry;
- }
+ /**
+ * <p>
+ * {@inheritDoc}
+ * </p>
+ *
+ * @see org.jboss.dna.spi.graph.NameFactory#getNamespaceRegistry()
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ return namespaceRegistry;
+ }
}
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,7 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
import org.jboss.dna.spi.graph.Name;
@@ -41,6 +41,7 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#OBJECT} values.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -48,8 +49,8 @@
private final ValueFactory<Binary> binaryValueFactory;
- public ObjectValueFactory( TextEncoder encoder, ValueFactory<String>
stringValueFactory, ValueFactory<Binary> binaryValueFactory ) {
- super(PropertyType.OBJECT, encoder, stringValueFactory);
+ public ObjectValueFactory( TextDecoder decoder, ValueFactory<String>
stringValueFactory, ValueFactory<Binary> binaryValueFactory ) {
+ super(PropertyType.OBJECT, decoder, stringValueFactory);
ArgCheck.isNotNull(binaryValueFactory, "binaryValueFactory");
this.binaryValueFactory = binaryValueFactory;
}
@@ -71,7 +72,7 @@
/**
* {@inheritDoc}
*/
- public Object create( String value, TextEncoder decoder ) {
+ public Object create( String value, TextDecoder decoder ) {
return this.getStringValueFactory().create(value, decoder);
}
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-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -32,7 +32,7 @@
import java.util.List;
import java.util.regex.Pattern;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
@@ -53,446 +53,414 @@
@Immutable
public class PathValueFactory extends AbstractValueFactory<Path> implements
PathFactory {
- /**
- * Regular expression used to identify the different segments in a path, using the
standard '/' delimiter. The expression is
- * simply:
- *
- * <pre>
- * /
- * </pre>
- */
- protected static final Pattern DELIMITER_PATTERN = Pattern.compile("/");
+ /**
+ * Regular expression used to identify the different segments in a path, using the
standard '/' delimiter. The expression is
+ * simply:
+ *
+ * <pre>
+ * /
+ * </pre>
+ */
+ protected static final Pattern DELIMITER_PATTERN = Pattern.compile("/");
- /**
- * Regular expression used to identify the different parts of a segment. The expression
is
- *
- * <pre>
- * ([ˆ*:/\[\]|]+)(:([ˆ*:/\[\]|]+))?(\[(\d+)])?
- * </pre>
- *
- * where the first part is accessed with group 1, the second part is accessed with group
3, and the index is accessed with
- * group 5.
- */
- protected static final Pattern SEGMENT_PATTERN =
Pattern.compile("([^:/]+)(:([^/\\[\\]]+))?(\\[(\\d+)])?");
+ /**
+ * Regular expression used to identify the different parts of a segment. The
expression is
+ *
+ * <pre>
+ * ([ˆ*:/\[\]|]+)(:([ˆ*:/\[\]|]+))?(\[(\d+)])?
+ * </pre>
+ *
+ * where the first part is accessed with group 1, the second part is accessed with
group 3, and the index is accessed with
+ * group 5.
+ */
+ protected static final Pattern SEGMENT_PATTERN =
Pattern.compile("([^:/]+)(:([^/\\[\\]]+))?(\\[(\\d+)])?");
- private final ValueFactory<Name> nameValueFactory;
+ private final ValueFactory<Name> nameValueFactory;
- public PathValueFactory( TextEncoder encoder,
- ValueFactory<String> stringValueFactory,
- ValueFactory<Name> nameValueFactory ) {
- super(PropertyType.PATH, encoder, stringValueFactory);
- ArgCheck.isNotNull(nameValueFactory, "nameValueFactory");
- this.nameValueFactory = nameValueFactory;
- }
+ public PathValueFactory( TextDecoder decoder, ValueFactory<String>
stringValueFactory, ValueFactory<Name> nameValueFactory ) {
+ super(PropertyType.PATH, decoder, stringValueFactory);
+ ArgCheck.isNotNull(nameValueFactory, "nameValueFactory");
+ this.nameValueFactory = nameValueFactory;
+ }
- /**
- * @return nameValueFactory
- */
- protected ValueFactory<Name> getNameValueFactory() {
- return this.nameValueFactory;
- }
+ /**
+ * @return nameValueFactory
+ */
+ protected ValueFactory<Name> getNameValueFactory() {
+ return this.nameValueFactory;
+ }
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
- * @see org.jboss.dna.spi.graph.PathFactory#create()
- */
- public Path create() {
- return BasicPath.ROOT;
- }
+ /**
+ * <p>
+ * {@inheritDoc}
+ * </p>
+ *
+ * @see org.jboss.dna.spi.graph.PathFactory#create()
+ */
+ public Path create() {
+ return BasicPath.ROOT;
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( String value ) {
- return create(value, getEncoder());
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( String value ) {
+ return create(value, getDecoder());
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( final String value,
- TextEncoder decoder ) throws ValueFormatException {
- if (value == null) return null;
- if (decoder == null) decoder = getEncoder();
- String trimmedValue = value.trim();
- int length = trimmedValue.length();
- boolean absolute = false;
- if (length == 0) {
- return BasicPath.ROOT;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( final String value, TextDecoder decoder ) throws
ValueFormatException {
+ if (value == null) return null;
+ String trimmedValue = value.trim();
+ int length = trimmedValue.length();
+ boolean absolute = false;
+ if (length == 0) {
+ return BasicPath.ROOT;
+ }
- // Remove the leading delimiter ...
- if (trimmedValue.charAt(0) == Path.DELIMITER) {
- trimmedValue = length > 1 ? trimmedValue.substring(1) : "";
- --length;
- absolute = true;
- }
- // remove the trailing delimiter ...
- if (length > 0 && trimmedValue.charAt(length - 1) == Path.DELIMITER) {
- trimmedValue = length > 1 ? trimmedValue.substring(0, length - 1) : "";
- length = trimmedValue.length();
- }
- if (length == 0) {
- return BasicPath.ROOT;
- }
+ // Remove the leading delimiter ...
+ if (trimmedValue.charAt(0) == Path.DELIMITER) {
+ trimmedValue = length > 1 ? trimmedValue.substring(1) : "";
+ --length;
+ absolute = true;
+ }
+ // remove the trailing delimiter ...
+ if (length > 0 && trimmedValue.charAt(length - 1) == Path.DELIMITER)
{
+ trimmedValue = length > 1 ? trimmedValue.substring(0, length - 1) :
"";
+ length = trimmedValue.length();
+ }
+ if (length == 0) {
+ return BasicPath.ROOT;
+ }
- // Parse the path into its segments ...
- List<Segment> segments = new ArrayList<Segment>();
- String[] pathSegments = DELIMITER_PATTERN.split(trimmedValue);
- if (pathSegments.length == 0) {
- throw new
ValueFormatException(SpiI18n.validPathMayNotContainEmptySegment.text(value));
- }
- assert pathSegments.length != 0;
- for (String segment : pathSegments) {
- assert segment != null;
- segment = segment.trim();
- if (segment.length() == 0) {
- throw new
ValueFormatException(SpiI18n.validPathMayNotContainEmptySegment.text(value));
- }
- // Create the name and add a segment with it ...
- segments.add(createSegment(segment, decoder));
- }
+ // Parse the path into its segments ...
+ List<Segment> segments = new ArrayList<Segment>();
+ String[] pathSegments = DELIMITER_PATTERN.split(trimmedValue);
+ if (pathSegments.length == 0) {
+ throw new
ValueFormatException(SpiI18n.validPathMayNotContainEmptySegment.text(value));
+ }
+ if (decoder == null) decoder = getDecoder();
+ assert pathSegments.length != 0;
+ assert decoder != null;
+ for (String segment : pathSegments) {
+ assert segment != null;
+ segment = segment.trim();
+ if (segment.length() == 0) {
+ throw new
ValueFormatException(SpiI18n.validPathMayNotContainEmptySegment.text(value));
+ }
+ // Create the name and add a segment with it ...
+ segments.add(createSegment(segment, decoder));
+ }
- // Create a path constructed from the supplied segments ...
- return new BasicPath(segments, absolute);
- }
+ // Create a path constructed from the supplied segments ...
+ return new BasicPath(segments, absolute);
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( int value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( int value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( long value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( long value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( boolean value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( boolean value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( float value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( float value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( double value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( double value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( BigDecimal value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( BigDecimal value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Calendar value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Calendar value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Date value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Date.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Date value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Date.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Name value ) {
- if (value == null) return null;
- List<Path.Segment> segments = new ArrayList<Path.Segment>(1);
- segments.add(new BasicPathSegment(value));
- return new BasicPath(segments, true);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Name value ) {
+ if (value == null) return null;
+ List<Path.Segment> segments = new ArrayList<Path.Segment>(1);
+ segments.add(new BasicPathSegment(value));
+ return new BasicPath(segments, true);
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Path value ) throws ValueFormatException {
- return value;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Path value ) throws ValueFormatException {
+ return value;
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Name... segmentNames ) {
- if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
- List<Segment> segments = new ArrayList<Segment>(segmentNames.length);
- for (Name segmentName : segmentNames) {
- if (segmentName == null) {
- ArgCheck.containsNoNulls(segmentNames, "segment names");
- }
- segments.add(new BasicPathSegment(segmentName));
- }
- return new BasicPath(segments, true);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Name... segmentNames ) {
+ if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
+ List<Segment> segments = new
ArrayList<Segment>(segmentNames.length);
+ for (Name segmentName : segmentNames) {
+ if (segmentName == null) {
+ ArgCheck.containsNoNulls(segmentNames, "segment names");
+ }
+ segments.add(new BasicPathSegment(segmentName));
+ }
+ return new BasicPath(segments, true);
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Segment... segments ) {
- if (segments == null || segments.length == 0) return BasicPath.ROOT;
- List<Segment> segmentsList = new ArrayList<Segment>(segments.length);
- for (Segment segment : segments) {
- if (segment == null) {
- ArgCheck.containsNoNulls(segments, "segments");
- }
- segmentsList.add(segment);
- }
- return new BasicPath(segmentsList, true);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Segment... segments ) {
+ if (segments == null || segments.length == 0) return BasicPath.ROOT;
+ List<Segment> segmentsList = new
ArrayList<Segment>(segments.length);
+ for (Segment segment : segments) {
+ if (segment == null) {
+ ArgCheck.containsNoNulls(segments, "segments");
+ }
+ segmentsList.add(segment);
+ }
+ return new BasicPath(segmentsList, true);
+ }
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
- * @see org.jboss.dna.spi.graph.PathFactory#createRelativePath()
- */
- public Path createRelativePath() {
- return BasicPath.SELF_PATH;
- }
+ /**
+ * <p>
+ * {@inheritDoc}
+ * </p>
+ *
+ * @see org.jboss.dna.spi.graph.PathFactory#createRelativePath()
+ */
+ public Path createRelativePath() {
+ return BasicPath.SELF_PATH;
+ }
- /**
- * {@inheritDoc}
- */
- public Path createRelativePath( Name... segmentNames ) {
- if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
- List<Segment> segments = new ArrayList<Segment>(segmentNames.length);
- for (Name segmentName : segmentNames) {
- if (segmentName == null) {
- ArgCheck.containsNoNulls(segmentNames, "segment names");
- }
- segments.add(new BasicPathSegment(segmentName));
- }
- return new BasicPath(segments, false);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path createRelativePath( Name... segmentNames ) {
+ if (segmentNames == null || segmentNames.length == 0) return BasicPath.ROOT;
+ List<Segment> segments = new
ArrayList<Segment>(segmentNames.length);
+ for (Name segmentName : segmentNames) {
+ if (segmentName == null) {
+ ArgCheck.containsNoNulls(segmentNames, "segment names");
+ }
+ segments.add(new BasicPathSegment(segmentName));
+ }
+ return new BasicPath(segments, false);
+ }
- /**
- * {@inheritDoc}
- */
- public Path createRelativePath( Segment... segments ) {
- if (segments == null || segments.length == 0) return BasicPath.ROOT;
- List<Segment> segmentsList = new ArrayList<Segment>(segments.length);
- for (Segment segment : segments) {
- if (segment == null) {
- ArgCheck.containsNoNulls(segments, "segments");
- }
- segmentsList.add(segment);
- }
- return new BasicPath(segmentsList, false);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path createRelativePath( Segment... segments ) {
+ if (segments == null || segments.length == 0) return BasicPath.ROOT;
+ List<Segment> segmentsList = new
ArrayList<Segment>(segments.length);
+ for (Segment segment : segments) {
+ if (segment == null) {
+ ArgCheck.containsNoNulls(segments, "segments");
+ }
+ segmentsList.add(segment);
+ }
+ return new BasicPath(segmentsList, false);
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Path parentPath,
- Name segmentName,
- int index ) {
- ArgCheck.isNotNull(parentPath, "parent path");
- ArgCheck.isNotNull(segmentName, "segment name");
- List<Segment> segments = new ArrayList<Segment>(parentPath.size() + 1);
- segments.addAll(parentPath.getSegmentsList());
- segments.add(new BasicPathSegment(segmentName, index));
- return new BasicPath(segments, parentPath.isAbsolute());
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Path parentPath, Name segmentName, int index ) {
+ ArgCheck.isNotNull(parentPath, "parent path");
+ ArgCheck.isNotNull(segmentName, "segment name");
+ List<Segment> segments = new ArrayList<Segment>(parentPath.size() +
1);
+ segments.addAll(parentPath.getSegmentsList());
+ segments.add(new BasicPathSegment(segmentName, index));
+ return new BasicPath(segments, parentPath.isAbsolute());
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Path parentPath,
- Name... segmentNames ) {
- ArgCheck.isNotNull(parentPath, "parent path");
- if (segmentNames == null || segmentNames.length == 0) return parentPath;
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Path parentPath, Name... segmentNames ) {
+ ArgCheck.isNotNull(parentPath, "parent path");
+ if (segmentNames == null || segmentNames.length == 0) return parentPath;
- List<Segment> segments = new ArrayList<Segment>(parentPath.size() + 1);
- segments.addAll(parentPath.getSegmentsList());
- for (Name segmentName : segmentNames) {
- if (segmentName == null) {
- ArgCheck.containsNoNulls(segmentNames, "segment names");
- }
- segments.add(new BasicPathSegment(segmentName));
- }
- return new BasicPath(segments, parentPath.isAbsolute());
- }
+ List<Segment> segments = new ArrayList<Segment>(parentPath.size() +
1);
+ segments.addAll(parentPath.getSegmentsList());
+ for (Name segmentName : segmentNames) {
+ if (segmentName == null) {
+ ArgCheck.containsNoNulls(segmentNames, "segment names");
+ }
+ segments.add(new BasicPathSegment(segmentName));
+ }
+ return new BasicPath(segments, parentPath.isAbsolute());
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Path parentPath,
- Segment... segments ) {
- ArgCheck.isNotNull(parentPath, "parent path");
- if (segments == null || segments.length == 0) return BasicPath.ROOT;
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Path parentPath, Segment... segments ) {
+ ArgCheck.isNotNull(parentPath, "parent path");
+ if (segments == null || segments.length == 0) return BasicPath.ROOT;
- List<Segment> segmentsList = new ArrayList<Segment>(parentPath.size() +
1);
- segmentsList.addAll(parentPath.getSegmentsList());
- for (Segment segment : segments) {
- if (segment == null) {
- ArgCheck.containsNoNulls(segments, "segments");
- }
- segmentsList.add(segment);
- }
- return new BasicPath(segmentsList, parentPath.isAbsolute());
- }
+ List<Segment> segmentsList = new ArrayList<Segment>(parentPath.size()
+ 1);
+ segmentsList.addAll(parentPath.getSegmentsList());
+ for (Segment segment : segments) {
+ if (segment == null) {
+ ArgCheck.containsNoNulls(segments, "segments");
+ }
+ segmentsList.add(segment);
+ }
+ return new BasicPath(segmentsList, parentPath.isAbsolute());
+ }
- /**
- * {@inheritDoc}
- */
- public Segment createSegment( Name segmentName ) {
- ArgCheck.isNotNull(segmentName, "segment name");
- if (Path.SELF_NAME.equals(segmentName)) return Path.SELF_SEGMENT;
- if (Path.PARENT_NAME.equals(segmentName)) return Path.PARENT_SEGMENT;
- return new BasicPathSegment(segmentName);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Segment createSegment( Name segmentName ) {
+ ArgCheck.isNotNull(segmentName, "segment name");
+ if (Path.SELF_NAME.equals(segmentName)) return Path.SELF_SEGMENT;
+ if (Path.PARENT_NAME.equals(segmentName)) return Path.PARENT_SEGMENT;
+ return new BasicPathSegment(segmentName);
+ }
- /**
- * {@inheritDoc}
- */
- public Segment createSegment( Name segmentName,
- int index ) {
- ArgCheck.isNotNull(segmentName, "segment name");
- if (Path.SELF_NAME.equals(segmentName)) return Path.SELF_SEGMENT;
- if (Path.PARENT_NAME.equals(segmentName)) return Path.PARENT_SEGMENT;
- return new BasicPathSegment(segmentName, index);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Segment createSegment( Name segmentName, int index ) {
+ ArgCheck.isNotNull(segmentName, "segment name");
+ if (Path.SELF_NAME.equals(segmentName)) return Path.SELF_SEGMENT;
+ if (Path.PARENT_NAME.equals(segmentName)) return Path.PARENT_SEGMENT;
+ return new BasicPathSegment(segmentName, index);
+ }
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.PathFactory#createSegment(java.lang.String)
- */
- public Segment createSegment( String segmentName ) {
- return createSegment(segmentName, getEncoder());
- }
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.PathFactory#createSegment(java.lang.String)
+ */
+ public Segment createSegment( String segmentName ) {
+ return createSegment(segmentName, getDecoder());
+ }
- /**
- * <p>
- * {@inheritDoc}
- * </p>
- *
- * @see org.jboss.dna.spi.graph.PathFactory#createSegment(java.lang.String,
org.jboss.dna.common.text.TextEncoder)
- */
- public Segment createSegment( String segmentName,
- TextEncoder encoder ) {
- ArgCheck.isNotNull(segmentName, "segment name");
- if (Path.SELF.equals(segmentName)) return Path.SELF_SEGMENT;
- if (Path.PARENT.equals(segmentName)) return Path.PARENT_SEGMENT;
- int startBracketNdx = segmentName.indexOf('[');
- if (startBracketNdx < 0) {
- return new BasicPathSegment(this.nameValueFactory.create(segmentName));
- }
- int endBracketNdx = segmentName.indexOf(']', startBracketNdx);
- if (endBracketNdx < 0) {
- throw new
IllegalArgumentException(SpiI18n.missingEndBracketInSegmentName.text(segmentName));
- }
- String ndx = segmentName.substring(startBracketNdx + 1, endBracketNdx);
- try {
- return new BasicPathSegment(this.nameValueFactory.create(segmentName.substring(0,
startBracketNdx)),
- Integer.parseInt(ndx));
- } catch (NumberFormatException err) {
- throw new IllegalArgumentException(SpiI18n.invalidIndexInSegmentName.text(ndx,
segmentName));
- }
- }
+ /**
+ * <p>
+ * {@inheritDoc}
+ * </p>
+ *
+ * @see org.jboss.dna.spi.graph.PathFactory#createSegment(java.lang.String,
org.jboss.dna.common.text.TextDecoder)
+ */
+ public Segment createSegment( String segmentName, TextDecoder decoder ) {
+ ArgCheck.isNotNull(segmentName, "segment name");
+ if (Path.SELF.equals(segmentName)) return Path.SELF_SEGMENT;
+ if (Path.PARENT.equals(segmentName)) return Path.PARENT_SEGMENT;
+ int startBracketNdx = segmentName.indexOf('[');
+ if (startBracketNdx < 0) {
+ return new BasicPathSegment(this.nameValueFactory.create(segmentName,
decoder));
+ }
+ int endBracketNdx = segmentName.indexOf(']', startBracketNdx);
+ if (endBracketNdx < 0) {
+ throw new
IllegalArgumentException(SpiI18n.missingEndBracketInSegmentName.text(segmentName));
+ }
+ String ndx = segmentName.substring(startBracketNdx + 1, endBracketNdx);
+ try {
+ return new
BasicPathSegment(this.nameValueFactory.create(segmentName.substring(0, startBracketNdx),
decoder), Integer.parseInt(ndx));
+ } catch (NumberFormatException err) {
+ throw new
IllegalArgumentException(SpiI18n.invalidIndexInSegmentName.text(ndx, segmentName));
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public Segment createSegment( String segmentName,
- int index ) {
- ArgCheck.isNotNull(segmentName, "segment name");
- if (Path.SELF.equals(segmentName)) return Path.SELF_SEGMENT;
- if (Path.PARENT.equals(segmentName)) return Path.PARENT_SEGMENT;
- return new BasicPathSegment(this.nameValueFactory.create(segmentName), index);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Segment createSegment( String segmentName, int index ) {
+ ArgCheck.isNotNull(segmentName, "segment name");
+ if (Path.SELF.equals(segmentName)) return Path.SELF_SEGMENT;
+ if (Path.PARENT.equals(segmentName)) return Path.PARENT_SEGMENT;
+ return new BasicPathSegment(this.nameValueFactory.create(segmentName), index);
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Reference value ) throws ValueFormatException {
- throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
-
Reference.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Reference value ) throws ValueFormatException {
+ throw new
ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(),
Reference.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( URI value ) throws ValueFormatException {
- if (value == null) return null;
- String asciiString = value.toASCIIString();
- // Remove any leading "./" ...
- if (asciiString.startsWith("./") && asciiString.length() > 2) {
- asciiString = asciiString.substring(2);
- }
- if (asciiString.indexOf('/') == -1) {
- return create(asciiString);
- }
- throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
-
Path.class.getSimpleName(),
- value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( URI value ) throws ValueFormatException {
+ if (value == null) return null;
+ String asciiString = value.toASCIIString();
+ // Remove any leading "./" ...
+ if (asciiString.startsWith("./") && asciiString.length() >
2) {
+ asciiString = asciiString.substring(2);
+ }
+ if (asciiString.indexOf('/') == -1) {
+ return create(asciiString);
+ }
+ throw new
ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(),
Path.class.getSimpleName(), value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( byte[] value ) throws ValueFormatException {
- // First attempt to create a string from the value, then a long from the string ...
- return create(getStringValueFactory().create(value));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( byte[] value ) throws ValueFormatException {
+ // First attempt to create a string from the value, then a long from the string
...
+ return create(getStringValueFactory().create(value));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( InputStream stream,
- int approximateLength ) throws IOException, ValueFormatException {
- // First attempt to create a string from the value, then a double from the string ...
- return create(getStringValueFactory().create(stream, approximateLength));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( InputStream stream, int approximateLength ) throws IOException,
ValueFormatException {
+ // First attempt to create a string from the value, then a double from the string
...
+ return create(getStringValueFactory().create(stream, approximateLength));
+ }
- /**
- * {@inheritDoc}
- */
- public Path create( Reader reader,
- int approximateLength ) throws IOException, ValueFormatException {
- // First attempt to create a string from the value, then a double from the string ...
- return create(getStringValueFactory().create(reader, approximateLength));
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( Reader reader, int approximateLength ) throws IOException,
ValueFormatException {
+ // First attempt to create a string from the value, then a double from the string
...
+ return create(getStringValueFactory().create(reader, approximateLength));
+ }
}
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.Map;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
@@ -42,6 +43,7 @@
/**
* The standard set of {@link ValueFactory value factories}.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -63,28 +65,33 @@
private final Map<PropertyType, ValueFactory<?>> factories;
private final NamespaceRegistry namespaceRegistry;
+ private final TextDecoder decoder;
private final TextEncoder encoder;
/**
- * Create a standard set of value factories, using the {@link
ValueFactory#DEFAULT_ENCODER default encoder/decoder}.
+ * Create a standard set of value factories, using the {@link
ValueFactory#DEFAULT_DECODER default decoder}.
+ *
* @param namespaceRegistry the namespace registry
* @throws IllegalArgumentException if the namespace registry is null
*/
public StandardValueFactories( NamespaceRegistry namespaceRegistry ) {
- this(namespaceRegistry, null);
+ this(namespaceRegistry, null, null);
}
/**
* Create a standard set of value factories, using the supplied encoder/decoder.
+ *
* @param namespaceRegistry the namespace registry
+ * @param decoder the decoder that should be used; if null, the {@link
ValueFactory#DEFAULT_DECODER default decoder} is used.
* @param encoder the encoder that should be used; if null, the {@link
ValueFactory#DEFAULT_ENCODER default encoder} is used.
* @param extraFactories any extra factories that should be used; any factory will
override the standard factories based upon
* the {@link ValueFactory#getPropertyType() factory's property type}.
* @throws IllegalArgumentException if the namespace registry is null
*/
- public StandardValueFactories( NamespaceRegistry namespaceRegistry, TextEncoder
encoder, ValueFactory<?>... extraFactories ) {
+ public StandardValueFactories( NamespaceRegistry namespaceRegistry, TextDecoder
decoder, TextEncoder encoder, ValueFactory<?>... extraFactories ) {
ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
this.namespaceRegistry = namespaceRegistry;
+ this.decoder = decoder != null ? decoder : ValueFactory.DEFAULT_DECODER;
this.encoder = encoder != null ? encoder : ValueFactory.DEFAULT_ENCODER;
Map<PropertyType, ValueFactory<?>> factories = new
HashMap<PropertyType, ValueFactory<?>>();
@@ -95,18 +102,18 @@
}
// Now assign the members, using the factories in the map or (if null) the
supplied default ...
- this.stringFactory = getFactory(factories, new
StringValueFactory(this.encoder));
- this.binaryFactory = getFactory(factories, new
InMemoryBinaryValueFactory(this.encoder, this.stringFactory));
- this.booleanFactory = getFactory(factories, new BooleanValueFactory(this.encoder,
this.stringFactory));
- this.dateFactory = (DateTimeFactory)getFactory(factories, new
JodaDateTimeValueFactory(this.encoder, this.stringFactory));
- this.decimalFactory = getFactory(factories, new DecimalValueFactory(this.encoder,
this.stringFactory));
- this.doubleFactory = getFactory(factories, new DoubleValueFactory(this.encoder,
this.stringFactory));
- this.longFactory = getFactory(factories, new LongValueFactory(this.encoder,
this.stringFactory));
- this.nameFactory = (NameFactory)getFactory(factories, new
NameValueFactory(this.namespaceRegistry, this.encoder, this.stringFactory));
- this.pathFactory = (PathFactory)getFactory(factories, new
PathValueFactory(this.encoder, this.stringFactory, this.nameFactory));
- this.referenceFactory = getFactory(factories, new
UuidReferenceValueFactory(this.encoder, this.stringFactory));
- this.uriFactory = getFactory(factories, new
UriValueFactory(this.namespaceRegistry, this.encoder, this.stringFactory));
- this.objectFactory = getFactory(factories, new ObjectValueFactory(this.encoder,
this.stringFactory, this.binaryFactory));
+ this.stringFactory = getFactory(factories, new StringValueFactory(this.decoder,
this.encoder));
+ this.binaryFactory = getFactory(factories, new
InMemoryBinaryValueFactory(this.decoder, this.stringFactory));
+ this.booleanFactory = getFactory(factories, new BooleanValueFactory(this.decoder,
this.stringFactory));
+ this.dateFactory = (DateTimeFactory)getFactory(factories, new
JodaDateTimeValueFactory(this.decoder, this.stringFactory));
+ this.decimalFactory = getFactory(factories, new DecimalValueFactory(this.decoder,
this.stringFactory));
+ this.doubleFactory = getFactory(factories, new DoubleValueFactory(this.decoder,
this.stringFactory));
+ this.longFactory = getFactory(factories, new LongValueFactory(this.decoder,
this.stringFactory));
+ this.nameFactory = (NameFactory)getFactory(factories, new
NameValueFactory(this.namespaceRegistry, this.decoder, this.stringFactory));
+ this.pathFactory = (PathFactory)getFactory(factories, new
PathValueFactory(this.decoder, this.stringFactory, this.nameFactory));
+ this.referenceFactory = getFactory(factories, new
UuidReferenceValueFactory(this.decoder, this.stringFactory));
+ this.uriFactory = getFactory(factories, new
UriValueFactory(this.namespaceRegistry, this.decoder, this.stringFactory));
+ this.objectFactory = getFactory(factories, new ObjectValueFactory(this.decoder,
this.stringFactory, this.binaryFactory));
// Wrap the factories with an unmodifiable ...
this.factories = Collections.unmodifiableMap(factories);
@@ -124,10 +131,10 @@
}
/**
- * @return encoder
+ * @return decoder
*/
- public TextEncoder getTextEncoder() {
- return this.encoder;
+ public TextDecoder getTextDecoder() {
+ return this.decoder;
}
/**
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -30,7 +30,9 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.common.util.IoUtil;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
@@ -42,16 +44,28 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#STRING} values.
+ *
* @author Randall Hauch
*/
@Immutable
public class StringValueFactory extends AbstractValueFactory<String> {
- public StringValueFactory( TextEncoder encoder ) {
- super(PropertyType.STRING, encoder, null);
+ private final TextEncoder encoder;
+
+ public StringValueFactory( TextDecoder decoder, TextEncoder encoder ) {
+ super(PropertyType.STRING, decoder, null);
+ ArgCheck.isNotNull(encoder, "encoder");
+ this.encoder = encoder;
}
/**
+ * @return encoder
+ */
+ public TextEncoder getEncoder() {
+ return this.encoder;
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -69,9 +83,9 @@
/**
* {@inheritDoc}
*/
- public String create( String value, TextEncoder decoder ) {
+ public String create( String value, TextDecoder decoder ) {
if (value == null) return value;
- if (decoder == null) decoder = getEncoder();
+ if (decoder == null) decoder = getDecoder();
return decoder.decode(value);
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -30,7 +30,7 @@
import java.util.Calendar;
import java.util.Date;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
@@ -43,6 +43,7 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#URI} values.
+ *
* @author Randall Hauch
*/
@Immutable
@@ -50,8 +51,8 @@
private final NamespaceRegistry namespaceRegistry;
- public UriValueFactory( NamespaceRegistry namespaceRegistry, TextEncoder encoder,
ValueFactory<String> stringValueFactory ) {
- super(PropertyType.URI, encoder, stringValueFactory);
+ public UriValueFactory( NamespaceRegistry namespaceRegistry, TextDecoder decoder,
ValueFactory<String> stringValueFactory ) {
+ super(PropertyType.URI, decoder, stringValueFactory);
ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
this.namespaceRegistry = namespaceRegistry;
}
@@ -71,9 +72,9 @@
/**
* {@inheritDoc}
*/
- public URI create( String value, TextEncoder decoder ) {
+ public URI create( String value, TextDecoder decoder ) {
// this probably doesn't really need to call the decoder, but by doing so
then we don't care at all what the decoder does
- return create(getEncoder(decoder).decode(value));
+ return create(getDecoder(decoder).decode(value));
}
/**
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -30,7 +30,7 @@
import java.util.Date;
import java.util.UUID;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -41,13 +41,14 @@
/**
* The standard {@link ValueFactory} for {@link PropertyType#REFERENCE} values.
+ *
* @author Randall Hauch
*/
@Immutable
public class UuidReferenceValueFactory extends AbstractValueFactory<Reference> {
- public UuidReferenceValueFactory( TextEncoder encoder, ValueFactory<String>
stringValueFactory ) {
- super(PropertyType.REFERENCE, encoder, stringValueFactory);
+ public UuidReferenceValueFactory( TextDecoder decoder, ValueFactory<String>
stringValueFactory ) {
+ super(PropertyType.REFERENCE, decoder, stringValueFactory);
}
/**
@@ -66,9 +67,9 @@
/**
* {@inheritDoc}
*/
- public Reference create( String value, TextEncoder decoder ) {
+ public Reference create( String value, TextDecoder decoder ) {
// this probably doesn't really need to call the decoder, but by doing so
then we don't care at all what the decoder does
- return create(getEncoder(decoder).decode(value));
+ return create(getDecoder(decoder).decode(value));
}
/**
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -33,7 +33,7 @@
import java.util.Calendar;
import java.util.Date;
import org.jboss.dna.common.text.NoOpEncoder;
-import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -48,19 +48,19 @@
*/
public class AbstractValueFactoryTest {
- public static final TextEncoder CUSTOM_ENCODER = new NoOpEncoder();
+ public static final TextDecoder CUSTOM_DECODER = new NoOpEncoder();
private static class MockFactory extends AbstractValueFactory<String> {
- protected MockFactory( TextEncoder encoder, StringValueFactory stringValueFactory
) {
- super(PropertyType.STRING, encoder, stringValueFactory);
+ protected MockFactory( TextDecoder decoder, StringValueFactory stringValueFactory
) {
+ super(PropertyType.STRING, decoder, stringValueFactory);
}
public String create( String value ) throws ValueFormatException {
return null;
}
- public String create( String value, TextEncoder decoder ) throws
ValueFormatException {
+ public String create( String value, TextDecoder decoder ) throws
ValueFormatException {
return null;
}
@@ -134,29 +134,29 @@
@Test
public void shouldHaveDefaultEncoderIfNullPassedIntoConstructor() {
- assertThat(factory.getEncoder(), is(notNullValue()));
- assertThat(factory.getEncoder(),
is(sameInstance(ValueFactory.DEFAULT_ENCODER)));
+ assertThat(factory.getDecoder(), is(notNullValue()));
+ assertThat(factory.getDecoder(),
is(sameInstance(ValueFactory.DEFAULT_DECODER)));
}
@Test
public void shouldReturnTextEncoderPassedIntoConstructor() {
- factory = new MockFactory(CUSTOM_ENCODER, null);
- assertThat(factory.getEncoder(), is(notNullValue()));
- assertThat(factory.getEncoder(), is(sameInstance(CUSTOM_ENCODER)));
+ factory = new MockFactory(CUSTOM_DECODER, null);
+ assertThat(factory.getDecoder(), is(notNullValue()));
+ assertThat(factory.getDecoder(), is(sameInstance(CUSTOM_DECODER)));
}
@Test
public void shouldReturnDefaultTextEncoderWhenNullPassedToGetEncoder() {
- assertThat(factory.getEncoder(),
is(sameInstance(ValueFactory.DEFAULT_ENCODER)));
- assertThat(factory.getEncoder(null),
is(sameInstance(ValueFactory.DEFAULT_ENCODER)));
- assertThat(factory.getEncoder(CUSTOM_ENCODER),
is(sameInstance(CUSTOM_ENCODER)));
+ assertThat(factory.getDecoder(),
is(sameInstance(ValueFactory.DEFAULT_DECODER)));
+ assertThat(factory.getDecoder(null),
is(sameInstance(ValueFactory.DEFAULT_DECODER)));
+ assertThat(factory.getDecoder(CUSTOM_DECODER),
is(sameInstance(CUSTOM_DECODER)));
}
@Test
public void shouldReturnSuppliedTextEncoderWhenNonNullPassedToGetEncoder() {
- assertThat(factory.getEncoder(),
is(sameInstance(ValueFactory.DEFAULT_ENCODER)));
- assertThat(factory.getEncoder(null),
is(sameInstance(ValueFactory.DEFAULT_ENCODER)));
- assertThat(factory.getEncoder(CUSTOM_ENCODER),
is(sameInstance(CUSTOM_ENCODER)));
+ assertThat(factory.getDecoder(),
is(sameInstance(ValueFactory.DEFAULT_DECODER)));
+ assertThat(factory.getDecoder(null),
is(sameInstance(ValueFactory.DEFAULT_DECODER)));
+ assertThat(factory.getDecoder(CUSTOM_DECODER),
is(sameInstance(CUSTOM_DECODER)));
}
@Test
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -41,7 +41,6 @@
private ValueFactory<String> stringValueFactory;
private NameValueFactory nameFactory;
private PathValueFactory factory;
- private TextEncoder encoder;
private Name validName;
private Path.Segment segment;
private Path.Segment segment2;
@@ -50,11 +49,10 @@
public void beforeEach() throws Exception {
this.registry = new BasicNamespaceRegistry();
this.registry.register("dna",
"http://www.jboss.org/dna/namespace");
- this.encoder = Path.DEFAULT_ENCODER;
- this.stringValueFactory = new StringValueFactory(encoder);
- this.nameFactory = new NameValueFactory(registry, encoder, stringValueFactory);
+ this.stringValueFactory = new StringValueFactory(Path.DEFAULT_DECODER,
Path.DEFAULT_ENCODER);
+ this.nameFactory = new NameValueFactory(registry, Path.DEFAULT_DECODER,
stringValueFactory);
this.validName = nameFactory.create("dna:something");
- this.factory = new PathValueFactory(encoder, stringValueFactory, nameFactory);
+ this.factory = new PathValueFactory(Path.DEFAULT_DECODER, stringValueFactory,
nameFactory);
}
@Test( expected = IllegalArgumentException.class )
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -46,731 +46,718 @@
*/
public class BasicPathTest {
- public static final TextEncoder NO_OP_ENCODER = Path.NO_OP_ENCODER;
- public static final Path ROOT = BasicPath.ROOT;
+ public static final TextEncoder NO_OP_ENCODER = Path.NO_OP_ENCODER;
+ public static final Path ROOT = BasicPath.ROOT;
- private BasicNamespaceRegistry namespaceRegistry;
- private String validNamespaceUri;
- private Path path;
- private Path path2;
- private Path.Segment[] validSegments;
- private List<Path.Segment> validSegmentsList;
- private Name[] validSegmentNames;
- private String validNamespacePrefix;
- private PathValueFactory pathFactory;
+ private BasicNamespaceRegistry namespaceRegistry;
+ private String validNamespaceUri;
+ private Path path;
+ private Path path2;
+ private Path.Segment[] validSegments;
+ private List<Path.Segment> validSegmentsList;
+ private Name[] validSegmentNames;
+ private String validNamespacePrefix;
+ private PathValueFactory pathFactory;
- @Before
- public void beforeEach() throws Exception {
- validNamespacePrefix = "dna";
- validNamespaceUri = "http://www.jboss.org/dna";
- validSegmentNames = new Name[] {new BasicName(validNamespaceUri, "a"), new
BasicName(validNamespaceUri, "b"),
- new BasicName(validNamespaceUri, "c")};
- validSegments = new Path.Segment[] {new BasicPathSegment(validSegmentNames[0]),
- new BasicPathSegment(validSegmentNames[1]), new
BasicPathSegment(validSegmentNames[1])};
- validSegmentsList = new ArrayList<Path.Segment>();
- for (Path.Segment segment : validSegments) {
- validSegmentsList.add(segment);
- }
- path = new BasicPath(validSegmentsList, true);
- namespaceRegistry = new BasicNamespaceRegistry();
- namespaceRegistry.register(validNamespacePrefix, validNamespaceUri);
- StringValueFactory stringValueFactory = new StringValueFactory(Path.DEFAULT_ENCODER);
- NameValueFactory nameValueFactory = new NameValueFactory(namespaceRegistry,
Path.DEFAULT_ENCODER, stringValueFactory);
- pathFactory = new PathValueFactory(Path.DEFAULT_ENCODER, stringValueFactory,
nameValueFactory);
- }
+ @Before
+ public void beforeEach() throws Exception {
+ validNamespacePrefix = "dna";
+ validNamespaceUri = "http://www.jboss.org/dna";
+ validSegmentNames = new Name[] {new BasicName(validNamespaceUri, "a"),
new BasicName(validNamespaceUri, "b"), new BasicName(validNamespaceUri,
"c")};
+ validSegments = new Path.Segment[] {new BasicPathSegment(validSegmentNames[0]),
new BasicPathSegment(validSegmentNames[1]), new BasicPathSegment(validSegmentNames[1])};
+ validSegmentsList = new ArrayList<Path.Segment>();
+ for (Path.Segment segment : validSegments) {
+ validSegmentsList.add(segment);
+ }
+ path = new BasicPath(validSegmentsList, true);
+ namespaceRegistry = new BasicNamespaceRegistry();
+ namespaceRegistry.register(validNamespacePrefix, validNamespaceUri);
+ StringValueFactory stringValueFactory = new
StringValueFactory(Path.DEFAULT_DECODER, Path.DEFAULT_ENCODER);
+ NameValueFactory nameValueFactory = new NameValueFactory(namespaceRegistry,
Path.DEFAULT_DECODER, stringValueFactory);
+ pathFactory = new PathValueFactory(Path.DEFAULT_DECODER, stringValueFactory,
nameValueFactory);
+ }
- @Test
- public void shouldCreateAbsolutePathFromListOfValidSegments() {
- path = new BasicPath(validSegmentsList, true);
- assertThat(path.isAbsolute(), is(true));
- assertThat(path.isNormalized(), is(true));
- assertThat(path.getSegmentsList(), is(validSegmentsList));
- assertThat(path.size(), is(validSegmentsList.size()));
- }
+ @Test
+ public void shouldCreateAbsolutePathFromListOfValidSegments() {
+ path = new BasicPath(validSegmentsList, true);
+ assertThat(path.isAbsolute(), is(true));
+ assertThat(path.isNormalized(), is(true));
+ assertThat(path.getSegmentsList(), is(validSegmentsList));
+ assertThat(path.size(), is(validSegmentsList.size()));
+ }
- @Test
- public void shouldCreateRelativePathFromListOfValidSegments() {
- path = new BasicPath(validSegmentsList, false);
- assertThat(path.isAbsolute(), is(false));
- assertThat(path.isNormalized(), is(true));
- assertThat(path.getSegmentsList(), is(validSegmentsList));
- assertThat(path.size(), is(validSegmentsList.size()));
- }
+ @Test
+ public void shouldCreateRelativePathFromListOfValidSegments() {
+ path = new BasicPath(validSegmentsList, false);
+ assertThat(path.isAbsolute(), is(false));
+ assertThat(path.isNormalized(), is(true));
+ assertThat(path.getSegmentsList(), is(validSegmentsList));
+ assertThat(path.size(), is(validSegmentsList.size()));
+ }
- @Test
- public void shouldCreateAbsolutePathWithParentSegment() {
- validSegmentsList.add(Path.PARENT_SEGMENT);
- path = new BasicPath(validSegmentsList, true);
- assertThat(path.isAbsolute(), is(true));
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getSegmentsList(), is(validSegmentsList));
- assertThat(path.size(), is(validSegmentsList.size()));
- }
+ @Test
+ public void shouldCreateAbsolutePathWithParentSegment() {
+ validSegmentsList.add(Path.PARENT_SEGMENT);
+ path = new BasicPath(validSegmentsList, true);
+ assertThat(path.isAbsolute(), is(true));
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getSegmentsList(), is(validSegmentsList));
+ assertThat(path.size(), is(validSegmentsList.size()));
+ }
- @Test
- public void shouldCreateRelativePathWithParentSegment() {
- validSegmentsList.add(Path.PARENT_SEGMENT);
- path = new BasicPath(validSegmentsList, false);
- assertThat(path.isAbsolute(), is(false));
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getSegmentsList(), is(validSegmentsList));
- assertThat(path.size(), is(validSegmentsList.size()));
- }
+ @Test
+ public void shouldCreateRelativePathWithParentSegment() {
+ validSegmentsList.add(Path.PARENT_SEGMENT);
+ path = new BasicPath(validSegmentsList, false);
+ assertThat(path.isAbsolute(), is(false));
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getSegmentsList(), is(validSegmentsList));
+ assertThat(path.size(), is(validSegmentsList.size()));
+ }
- @Test
- public void shouldCreateAbsolutePathWithSelfSegment() {
- validSegmentsList.add(Path.SELF_SEGMENT);
- path = new BasicPath(validSegmentsList, true);
- assertThat(path.isAbsolute(), is(true));
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getSegmentsList(), is(validSegmentsList));
- assertThat(path.size(), is(validSegmentsList.size()));
- }
+ @Test
+ public void shouldCreateAbsolutePathWithSelfSegment() {
+ validSegmentsList.add(Path.SELF_SEGMENT);
+ path = new BasicPath(validSegmentsList, true);
+ assertThat(path.isAbsolute(), is(true));
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getSegmentsList(), is(validSegmentsList));
+ assertThat(path.size(), is(validSegmentsList.size()));
+ }
- @Test
- public void shouldCreateRelativePathWithSelfSegment() {
- validSegmentsList.add(Path.SELF_SEGMENT);
- path = new BasicPath(validSegmentsList, false);
- assertThat(path.isAbsolute(), is(false));
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getSegmentsList(), is(validSegmentsList));
- assertThat(path.size(), is(validSegmentsList.size()));
- }
+ @Test
+ public void shouldCreateRelativePathWithSelfSegment() {
+ validSegmentsList.add(Path.SELF_SEGMENT);
+ path = new BasicPath(validSegmentsList, false);
+ assertThat(path.isAbsolute(), is(false));
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getSegmentsList(), is(validSegmentsList));
+ assertThat(path.size(), is(validSegmentsList.size()));
+ }
- @Test
- public void shouldCreatePathWithNoNamespacePrefixes() {
- path = pathFactory.create("/a/b/c/");
- assertThat(path.size(), is(3));
- assertThat(path, hasSegments(pathFactory, "a", "b",
"c"));
- }
+ @Test
+ public void shouldCreatePathWithNoNamespacePrefixes() {
+ path = pathFactory.create("/a/b/c/");
+ assertThat(path.size(), is(3));
+ assertThat(path, hasSegments(pathFactory, "a", "b",
"c"));
+ }
- @Test
- public void shouldConstructRelativePath() {
- assertThat(pathFactory.create("a/b/c").isAbsolute(), is(false));
- assertThat(pathFactory.create("a/b/c").isNormalized(), is(true));
- assertThat(pathFactory.create("a/b/c").size(), is(3));
- assertThat(pathFactory.create("a/b/c").getString(namespaceRegistry),
is("a/b/c"));
- }
+ @Test
+ public void shouldConstructRelativePath() {
+ assertThat(pathFactory.create("a/b/c").isAbsolute(), is(false));
+ assertThat(pathFactory.create("a/b/c").isNormalized(), is(true));
+ assertThat(pathFactory.create("a/b/c").size(), is(3));
+ assertThat(pathFactory.create("a/b/c").getString(namespaceRegistry),
is("a/b/c"));
+ }
- @Test
- public void shouldConstructRelativePathToSelf() {
- assertThat(pathFactory.create(".").isAbsolute(), is(false));
- assertThat(pathFactory.create(".").size(), is(1));
- assertThat(pathFactory.create("."), hasSegments(pathFactory, Path.SELF));
+ @Test
+ public void shouldConstructRelativePathToSelf() {
+ assertThat(pathFactory.create(".").isAbsolute(), is(false));
+ assertThat(pathFactory.create(".").size(), is(1));
+ assertThat(pathFactory.create("."), hasSegments(pathFactory,
Path.SELF));
- assertThat(pathFactory.create("./").isAbsolute(), is(false));
- assertThat(pathFactory.create("./").size(), is(1));
- assertThat(pathFactory.create("./"), hasSegments(pathFactory, Path.SELF));
- }
+ assertThat(pathFactory.create("./").isAbsolute(), is(false));
+ assertThat(pathFactory.create("./").size(), is(1));
+ assertThat(pathFactory.create("./"), hasSegments(pathFactory,
Path.SELF));
+ }
- @Test
- public void shouldConstructRelativePathToParent() {
- assertThat(pathFactory.create("..").isAbsolute(), is(false));
- assertThat(pathFactory.create("..").size(), is(1));
- assertThat(pathFactory.create(".."), hasSegments(pathFactory, Path.PARENT));
+ @Test
+ public void shouldConstructRelativePathToParent() {
+ assertThat(pathFactory.create("..").isAbsolute(), is(false));
+ assertThat(pathFactory.create("..").size(), is(1));
+ assertThat(pathFactory.create(".."), hasSegments(pathFactory,
Path.PARENT));
- assertThat(pathFactory.create("../").isAbsolute(), is(false));
- assertThat(pathFactory.create("../").size(), is(1));
- assertThat(pathFactory.create("../"), hasSegments(pathFactory,
Path.PARENT));
- }
+ assertThat(pathFactory.create("../").isAbsolute(), is(false));
+ assertThat(pathFactory.create("../").size(), is(1));
+ assertThat(pathFactory.create("../"), hasSegments(pathFactory,
Path.PARENT));
+ }
- @Test
- public void shouldConstructRootPathFromStringWithSingleDelimiter() {
- assertThat(pathFactory.create("/"), is(ROOT));
- assertThat(pathFactory.create("/").isRoot(), is(true));
- }
+ @Test
+ public void shouldConstructRootPathFromStringWithSingleDelimiter() {
+ assertThat(pathFactory.create("/"), is(ROOT));
+ assertThat(pathFactory.create("/").isRoot(), is(true));
+ }
- @Test( expected = ValueFormatException.class )
- public void shouldNotConstructPathWithSuccessiveDelimiters() {
- pathFactory.create("///a/b///c//d//");
- }
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotConstructPathWithSuccessiveDelimiters() {
+ pathFactory.create("///a/b///c//d//");
+ }
- @Test( expected = ValueFormatException.class )
- public void shouldNotConstructPathWithOnlyDelimiters() {
- pathFactory.create("///");
- }
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotConstructPathWithOnlyDelimiters() {
+ pathFactory.create("///");
+ }
- @Test( expected = IllegalArgumentException.class )
- public void shouldNotConstructPathFromNullList() {
- new BasicPath(null, true);
- }
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotConstructPathFromNullList() {
+ new BasicPath(null, true);
+ }
- @Test
- public void shouldConstructPathFromStringAndShouldIgnoreLeadingAndTrailingWhitespace()
{
- assertThat(pathFactory.create(" \t / \t").toString(), is("/"));
- }
+ @Test
+ public void
shouldConstructPathFromStringAndShouldIgnoreLeadingAndTrailingWhitespace() {
+ assertThat(pathFactory.create(" \t / \t").toString(),
is("/"));
+ }
- @Test
- public void shouldConstructRelativePathIfSuppliedPathHasNoLeadingDelimiter() {
- assertThat(pathFactory.create("a"), hasSegments(pathFactory,
"a"));
- }
+ @Test
+ public void shouldConstructRelativePathIfSuppliedPathHasNoLeadingDelimiter() {
+ assertThat(pathFactory.create("a"), hasSegments(pathFactory,
"a"));
+ }
- @Test
- public void shouldHaveSizeThatReflectsNumberOfSegments() {
- assertThat(path.size(), is(validSegmentsList.size()));
- }
+ @Test
+ public void shouldHaveSizeThatReflectsNumberOfSegments() {
+ assertThat(path.size(), is(validSegmentsList.size()));
+ }
- @Test
- public void shouldIterateOverAllSegmentsReturnedByList() {
- Iterator<Path.Segment> expectedIter = validSegmentsList.iterator();
- for (Path.Segment segment : path) {
- assertThat(segment, is(expectedIter.next()));
- }
+ @Test
+ public void shouldIterateOverAllSegmentsReturnedByList() {
+ Iterator<Path.Segment> expectedIter = validSegmentsList.iterator();
+ for (Path.Segment segment : path) {
+ assertThat(segment, is(expectedIter.next()));
+ }
- expectedIter = path.getSegmentsList().iterator();
- for (Path.Segment segment : path) {
- assertThat(segment, is(expectedIter.next()));
- }
- }
+ expectedIter = path.getSegmentsList().iterator();
+ for (Path.Segment segment : path) {
+ assertThat(segment, is(expectedIter.next()));
+ }
+ }
- @Test
- public void shouldReturnRootForAncestorOfRoot() {
- assertThat(BasicPath.ROOT.getAncestor(), is(ROOT));
- }
+ @Test
+ public void shouldReturnRootForAncestorOfRoot() {
+ assertThat(BasicPath.ROOT.getAncestor(), is(ROOT));
+ }
- @Test
- public void shouldReturnAncestorForNodeOtherThanRoot() {
- assertThat(path.getAncestor(), is(pathFactory.create("/dna:a/dna:b")));
- assertThat(path.getAncestor().getAncestor(),
is(pathFactory.create("/dna:a")));
- assertThat(path.getAncestor().getAncestor().getAncestor(), is(ROOT));
- }
+ @Test
+ public void shouldReturnAncestorForNodeOtherThanRoot() {
+ assertThat(path.getAncestor(),
is(pathFactory.create("/dna:a/dna:b")));
+ assertThat(path.getAncestor().getAncestor(),
is(pathFactory.create("/dna:a")));
+ assertThat(path.getAncestor().getAncestor().getAncestor(), is(ROOT));
+ }
- @Test
- public void shouldReturnNthDegreeAncestor() {
- assertThat(path.getAncestor(1), is(pathFactory.create("/dna:a/dna:b")));
- assertThat(path.getAncestor(2), is(pathFactory.create("/dna:a")));
- assertThat(path.getAncestor(3), is(ROOT));
- }
+ @Test
+ public void shouldReturnNthDegreeAncestor() {
+ assertThat(path.getAncestor(1),
is(pathFactory.create("/dna:a/dna:b")));
+ assertThat(path.getAncestor(2), is(pathFactory.create("/dna:a")));
+ assertThat(path.getAncestor(3), is(ROOT));
+ }
- @Test( expected = PathNotFoundException.class )
- public void shouldNotAllowAncestorDegreeLargerThanSize() {
- path.getAncestor(path.size() + 1);
- }
+ @Test( expected = PathNotFoundException.class )
+ public void shouldNotAllowAncestorDegreeLargerThanSize() {
+ path.getAncestor(path.size() + 1);
+ }
- @Test( expected = IllegalArgumentException.class )
- public void shouldNotAllowNegativeAncestorDegree() {
- path.getAncestor(-1);
- }
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNegativeAncestorDegree() {
+ path.getAncestor(-1);
+ }
- @Test
- public void shouldReturnRootForAnyAncestorExactDegreeFromRoot() {
- assertThat(path.getAncestor(path.size()), is(ROOT));
- assertThat(ROOT.getAncestor(0), is(ROOT));
- }
+ @Test
+ public void shouldReturnRootForAnyAncestorExactDegreeFromRoot() {
+ assertThat(path.getAncestor(path.size()), is(ROOT));
+ assertThat(ROOT.getAncestor(0), is(ROOT));
+ }
- @Test
- public void shouldConsiderRootTheLowestCommonAncestorOfAnyNodeAndRoot() {
- assertThat(path.getCommonAncestor(ROOT), is(ROOT));
- assertThat(ROOT.getCommonAncestor(path), is(ROOT));
- }
+ @Test
+ public void shouldConsiderRootTheLowestCommonAncestorOfAnyNodeAndRoot() {
+ assertThat(path.getCommonAncestor(ROOT), is(ROOT));
+ assertThat(ROOT.getCommonAncestor(path), is(ROOT));
+ }
- @Test
- public void shouldReturnNullForLowestCommonAncestorWithNullPath() {
- assertThat(path.getCommonAncestor(null), is(nullValue()));
- }
+ @Test
+ public void shouldReturnNullForLowestCommonAncestorWithNullPath() {
+ assertThat(path.getCommonAncestor(null), is(nullValue()));
+ }
- @Test
- public void shouldFindLowestCommonAncestorBetweenTwoNonRootNodesOnCommonBranch() {
- Path path1 = pathFactory.create("/a/y/z");
- Path path2 = pathFactory.create("/a/b/c");
- Path common = pathFactory.create("/a");
- assertThat(path1.getCommonAncestor(path2), is(common));
+ @Test
+ public void shouldFindLowestCommonAncestorBetweenTwoNonRootNodesOnCommonBranch() {
+ Path path1 = pathFactory.create("/a/y/z");
+ Path path2 = pathFactory.create("/a/b/c");
+ Path common = pathFactory.create("/a");
+ assertThat(path1.getCommonAncestor(path2), is(common));
- path1 = pathFactory.create("/a/b/c");
- path2 = pathFactory.create("/a/b/c/d");
- common = path1;
- assertThat(path1.getCommonAncestor(path2), is(common));
+ path1 = pathFactory.create("/a/b/c");
+ path2 = pathFactory.create("/a/b/c/d");
+ common = path1;
+ assertThat(path1.getCommonAncestor(path2), is(common));
- path1 = pathFactory.create("/a/b/c/x/y/");
- path2 = pathFactory.create("/a/b/c/d/e/f/");
- common = pathFactory.create("/a/b/c");
- assertThat(path1.getCommonAncestor(path2), is(common));
- }
+ path1 = pathFactory.create("/a/b/c/x/y/");
+ path2 = pathFactory.create("/a/b/c/d/e/f/");
+ common = pathFactory.create("/a/b/c");
+ assertThat(path1.getCommonAncestor(path2), is(common));
+ }
- @Test
- public void shouldConsiderRootTheLowestCommonAncestorOfAnyNodesOnSeparateBrances() {
- Path path1 = pathFactory.create("/x/y/z");
- Path path2 = pathFactory.create("/a/b/c");
- Path common = ROOT;
- assertThat(path1.getCommonAncestor(path2), is(common));
- }
+ @Test
+ public void shouldConsiderRootTheLowestCommonAncestorOfAnyNodesOnSeparateBrances() {
+ Path path1 = pathFactory.create("/x/y/z");
+ Path path2 = pathFactory.create("/a/b/c");
+ Path common = ROOT;
+ assertThat(path1.getCommonAncestor(path2), is(common));
+ }
- @Test
- public void shouldConsiderNodeToBeAncestorOfEveryDecendantNode() {
- Path path1 = pathFactory.create("/a/y/z");
- Path path2 = pathFactory.create("/a/b/c");
- Path path3 = pathFactory.create("/x/b/c");
- Path path4 =
pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z");
- Path common = pathFactory.create("/a");
- assertThat(common.isAncestorOf(path1), is(true));
- assertThat(common.isAncestorOf(path2), is(true));
- assertThat(common.isAncestorOf(path3), is(false));
+ @Test
+ public void shouldConsiderNodeToBeAncestorOfEveryDecendantNode() {
+ Path path1 = pathFactory.create("/a/y/z");
+ Path path2 = pathFactory.create("/a/b/c");
+ Path path3 = pathFactory.create("/x/b/c");
+ Path path4 =
pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z");
+ Path common = pathFactory.create("/a");
+ assertThat(common.isAncestorOf(path1), is(true));
+ assertThat(common.isAncestorOf(path2), is(true));
+ assertThat(common.isAncestorOf(path3), is(false));
- assertThat(path1.getAncestor().isAncestorOf(path1), is(true));
- for (int i = 1; i < path1.size(); ++i) {
- assertThat(path1.getAncestor(i).isAncestorOf(path1), is(true));
- }
- for (int i = 1; i < path2.size(); ++i) {
- assertThat(path2.getAncestor(i).isAncestorOf(path2), is(true));
- }
- for (int i = 1; i < path3.size(); ++i) {
- assertThat(path3.getAncestor(i).isAncestorOf(path3), is(true));
- }
- for (int i = 1; i < path4.size(); ++i) {
- assertThat(path4.getAncestor(i).isAncestorOf(path4), is(true));
- }
- }
+ assertThat(path1.getAncestor().isAncestorOf(path1), is(true));
+ for (int i = 1; i < path1.size(); ++i) {
+ assertThat(path1.getAncestor(i).isAncestorOf(path1), is(true));
+ }
+ for (int i = 1; i < path2.size(); ++i) {
+ assertThat(path2.getAncestor(i).isAncestorOf(path2), is(true));
+ }
+ for (int i = 1; i < path3.size(); ++i) {
+ assertThat(path3.getAncestor(i).isAncestorOf(path3), is(true));
+ }
+ for (int i = 1; i < path4.size(); ++i) {
+ assertThat(path4.getAncestor(i).isAncestorOf(path4), is(true));
+ }
+ }
- @Test
- public void shouldConsiderNodeToBeDecendantOfEveryAncestorNode() {
- Path path1 = pathFactory.create("/a/y/z");
- Path path2 = pathFactory.create("/a/b/c");
- Path path3 = pathFactory.create("/x/b/c");
- Path path4 =
pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z");
- Path common = pathFactory.create("/a");
- assertThat(path1.isDecendantOf(common), is(true));
- assertThat(path2.isDecendantOf(common), is(true));
- assertThat(path3.isDecendantOf(common), is(false));
+ @Test
+ public void shouldConsiderNodeToBeDecendantOfEveryAncestorNode() {
+ Path path1 = pathFactory.create("/a/y/z");
+ Path path2 = pathFactory.create("/a/b/c");
+ Path path3 = pathFactory.create("/x/b/c");
+ Path path4 =
pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z");
+ Path common = pathFactory.create("/a");
+ assertThat(path1.isDecendantOf(common), is(true));
+ assertThat(path2.isDecendantOf(common), is(true));
+ assertThat(path3.isDecendantOf(common), is(false));
- assertThat(path1.getAncestor().isAncestorOf(path1), is(true));
- for (int i = 1; i < path1.size(); ++i) {
- assertThat(path1.isDecendantOf(path1.getAncestor(i)), is(true));
- }
- for (int i = 1; i < path2.size(); ++i) {
- assertThat(path2.isDecendantOf(path2.getAncestor(i)), is(true));
- }
- for (int i = 1; i < path3.size(); ++i) {
- assertThat(path3.isDecendantOf(path3.getAncestor(i)), is(true));
- }
- for (int i = 1; i < path4.size(); ++i) {
- assertThat(path4.isDecendantOf(path4.getAncestor(i)), is(true));
- }
- }
+ assertThat(path1.getAncestor().isAncestorOf(path1), is(true));
+ for (int i = 1; i < path1.size(); ++i) {
+ assertThat(path1.isDecendantOf(path1.getAncestor(i)), is(true));
+ }
+ for (int i = 1; i < path2.size(); ++i) {
+ assertThat(path2.isDecendantOf(path2.getAncestor(i)), is(true));
+ }
+ for (int i = 1; i < path3.size(); ++i) {
+ assertThat(path3.isDecendantOf(path3.getAncestor(i)), is(true));
+ }
+ for (int i = 1; i < path4.size(); ++i) {
+ assertThat(path4.isDecendantOf(path4.getAncestor(i)), is(true));
+ }
+ }
- @Test
- public void shouldNotConsiderNodeToBeAncestorOfItself() {
- Path path1 = pathFactory.create("/a/y/z");
- Path path2 = pathFactory.create("/a/b/c");
- Path path3 = pathFactory.create("/x/b/c");
- assertThat(path1.isAncestorOf(path1), is(false));
- assertThat(path2.isAncestorOf(path2), is(false));
- assertThat(path3.isAncestorOf(path3), is(false));
- assertThat(ROOT.isAncestorOf(ROOT), is(false));
- }
+ @Test
+ public void shouldNotConsiderNodeToBeAncestorOfItself() {
+ Path path1 = pathFactory.create("/a/y/z");
+ Path path2 = pathFactory.create("/a/b/c");
+ Path path3 = pathFactory.create("/x/b/c");
+ assertThat(path1.isAncestorOf(path1), is(false));
+ assertThat(path2.isAncestorOf(path2), is(false));
+ assertThat(path3.isAncestorOf(path3), is(false));
+ assertThat(ROOT.isAncestorOf(ROOT), is(false));
+ }
- @Test
- public void shouldNotConsiderNodeToBeDecendantOfItself() {
- Path path1 = pathFactory.create("/a/y/z");
- Path path2 = pathFactory.create("/a/b/c");
- Path path3 = pathFactory.create("/x/b/c");
- assertThat(path1.isDecendantOf(path1), is(false));
- assertThat(path2.isDecendantOf(path2), is(false));
- assertThat(path3.isDecendantOf(path3), is(false));
- assertThat(ROOT.isDecendantOf(ROOT), is(false));
- }
+ @Test
+ public void shouldNotConsiderNodeToBeDecendantOfItself() {
+ Path path1 = pathFactory.create("/a/y/z");
+ Path path2 = pathFactory.create("/a/b/c");
+ Path path3 = pathFactory.create("/x/b/c");
+ assertThat(path1.isDecendantOf(path1), is(false));
+ assertThat(path2.isDecendantOf(path2), is(false));
+ assertThat(path3.isDecendantOf(path3), is(false));
+ assertThat(ROOT.isDecendantOf(ROOT), is(false));
+ }
- @Test
- public void shouldNotConsiderRootToBeDecendantOfAnyNode() {
- Path path1 = pathFactory.create("/a/y/z");
- Path path2 = pathFactory.create("/a/b/c");
- Path path3 = pathFactory.create("/x/b/c");
- Path common = pathFactory.create("/a");
- assertThat(ROOT.isDecendantOf(path1), is(false));
- assertThat(ROOT.isDecendantOf(path2), is(false));
- assertThat(ROOT.isDecendantOf(path3), is(false));
- assertThat(ROOT.isDecendantOf(common), is(false));
- }
+ @Test
+ public void shouldNotConsiderRootToBeDecendantOfAnyNode() {
+ Path path1 = pathFactory.create("/a/y/z");
+ Path path2 = pathFactory.create("/a/b/c");
+ Path path3 = pathFactory.create("/x/b/c");
+ Path common = pathFactory.create("/a");
+ assertThat(ROOT.isDecendantOf(path1), is(false));
+ assertThat(ROOT.isDecendantOf(path2), is(false));
+ assertThat(ROOT.isDecendantOf(path3), is(false));
+ assertThat(ROOT.isDecendantOf(common), is(false));
+ }
- @Test
- public void shouldConsiderRootToBeAncestorOfAnyNode() {
- Path path1 = pathFactory.create("/a/y/z");
- Path path2 = pathFactory.create("/a/b/c");
- Path path3 = pathFactory.create("/x/b/c");
- Path common = pathFactory.create("/a");
- assertThat(ROOT.isAncestorOf(path1), is(true));
- assertThat(ROOT.isAncestorOf(path2), is(true));
- assertThat(ROOT.isAncestorOf(path3), is(true));
- assertThat(ROOT.isAncestorOf(common), is(true));
- }
+ @Test
+ public void shouldConsiderRootToBeAncestorOfAnyNode() {
+ Path path1 = pathFactory.create("/a/y/z");
+ Path path2 = pathFactory.create("/a/b/c");
+ Path path3 = pathFactory.create("/x/b/c");
+ Path common = pathFactory.create("/a");
+ assertThat(ROOT.isAncestorOf(path1), is(true));
+ assertThat(ROOT.isAncestorOf(path2), is(true));
+ assertThat(ROOT.isAncestorOf(path3), is(true));
+ assertThat(ROOT.isAncestorOf(common), is(true));
+ }
- @Test
- public void shouldNotConsiderRootToBeAncestorOfItself() {
- assertThat(ROOT.isAncestorOf(ROOT), is(false));
- }
+ @Test
+ public void shouldNotConsiderRootToBeAncestorOfItself() {
+ assertThat(ROOT.isAncestorOf(ROOT), is(false));
+ }
- @Test
- public void shouldNotConsiderRootToBeDecendantOfItself() {
- assertThat(ROOT.isDecendantOf(ROOT), is(false));
- }
+ @Test
+ public void shouldNotConsiderRootToBeDecendantOfItself() {
+ assertThat(ROOT.isDecendantOf(ROOT), is(false));
+ }
- @Test
- public void shouldNeverBeDecendantOfNullPath() {
- assertThat(path.isDecendantOf(null), is(false));
- assertThat(ROOT.isDecendantOf(null), is(false));
- }
+ @Test
+ public void shouldNeverBeDecendantOfNullPath() {
+ assertThat(path.isDecendantOf(null), is(false));
+ assertThat(ROOT.isDecendantOf(null), is(false));
+ }
- @Test
- public void shouldReturnNullForLastSegmentOfRoot() {
- assertThat(ROOT.getLastSegment(), is(nullValue()));
- }
+ @Test
+ public void shouldReturnNullForLastSegmentOfRoot() {
+ assertThat(ROOT.getLastSegment(), is(nullValue()));
+ }
- @Test
- public void shouldReturnLastSegmentOfNonRootPath() {
- Path path1 = pathFactory.create("/a/y/z");
- Path path2 = pathFactory.create("/a/b/c");
- Path path3 = pathFactory.create("/x/b/c");
- Path path4 =
pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x");
- assertThat(path1.getLastSegment().getName().getLocalName(), is("z"));
- assertThat(path2.getLastSegment().getName().getLocalName(), is("c"));
- assertThat(path3.getLastSegment().getName().getLocalName(), is("c"));
- assertThat(path4.getLastSegment().getName().getLocalName(), is("x"));
- }
+ @Test
+ public void shouldReturnLastSegmentOfNonRootPath() {
+ Path path1 = pathFactory.create("/a/y/z");
+ Path path2 = pathFactory.create("/a/b/c");
+ Path path3 = pathFactory.create("/x/b/c");
+ Path path4 =
pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x");
+ assertThat(path1.getLastSegment().getName().getLocalName(), is("z"));
+ assertThat(path2.getLastSegment().getName().getLocalName(), is("c"));
+ assertThat(path3.getLastSegment().getName().getLocalName(), is("c"));
+ assertThat(path4.getLastSegment().getName().getLocalName(), is("x"));
+ }
- @Test
- public void shouldNormalizePathWithSelfAndParentReferences() {
- path = pathFactory.create("/a/b/c/../d/./e/../..");
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a",
"b"));
- assertThat(path.getNormalizedPath().isAbsolute(), is(true));
- assertThat(path.getNormalizedPath().isNormalized(), is(true));
+ @Test
+ public void shouldNormalizePathWithSelfAndParentReferences() {
+ path = pathFactory.create("/a/b/c/../d/./e/../..");
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a",
"b"));
+ assertThat(path.getNormalizedPath().isAbsolute(), is(true));
+ assertThat(path.getNormalizedPath().isNormalized(), is(true));
- path = pathFactory.create("a/b/c/../d/./e/../..");
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a",
"b"));
- assertThat(path.getNormalizedPath().isAbsolute(), is(false));
- assertThat(path.getNormalizedPath().isNormalized(), is(true));
- }
+ path = pathFactory.create("a/b/c/../d/./e/../..");
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a",
"b"));
+ assertThat(path.getNormalizedPath().isAbsolute(), is(false));
+ assertThat(path.getNormalizedPath().isNormalized(), is(true));
+ }
- @Test
- public void shouldAlreadyBeNormalizedIfPathContainsNoParentOrSelfReferences() {
- assertThat(pathFactory.create("/a/b/c/d/e").isNormalized(), is(true));
- assertThat(pathFactory.create("a/b/c/d/e").isNormalized(), is(true));
- assertThat(pathFactory.create("a").isNormalized(), is(true));
- assertThat(pathFactory.create("/a").isNormalized(), is(true));
- assertThat(ROOT.isNormalized(), is(true));
- }
+ @Test
+ public void shouldAlreadyBeNormalizedIfPathContainsNoParentOrSelfReferences() {
+ assertThat(pathFactory.create("/a/b/c/d/e").isNormalized(), is(true));
+ assertThat(pathFactory.create("a/b/c/d/e").isNormalized(), is(true));
+ assertThat(pathFactory.create("a").isNormalized(), is(true));
+ assertThat(pathFactory.create("/a").isNormalized(), is(true));
+ assertThat(ROOT.isNormalized(), is(true));
+ }
- @Test
- public void shouldNotBeNormalizedIfPathContainsParentOrSelfReferences() {
- assertThat(pathFactory.create("/a/b/c/../d/./e/../..").isNormalized(),
is(false));
- assertThat(pathFactory.create("a/b/c/../d/./e/../..").isNormalized(),
is(false));
- assertThat(pathFactory.create("a/b/c/./d").isNormalized(), is(false));
- assertThat(pathFactory.create("/a/b/c/../d").isNormalized(), is(false));
- assertThat(pathFactory.create(".").isNormalized(), is(false));
- assertThat(pathFactory.create("/.").isNormalized(), is(false));
- }
+ @Test
+ public void shouldNotBeNormalizedIfPathContainsParentOrSelfReferences() {
+ assertThat(pathFactory.create("/a/b/c/../d/./e/../..").isNormalized(),
is(false));
+ assertThat(pathFactory.create("a/b/c/../d/./e/../..").isNormalized(),
is(false));
+ assertThat(pathFactory.create("a/b/c/./d").isNormalized(), is(false));
+ assertThat(pathFactory.create("/a/b/c/../d").isNormalized(),
is(false));
+ assertThat(pathFactory.create(".").isNormalized(), is(false));
+ assertThat(pathFactory.create("/.").isNormalized(), is(false));
+ }
- @Test( expected = InvalidPathException.class )
- public void shouldFailToReturnNormalizedPathIfPathContainsReferencesToParentsAboveRoot()
{
- path = pathFactory.create("/a/../../../..");
- assertThat(path.isNormalized(), is(false));
- path.getNormalizedPath();
- }
+ @Test( expected = InvalidPathException.class )
+ public void
shouldFailToReturnNormalizedPathIfPathContainsReferencesToParentsAboveRoot() {
+ path = pathFactory.create("/a/../../../..");
+ assertThat(path.isNormalized(), is(false));
+ path.getNormalizedPath();
+ }
- @Test
- public void
shouldReturnRootPathAsTheNormalizedPathForAnAbsolutePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved()
{
- // "/a/../b/../c/.." => "/"
- path = pathFactory.create("/a/../b/../c/../");
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getNormalizedPath(), is(ROOT));
- }
+ @Test
+ public void
shouldReturnRootPathAsTheNormalizedPathForAnAbsolutePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved()
{
+ // "/a/../b/../c/.." => "/"
+ path = pathFactory.create("/a/../b/../c/../");
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getNormalizedPath(), is(ROOT));
+ }
- @Test
- public void
shouldReturnSelfPathAsTheNormalizedPathForARelativePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved()
{
- // "a/../b/../c/.." => "."
- path = pathFactory.create("a/../b/../c/../");
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getNormalizedPath().size(), is(1));
- assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "."));
- }
+ @Test
+ public void
shouldReturnSelfPathAsTheNormalizedPathForARelativePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved()
{
+ // "a/../b/../c/.." => "."
+ path = pathFactory.create("a/../b/../c/../");
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getNormalizedPath().size(), is(1));
+ assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "."));
+ }
- @Test
- public void shouldNotHaveAnyParentOrSelfReferencesInTheNormalizedPathOfAnAbsolutePath()
{
- path = pathFactory.create("/a/b/c/../d/./e/../..");
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a",
"b"));
- assertThat(path.getNormalizedPath().isAbsolute(), is(true));
- assertThat(path.getNormalizedPath().isNormalized(), is(true));
- }
+ @Test
+ public void
shouldNotHaveAnyParentOrSelfReferencesInTheNormalizedPathOfAnAbsolutePath() {
+ path = pathFactory.create("/a/b/c/../d/./e/../..");
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a",
"b"));
+ assertThat(path.getNormalizedPath().isAbsolute(), is(true));
+ assertThat(path.getNormalizedPath().isNormalized(), is(true));
+ }
- @Test
- public void shouldNotHaveAnyParentReferencesInTheNormalizedPathOfARelativePath() {
- path = pathFactory.create("a/b/c/../d/./e/../..");
- assertThat(path.isNormalized(), is(false));
- assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a",
"b"));
- assertThat(path.getNormalizedPath().isAbsolute(), is(false));
- assertThat(path.getNormalizedPath().isNormalized(), is(true));
- }
+ @Test
+ public void shouldNotHaveAnyParentReferencesInTheNormalizedPathOfARelativePath() {
+ path = pathFactory.create("a/b/c/../d/./e/../..");
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a",
"b"));
+ assertThat(path.getNormalizedPath().isAbsolute(), is(false));
+ assertThat(path.getNormalizedPath().isNormalized(), is(true));
+ }
- @Test( expected = InvalidPathException.class )
- public void shouldNotComputeCanonicalPathOfNodeThatIsNotAbsolute() {
- pathFactory.create("a/b/c/../d/./e/../..").getCanonicalPath();
- }
+ @Test( expected = InvalidPathException.class )
+ public void shouldNotComputeCanonicalPathOfNodeThatIsNotAbsolute() {
+ pathFactory.create("a/b/c/../d/./e/../..").getCanonicalPath();
+ }
- @Test
- public void shouldReturnNormalizedPathForTheCanonicalPathOfAbsolutePath() {
- path = pathFactory.create("/a/b/c/../d/./e/../..");
- assertThat(path.isNormalized(), is(false));
- assertThat(path.isAbsolute(), is(true));
- assertThat(path.getCanonicalPath(), hasSegments(pathFactory, "a",
"b"));
- assertThat(path.getCanonicalPath().isAbsolute(), is(true));
- assertThat(path.getCanonicalPath().isNormalized(), is(true));
- }
+ @Test
+ public void shouldReturnNormalizedPathForTheCanonicalPathOfAbsolutePath() {
+ path = pathFactory.create("/a/b/c/../d/./e/../..");
+ assertThat(path.isNormalized(), is(false));
+ assertThat(path.isAbsolute(), is(true));
+ assertThat(path.getCanonicalPath(), hasSegments(pathFactory, "a",
"b"));
+ assertThat(path.getCanonicalPath().isAbsolute(), is(true));
+ assertThat(path.getCanonicalPath().isNormalized(), is(true));
+ }
- @Test
- public void shouldReturnSameSegmentsInIteratorAndArrayAndList() {
- testSegmentsByIteratorAndListAndArray("/a/b/c/../d/./e/../..", "a",
"b", "c", "..", "d", ".", "e",
"..", "..");
- testSegmentsByIteratorAndListAndArray("/a/b/c", "a", "b",
"c");
- testSegmentsByIteratorAndListAndArray("a/b/c/../d/./e/../..", "a",
"b", "c", "..", "d", ".", "e",
"..", "..");
- testSegmentsByIteratorAndListAndArray("a/b/c", "a", "b",
"c");
- testSegmentsByIteratorAndListAndArray("");
- testSegmentsByIteratorAndListAndArray(ROOT.getString());
- }
+ @Test
+ public void shouldReturnSameSegmentsInIteratorAndArrayAndList() {
+ testSegmentsByIteratorAndListAndArray("/a/b/c/../d/./e/../..",
"a", "b", "c", "..", "d", ".",
"e", "..", "..");
+ testSegmentsByIteratorAndListAndArray("/a/b/c", "a",
"b", "c");
+ testSegmentsByIteratorAndListAndArray("a/b/c/../d/./e/../..",
"a", "b", "c", "..", "d", ".",
"e", "..", "..");
+ testSegmentsByIteratorAndListAndArray("a/b/c", "a",
"b", "c");
+ testSegmentsByIteratorAndListAndArray("");
+ testSegmentsByIteratorAndListAndArray(ROOT.getString());
+ }
- public void testSegmentsByIteratorAndListAndArray( String pathStr,
- String... expectedSegmentStrings ) {
- path = pathFactory.create(pathStr);
- assertThat(expectedSegmentStrings.length, is(path.size()));
- Path.Segment[] segmentArray = path.getSegmentsArray();
- List<Path.Segment> segmentList = path.getSegmentsList();
- assertThat(segmentArray.length, is(path.size()));
- assertThat(segmentList.size(), is(path.size()));
- Iterator<Path.Segment> iter = path.iterator();
- Iterator<Path.Segment> listIter = segmentList.iterator();
- for (int i = 0; i != path.size(); ++i) {
- Path.Segment expected = pathFactory.createSegment(expectedSegmentStrings[i]);
- assertThat(path.getSegment(i), is(expected));
- assertThat(segmentArray[i], is(expected));
- assertThat(segmentList.get(i), is(expected));
- assertThat(iter.next(), is(expected));
- assertThat(listIter.next(), is(expected));
- }
- assertThat(iter.hasNext(), is(false));
- assertThat(listIter.hasNext(), is(false));
- }
+ public void testSegmentsByIteratorAndListAndArray( String pathStr, String...
expectedSegmentStrings ) {
+ path = pathFactory.create(pathStr);
+ assertThat(expectedSegmentStrings.length, is(path.size()));
+ Path.Segment[] segmentArray = path.getSegmentsArray();
+ List<Path.Segment> segmentList = path.getSegmentsList();
+ assertThat(segmentArray.length, is(path.size()));
+ assertThat(segmentList.size(), is(path.size()));
+ Iterator<Path.Segment> iter = path.iterator();
+ Iterator<Path.Segment> listIter = segmentList.iterator();
+ for (int i = 0; i != path.size(); ++i) {
+ Path.Segment expected =
pathFactory.createSegment(expectedSegmentStrings[i]);
+ assertThat(path.getSegment(i), is(expected));
+ assertThat(segmentArray[i], is(expected));
+ assertThat(segmentList.get(i), is(expected));
+ assertThat(iter.next(), is(expected));
+ assertThat(listIter.next(), is(expected));
+ }
+ assertThat(iter.hasNext(), is(false));
+ assertThat(listIter.hasNext(), is(false));
+ }
- @Test
- public void shouldGetStringWithNamespaceUrisIfNoNamespaceRegistryIsProvided() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- assertThat(path.getString(NO_OP_ENCODER),
-
is("/{http://www.jboss.org/dna}a/{}b/{http://www.jboss.org/dna}c/../...);
- }
+ @Test
+ public void shouldGetStringWithNamespaceUrisIfNoNamespaceRegistryIsProvided() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ assertThat(path.getString(NO_OP_ENCODER),
is("/{http://www.jboss.org/dna}a/{}b/{http://www.jboss.org/dna}c/../...);
+ }
- @Test
- public void
shouldGetStringWithNamespacePrefixesForAllNamesIfNamespaceRegistryIsProvided() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- assertThat(path.getString(namespaceRegistry, NO_OP_ENCODER),
is("/dna:a/b/dna:c/../d/./dna:e/../.."));
- namespaceRegistry.register("dna2", validNamespaceUri);
- assertThat(path.getString(namespaceRegistry, NO_OP_ENCODER),
is("/dna2:a/b/dna2:c/../d/./dna2:e/../.."));
- }
+ @Test
+ public void
shouldGetStringWithNamespacePrefixesForAllNamesIfNamespaceRegistryIsProvided() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ assertThat(path.getString(namespaceRegistry, NO_OP_ENCODER),
is("/dna:a/b/dna:c/../d/./dna:e/../.."));
+ namespaceRegistry.register("dna2", validNamespaceUri);
+ assertThat(path.getString(namespaceRegistry, NO_OP_ENCODER),
is("/dna2:a/b/dna2:c/../d/./dna2:e/../.."));
+ }
- @Test( expected = IndexOutOfBoundsException.class )
- public void shouldFailToReturnSubpathIfStartingIndexIsNegative() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- path.subpath(-1);
- }
+ @Test( expected = IndexOutOfBoundsException.class )
+ public void shouldFailToReturnSubpathIfStartingIndexIsNegative() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ path.subpath(-1);
+ }
- @Test( expected = IndexOutOfBoundsException.class )
- public void
shouldFailToReturnSubpathWithoutEndingIndexIfStartingIndexIsEqualToOrLargerThanSize() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- path.subpath(path.size() + 1);
- }
+ @Test( expected = IndexOutOfBoundsException.class )
+ public void
shouldFailToReturnSubpathWithoutEndingIndexIfStartingIndexIsEqualToOrLargerThanSize() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ path.subpath(path.size() + 1);
+ }
- @Test( expected = IndexOutOfBoundsException.class )
- public void
shouldFailToReturnSubpathWithEndingIndexIfStartingIndexIsEqualToOrLargerThanSize() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- path.subpath(path.size() + 1, path.size() + 2);
- }
+ @Test( expected = IndexOutOfBoundsException.class )
+ public void
shouldFailToReturnSubpathWithEndingIndexIfStartingIndexIsEqualToOrLargerThanSize() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ path.subpath(path.size() + 1, path.size() + 2);
+ }
- @Test( expected = IndexOutOfBoundsException.class )
- public void shouldFailToReturnSubpathIfEndingIndexIsSmallerThanStartingIndex() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- path.subpath(2, 1);
- }
+ @Test( expected = IndexOutOfBoundsException.class )
+ public void shouldFailToReturnSubpathIfEndingIndexIsSmallerThanStartingIndex() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ path.subpath(2, 1);
+ }
- @Test( expected = IndexOutOfBoundsException.class )
- public void shouldFailToReturnSubpathIfEndingIndexIsEqualToOrLargerThanSize() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- path.subpath(2, path.size() + 1);
- }
+ @Test( expected = IndexOutOfBoundsException.class )
+ public void shouldFailToReturnSubpathIfEndingIndexIsEqualToOrLargerThanSize() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ path.subpath(2, path.size() + 1);
+ }
- @Test
- public void shouldReturnRootAsSubpathIfStartingIndexAndEndingIndexAreBothZero() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- assertThat(path.subpath(0, 0), is(ROOT));
- }
+ @Test
+ public void shouldReturnRootAsSubpathIfStartingIndexAndEndingIndexAreBothZero() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ assertThat(path.subpath(0, 0), is(ROOT));
+ }
- @Test
- public void shouldReturnSubpathIfValidStartingIndexAndNoEndingIndexAreProvided() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- assertThat(path.subpath(0), hasSegments(pathFactory, "dna:a", "b",
"dna:c", "..", "d", ".", "dna:e",
"..", ".."));
- assertThat(path.subpath(0), is(path));
- assertThat(path.subpath(0), is(sameInstance(path)));
- assertThat(path.subpath(1), hasSegments(pathFactory, "b", "dna:c",
"..", "d", ".", "dna:e", "..",
".."));
- assertThat(path.subpath(2), hasSegments(pathFactory, "dna:c", "..",
"d", ".", "dna:e", "..", ".."));
- assertThat(path.subpath(3), hasSegments(pathFactory, "..", "d",
".", "dna:e", "..", ".."));
- assertThat(path.subpath(4), hasSegments(pathFactory, "d", ".",
"dna:e", "..", ".."));
- assertThat(path.subpath(5), hasSegments(pathFactory, ".", "dna:e",
"..", ".."));
- assertThat(path.subpath(6), hasSegments(pathFactory, "dna:e", "..",
".."));
- assertThat(path.subpath(7), hasSegments(pathFactory, "..", ".."));
- assertThat(path.subpath(8), hasSegments(pathFactory, ".."));
+ @Test
+ public void shouldReturnSubpathIfValidStartingIndexAndNoEndingIndexAreProvided() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ assertThat(path.subpath(0), hasSegments(pathFactory, "dna:a",
"b", "dna:c", "..", "d", ".",
"dna:e", "..", ".."));
+ assertThat(path.subpath(0), is(path));
+ assertThat(path.subpath(0), is(sameInstance(path)));
+ assertThat(path.subpath(1), hasSegments(pathFactory, "b",
"dna:c", "..", "d", ".", "dna:e",
"..", ".."));
+ assertThat(path.subpath(2), hasSegments(pathFactory, "dna:c",
"..", "d", ".", "dna:e", "..",
".."));
+ assertThat(path.subpath(3), hasSegments(pathFactory, "..",
"d", ".", "dna:e", "..", ".."));
+ assertThat(path.subpath(4), hasSegments(pathFactory, "d",
".", "dna:e", "..", ".."));
+ assertThat(path.subpath(5), hasSegments(pathFactory, ".",
"dna:e", "..", ".."));
+ assertThat(path.subpath(6), hasSegments(pathFactory, "dna:e",
"..", ".."));
+ assertThat(path.subpath(7), hasSegments(pathFactory, "..",
".."));
+ assertThat(path.subpath(8), hasSegments(pathFactory, ".."));
- path = pathFactory.create("dna:a/b/dna:c/../d/./dna:e/../..");
- assertThat(path.subpath(0), hasSegments(pathFactory, "dna:a", "b",
"dna:c", "..", "d", ".", "dna:e",
"..", ".."));
- assertThat(path.subpath(0), is(path));
- assertThat(path.subpath(0), is(sameInstance(path)));
- assertThat(path.subpath(1), hasSegments(pathFactory, "b", "dna:c",
"..", "d", ".", "dna:e", "..",
".."));
- assertThat(path.subpath(2), hasSegments(pathFactory, "dna:c", "..",
"d", ".", "dna:e", "..", ".."));
- assertThat(path.subpath(3), hasSegments(pathFactory, "..", "d",
".", "dna:e", "..", ".."));
- assertThat(path.subpath(4), hasSegments(pathFactory, "d", ".",
"dna:e", "..", ".."));
- assertThat(path.subpath(5), hasSegments(pathFactory, ".", "dna:e",
"..", ".."));
- assertThat(path.subpath(6), hasSegments(pathFactory, "dna:e", "..",
".."));
- assertThat(path.subpath(7), hasSegments(pathFactory, "..", ".."));
- assertThat(path.subpath(8), hasSegments(pathFactory, ".."));
- }
+ path = pathFactory.create("dna:a/b/dna:c/../d/./dna:e/../..");
+ assertThat(path.subpath(0), hasSegments(pathFactory, "dna:a",
"b", "dna:c", "..", "d", ".",
"dna:e", "..", ".."));
+ assertThat(path.subpath(0), is(path));
+ assertThat(path.subpath(0), is(sameInstance(path)));
+ assertThat(path.subpath(1), hasSegments(pathFactory, "b",
"dna:c", "..", "d", ".", "dna:e",
"..", ".."));
+ assertThat(path.subpath(2), hasSegments(pathFactory, "dna:c",
"..", "d", ".", "dna:e", "..",
".."));
+ assertThat(path.subpath(3), hasSegments(pathFactory, "..",
"d", ".", "dna:e", "..", ".."));
+ assertThat(path.subpath(4), hasSegments(pathFactory, "d",
".", "dna:e", "..", ".."));
+ assertThat(path.subpath(5), hasSegments(pathFactory, ".",
"dna:e", "..", ".."));
+ assertThat(path.subpath(6), hasSegments(pathFactory, "dna:e",
"..", ".."));
+ assertThat(path.subpath(7), hasSegments(pathFactory, "..",
".."));
+ assertThat(path.subpath(8), hasSegments(pathFactory, ".."));
+ }
- @Test
- public void shouldReturnSubpathIfValidStartingIndexAndEndingIndexAreProvided() {
- path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
- assertThat(path.subpath(0, path.size()), hasSegments(pathFactory,
- "dna:a",
- "b",
- "dna:c",
- "..",
- "d",
- ".",
- "dna:e",
- "..",
- ".."));
- assertThat(path.subpath(0, path.size()), is(path));
- assertThat(path.subpath(0, path.size()), is(sameInstance(path)));
- assertThat(path.subpath(1, path.size()), hasSegments(pathFactory, "b",
"dna:c", "..", "d", ".", "dna:e",
"..", ".."));
- assertThat(path.subpath(2, path.size()), hasSegments(pathFactory, "dna:c",
"..", "d", ".", "dna:e", "..",
".."));
- assertThat(path.subpath(3, path.size()), hasSegments(pathFactory, "..",
"d", ".", "dna:e", "..", ".."));
- assertThat(path.subpath(4, path.size()), hasSegments(pathFactory, "d",
".", "dna:e", "..", ".."));
- assertThat(path.subpath(5, path.size()), hasSegments(pathFactory, ".",
"dna:e", "..", ".."));
- assertThat(path.subpath(6, path.size()), hasSegments(pathFactory, "dna:e",
"..", ".."));
- assertThat(path.subpath(7, path.size()), hasSegments(pathFactory, "..",
".."));
- assertThat(path.subpath(8, path.size()), hasSegments(pathFactory, ".."));
+ @Test
+ public void shouldReturnSubpathIfValidStartingIndexAndEndingIndexAreProvided() {
+ path = pathFactory.create("/dna:a/b/dna:c/../d/./dna:e/../..");
+ assertThat(path.subpath(0, path.size()), hasSegments(pathFactory,
"dna:a", "b", "dna:c", "..", "d",
".", "dna:e", "..", ".."));
+ assertThat(path.subpath(0, path.size()), is(path));
+ assertThat(path.subpath(0, path.size()), is(sameInstance(path)));
+ assertThat(path.subpath(1, path.size()), hasSegments(pathFactory, "b",
"dna:c", "..", "d", ".", "dna:e",
"..", ".."));
+ assertThat(path.subpath(2, path.size()), hasSegments(pathFactory,
"dna:c", "..", "d", ".", "dna:e",
"..", ".."));
+ assertThat(path.subpath(3, path.size()), hasSegments(pathFactory, "..",
"d", ".", "dna:e", "..", ".."));
+ assertThat(path.subpath(4, path.size()), hasSegments(pathFactory, "d",
".", "dna:e", "..", ".."));
+ assertThat(path.subpath(5, path.size()), hasSegments(pathFactory, ".",
"dna:e", "..", ".."));
+ assertThat(path.subpath(6, path.size()), hasSegments(pathFactory,
"dna:e", "..", ".."));
+ assertThat(path.subpath(7, path.size()), hasSegments(pathFactory, "..",
".."));
+ assertThat(path.subpath(8, path.size()), hasSegments(pathFactory,
".."));
- assertThat(path.subpath(0, 2), hasSegments(pathFactory, "dna:a",
"b"));
- assertThat(path.subpath(1, 2), hasSegments(pathFactory, "b"));
- assertThat(path.subpath(1, 5), hasSegments(pathFactory, "b",
"dna:c", "..", "d"));
- assertThat(path.subpath(2, 5), hasSegments(pathFactory, "dna:c",
"..", "d"));
- assertThat(path.subpath(3, 5), hasSegments(pathFactory, "..",
"d"));
- }
+ assertThat(path.subpath(0, 2), hasSegments(pathFactory, "dna:a",
"b"));
+ assertThat(path.subpath(1, 2), hasSegments(pathFactory, "b"));
+ assertThat(path.subpath(1, 5), hasSegments(pathFactory, "b",
"dna:c", "..", "d"));
+ assertThat(path.subpath(2, 5), hasSegments(pathFactory, "dna:c",
"..", "d"));
+ assertThat(path.subpath(3, 5), hasSegments(pathFactory, "..",
"d"));
+ }
- @Test
- public void shouldFindRelativePaths() {
- path = pathFactory.create("/a/b/c/d");
- assertThat(path.relativeTo(pathFactory.create("/a/e/f")),
is(pathFactory.create("../../b/c/d")));
- assertThat(path.relativeTo(pathFactory.create("/e/f")),
is(pathFactory.create("../../a/b/c/d")));
+ @Test
+ public void shouldFindRelativePaths() {
+ path = pathFactory.create("/a/b/c/d");
+ assertThat(path.relativeTo(pathFactory.create("/a/e/f")),
is(pathFactory.create("../../b/c/d")));
+ assertThat(path.relativeTo(pathFactory.create("/e/f")),
is(pathFactory.create("../../a/b/c/d")));
- }
+ }
- @Test( expected = InvalidPathException.class )
- public void shouldNotAllowFindingRelativePathsFromRelativePaths() {
- path = pathFactory.create("a/b/c/d");
- path.relativeTo(pathFactory.create("/e/f"));
+ @Test( expected = InvalidPathException.class )
+ public void shouldNotAllowFindingRelativePathsFromRelativePaths() {
+ path = pathFactory.create("a/b/c/d");
+ path.relativeTo(pathFactory.create("/e/f"));
- }
+ }
- @Test( expected = InvalidPathException.class )
- public void shouldNotResolveRelativePathToAnotherRelativePath() {
- path = pathFactory.create("/a/b/c/d");
- path.relativeTo(pathFactory.create("e/f"));
+ @Test( expected = InvalidPathException.class )
+ public void shouldNotResolveRelativePathToAnotherRelativePath() {
+ path = pathFactory.create("/a/b/c/d");
+ path.relativeTo(pathFactory.create("e/f"));
- }
+ }
- @Test( expected = InvalidPathException.class )
- public void shouldNotResolveRelativePathUsingAnAbsolutePath() {
- path = pathFactory.create("/a/b/c/d");
- path.resolve(pathFactory.create("/e/f"));
- }
+ @Test( expected = InvalidPathException.class )
+ public void shouldNotResolveRelativePathUsingAnAbsolutePath() {
+ path = pathFactory.create("/a/b/c/d");
+ path.resolve(pathFactory.create("/e/f"));
+ }
- @Test
- public void shouldResolveRelativePathToAbsolutePath() {
- path = pathFactory.create("/a/b/c/d");
- path2 = path.resolve(pathFactory.create("../../e/f"));
- assertThat(path2, is(pathFactory.create("/a/b/e/f")));
- assertThat(path2.isAbsolute(), is(true));
- assertThat(path2.isNormalized(), is(true));
- }
+ @Test
+ public void shouldResolveRelativePathToAbsolutePath() {
+ path = pathFactory.create("/a/b/c/d");
+ path2 = path.resolve(pathFactory.create("../../e/f"));
+ assertThat(path2, is(pathFactory.create("/a/b/e/f")));
+ assertThat(path2.isAbsolute(), is(true));
+ assertThat(path2.isNormalized(), is(true));
+ }
- @Test
- public void shouldOrderPathsCorrectly() {
- List<Path> paths = new ArrayList<Path>();
- paths.add(pathFactory.create("/a"));
- paths.add(pathFactory.create("/a/b"));
- paths.add(pathFactory.create("/a/b/alpha"));
- paths.add(pathFactory.create("/a/b/beta"));
- paths.add(pathFactory.create("/a/b/dna:mixinTypes"));
- paths.add(pathFactory.create("/a/b/dna:name"));
- paths.add(pathFactory.create("/a/b/dna:primaryType"));
- paths.add(pathFactory.create("/a/c[1]"));
- paths.add(pathFactory.create("/a/c[1]/alpha"));
- paths.add(pathFactory.create("/a/c[1]/beta"));
- paths.add(pathFactory.create("/a/c[1]/dna:mixinTypes"));
- paths.add(pathFactory.create("/a/c[1]/dna:name"));
- paths.add(pathFactory.create("/a/c[1]/dna:primaryType"));
- paths.add(pathFactory.create("/a/c[2]"));
- paths.add(pathFactory.create("/a/c[2]/alpha"));
- paths.add(pathFactory.create("/a/c[2]/beta"));
- paths.add(pathFactory.create("/a/c[2]/dna:mixinTypes"));
- paths.add(pathFactory.create("/a/c[2]/dna:name"));
- paths.add(pathFactory.create("/a/c[2]/dna:primaryType"));
+ @Test
+ public void shouldOrderPathsCorrectly() {
+ List<Path> paths = new ArrayList<Path>();
+ paths.add(pathFactory.create("/a"));
+ paths.add(pathFactory.create("/a/b"));
+ paths.add(pathFactory.create("/a/b/alpha"));
+ paths.add(pathFactory.create("/a/b/beta"));
+ paths.add(pathFactory.create("/a/b/dna:mixinTypes"));
+ paths.add(pathFactory.create("/a/b/dna:name"));
+ paths.add(pathFactory.create("/a/b/dna:primaryType"));
+ paths.add(pathFactory.create("/a/c[1]"));
+ paths.add(pathFactory.create("/a/c[1]/alpha"));
+ paths.add(pathFactory.create("/a/c[1]/beta"));
+ paths.add(pathFactory.create("/a/c[1]/dna:mixinTypes"));
+ paths.add(pathFactory.create("/a/c[1]/dna:name"));
+ paths.add(pathFactory.create("/a/c[1]/dna:primaryType"));
+ paths.add(pathFactory.create("/a/c[2]"));
+ paths.add(pathFactory.create("/a/c[2]/alpha"));
+ paths.add(pathFactory.create("/a/c[2]/beta"));
+ paths.add(pathFactory.create("/a/c[2]/dna:mixinTypes"));
+ paths.add(pathFactory.create("/a/c[2]/dna:name"));
+ paths.add(pathFactory.create("/a/c[2]/dna:primaryType"));
- // Randomize the list of paths, so we have something to sort ...
- List<Path> randomizedPaths = new ArrayList<Path>(paths);
- Collections.shuffle(randomizedPaths);
- assertThat(randomizedPaths, is(not(paths)));
+ // Randomize the list of paths, so we have something to sort ...
+ List<Path> randomizedPaths = new ArrayList<Path>(paths);
+ Collections.shuffle(randomizedPaths);
+ assertThat(randomizedPaths, is(not(paths)));
- // Sort ...
- Collections.sort(randomizedPaths);
- assertThat(randomizedPaths, is(paths));
- }
+ // Sort ...
+ Collections.sort(randomizedPaths);
+ assertThat(randomizedPaths, is(paths));
+ }
- @Test
- public void shouldGetNormalizedPathOfSelfShouldBeSame() {
- assertThat(pathFactory.create(".").getNormalizedPath(),
is(pathFactory.create(".")));
- assertThat(pathFactory.create("./").getNormalizedPath(),
is(pathFactory.create(".")));
- assertThat(pathFactory.create("./././").getNormalizedPath(),
is(pathFactory.create(".")));
- }
+ @Test
+ public void shouldGetNormalizedPathOfSelfShouldBeSame() {
+ assertThat(pathFactory.create(".").getNormalizedPath(),
is(pathFactory.create(".")));
+ assertThat(pathFactory.create("./").getNormalizedPath(),
is(pathFactory.create(".")));
+ assertThat(pathFactory.create("./././").getNormalizedPath(),
is(pathFactory.create(".")));
+ }
- @Test
- public void shouldGetNormalizedPathWithParentReferences() {
- assertThat(pathFactory.create("..").getNormalizedPath(),
is(pathFactory.create("..")));
- assertThat(pathFactory.create("../").getNormalizedPath(),
is(pathFactory.create("../")));
- assertThat(pathFactory.create("../../../../../..").getNormalizedPath(),
is(pathFactory.create("../../../../../..")));
- }
+ @Test
+ public void shouldGetNormalizedPathWithParentReferences() {
+ assertThat(pathFactory.create("..").getNormalizedPath(),
is(pathFactory.create("..")));
+ assertThat(pathFactory.create("../").getNormalizedPath(),
is(pathFactory.create("../")));
+ assertThat(pathFactory.create("../../../../../..").getNormalizedPath(),
is(pathFactory.create("../../../../../..")));
+ }
- @Test
- public void shouldGetRelativePathUsingSelf() {
- path = pathFactory.create("/a/b/c/d/e/f");
- assertThat(path.resolve(pathFactory.create(".")), is(sameInstance(path)));
- assertThat(path.resolve(pathFactory.create("././.")),
is(sameInstance(path)));
- }
+ @Test
+ public void shouldGetRelativePathUsingSelf() {
+ path = pathFactory.create("/a/b/c/d/e/f");
+ assertThat(path.resolve(pathFactory.create(".")),
is(sameInstance(path)));
+ assertThat(path.resolve(pathFactory.create("././.")),
is(sameInstance(path)));
+ }
- @Test
- public void shouldResolveRelativePathToParent() {
- path = pathFactory.create("/a/b/c/d/e/f");
- assertThat(path.resolve(pathFactory.create("..")), is(path.getAncestor()));
- assertThat(path.resolve(pathFactory.create("..")), hasSegments(pathFactory,
"a", "b", "c", "d", "e"));
- }
+ @Test
+ public void shouldResolveRelativePathToParent() {
+ path = pathFactory.create("/a/b/c/d/e/f");
+ assertThat(path.resolve(pathFactory.create("..")),
is(path.getAncestor()));
+ assertThat(path.resolve(pathFactory.create("..")),
hasSegments(pathFactory, "a", "b", "c", "d",
"e"));
+ }
- @Test
- public void shouldResolveRelativePaths() {
- path = pathFactory.create("/a/b/c/d/e/f");
- assertThat(path.resolve(pathFactory.create("../../../../../..")),
is(sameInstance(ROOT)));
- assertThat(path.resolve(pathFactory.create("../..")),
is(path.getAncestor().getAncestor()));
- assertThat(path.resolve(pathFactory.create("../..")),
hasSegments(pathFactory, "a", "b", "c", "d"));
- assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")),
is(path.getAncestor()));
- assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")),
hasSegments(pathFactory, "a", "b", "c", "d",
"e"));
- assertThat(path.resolve(pathFactory.create("../x")), hasSegments(pathFactory,
"a", "b", "c", "d", "e",
"x"));
- }
+ @Test
+ public void shouldResolveRelativePaths() {
+ path = pathFactory.create("/a/b/c/d/e/f");
+ assertThat(path.resolve(pathFactory.create("../../../../../..")),
is(sameInstance(ROOT)));
+ assertThat(path.resolve(pathFactory.create("../..")),
is(path.getAncestor().getAncestor()));
+ assertThat(path.resolve(pathFactory.create("../..")),
hasSegments(pathFactory, "a", "b", "c", "d"));
+ assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")),
is(path.getAncestor()));
+ assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")),
hasSegments(pathFactory, "a", "b", "c", "d",
"e"));
+ assertThat(path.resolve(pathFactory.create("../x")),
hasSegments(pathFactory, "a", "b", "c", "d",
"e", "x"));
+ }
- public void shouldResolveNonAbsolutePaths() {
- path = pathFactory.create("a/b/c");
- assertThat(path, hasSegments(pathFactory, "a", "b",
"c"));
- }
+ public void shouldResolveNonAbsolutePaths() {
+ path = pathFactory.create("a/b/c");
+ assertThat(path, hasSegments(pathFactory, "a", "b",
"c"));
+ }
}
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BooleanValueFactoryTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -28,7 +28,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
@@ -51,9 +50,8 @@
*/
@Before
public void setUp() throws Exception {
- TextEncoder encoder = Path.URL_ENCODER;
- stringFactory = new StringValueFactory(encoder);
- factory = new BooleanValueFactory(encoder, stringFactory);
+ stringFactory = new StringValueFactory(Path.URL_DECODER, Path.DEFAULT_ENCODER);
+ factory = new BooleanValueFactory(Path.URL_DECODER, stringFactory);
context = new Mockery();
}
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DecimalValueFactoryTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
@@ -52,9 +51,8 @@
*/
@Before
public void setUp() throws Exception {
- TextEncoder encoder = Path.URL_ENCODER;
- stringFactory = new StringValueFactory(encoder);
- factory = new DecimalValueFactory(encoder, stringFactory);
+ stringFactory = new StringValueFactory(Path.URL_DECODER, Path.DEFAULT_ENCODER);
+ factory = new DecimalValueFactory(Path.URL_DECODER, stringFactory);
context = new Mockery();
}
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/DoubleValueFactoryTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
@@ -52,9 +51,8 @@
*/
@Before
public void setUp() throws Exception {
- TextEncoder encoder = Path.URL_ENCODER;
- stringFactory = new StringValueFactory(encoder);
- factory = new DoubleValueFactory(encoder, stringFactory);
+ stringFactory = new StringValueFactory(Path.URL_DECODER, Path.URL_ENCODER);
+ factory = new DoubleValueFactory(Path.URL_DECODER, stringFactory);
context = new Mockery();
}
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactoryTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -56,13 +56,13 @@
@Before
public void setUp() throws Exception {
encoder = Path.URL_ENCODER;
- stringFactory = new StringValueFactory(encoder);
- factory = new InMemoryBinaryValueFactory(encoder, stringFactory);
+ stringFactory = new StringValueFactory(Path.URL_DECODER, encoder);
+ factory = new InMemoryBinaryValueFactory(Path.URL_DECODER, stringFactory);
namespaceRegistry = new BasicNamespaceRegistry();
namespaceRegistry.register("jboss", "http://www.jboss.org");
namespaceRegistry.register("dna",
"http://www.jboss.org/dna");
- nameFactory = new NameValueFactory(namespaceRegistry, encoder, stringFactory);
- pathFactory = new PathValueFactory(encoder, stringFactory, nameFactory);
+ nameFactory = new NameValueFactory(namespaceRegistry, Path.URL_DECODER,
stringFactory);
+ pathFactory = new PathValueFactory(Path.URL_DECODER, stringFactory,
nameFactory);
}
@Test
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactoryTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -28,7 +28,6 @@
import java.math.BigDecimal;
import java.net.URI;
import java.util.Calendar;
-import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.spi.graph.DateTime;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
@@ -61,9 +60,8 @@
*/
@Before
public void setUp() throws Exception {
- TextEncoder encoder = Path.URL_ENCODER;
- stringFactory = new StringValueFactory(encoder);
- factory = new JodaDateTimeValueFactory(encoder, stringFactory);
+ stringFactory = new StringValueFactory(Path.URL_DECODER, Path.URL_ENCODER);
+ factory = new JodaDateTimeValueFactory(Path.URL_DECODER, stringFactory);
context = new Mockery();
}
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/LongValueFactoryTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -29,7 +29,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
@@ -52,9 +51,8 @@
*/
@Before
public void setUp() throws Exception {
- TextEncoder encoder = Path.URL_ENCODER;
- stringFactory = new StringValueFactory(encoder);
- factory = new LongValueFactory(encoder, stringFactory);
+ stringFactory = new StringValueFactory(Path.URL_DECODER, Path.URL_ENCODER);
+ factory = new LongValueFactory(Path.URL_DECODER, stringFactory);
context = new Mockery();
}
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -23,6 +23,7 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
+import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NamespaceRegistry;
@@ -37,84 +38,86 @@
*/
public class NameValueFactoryTest {
- public static final TextEncoder NO_OP_ENCODER = Path.NO_OP_ENCODER;
+ public static final TextEncoder NO_OP_ENCODER = Path.NO_OP_ENCODER;
- private NamespaceRegistry registry;
- private ValueFactory<String> stringValueFactory;
- private NameValueFactory factory;
- private TextEncoder encoder;
- private Name name;
+ private NamespaceRegistry registry;
+ private ValueFactory<String> stringValueFactory;
+ private NameValueFactory factory;
+ private TextEncoder encoder;
+ private TextDecoder decoder;
+ private Name name;
- @Before
- public void beforeEach() throws Exception {
- this.registry = new BasicNamespaceRegistry();
- this.registry.register("dna",
"http://www.jboss.org/dna/namespace");
- this.encoder = Path.DEFAULT_ENCODER;
- this.stringValueFactory = new StringValueFactory(encoder);
- this.factory = new NameValueFactory(registry, encoder, stringValueFactory);
- }
+ @Before
+ public void beforeEach() throws Exception {
+ this.registry = new BasicNamespaceRegistry();
+ this.registry.register("dna",
"http://www.jboss.org/dna/namespace");
+ this.encoder = Path.DEFAULT_ENCODER;
+ this.decoder = Path.DEFAULT_DECODER;
+ this.stringValueFactory = new StringValueFactory(decoder, encoder);
+ this.factory = new NameValueFactory(registry, decoder, stringValueFactory);
+ }
- @Test
- public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormatWithoutPrefix() {
- name = factory.create("a");
- assertThat(name.getLocalName(), is("a"));
- assertThat(name.getNamespaceUri(),
is(this.registry.getNamespaceForPrefix("")));
- }
+ @Test
+ public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormatWithoutPrefix()
{
+ name = factory.create("a");
+ assertThat(name.getLocalName(), is("a"));
+ assertThat(name.getNamespaceUri(),
is(this.registry.getNamespaceForPrefix("")));
+ }
- @Test
- public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormat() {
- name = factory.create("dna:something");
- assertThat(name.getLocalName(), is("something"));
- assertThat(name.getNamespaceUri(),
is("http://www.jboss.org/dna/namespace"));
- assertThat(name.getString(NO_OP_ENCODER),
is("{http://www.jboss.org/dna/namespace}something"));
- }
+ @Test
+ public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormat() {
+ name = factory.create("dna:something");
+ assertThat(name.getLocalName(), is("something"));
+ assertThat(name.getNamespaceUri(),
is("http://www.jboss.org/dna/namespace"));
+ assertThat(name.getString(NO_OP_ENCODER),
is("{http://www.jboss.org/dna/namespace}something"));
+ }
- @Test
- public void shouldCreateNameFromSingleEncodedStringInPrefixedNamespaceFormat() {
- name = factory.create(encoder.encode("dna") + ":" +
encoder.encode("some/thing"));
- assertThat(name.getLocalName(), is("some/thing"));
- assertThat(name.getNamespaceUri(),
is("http://www.jboss.org/dna/namespace"));
- assertThat(name.getString(NO_OP_ENCODER),
is("{http://www.jboss.org/dna/namespace}some/thing"));
- }
+ @Test
+ public void shouldCreateNameFromSingleEncodedStringInPrefixedNamespaceFormat() {
+ name = factory.create(encoder.encode("dna") + ":" +
encoder.encode("some/thing"));
+ assertThat(name.getLocalName(), is("some/thing"));
+ assertThat(name.getNamespaceUri(),
is("http://www.jboss.org/dna/namespace"));
+ assertThat(name.getString(NO_OP_ENCODER),
is("{http://www.jboss.org/dna/namespace}some/thing"));
+ }
- @Test
- public void shouldCreateNameFromSingleStringInStandardFullNamespaceFormat() {
- name =
factory.create("{http://www.jboss.org/dna/namespace}something");
- assertThat(name.getLocalName(), is("something"));
- assertThat(name.getNamespaceUri(),
is("http://www.jboss.org/dna/namespace"));
- assertThat(name.getString(NO_OP_ENCODER),
is("{http://www.jboss.org/dna/namespace}something"));
- }
+ @Test
+ public void shouldCreateNameFromSingleStringInStandardFullNamespaceFormat() {
+ name =
factory.create("{http://www.jboss.org/dna/namespace}something");
+ assertThat(name.getLocalName(), is("something"));
+ assertThat(name.getNamespaceUri(),
is("http://www.jboss.org/dna/namespace"));
+ assertThat(name.getString(NO_OP_ENCODER),
is("{http://www.jboss.org/dna/namespace}something"));
+ }
- @Test
- public void shouldCreateNameFromSingleEncodedStringInStandardFullNamespaceFormat() {
- name = factory.create("{" +
encoder.encode("http://www.jboss.org/dna/namespace") + "}" +
encoder.encode("some/thing"));
- assertThat(name.getLocalName(), is("some/thing"));
- assertThat(name.getNamespaceUri(),
is("http://www.jboss.org/dna/namespace"));
- assertThat(name.getString(NO_OP_ENCODER),
is("{http://www.jboss.org/dna/namespace}some/thing"));
- }
+ @Test
+ public void shouldCreateNameFromSingleEncodedStringInStandardFullNamespaceFormat() {
+ name = factory.create("{" +
encoder.encode("http://www.jboss.org/dna/namespace") + "}" +
encoder.encode("some/thing"));
+ assertThat(name.getLocalName(), is("some/thing"));
+ assertThat(name.getNamespaceUri(),
is("http://www.jboss.org/dna/namespace"));
+ assertThat(name.getString(NO_OP_ENCODER),
is("{http://www.jboss.org/dna/namespace}some/thing"));
+ }
- @Test
- public void shouldProvideAccessToNamespaceRegistryPassedInConstructor() {
- assertThat(factory.getNamespaceRegistry(), is(registry));
- }
+ @Test
+ public void shouldProvideAccessToNamespaceRegistryPassedInConstructor() {
+ assertThat(factory.getNamespaceRegistry(), is(registry));
+ }
- @Test( expected = IllegalArgumentException.class )
- public void shouldNotAllowNullLocalName() {
- factory.create("a", (String)null);
- }
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNullLocalName() {
+ factory.create("a", (String)null);
+ }
- @Test( expected = IllegalArgumentException.class )
- public void shouldNotAllowNullLocalNameWithEncoder() {
- factory.create("a", null, encoder);
- }
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNullLocalNameWithEncoder() {
+ factory.create("a", null, decoder);
+ }
- @Test( expected = IllegalArgumentException.class )
- public void shouldNotAllowEmptyLocalName() {
- factory.create("a", "");
- }
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowEmptyLocalName() {
+ factory.create("a", "");
+ }
- @Test( expected = IllegalArgumentException.class )
- public void shouldNotAllowEmptyLocalNameWithEncoder() {
- factory.create("a", "", encoder);
- }
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowEmptyLocalNameWithEncoder() {
+ factory.create("a", "", decoder);
+ }
}
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java 2008-06-02
20:19:51 UTC (rev 234)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java 2008-06-03
17:32:57 UTC (rev 235)
@@ -44,7 +44,6 @@
private ValueFactory<String> stringValueFactory;
private NameValueFactory nameFactory;
private PathValueFactory factory;
- private TextEncoder encoder;
private Path path;
private Path path2;
@@ -52,10 +51,9 @@
public void beforeEach() throws Exception {
this.registry = new BasicNamespaceRegistry();
this.registry.register("dna",
"http://www.jboss.org/dna/namespace");
- this.encoder = Path.DEFAULT_ENCODER;
- this.stringValueFactory = new StringValueFactory(encoder);
- this.nameFactory = new NameValueFactory(registry, encoder, stringValueFactory);
- this.factory = new PathValueFactory(encoder, stringValueFactory, nameFactory);
+ this.stringValueFactory = new StringValueFactory(Path.DEFAULT_DECODER,
Path.DEFAULT_ENCODER);
+ this.nameFactory = new NameValueFactory(registry, Path.DEFAULT_DECODER,
stringValueFactory);
+ this.factory = new PathValueFactory(Path.DEFAULT_DECODER, stringValueFactory,
nameFactory);
}
protected List<Path.Segment> getSegments( String... segments ) {