Author: rhauch
Date: 2008-05-27 15:24:32 -0400 (Tue, 27 May 2008)
New Revision: 199
Added:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java
Modified:
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Added and refined documentation. Added more unit tests. Added modification methods to
the NamespaceRegistry interface.
Modified:
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java
===================================================================
---
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -21,6 +21,9 @@
*/
package org.jboss.dna.repository.util;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.jboss.dna.common.util.ArgCheck;
@@ -79,7 +82,7 @@
/**
* {@inheritDoc}
*/
- public String getPrefixForNamespaceUri( String namespaceUri ) {
+ public String getPrefixForNamespaceUri( String namespaceUri, boolean
generateIfMissing ) {
Session session = null;
try {
session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
@@ -113,4 +116,47 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
+ public String register( String prefix, String namespaceUri ) {
+ String previousNamespaceUriForPrefix = null;
+ Session session = null;
+ try {
+ session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
+ previousNamespaceUriForPrefix = session.getNamespacePrefix(namespaceUri);
+ javax.jcr.NamespaceRegistry registry =
session.getWorkspace().getNamespaceRegistry();
+ registry.registerNamespace(prefix, namespaceUri);
+ } catch (RepositoryException e) {
+ throw new NamespaceException(e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ return previousNamespaceUriForPrefix;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getRegisteredNamespaceUris() {
+ Session session = null;
+ try {
+ session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
+ javax.jcr.NamespaceRegistry registry =
session.getWorkspace().getNamespaceRegistry();
+ Set<String> result = new HashSet<String>();
+ for (String uri : registry.getURIs()) {
+ result.add(uri);
+ }
+ return Collections.unmodifiableSet(result);
+ } catch (RepositoryException e) {
+ throw new NamespaceException(e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -23,13 +23,13 @@
import java.io.InputStream;
import java.io.Serializable;
-import net.jcip.annotations.ThreadSafe;
+import net.jcip.annotations.Immutable;
/**
- * Value holder for binary data.
+ * Value holder for binary data. Binary instances are not mutable.
* @author Randall Hauch
*/
-@ThreadSafe
+@Immutable
public interface Binary extends Comparable<Binary>, Serializable {
/**
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -23,6 +23,7 @@
import java.io.Serializable;
import java.util.Locale;
+import net.jcip.annotations.Immutable;
/**
* An immutable date-time class that represents an instance in time. This class is
designed to hide the horrible implementations
@@ -32,6 +33,7 @@
* classes.
* @author Randall Hauch
*/
+@Immutable
public interface DateTime extends Comparable<DateTime>, Serializable {
/**
@@ -164,4 +166,31 @@
* @return the milliseconds
*/
int getMillisOfSecond();
+
+ /**
+ * Get the number of hours that this time zone is offset from UTC.
+ * @return the number of hours
+ */
+ int getTimeZoneOffsetHours();
+
+ /**
+ * Get the identifier of the time zone in which this instant is defined
+ * @return the time zone identifier; never null
+ */
+ String getTimeZoneId();
+
+ /**
+ * Convert this time to the same instant in the UTC time zone.
+ * @return this instant in time in the specified time zone
+ */
+ DateTime toUtcTimeZone();
+
+ /**
+ * Convert this time to the time zone given by the supplied identifier.
+ * @param timeZoneId the time zone identifier
+ * @return the instant in the specified time zone
+ * @throws IllegalArgumentException if the time zone identifier is null or is
invalid
+ */
+ DateTime toTimeZone( String timeZoneId );
+
}
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -21,9 +21,14 @@
*/
package org.jboss.dna.spi.graph;
+import java.util.Set;
+import net.jcip.annotations.ThreadSafe;
+
/**
+ * Registry of namespaces, which are used to provide isolated and independent domains for
{@link Name names}.
* @author Randall Hauch
*/
+@ThreadSafe
public interface NamespaceRegistry {
/**
@@ -41,21 +46,38 @@
String getNamespaceForPrefix( String prefix );
/**
- * Return the prefix used for the supplied namespace URI. In effect, every URI should
have a corresponding prefix, even if
- * that prefix is automatically generated. Therefore,
- * @param namespaceUri
+ * Return the prefix used for the supplied namespace URI.
+ * @param namespaceUri the namespace URI
+ * @param generateIfMissing true if the namespace URI has not already been registered
and the method should auto-register the
+ * namespace with a generated prefix, or false if the method should never
auto-register the namespace
* @return the prefix currently being used for the namespace; never null but possibly
empty for the default namespace
* @throws IllegalArgumentException if the namespace URI is null
+ * @see #isRegisteredNamespaceUri(String)
*/
- String getPrefixForNamespaceUri( String namespaceUri );
+ String getPrefixForNamespaceUri( String namespaceUri, boolean generateIfMissing );
/**
- * Return whether there is a registered prefix for the supplied namespace URI. Those
namespace URIs that have not been
- * registered may result in {@link #getPrefixForNamespaceUri(String) automatically
generated prefixes}.
+ * Return whether there is a registered prefix for the supplied namespace URI.
* @param namespaceUri the namespace URI
* @return true if the supplied namespace has been registered with a prefix, or false
otherwise
* @throws IllegalArgumentException if the namespace URI is null
*/
boolean isRegisteredNamespaceUri( String namespaceUri );
+ /**
+ * Register a new namespace using the supplied prefix, returning the namespace URI
previously registered under that prefix.
+ * @param prefix the prefix for the namespace, or null if a namesapce prefix should
be generated automatically
+ * @param namespaceUri the namespace URI
+ * @return the namespace URI that was previously registered with the supplied prefix,
or null if the prefix was not previously
+ * bound to a namespace URI
+ * @throws IllegalArgumentException if the namespace URI is null
+ */
+ String register( String prefix, String namespaceUri );
+
+ /**
+ * Obtain the set of namespaces that are registered.
+ * @return the set of
+ */
+ Set<String> getRegisteredNamespaceUris();
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-24
17:08:43 UTC (rev 198)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -195,6 +195,370 @@
}
/**
+ * Singleton instance of the name referencing a self, provided as a convenience.
+ */
+ public static final Name SELF_NAME = new Name() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getLocalName() {
+ return SELF;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNamespaceUri() {
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return getString(DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ return encoder.encode(SELF);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ return getString(namespaceRegistry, DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder
) {
+ return encoder.encode(SELF);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Name that ) {
+ if (this == that) return 0;
+ int diff = this.getLocalName().compareTo(that.getLocalName());
+ if (diff != 0) return diff;
+ return this.getNamespaceUri().compareTo(that.getNamespaceUri());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof Name) {
+ Name that = (Name)obj;
+ if (!this.getLocalName().equals(that.getLocalName())) return false;
+ return this.getNamespaceUri().equals(that.getNamespaceUri());
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return SELF;
+ }
+
+ };
+
+ /**
+ * Singleton instance of the name referencing a parent, provided as a convenience.
+ */
+ public static final Name PARENT_NAME = new Name() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getLocalName() {
+ return PARENT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNamespaceUri() {
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return getString(DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ return encoder.encode(PARENT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ return getString(namespaceRegistry, DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder
) {
+ return encoder.encode(PARENT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Name that ) {
+ if (this == that) return 0;
+ int diff = this.getLocalName().compareTo(that.getLocalName());
+ if (diff != 0) return diff;
+ return this.getNamespaceUri().compareTo(that.getNamespaceUri());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof Name) {
+ Name that = (Name)obj;
+ if (!this.getLocalName().equals(that.getLocalName())) return false;
+ return this.getNamespaceUri().equals(that.getNamespaceUri());
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return PARENT;
+ }
+
+ };
+
+ /**
+ * Singleton instance of the path segment referencing a parent, provided as a
convenience.
+ */
+ public static final Path.Segment SELF_SEGMENT = new Path.Segment() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getIndex() {
+ return NO_INDEX;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name getName() {
+ return SELF_NAME;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return SELF_NAME.getString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ return SELF_NAME.getString(encoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ return SELF_NAME.getString(namespaceRegistry);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder
) {
+ return SELF_NAME.getString(namespaceRegistry, encoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasIndex() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isParentReference() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSelfReference() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Segment that ) {
+ if (this == that) return 0;
+ int diff = this.getName().compareTo(that.getName());
+ if (diff != 0) return diff;
+ return this.getIndex() - that.getIndex();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof Segment) {
+ Segment that = (Segment)obj;
+ if (!this.getName().equals(that.getName())) return false;
+ return this.hasIndex() == that.hasIndex();
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return SELF_NAME.toString();
+ }
+ };
+
+ /**
+ * Singleton instance of the path segment referencing a parent, provided as a
convenience.
+ */
+ public static final Path.Segment PARENT_SEGMENT = new Path.Segment() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getIndex() {
+ return NO_INDEX;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name getName() {
+ return PARENT_NAME;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return PARENT_NAME.getString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ return PARENT_NAME.getString(encoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ return PARENT_NAME.getString(namespaceRegistry);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder
) {
+ return PARENT_NAME.getString(namespaceRegistry, encoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasIndex() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isParentReference() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSelfReference() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Segment that ) {
+ if (this == that) return 0;
+ int diff = this.getName().compareTo(that.getName());
+ if (diff != 0) return diff;
+ return this.getIndex() - that.getIndex();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this == obj) return true;
+ if (obj instanceof Segment) {
+ Segment that = (Segment)obj;
+ if (!this.getName().equals(that.getName())) return false;
+ return this.hasIndex() == that.hasIndex();
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return PARENT_NAME.toString();
+ }
+ };
+
+ /**
* Return the number of segments in this path.
* @return the number of path segments
*/
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -25,11 +25,14 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Iterator;
+import net.jcip.annotations.Immutable;
/**
- * Representation of a property consisting of a name and value(s).
+ * Representation of a property consisting of a name and value(s). Note that this
property is immutable, meaning that the property
+ * values may not be changed through this interface.
* @author Randall Hauch
*/
+@Immutable
public interface Property extends Iterable<Object>, Comparable<Property> {
/**
@@ -90,6 +93,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the values; never null
* @see Iterable#iterator()
*/
@@ -102,6 +108,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @param type the property type defining the form of the values to be returned; if
null, the
* {@link #getPropertyType() property's type} is used
* @return an iterator over the values; never null
@@ -114,6 +123,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the String values; never null
*/
Iterator<String> getStringValues();
@@ -124,6 +136,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the {@link Binary} values; never null
*/
Iterator<Binary> getBinaryValues();
@@ -134,6 +149,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the long values; never null
*/
Iterator<Long> getLongValues();
@@ -144,6 +162,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the double values; never null
*/
Iterator<Double> getDoubleValues();
@@ -155,6 +176,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the decimal values; never null
*/
Iterator<BigDecimal> getDecimalValues();
@@ -166,6 +190,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Calendar values; never null
*/
Iterator<Calendar> getDateValues();
@@ -177,6 +204,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Boolean values; never null
*/
Iterator<Boolean> getBooleanValues();
@@ -188,6 +218,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Name values; never null
*/
Iterator<Name> getNameValues();
@@ -199,6 +232,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Path values; never null
*/
Iterator<Path> getPathValues();
@@ -210,6 +246,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the Reference values; never null
*/
Iterator<Reference> getReferenceValues();
@@ -220,6 +259,9 @@
* <p>
* A valid iterator is returned if the property has {@link #isSingle() single valued}
or {@link #isMultiple() multi-valued}.
* </p>
+ * <p>
+ * The resulting iterator is immutable, and all property values are immutable.
+ * </p>
* @return an iterator over the URI values; never null
*/
Iterator<URI> getUriValues();
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -22,11 +22,14 @@
package org.jboss.dna.spi.graph;
import java.io.Serializable;
+import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
/**
+ * A representation of a reference to another node. Node references may not necessarily
resolve to an existing node.
* @author Randall Hauch
*/
+@Immutable
public interface Reference extends Comparable<Reference>, Serializable {
/**
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -84,7 +84,7 @@
*/
public String getString( NamespaceRegistry namespaceRegistry ) {
ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
- String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri);
+ String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri,
true);
if (prefix != null) {
return prefix + ":" + this.localName;
}
@@ -96,8 +96,8 @@
*/
public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder )
{
ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
- String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri);
- if (prefix != null) {
+ String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri,
true);
+ if (prefix != null && prefix.length() != 0) {
return encoder.encode(prefix) + ":" +
encoder.encode(this.localName);
}
return this.localName;
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -21,11 +21,16 @@
*/
package org.jboss.dna.spi.graph.impl;
+import java.text.DecimalFormat;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.NamespaceRegistry;
@@ -36,17 +41,58 @@
@ThreadSafe
public class BasicNamespaceRegistry implements NamespaceRegistry {
+ public static final String DEFAULT_NAMESPACE_URI = "";
+ public static final String DEFAULT_PREFIX_TEMPLATE = "ns##000";
+ public static final String DEFAULT_PREFIX_NUMBER_FORMAT = "##000";
+
private final ReadWriteLock registryLock = new ReentrantReadWriteLock();
private final Map<String, String> namespacesByPrefix = new HashMap<String,
String>();
private final Map<String, String> prefixesByNamespace = new HashMap<String,
String>();
+ private String generatedPrefixTemplate = DEFAULT_PREFIX_TEMPLATE;
+ private int nextGeneratedPrefixNumber = 1;
/**
*
*/
public BasicNamespaceRegistry() {
+ this(DEFAULT_NAMESPACE_URI);
}
/**
+ * @param defaultNamespaceUri the namespace URI to use for the default prefix
+ */
+ public BasicNamespaceRegistry( final String defaultNamespaceUri ) {
+ register("", defaultNamespaceUri);
+ }
+
+ /**
+ * @return prefixTemplate
+ */
+ public String getGeneratedPrefixTemplate() {
+ Lock lock = this.registryLock.readLock();
+ try {
+ lock.lock();
+ return this.generatedPrefixTemplate;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * @param prefixTemplate Sets prefixTemplate to the specified value.
+ */
+ public void setGeneratedPrefixTemplate( String prefixTemplate ) {
+ if (prefixTemplate == null) prefixTemplate = DEFAULT_PREFIX_TEMPLATE;
+ Lock lock = this.registryLock.writeLock();
+ try {
+ lock.lock();
+ this.generatedPrefixTemplate = prefixTemplate;
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
* {@inheritDoc}
*/
public String getNamespaceForPrefix( String prefix ) {
@@ -63,15 +109,34 @@
/**
* {@inheritDoc}
*/
- public String getPrefixForNamespaceUri( String namespaceUri ) {
+ public String getPrefixForNamespaceUri( String namespaceUri, boolean
generateIfMissing ) {
ArgCheck.isNotNull(namespaceUri, "namespaceUri");
+ String prefix = null;
Lock lock = this.registryLock.readLock();
try {
lock.lock();
- return this.prefixesByNamespace.get(namespaceUri);
+ prefix = this.prefixesByNamespace.get(namespaceUri);
} finally {
lock.unlock();
}
+ if (prefix == null && generateIfMissing) {
+ // Get a write lock ...
+ lock = this.registryLock.writeLock();
+ try {
+ lock.lock();
+ // Since we got a new lock, we need to check again ...
+ prefix = this.prefixesByNamespace.get(namespaceUri);
+ if (prefix == null) {
+ // Now we can genereate a prefix and register it ...
+ prefix = this.generatePrefix();
+ this.register(prefix, namespaceUri);
+ }
+ return prefix;
+ } finally {
+ lock.unlock();
+ }
+ }
+ return prefix;
}
/**
@@ -101,15 +166,18 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public String register( String prefix, String namespaceUri ) {
- ArgCheck.isNotNull(prefix, "prefix");
- ArgCheck.isNotEmpty(namespaceUri, "namespaceUri");
+ ArgCheck.isNotNull(namespaceUri, "namespaceUri");
String previousNamespaceForPrefix = null;
- prefix = prefix.trim();
namespaceUri = namespaceUri.trim();
Lock lock = this.registryLock.writeLock();
try {
lock.lock();
+ if (prefix == null) prefix = generatePrefix();
+ prefix = prefix.trim();
previousNamespaceForPrefix = this.namespacesByPrefix.put(prefix,
namespaceUri);
String previousPrefix = this.prefixesByNamespace.put(namespaceUri, prefix);
if (previousPrefix != null) {
@@ -121,4 +189,25 @@
return previousNamespaceForPrefix;
}
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getRegisteredNamespaceUris() {
+ Set<String> result = new HashSet<String>();
+ Lock lock = this.registryLock.readLock();
+ try {
+ lock.lock();
+ result.addAll(this.prefixesByNamespace.keySet());
+ } finally {
+ lock.unlock();
+ }
+ return Collections.unmodifiableSet(result);
+ }
+
+ @GuardedBy( "registryLock" )
+ protected String generatePrefix() {
+ DecimalFormat formatter = new DecimalFormat(this.generatedPrefixTemplate);
+ return formatter.format(nextGeneratedPrefixNumber++);
+ }
+
}
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -48,7 +48,7 @@
public static final Path ROOT = new BasicPath(EMPTY_SEGMENTS, true);
- protected static final Path SELF_PATH = new
BasicPath(Collections.singletonList(BasicPathSegment.SELF_SEGMENT), false);
+ protected static final Path SELF_PATH = new
BasicPath(Collections.singletonList(Path.SELF_SEGMENT), false);
private final List<Segment> segments;
private final boolean absolute;
@@ -362,14 +362,14 @@
int numberOfParentReferences = startingPath.size() - lengthOfCommonAncestor;
List<Segment> relativeSegments = new ArrayList<Segment>();
for (int i = 0; i != numberOfParentReferences; ++i) {
- relativeSegments.add(BasicPathSegment.PARENT_SEGMENT);
+ relativeSegments.add(Path.PARENT_SEGMENT);
}
// Add the segments of this path from the common ancestor ...
for (int i = lengthOfCommonAncestor; i < this.size(); ++i) {
relativeSegments.add(this.segments.get(i));
}
if (relativeSegments.isEmpty()) {
- relativeSegments.add(BasicPathSegment.SELF_SEGMENT);
+ relativeSegments.add(Path.SELF_SEGMENT);
}
return new BasicPath(relativeSegments, false);
}
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -35,9 +35,6 @@
@Immutable
public class BasicPathSegment implements Path.Segment {
- public static final Path.Segment SELF_SEGMENT = new BasicPathSegment(new
BasicName("", Path.SELF));
- public static final Path.Segment PARENT_SEGMENT = new BasicPathSegment(new
BasicName("", Path.PARENT));
-
private final Name name;
private final int index;
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -26,6 +26,7 @@
import java.util.GregorianCalendar;
import java.util.Locale;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.ArgCheck;
import org.joda.time.Chronology;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -37,13 +38,23 @@
@Immutable
public class JodaDateTime implements org.jboss.dna.spi.graph.DateTime {
+ private static final int MILLIS_IN_HOUR = 1000 * 60 * 60;
+
private final DateTime instance;
private transient String formattedString;
+ public JodaDateTime() {
+ this.instance = new DateTime();
+ }
+
public JodaDateTime( String iso8601 ) {
this.instance = new DateTime(iso8601);
}
+ public JodaDateTime( String iso8601, String timeZoneId ) {
+ this.instance = new DateTime(iso8601, DateTimeZone.forID(timeZoneId));
+ }
+
public JodaDateTime( long milliseconds ) {
this.instance = new DateTime(milliseconds);
}
@@ -215,6 +226,21 @@
/**
* {@inheritDoc}
*/
+ public int getTimeZoneOffsetHours() {
+ // return this.instance.getZone().toTimeZone().getRawOffset() / MILLIS_IN_HOUR;
+ return this.instance.getZone().getOffset(this.instance.getMillis()) /
MILLIS_IN_HOUR;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getTimeZoneId() {
+ return this.instance.getZone().getID();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Calendar toCalendar() {
return toCalendar(null);
}
@@ -279,4 +305,21 @@
return getString();
}
+ /**
+ * {@inheritDoc}
+ */
+ public org.jboss.dna.spi.graph.DateTime toUtcTimeZone() {
+ DateTime jodaTime = this.instance.withZone(DateTimeZone.forID("UTC"));
+ return new JodaDateTime(jodaTime);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public org.jboss.dna.spi.graph.DateTime toTimeZone( String timeZoneId ) {
+ ArgCheck.isNotNull(timeZoneId, "time zone identifier");
+ DateTime jodaTime = this.instance.withZone(DateTimeZone.forID(timeZoneId));
+ return new JodaDateTime(jodaTime);
+ }
+
}
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -186,7 +186,7 @@
* {@inheritDoc}
*/
public DateTime create() {
- return null;
+ return new JodaDateTime();
}
/**
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -97,16 +97,13 @@
String prefix = matcher.group(2);
String localName = matcher.group(3);
// Decode the parts ...
- prefix = decoder.decode(prefix);
+ prefix = prefix == null ? "" : decoder.decode(prefix);
localName = decoder.decode(localName);
// Look for a namespace match ...
- String namespaceUri = "";
- if (prefix != null) {
- namespaceUri = this.namespaceRegistry.getNamespaceForPrefix(prefix);
- // Fail if no namespace is found ...
- if (namespaceUri == null) {
- throw new
NamespaceException(SpiI18n.noNamespaceRegisteredForPrefix.text(prefix));
- }
+ 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);
}
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
---
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -334,6 +334,8 @@
*/
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);
}
@@ -342,6 +344,8 @@
*/
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);
}
@@ -350,6 +354,8 @@
*/
public Segment createSegment( String segmentName ) {
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));
}
@@ -358,6 +364,8 @@
*/
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);
}
Modified:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java
===================================================================
---
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistryTest.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -22,6 +22,7 @@
package org.jboss.dna.spi.graph.impl;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
import org.junit.Before;
@@ -42,7 +43,7 @@
@Before
public void setUp() throws Exception {
namespaceRegistry = new BasicNamespaceRegistry();
- validNamespaceUri1 = "http://www.jboss.org/dna";
+ validNamespaceUri1 = "http://www.jboss.org/dna/2";
validNamespaceUri2 = "http://acme.com/something";
validNamespaceUri3 = "http://www.redhat.com";
validPrefix1 = "dna";
@@ -73,36 +74,47 @@
@Test
public void shouldReturnNullForPrefixIfNamespaceUriIsNotRegistered() {
- assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3),
is(nullValue()));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3, false),
is(nullValue()));
// now register some namespaces ...
namespaceRegistry.register(validPrefix1, validNamespaceUri1);
namespaceRegistry.register(validPrefix2, validNamespaceUri2);
- assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3),
is(nullValue()));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3, false),
is(nullValue()));
}
@Test
+ public void shouldGeneratePrefixIfNamespaceUriIsNotRegistered() {
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3, false),
is(nullValue()));
+ // Now get the generated prefix ...
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri3, true),
is("ns001"));
+ // Change the template ...
+ namespaceRegistry.setGeneratedPrefixTemplate("xyz0000abc");
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri2, true),
is("xyz0002abc"));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri2, true),
is("xyz0002abc"));
+ // Change the template again ...
+ namespaceRegistry.setGeneratedPrefixTemplate("xyz####abc");
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri1, true),
is("xyz3abc"));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri1, true),
is("xyz3abc"));
+ }
+
+ @Test
public void shouldReturnPrefixForNamespaceUriThatIsRegistered() {
namespaceRegistry.register(validPrefix1, validNamespaceUri1);
namespaceRegistry.register(validPrefix2, validNamespaceUri2);
- assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri1),
is(validPrefix1));
- assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri2),
is(validPrefix2));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri1, false),
is(validPrefix1));
+ assertThat(namespaceRegistry.getPrefixForNamespaceUri(validNamespaceUri2, false),
is(validPrefix2));
}
@Test( expected = IllegalArgumentException.class )
public void shouldNotAllowNullNamespaceUriParameterWhenGettingPrefix() {
- namespaceRegistry.getPrefixForNamespaceUri(null);
+ namespaceRegistry.getPrefixForNamespaceUri(null, false);
}
@Test
- public void shouldReturnNullDefaultNamespaceUriWhenNoNamespacesAreRegistered() {
- assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(nullValue()));
- }
-
- @Test
- public void
shouldReturnNullDefaultNamespaceUriWhenThereAreNamespacesRegisteredButNoneRegisteredWithZeroLengthPrefix()
{
+ public void shouldAlwaysHaveDefaultNamespaceRegistered() {
+ assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(notNullValue()));
namespaceRegistry.register(validPrefix1, validNamespaceUri1);
namespaceRegistry.register(validPrefix2, validNamespaceUri2);
- assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(nullValue()));
+ assertThat(namespaceRegistry.getDefaultNamespaceUri(), is(notNullValue()));
}
@Test
Modified:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
===================================================================
---
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -133,13 +133,13 @@
@Test
public void shouldConsiderSegmentCreatedWithSelfReferenceToBeEqualToStaticSingleton()
{
segment = factory.createSegment(Path.SELF);
- assertThat(segment.equals(BasicPathSegment.SELF_SEGMENT), is(true));
+ assertThat(segment.equals(Path.SELF_SEGMENT), is(true));
}
@Test
public void
shouldConsiderSegmentCreatedWithParentReferenceToBeEqualToStaticSingleton() {
segment = factory.createSegment(Path.PARENT);
- assertThat(segment.equals(BasicPathSegment.PARENT_SEGMENT), is(true));
+ assertThat(segment.equals(Path.PARENT_SEGMENT), is(true));
}
}
Modified:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
===================================================================
---
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -95,7 +95,7 @@
@Test
public void shouldCreateAbsolutePathWithParentSegment() {
- validSegmentsList.add(BasicPathSegment.PARENT_SEGMENT);
+ validSegmentsList.add(Path.PARENT_SEGMENT);
path = new BasicPath(validSegmentsList, true);
assertThat(path.isAbsolute(), is(true));
assertThat(path.isNormalized(), is(false));
@@ -105,7 +105,7 @@
@Test
public void shouldCreateRelativePathWithParentSegment() {
- validSegmentsList.add(BasicPathSegment.PARENT_SEGMENT);
+ validSegmentsList.add(Path.PARENT_SEGMENT);
path = new BasicPath(validSegmentsList, false);
assertThat(path.isAbsolute(), is(false));
assertThat(path.isNormalized(), is(false));
@@ -115,7 +115,7 @@
@Test
public void shouldCreateAbsolutePathWithSelfSegment() {
- validSegmentsList.add(BasicPathSegment.SELF_SEGMENT);
+ validSegmentsList.add(Path.SELF_SEGMENT);
path = new BasicPath(validSegmentsList, true);
assertThat(path.isAbsolute(), is(true));
assertThat(path.isNormalized(), is(false));
@@ -125,7 +125,7 @@
@Test
public void shouldCreateRelativePathWithSelfSegment() {
- validSegmentsList.add(BasicPathSegment.SELF_SEGMENT);
+ validSegmentsList.add(Path.SELF_SEGMENT);
path = new BasicPath(validSegmentsList, false);
assertThat(path.isAbsolute(), is(false));
assertThat(path.isNormalized(), is(false));
Added:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java
===================================================================
---
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java
(rev 0)
+++
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -0,0 +1,82 @@
+/*
+ * 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.spi.graph.impl;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.text.StringStartsWith.startsWith;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class JodaDateTimeTest {
+
+ private JodaDateTime instant;
+ private String iso8601instance;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ iso8601instance = "2008-05-10T13:22:04.678";
+ }
+
+ @Test
+ public void shouldConstructWithIso8601FormattedStringWithoutZone() {
+ instant = new JodaDateTime(iso8601instance, "UTC");
+ assertThat(instant.getString(), startsWith(iso8601instance));
+ assertThat(instant.getYearOfCentury(), is(8));
+ assertThat(instant.getYear(), is(2008));
+ assertThat(instant.getMonthOfYear(), is(5));
+ assertThat(instant.getDayOfMonth(), is(10));
+ assertThat(instant.getDayOfWeek(), is(6));
+ assertThat(instant.getHourOfDay(), is(13));
+ assertThat(instant.getMinuteOfHour(), is(22));
+ assertThat(instant.getSecondOfMinute(), is(04));
+ assertThat(instant.getMillisOfSecond(), is(678));
+ assertThat(instant.getTimeZoneId(), is("UTC"));
+ assertThat(instant.getTimeZoneOffsetHours(), is(0));
+ }
+
+ @Test
+ public void shouldConstructWithIso8601FormattedString() {
+ iso8601instance = "2008-05-10T13:22:04.678-04:00";
+ instant = new JodaDateTime(iso8601instance);
+ instant = (JodaDateTime)instant.toTimeZone("UTC");
+ assertThat(instant.getString(), is("2008-05-10T17:22:04.678Z"));
+ assertThat(instant.getYearOfCentury(), is(8));
+ assertThat(instant.getYear(), is(2008));
+ assertThat(instant.getMonthOfYear(), is(5));
+ assertThat(instant.getDayOfMonth(), is(10));
+ assertThat(instant.getDayOfWeek(), is(6));
+ assertThat(instant.getHourOfDay(), is(17));
+ assertThat(instant.getMinuteOfHour(), is(22));
+ assertThat(instant.getSecondOfMinute(), is(04));
+ assertThat(instant.getMillisOfSecond(), is(678));
+ assertThat(instant.getTimeZoneId(), is("UTC"));
+ assertThat(instant.getTimeZoneOffsetHours(), is(0));
+ }
+
+}
Property changes on:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/JodaDateTimeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java
===================================================================
---
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java 2008-05-24
17:08:43 UTC (rev 198)
+++
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java 2008-05-27
19:24:32 UTC (rev 199)
@@ -53,6 +53,13 @@
}
@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"));