DNA SVN: r185 - in branches/federation: dna-common/src/main/java/org/jboss/dna/common/util and 13 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-23 12:12:06 -0400 (Fri, 23 May 2008)
New Revision: 185
Added:
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/NamespaceException.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.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/ObjectValueFactory.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/AbstractValueComparatorsTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BinaryValueComparatorTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BooleanValueComparatorTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DateValueComparatorTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DecimalValueComparatorTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DoubleValueComparatorTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/LongValueComparatorTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/NameValueComparatorTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/StringValueComparatorTest.java
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.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/IsPathContaining.java
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/PathValueFactoryTest.java
Removed:
branches/federation/dna-common/src/main/java/org/jboss/dna/common/jcr/
branches/federation/dna-common/src/test/java/org/jboss/dna/common/jcr/PathTest.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java
Modified:
branches/federation/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
branches/federation/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/ExecutionContext.java
branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/SimpleExecutionContext.java
branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/util/MockExecutionContext.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.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/PathFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.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/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/InMemoryBinary.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/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties
branches/federation/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Created unit tests for several of the basic implementation classes, and in the process changes some of the interfaces to handle functionality that was missing or incorrect.
Modified: branches/federation/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
===================================================================
--- branches/federation/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -41,21 +41,23 @@
public static I18n i18nFieldNotPublic;
public static I18n i18nFieldNotStatic;
public static I18n i18nLocalizationFileNotFound;
- public static I18n i18nLocalizationProblems;
- public static I18n i18nRequiredToSuppliedParameterMismatch;
+ public static I18n i18nLocalizationProblems;
+ public static I18n i18nRequiredToSuppliedParameterMismatch;
- /**
- * Parameters:
- * <ol>
- * <li>{@link I18n#id() Property}</li>
- * <li>Localization file URL</li>
- * </ol>
- */
+ /**
+ * Parameters:
+ * <ol>
+ * <li>{@link I18n#id() Property}</li>
+ * <li>Localization file URL</li>
+ * </ol>
+ */
public static I18n i18nPropertyDuplicate;
public static I18n i18nPropertyMissing;
public static I18n i18nPropertyUnused;
// Core-related fields
+ public static I18n argumentMayNotBeLessThan;
+ public static I18n argumentMayNotBeGreaterThan;
public static I18n argumentMayNotBeNegative;
public static I18n argumentMayNotBePositive;
public static I18n argumentMustBeNegative;
@@ -75,7 +77,7 @@
public static I18n argumentDidNotContainKey;
public static I18n argumentMayNotContainNullValue;
public static I18n componentClassnameNotValid;
- public static I18n componentNotConfigured;
+ public static I18n componentNotConfigured;
public static I18n dateParsingFailure;
public static I18n initialProgressMonitorTaskName;
public static I18n nullProgressMonitorTaskName;
@@ -85,7 +87,7 @@
public static I18n pathIsNotRelative;
public static I18n pathCannotBeNormalized;
public static I18n progressMonitorBeginTask;
- public static I18n progressMonitorStatus;
+ public static I18n progressMonitorStatus;
public static I18n requiredToSuppliedParameterMismatch;
static {
@@ -97,14 +99,14 @@
}
public static Set<Locale> getLocalizationProblemLocales() {
- return I18n.getLocalizationProblemLocales(CommonI18n.class);
- }
+ return I18n.getLocalizationProblemLocales(CommonI18n.class);
+ }
public static Set<String> getLocalizationProblems() {
- return I18n.getLocalizationProblems(CommonI18n.class);
- }
+ return I18n.getLocalizationProblems(CommonI18n.class);
+ }
public static Set<String> getLocalizationProblems( Locale locale ) {
- return I18n.getLocalizationProblems(CommonI18n.class, locale);
- }
+ return I18n.getLocalizationProblems(CommonI18n.class, locale);
+ }
}
Modified: branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java
===================================================================
--- branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-common/src/main/java/org/jboss/dna/common/util/ArgCheck.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -35,6 +35,32 @@
// ########################## int METHODS ###################################
/**
+ * Check that the argument is not less than the supplied value
+ * @param argument The argument
+ * @param notLessThanValue the value that is to be used to check the value
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If argument is negative (<0)
+ */
+ public static void isNotLessThan( int argument, int notLessThanValue, String name ) {
+ if (argument < notLessThanValue) {
+ throw new IllegalArgumentException(CommonI18n.argumentMayNotBeLessThan.text(name, argument, notLessThanValue));
+ }
+ }
+
+ /**
+ * Check that the argument is not greater than the supplied value
+ * @param argument The argument
+ * @param notGreaterThanValue the value that is to be used to check the value
+ * @param name The name of the argument
+ * @throws IllegalArgumentException If argument is negative (<0)
+ */
+ public static void isNotGreaterThan( int argument, int notGreaterThanValue, String name ) {
+ if (argument < notGreaterThanValue) {
+ throw new IllegalArgumentException(CommonI18n.argumentMayNotBeGreaterThan.text(name, argument, notGreaterThanValue));
+ }
+ }
+
+ /**
* Check that the argument is non-negative (>=0).
* @param argument The argument
* @param name The name of the argument
Modified: branches/federation/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
===================================================================
--- branches/federation/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2008-05-23 16:12:06 UTC (rev 185)
@@ -15,6 +15,8 @@
i18nRequiredToSuppliedParameterMismatch = Internationalization field "{0}" in {1}: {2}
# Core-related fields
+argumentMayNotBeGreaterThan = The {0} argument value, {1}, may not be greater than {2}
+argumentMayNotBeLessThan = The {0} argument value, {1}, may not be less than {2}
argumentMayNotBeNegative = The {0} argument value, {1}, may not be negative
argumentMayNotBePositive = The {0} argument value, {1}, may not be positive
argumentMustBeNegative = The {0} argument value, {1}, must be negative
Deleted: branches/federation/dna-common/src/test/java/org/jboss/dna/common/jcr/PathTest.java
===================================================================
--- branches/federation/dna-common/src/test/java/org/jboss/dna/common/jcr/PathTest.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-common/src/test/java/org/jboss/dna/common/jcr/PathTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -1,438 +0,0 @@
-/*
- * 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.jcr;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.hamcrest.core.IsNot.not;
-import static org.hamcrest.core.IsSame.sameInstance;
-import static org.junit.Assert.assertThat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import org.jboss.dna.common.text.Jsr283Encoder;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Randall Hauch
- */
-public class PathTest {
-
- private Path validPath;
-
- @Before
- public void beforeEach() throws Exception {
- this.validPath = new Path("/a/b/c/d/e/f");
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldNotConstructPathFromEmptyString() {
- new Path("");
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldNotConstructPathFromStringWithOnlyWhitespace() {
- new Path(" \t ");
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldNotConstructPathWithSuccessiveDelimiters() {
- new Path("///a/b///c//d//");
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldNotConstructPathWithOnlyDelimiters() {
- new Path("///");
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldNotConstructPathFromNullString() {
- new Path((String)null);
- }
-
- @Test
- public void shouldConstructPathFromStringAndShouldIgnoreLeadingAndTrailingWhitespace() {
- assertThat(new Path(" \t / \t").toString(), is("/"));
- }
-
- @Test
- public void shouldConstructRelativePathIfSuppliedPathHasNoLeadingDelimiter() {
- assertThat(new Path("a").toString(), is("a"));
- }
-
- @Test
- public void shouldConstructRootPathFromStringWithSingleDelimiter() {
- assertThat(new Path("/"), is(Path.ROOT));
- assertThat(new Path("/").isRoot(), is(true));
- }
-
- @Test
- public void shouldConstructRelativePath() {
- assertThat(new Path("a/b/c").isAbsolute(), is(false));
- assertThat(new Path("a/b/c").isNormalized(), is(true));
- assertThat(new Path("a/b/c").size(), is(3));
- assertThat(new Path("a/b/c").getString(), is("a/b/c"));
- assertThat(new Path("a/b/c").toStringArray(), is(new String[] {"a", "b", "c"}));
- }
-
- @Test
- public void shouldConstructRelativePathToSelf() {
- assertThat(new Path(".").isAbsolute(), is(false));
- assertThat(new Path(".").size(), is(1));
- assertThat(new Path(".").getSegment(0), is(Path.SELF_SEGMENT));
-
- assertThat(new Path("./").isAbsolute(), is(false));
- assertThat(new Path("./").size(), is(1));
- assertThat(new Path("./").getSegment(0), is(Path.SELF_SEGMENT));
- }
-
- @Test
- public void shouldConstructRelativePathToParent() {
- assertThat(new Path("..").isAbsolute(), is(false));
- assertThat(new Path("..").size(), is(1));
- assertThat(new Path("..").getSegment(0), is(Path.PARENT_SEGMENT));
-
- assertThat(new Path("../").isAbsolute(), is(false));
- assertThat(new Path("../").size(), is(1));
- assertThat(new Path("../").getSegment(0), is(Path.PARENT_SEGMENT));
- }
-
- @Test
- public void shouldConstructPathCorrectlyFromStrings() {
- assertThat(new Path("/a/b/c/d").toStringArray(), is(new String[] {"a", "b", "c", "d"}));
- assertThat(new Path("/a").toStringArray(), is(new String[] {"a"}));
- }
-
- @Test
- public void shouldSupportClone() {
- assertThat(validPath.clone(), is(validPath));
- assertThat(validPath.clone(), is(not(sameInstance(validPath))));
- }
-
- @Test
- public void shouldConstructPathCorrectlyFromStringsWithEncodedCharactersUsingUrlEncoder() {
- assertThat(new Path("/a%3c%20_%2fc", Path.URL_ENCODER).toStringArray(), is(new String[] {"a< _/c"}));
- assertThat(new Path("/%2f", Path.URL_ENCODER).toStringArray(), is(new String[] {"/"}));
- assertThat(new Path("/abcdefghijklmnopqrstuvwxyz", Path.URL_ENCODER).toStringArray(), is(new String[] {"abcdefghijklmnopqrstuvwxyz"}));
- assertThat(new Path("/ABCDEFGHIJKLMNOPQRSTUVWXYZ", Path.URL_ENCODER).toStringArray(), is(new String[] {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}));
- assertThat(new Path("/0123456789", Path.URL_ENCODER).toStringArray(), is(new String[] {"0123456789"}));
- assertThat(new Path("/-_.!~*\'()", Path.URL_ENCODER).toStringArray(), is(new String[] {"-_.!~*\'()"}));
- assertThat(new Path("/%60%40%23%24%5e%26%7b%5b%7d%5d%7c%3a%3b%22%3c%2c%3e%3f%2f%20", Path.URL_ENCODER).toStringArray(), is(new String[] {"`@#$^&{[}]|:;\"<,>?/ "}));
- }
-
- @Test
- public void shouldConstructPathCorrectlyFromStringsWithEncodedCharactersUsingJsr283Encoder() {
- assertThat(new Path("/abcdefghijklmnopqrstuvwxyz", Path.JSR283_ENCODER).toStringArray(), is(new String[] {"abcdefghijklmnopqrstuvwxyz"}));
- assertThat(new Path("/ABCDEFGHIJKLMNOPQRSTUVWXYZ", Path.JSR283_ENCODER).toStringArray(), is(new String[] {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}));
- assertThat(new Path("/0123456789", Path.JSR283_ENCODER).toStringArray(), is(new String[] {"0123456789"}));
- assertThat(new Path("/\uF02F-_.!~\uF02A\'()`@#$^&{\uF05B}\uF05D\uF07C\uF03A;\"<,>?", Path.JSR283_ENCODER).toStringArray(), is(new String[] {"/-_.!~*\'()`@#$^&{[}]|:;\"<,>?"}));
- }
-
- @Test
- public void shouldConstructPathCorrectlyFromStringsWithEncodedCharactersUsingDefaultEncoder() {
- assertThat(new Path("/abcdefghijklmnopqrstuvwxyz", Path.DEFAULT_ENCODER).toStringArray(), is(new String[] {"abcdefghijklmnopqrstuvwxyz"}));
- assertThat(new Path("/ABCDEFGHIJKLMNOPQRSTUVWXYZ", Path.DEFAULT_ENCODER).toStringArray(), is(new String[] {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}));
- assertThat(new Path("/0123456789", Path.DEFAULT_ENCODER).toStringArray(), is(new String[] {"0123456789"}));
- assertThat(new Path("/\uF02F-_.!~\uF02A\'()`@#$^&{\uF05B}\uF05D\uF07C\uF03A;\"<,>?", Path.DEFAULT_ENCODER).toStringArray(), is(new String[] {"/-_.!~*\'()`@#$^&{[}]|:;\"<,>?"}));
-
- assertThat(new Path("/abcdefghijklmnopqrstuvwxyz", null).toStringArray(), is(new String[] {"abcdefghijklmnopqrstuvwxyz"}));
- assertThat(new Path("/ABCDEFGHIJKLMNOPQRSTUVWXYZ", null).toStringArray(), is(new String[] {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}));
- assertThat(new Path("/0123456789", null).toStringArray(), is(new String[] {"0123456789"}));
- assertThat(new Path("/\uF02F-_.!~\uF02A\'()`@#$^&{\uF05B}\uF05D\uF07C\uF03A;\"<,>?", null).toStringArray(), is(new String[] {"/-_.!~*\'()`@#$^&{[}]|:;\"<,>?"}));
-
- assertThat(new Path("/abcdefghijklmnopqrstuvwxyz").toStringArray(), is(new String[] {"abcdefghijklmnopqrstuvwxyz"}));
- assertThat(new Path("/ABCDEFGHIJKLMNOPQRSTUVWXYZ").toStringArray(), is(new String[] {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}));
- assertThat(new Path("/0123456789").toStringArray(), is(new String[] {"0123456789"}));
- assertThat(new Path("/\uF02F-_.!~\uF02A\'()`@#$^&{\uF05B}\uF05D\uF07C\uF03A;\"<,>?").toStringArray(), is(new String[] {"/-_.!~*\'()`@#$^&{[}]|:;\"<,>?"}));
- }
-
- @Test
- public void shouldUseTheJsr283EncoderForTheDefaultEncoder() {
- assertThat(Path.DEFAULT_ENCODER, is(sameInstance(Path.JSR283_ENCODER)));
- assertThat(Path.DEFAULT_ENCODER, is(instanceOf(Jsr283Encoder.class)));
- }
-
- @Test
- public void shouldReturnEmptyIteratorForRootPath() {
- assertThat(Path.ROOT.iterator().hasNext(), is(false));
- }
-
- @Test( expected = UnsupportedOperationException.class )
- public void shouldReturnUnmodifiableList() {
- validPath.toList().remove(1);
- }
-
- @Test
- public void shouldReturnEquivalentListAndArray() {
- List<Path.Segment> list = validPath.toList();
- Path.Segment[] array = validPath.toArray();
- assertThat(list.size(), is(validPath.size()));
- assertThat(array.length, is(validPath.size()));
- assertThat(list.toArray(), is(equalTo((Object[])array)));
- }
-
- @Test
- public void shouldConsiderRootToHaveNoElements() {
- assertThat(Path.ROOT.isRoot(), is(true));
- assertThat(Path.ROOT.size(), is(0));
- assertThat(Path.ROOT.toArray(), is(new Path.Segment[] {}));
- assertThat(Path.ROOT.toList(), is((List<Path.Segment>)new ArrayList<Path.Segment>()));
- assertThat(Path.ROOT.getString(), is("/"));
- assertThat(Path.ROOT.getString(Path.DEFAULT_ENCODER), is("/"));
- assertThat(Path.ROOT.getString(Path.JSR283_ENCODER), is("/"));
- assertThat(Path.ROOT.getString(Path.URL_ENCODER), is("/"));
- assertThat(new Path("/"), is(Path.ROOT));
- }
-
- @Test
- public void shouldReturnSameObjectWhenGettingParentOfRoot() {
- assertThat(Path.ROOT.getAncestor(), is(sameInstance(Path.ROOT)));
- }
-
- @Test
- public void shouldUseSameSegmentListInstanceInClone() {
- assertThat(validPath.clone().toList(), is(sameInstance(validPath.toList())));
- }
-
- @Test
- public void shouldConsiderTwoPathsEqualIfTheyHaveTheSamePathSegments() {
- assertThat(new Path("/a/b/c"), is(new Path("/a/b/c")));
- assertThat(new Path("/a/b/c"), is(new Path("/a/b/c/")));
- assertThat(new Path("/"), is(new Path("/")));
- }
-
- @Test
- public void shouldBeCaseSensitiveInEqualsAndCompareToAndSameAs() {
- assertThat(new Path("/a/b/c"), is(not(new Path("/a/B/c"))));
- assertThat(new Path("/a/b/c").isSame(new Path("/a/B/c")), is(false));
- assertThat(new Path("/a/b/c").equals(new Path("/a/B/c")), is(false));
- assertThat(new Path("/a/b/c").compareTo(new Path("/a/B/c")) != 0, is(true));
- }
-
- @Test
- public void shouldGetNormalizedPathOfSelfShouldBeSame() {
- assertThat(new Path(".").getNormalizedPath(), is(new Path(".")));
- assertThat(new Path("./").getNormalizedPath(), is(new Path(".")));
- assertThat(new Path("./././").getNormalizedPath(), is(new Path(".")));
- }
-
- @Test
- public void shouldGetNormalizedPathWithParentReferences() {
- assertThat(new Path("..").getNormalizedPath(), is(new Path("..")));
- assertThat(new Path("../").getNormalizedPath(), is(new Path("../")));
- assertThat(new Path("../../../../../..").getNormalizedPath(), is(new Path("../../../../../..")));
- }
-
- @Test
- public void shouldGetRelativePathUsingSelf() {
- assertThat(validPath.resolve("."), is(sameInstance(validPath)));
- assertThat(validPath.resolve("././."), is(sameInstance(validPath)));
- }
-
- @Test
- public void shouldResolveRelativePathToParent() {
- assertThat(validPath.resolve(".."), is(validPath.getAncestor()));
- assertThat(validPath.resolve("..").toStringArray(), is(new String[] {"a", "b", "c", "d", "e"}));
- }
-
- @Test
- public void shouldResolveRelativePaths() {
- assertThat(validPath.resolve("../../../../../.."), is(sameInstance(Path.ROOT)));
- assertThat(validPath.resolve("../.."), is(validPath.getAncestor().getAncestor()));
- assertThat(validPath.resolve("../..").toStringArray(), is(new String[] {"a", "b", "c", "d"}));
- assertThat(validPath.resolve("../x/../y/../z/.."), is(validPath.getAncestor()));
- assertThat(validPath.resolve("../x/../y/../z/..").toStringArray(), is(new String[] {"a", "b", "c", "d", "e"}));
- assertThat(validPath.resolve("../x").toStringArray(), is(new String[] {"a", "b", "c", "d", "e", "x"}));
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldNotResolveRelativePathWithMoreParentReferencesThanThePath() {
- validPath.resolve("../../../../../../..");
- }
-
- @Test
- public void shouldResolveNonAbsolutePaths() {
- validPath = new Path("a/b/c");
- assertThat(validPath.toStringArray(), is(new String[] {"a", "b", "c"}));
- }
-
- @Test
- public void shouldResolveAbsolutePathsWithIndexes() {
- validPath = new Path("/a/b[3]/c");
- assertThat(validPath.toStringArray(), is(new String[] {"a", "b[3]", "c"}));
-
- validPath = new Path("/a/b[3]/c[4]");
- assertThat(validPath.toStringArray(), is(new String[] {"a", "b[3]", "c[4]"}));
- }
-
- @Test
- public void shouldResolveNonAbsolutePathsWithIndexes() {
- validPath = new Path("a/b[3]/c");
- assertThat(validPath.toStringArray(), is(new String[] {"a", "b[3]", "c"}));
-
- validPath = new Path("a/b[3]/c[4]");
- assertThat(validPath.toStringArray(), is(new String[] {"a", "b[3]", "c[4]"}));
- }
-
- @Test
- public void shouldReturnRootInstanceForParentOfPathWithOneSegment() {
- assertThat(new Path("/a").getAncestor(), is(sameInstance(Path.ROOT)));
- }
-
- @Test
- public void shouldNotConsiderPathToBeAncestorOfItself() {
- assertThat(validPath.isAncestorOf(validPath), is(false));
- assertThat(validPath.isAncestorOf(validPath.clone()), is(false));
- }
-
- @Test
- public void shouldNotConsiderPathToBeDecendantOfItself() {
- assertThat(validPath.isDecendantOf(validPath), is(false));
- assertThat(validPath.isDecendantOf(validPath.clone()), is(false));
- }
-
- @Test
- public void shouldConsiderParentPathTransitivelyToAllBeAncestors() {
- Path path = validPath;
- while (!path.isRoot()) {
- Path parent = path.getAncestor();
- // Check ancestry ...
- assertThat(parent.isAncestorOf(validPath), is(true));
- assertThat(parent.isAncestorOf(path), is(true));
- assertThat(path.isAncestorOf(parent), is(false));
- assertThat(validPath.isAncestorOf(parent), is(false));
-
- assertThat(validPath.isDecendantOf(parent), is(true));
- assertThat(path.isDecendantOf(parent), is(true));
- assertThat(parent.isDecendantOf(validPath), is(false));
- assertThat(parent.isDecendantOf(path), is(false));
-
- // Check whether the parent is the root ...
- if (parent.size() == 0) {
- assertThat(parent, is(sameInstance(Path.ROOT)));
- assertThat(parent.getAncestor(), is(sameInstance(Path.ROOT)));
- }
- assertThat(parent.size() + 1, is(path.size()));
- path = parent;
- }
- }
-
- @Test
- public void shouldReturnSameInstanceWhenAppendingNullSegment() {
- assertThat(validPath.append((String)null), is(sameInstance(validPath)));
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldFailWhenAppendingBlankSegment() {
- validPath.append(" \t ");
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldFailWhenAppendingEmptySegment() {
- validPath.append("");
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldFailWhenAppendingBlankSegmentWithMultipleSegments() {
- validPath.append("a", "b", " \t ");
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldFailWhenAppendingEmptySegmentWithMultipleSegments() {
- validPath.append("a", "b", "");
- }
-
- @Test
- public void shouldReturnEquivalentPathsWhetherAppendingMultipleSegmentsOrAppendingMultipleTimes() {
- assertThat(validPath.append("x", "y", "z"), is(validPath.append("x").append("y").append("z")));
- }
-
- @Test
- public void shouldDecodeSegmentsWhenAppendingWithSpecificTextEncoder() {
- assertThat(validPath.append("^/ ", Path.JSR283_ENCODER).getString(), is(validPath.getString() + "/^\uF02F "));
- assertThat(validPath.append("^/", Path.URL_ENCODER).getString(Path.URL_ENCODER), is(validPath.getString(Path.URL_ENCODER) + "/%5e%2f"));
- }
-
- @Test( expected = InvalidPathException.class )
- public void shouldNotDecodeSegmentsWhenAppendingWithoutSpecificTextEncoder() {
- validPath.append("^/ ");
- }
-
- @Test
- public void shouldOrderPathsCorrectly() {
- List<Path> paths = new ArrayList<Path>();
- paths.add(new Path("/a"));
- paths.add(new Path("/a/b"));
- paths.add(new Path("/a/b/alpha"));
- paths.add(new Path("/a/b/beta"));
- paths.add(new Path("/a/b/jcr:mixinTypes"));
- paths.add(new Path("/a/b/jcr:name"));
- paths.add(new Path("/a/b/jcr:primaryType"));
- paths.add(new Path("/a/c[1]"));
- paths.add(new Path("/a/c[1]/alpha"));
- paths.add(new Path("/a/c[1]/beta"));
- paths.add(new Path("/a/c[1]/jcr:mixinTypes"));
- paths.add(new Path("/a/c[1]/jcr:name"));
- paths.add(new Path("/a/c[1]/jcr:primaryType"));
- paths.add(new Path("/a/c[2]"));
- paths.add(new Path("/a/c[2]/alpha"));
- paths.add(new Path("/a/c[2]/beta"));
- paths.add(new Path("/a/c[2]/jcr:mixinTypes"));
- paths.add(new Path("/a/c[2]/jcr:name"));
- paths.add(new Path("/a/c[2]/jcr: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)));
-
- // Sort ...
- Collections.sort(randomizedPaths);
- assertThat(randomizedPaths, is(paths));
- }
-
- @Test
- public void shouldGetRelativePathToAncestorPath() {
- assertThat(new Path("/a/b/c/d").relativeTo(new Path("/a/b/c")), is(new Path("d")));
- assertThat(new Path("/a/b/c/d/e").relativeTo(new Path("/a/b/c")), is(new Path("d/e")));
- }
-
- @Test
- public void shouldGetRelativePathToDecendantPath() {
- assertThat(new Path("/a/b/c").relativeTo(new Path("/a/b/c/d")), is(new Path("..")));
- assertThat(new Path("/a/b/c").relativeTo(new Path("/a/b/c/d/e")), is(new Path("../..")));
- }
-
- @Test
- public void shouldGetRelativePathToPathWithCommonAncestor() {
- assertThat(new Path("/a/b/c/d").relativeTo(new Path("/a/b/e/f")), is(new Path("../../c/d")));
- }
-
- @Test
- public void shouldGetRelativePathToPathWithNoCommonAncestor() {
- assertThat(new Path("/a/b/c").relativeTo(new Path("/e/f")), is(new Path("../../a/b/c")));
- assertThat(new Path("/e/f/").relativeTo(new Path("/a/b/c")), is(new Path("../../../e/f")));
- }
-
-}
Modified: branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java
===================================================================
--- branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerOutputMap.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -30,8 +30,10 @@
import java.util.Map;
import net.jcip.annotations.Immutable;
import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.common.jcr.Path;
+import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
import org.jboss.dna.spi.sequencers.SequencerOutput;
/**
@@ -47,9 +49,12 @@
private final Map<Path, List<PropertyValue>> data;
private boolean valuesSorted = true;
+ private final PathFactory pathFactory;
- public SequencerOutputMap() {
+ public SequencerOutputMap( PathFactory pathFactory ) {
+ ArgCheck.isNotNull(pathFactory, "pathFactory");
this.data = new HashMap<Path, List<PropertyValue>>();
+ this.pathFactory = pathFactory;
}
/**
@@ -62,7 +67,7 @@
if (nodePath.endsWith("/")) nodePath = nodePath.replaceFirst("/+$", "");
// Find or create the entry for this node ...
- Path path = new Path(nodePath);
+ Path path = pathFactory.create(nodePath);
List<PropertyValue> properties = this.data.get(path);
if (properties == null) {
if (values == null || values.length == 0) return; // do nothing
@@ -86,11 +91,11 @@
if (paths == null || paths.length == 0) {
setProperty(nodePath, property, (Object[])null);
} else if (paths.length == 1) {
- setProperty(nodePath, property, new Path(paths[0]));
+ setProperty(nodePath, property, pathFactory.create(paths[0]));
} else {
Path[] pathsArray = new Path[paths.length];
for (int i = 0; i != paths.length; ++i) {
- pathsArray[i] = new Path(paths[i]);
+ pathsArray[i] = pathFactory.create(paths[i]);
}
setProperty(nodePath, property, (Object[])pathsArray);
}
Modified: branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
===================================================================
--- branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -60,6 +60,8 @@
import org.jboss.dna.repository.util.JcrTools;
import org.jboss.dna.repository.util.RepositoryNodePath;
import org.jboss.dna.repository.util.SessionFactory;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.ValueFactories;
/**
* A sequencing system is used to monitor changes in the content of {@link Repository JCR repositories} and to sequence the
@@ -564,17 +566,19 @@
protected class Context implements ExecutionContext {
+ protected final ExecutionContext delegate;
protected final SessionFactory factory;
private final Set<Session> sessions = new HashSet<Session>();
protected final AtomicBoolean closed = new AtomicBoolean(false);
protected Context() {
- final SessionFactory delegate = SequencingService.this.getExecutionContext().getSessionFactory();
+ this.delegate = SequencingService.this.getExecutionContext();
+ final SessionFactory delegateSessionFactory = this.delegate.getSessionFactory();
this.factory = new SessionFactory() {
public Session createSession( String name ) throws RepositoryException {
if (closed.get()) throw new IllegalStateException(RepositoryI18n.executionContextHasBeenClosed.text());
- Session session = delegate.createSession(name);
+ Session session = delegateSessionFactory.createSession(name);
recordSession(session);
return session;
}
@@ -588,6 +592,20 @@
/**
* {@inheritDoc}
*/
+ public NamespaceRegistry getNamespaceRegistry() {
+ return this.delegate.getNamespaceRegistry();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactories getValueFactories() {
+ return this.delegate.getValueFactories();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public SessionFactory getSessionFactory() {
return this.factory;
}
Modified: branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
===================================================================
--- branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -29,13 +29,15 @@
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import org.jboss.dna.common.jcr.Path;
import org.jboss.dna.common.monitor.ProgressMonitor;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.repository.RepositoryI18n;
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.util.ExecutionContext;
import org.jboss.dna.repository.util.RepositoryNodePath;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
import org.jboss.dna.spi.sequencers.StreamSequencer;
/**
@@ -88,7 +90,7 @@
progressMonitor.worked(10);
// Get the binary property with the image content, and build the image metadata from the image ...
- SequencerOutputMap output = new SequencerOutputMap();
+ SequencerOutputMap output = new SequencerOutputMap(context.getValueFactories().getPathFactory());
InputStream stream = null;
Throwable firstError = null;
ProgressMonitor sequencingMonitor = progressMonitor.createSubtask(50);
@@ -159,7 +161,9 @@
*/
protected boolean saveOutput( Node outputNode, SequencerOutputMap output, ExecutionContext context ) throws RepositoryException {
if (output.isEmpty()) return false;
- final Path outputNodePath = new Path(outputNode.getPath());
+ final PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ final NamespaceRegistry namespaceRegistry = context.getNamespaceRegistry();
+ final Path outputNodePath = pathFactory.create(outputNode.getPath());
// Iterate over the entries in the output, in Path's natural order (shorter paths first and in lexicographical order by
// prefix and name)
@@ -175,14 +179,14 @@
Node targetNode = outputNode;
for (int i = 0, max = relativePath.size(); i != max; ++i) {
Path.Segment segment = relativePath.getSegment(i);
- String qualifiedName = segment.getQualifiedName(true);
+ String qualifiedName = segment.getString(namespaceRegistry);
if (targetNode.hasNode(qualifiedName)) {
targetNode = targetNode.getNode(qualifiedName);
} else {
// It doesn't exist, so create it ...
if (segment.hasIndex()) {
// Use a name without an index ...
- qualifiedName = segment.getQualifiedName(false);
+ qualifiedName = segment.getName().getString(namespaceRegistry);
}
// We only have the primary type for the final one ...
if (i == (max - 1) && primaryType != null) {
Modified: branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/ExecutionContext.java
===================================================================
--- branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/ExecutionContext.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/ExecutionContext.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -22,6 +22,8 @@
package org.jboss.dna.repository.util;
import javax.jcr.Session;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.ValueFactories;
/**
* The context of an execution.
@@ -30,6 +32,18 @@
public interface ExecutionContext {
/**
+ * Get the namespace registry.
+ * @return the namespace registry; never null
+ */
+ NamespaceRegistry getNamespaceRegistry();
+
+ /**
+ * Get the factories that are to be used to create property values of various types.
+ * @return the set of value factories; never null
+ */
+ ValueFactories getValueFactories();
+
+ /**
* Get the session factory, which can be used to obtain sessions temporarily for this context. Any session obtained from this
* factory should be {@link Session#logout() closed} before the execution finishes.
* @return the session factory
Added: 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 (rev 0)
+++ branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,116 @@
+/*
+ * 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.repository.util;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.NamespaceException;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+
+/**
+ * @author Randall Hauch
+ */
+public class JcrNamespaceRegistry implements NamespaceRegistry {
+
+ private final String repositoryWorkspaceName;
+ private final SessionFactory sessionFactory;
+
+ public JcrNamespaceRegistry( SessionFactory sessionFactory, String repositoryWorkspaceName ) {
+ ArgCheck.isNotNull(sessionFactory, "sessionFactory");
+ ArgCheck.isNotNull(repositoryWorkspaceName, "repositoryWorkspaceName");
+ this.repositoryWorkspaceName = repositoryWorkspaceName;
+ this.sessionFactory = sessionFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDefaultNamespaceUri() {
+ Session session = null;
+ try {
+ session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
+ return session.getNamespaceURI("");
+ } catch (RepositoryException e) {
+ throw new NamespaceException(e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNamespaceForPrefix( String prefix ) {
+ Session session = null;
+ try {
+ session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
+ return session.getNamespaceURI(prefix);
+ } catch (RepositoryException e) {
+ throw new NamespaceException(e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPrefixForNamespaceUri( String namespaceUri ) {
+ Session session = null;
+ try {
+ session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
+ return session.getNamespacePrefix(namespaceUri);
+ } catch (RepositoryException e) {
+ throw new NamespaceException(e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isRegisteredNamespaceUri( String namespaceUri ) {
+ Session session = null;
+ try {
+ session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
+ session.getNamespacePrefix(namespaceUri);
+ return true;
+ } catch (javax.jcr.NamespaceException e) {
+ return false;
+ } catch (RepositoryException e) {
+ throw new NamespaceException(e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ }
+
+}
Property changes on: branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/SimpleExecutionContext.java
===================================================================
--- branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/SimpleExecutionContext.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-repository/src/main/java/org/jboss/dna/repository/util/SimpleExecutionContext.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -22,6 +22,9 @@
package org.jboss.dna.repository.util;
import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.impl.StandardValueFactories;
/**
* @author Randall Hauch
@@ -30,15 +33,42 @@
private final JcrTools tools = new JcrTools();
private final SessionFactory sessionFactory;
+ private final ValueFactories valueFactories;
+ private final NamespaceRegistry namespaceRegistry;
- public SimpleExecutionContext( SessionFactory sessionFactory ) {
+ public SimpleExecutionContext( SessionFactory sessionFactory, String repositoryWorkspaceForNamespaceRegistry ) {
+ this(sessionFactory, new JcrNamespaceRegistry(sessionFactory, repositoryWorkspaceForNamespaceRegistry), null);
+ }
+
+ public SimpleExecutionContext( SessionFactory sessionFactory, NamespaceRegistry namespaceRegistry ) {
+ this(sessionFactory, namespaceRegistry, null);
+ }
+
+ public SimpleExecutionContext( SessionFactory sessionFactory, NamespaceRegistry namespaceRegistry, ValueFactories valueFactories ) {
ArgCheck.isNotNull(sessionFactory, "session factory");
+ ArgCheck.isNotNull(namespaceRegistry, "namespace registry");
this.sessionFactory = sessionFactory;
+ this.namespaceRegistry = namespaceRegistry;
+ this.valueFactories = valueFactories != null ? valueFactories : new StandardValueFactories(this.namespaceRegistry);
}
/**
* {@inheritDoc}
*/
+ public NamespaceRegistry getNamespaceRegistry() {
+ return this.namespaceRegistry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactories getValueFactories() {
+ return this.valueFactories;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public SessionFactory getSessionFactory() {
return this.sessionFactory;
}
Modified: branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
===================================================================
--- branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -47,6 +47,8 @@
import org.jboss.dna.repository.util.JcrTools;
import org.jboss.dna.repository.util.RepositoryNodePath;
import org.jboss.dna.repository.util.SessionFactory;
+import org.jboss.dna.repository.util.SimpleExecutionContext;
+import org.jboss.dna.spi.graph.impl.BasicNamespaceRegistry;
import org.jboss.dna.spi.sequencers.SequencerOutput;
import org.jboss.dna.spi.sequencers.StreamSequencer;
import org.junit.After;
@@ -74,26 +76,17 @@
public void beforeEach() throws Exception {
final JcrTools tools = new JcrTools();
this.tools = tools;
- sequencerOutput = new SequencerOutputMap();
- progressMonitor = new RecordingProgressMonitor(StreamSequencerAdapterTest.class.getName());
final SessionFactory sessionFactory = new SessionFactory() {
public Session createSession( String name ) {
return createTestSession();
}
};
- context = new ExecutionContext() {
-
- public SessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- public JcrTools getTools() {
- return tools;
- }
- };
+ this.context = new SimpleExecutionContext(sessionFactory, new BasicNamespaceRegistry(), null);
+ this.sequencerOutput = new SequencerOutputMap(this.context.getValueFactories().getPathFactory());
+ this.progressMonitor = new RecordingProgressMonitor(StreamSequencerAdapterTest.class.getName());
final SequencerOutputMap finalOutput = sequencerOutput;
- streamSequencer = new StreamSequencer() {
+ this.streamSequencer = new StreamSequencer() {
/**
* This method always copies the {@link StreamSequencerAdapterTest#sequencerOutput} data into the output {@inheritDoc},
Modified: branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/util/MockExecutionContext.java
===================================================================
--- branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/util/MockExecutionContext.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-repository/src/test/java/org/jboss/dna/repository/util/MockExecutionContext.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -28,20 +28,14 @@
import javax.jcr.Session;
import org.jboss.dna.common.SystemFailureException;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
-import org.jboss.dna.repository.util.ExecutionContext;
-import org.jboss.dna.repository.util.JcrTools;
-import org.jboss.dna.repository.util.SessionFactory;
/**
* @author Randall Hauch
*/
-public class MockExecutionContext implements ExecutionContext {
+public class MockExecutionContext extends SimpleExecutionContext {
- private JcrTools tools = new JcrTools();
- private SessionFactory sessionFactory;
-
public MockExecutionContext( final AbstractJcrRepositoryTest test, final String repositoryName ) {
- this.sessionFactory = new SessionFactory() {
+ super(new SessionFactory() {
public Session createSession( String name ) throws RepositoryException {
assertThat(name, is(repositoryName));
@@ -51,17 +45,7 @@
throw new SystemFailureException(e);
}
}
- };
+ }, repositoryName);
}
- public SessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- /**
- * {@inheritDoc}
- */
- public JcrTools getTools() {
- return tools;
- }
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -31,21 +31,23 @@
*/
public final class SpiI18n {
- public static I18n unableToDiscoverPropertyType;
+ public static I18n unableToDiscoverPropertyTypeForNullValue;
public static I18n errorReadingPropertyValueBytes;
public static I18n valueJavaTypeNotCompatibleWithPropertyType;
public static I18n errorConvertingBinaryValueToString;
public static I18n errorCreatingValue;
public static I18n unableToCreateValue;
- public static I18n unableToCreatePathFromEmptyString;
public static I18n validPathMayNotContainEmptySegment;
+ public static I18n noNamespaceRegisteredForPrefix;
public static I18n pathAncestorDegreeIsInvalid;
public static I18n pathIsAlreadyAbsolute;
public static I18n pathIsNotAbsolute;
public static I18n pathIsNotRelative;
public static I18n pathCannotBeNormalized;
+ public static I18n unbleToCreateSubpathBeginIndexGreaterThanOrEqualToSize;
+ public static I18n unbleToCreateSubpathBeginIndexGreaterThanOrEqualToEndingIndex;
public static I18n invalidQualifiedNameString;
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceException.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceException.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceException.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public class NamespaceException extends RuntimeException {
+
+ /**
+ *
+ */
+ public NamespaceException() {
+ }
+
+ /**
+ * @param message
+ */
+ public NamespaceException( String message ) {
+ super(message);
+
+ }
+
+ /**
+ * @param cause
+ */
+ public NamespaceException( Throwable cause ) {
+ super(cause);
+
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public NamespaceException( String message, Throwable cause ) {
+ super(message, cause);
+
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -26,8 +26,36 @@
*/
public interface NamespaceRegistry {
+ /**
+ * Return the namespace URI that is currently mapped to the empty prefix, or null if there is no current default namespace.
+ * @return the namespace URI that represents the default namespace, or null if there is no default namespace
+ */
+ String getDefaultNamespaceUri();
+
+ /**
+ * Get the namespace URI for the supplied prefix.
+ * @param prefix the namespace prefix
+ * @return the namespace URI for the supplied prefix, or null if there is no namespace currently registered to use that prefix
+ * @throws IllegalArgumentException if the prefix is null
+ */
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 currently being used for the namespace; never null but possibly empty for the default namespace
+ * @throws IllegalArgumentException if the namespace URI is null
+ */
String getPrefixForNamespaceUri( String namespaceUri );
+ /**
+ * 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}.
+ * @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 );
+
}
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-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -114,7 +114,7 @@
/**
* The index that will be returned for a {@link Segment} that {@link Segment#hasIndex() has no index}.
*/
- public static final int NO_INDEX = 0;
+ public static final int NO_INDEX = -1;
/**
* Representation of the segments that occur within a path.
@@ -169,6 +169,29 @@
* @see #getString()
*/
public String getString( TextEncoder encoder );
+
+ /**
+ * 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 );
+
+ /**
+ * 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 );
}
/**
@@ -315,11 +338,21 @@
public Segment getSegment( int index );
/**
+ * 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 );
+
+ /**
* 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 substring.
+ * @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>.
*/
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -98,6 +98,23 @@
* @return the segment
* @throws IllegalArgumentException if the segment name reference is null
*/
+ Path.Segment createSegment( String 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( 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 );
/**
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -26,7 +26,6 @@
import java.util.Calendar;
import java.util.Comparator;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.SpiI18n;
import com.sun.tools.javac.tree.Tree.Binary;
@@ -36,18 +35,18 @@
@Immutable
public enum PropertyType {
- STRING("String", PropertyValues.STRING_COMPARATOR, String.class),
- BINARY("Binary", PropertyValues.BINARY_COMPARATOR, Binary.class),
- LONG("Long", PropertyValues.LONG_COMPARATOR, Long.class),
- DOUBLE("Double", PropertyValues.DOUBLE_COMPARATOR, Double.class),
- DECIMAL("Decimal", PropertyValues.DECIMAL_COMPARATOR, BigDecimal.class),
- DATE("Date", PropertyValues.DATE_COMPARATOR, Calendar.class),
- BOOLEAN("Boolean", PropertyValues.BOOLEAN_COMPARATOR, Boolean.class),
- NAME("Name", PropertyValues.NAME_COMPARATOR, Name.class),
- PATH("Path", PropertyValues.PATH_COMPARATOR, Path.class),
- REFERENCE("Reference", PropertyValues.REFERENCE_COMPARATOR, Reference.class),
- URI("URI", PropertyValues.URI_COMPARATOR, URI.class),
- UNDEFINED("undefined", PropertyValues.UNDEFINED_COMPARATOR, Comparable.class);
+ STRING("String", ValueComparators.STRING_COMPARATOR, String.class),
+ BINARY("Binary", ValueComparators.BINARY_COMPARATOR, Binary.class),
+ LONG("Long", ValueComparators.LONG_COMPARATOR, Long.class),
+ DOUBLE("Double", ValueComparators.DOUBLE_COMPARATOR, Double.class),
+ DECIMAL("Decimal", ValueComparators.DECIMAL_COMPARATOR, BigDecimal.class),
+ DATE("Date", ValueComparators.CALENDAR_COMPARATOR, Calendar.class),
+ BOOLEAN("Boolean", ValueComparators.BOOLEAN_COMPARATOR, Boolean.class),
+ NAME("Name", ValueComparators.NAME_COMPARATOR, Name.class),
+ PATH("Path", ValueComparators.PATH_COMPARATOR, Path.class),
+ REFERENCE("Reference", ValueComparators.REFERENCE_COMPARATOR, Reference.class),
+ URI("URI", ValueComparators.URI_COMPARATOR, URI.class),
+ OBJECT("Object", ValueComparators.OBJECT_COMPARATOR, Object.class);
private final String name;
private final Comparator comparator;
@@ -77,11 +76,12 @@
public static PropertyType discoverType( Object value ) {
if (value == null) {
- throw new ValueFormatException(SpiI18n.unableToDiscoverPropertyType.text(value));
+ throw new ValueFormatException(SpiI18n.unableToDiscoverPropertyTypeForNullValue.text());
}
for (PropertyType type : PropertyType.values()) {
+ if (type == OBJECT) continue;
if (type.isInstance(value)) return type;
}
- throw new ValueFormatException(SpiI18n.unableToDiscoverPropertyType.text(StringUtil.readableString(value)));
+ return OBJECT;
}
}
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -1,441 +0,0 @@
-/*
- * 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;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.util.Calendar;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.UUID;
-import org.jboss.dna.common.util.DateUtil;
-import org.jboss.dna.spi.SpiI18n;
-
-/**
- * @author Randall Hauch
- */
-public class PropertyValues {
-
- /**
- * A comparator of string values.
- */
- public static final Comparator<String> STRING_COMPARATOR = new Comparator<String>() {
-
- public int compare( String o1, String o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of integer values.
- */
- public static final Comparator<Integer> INTEGER_COMPARATOR = new Comparator<Integer>() {
-
- public int compare( Integer o1, Integer o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of long values.
- */
- public static final Comparator<Long> LONG_COMPARATOR = new Comparator<Long>() {
-
- public int compare( Long o1, Long o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of float values.
- */
- public static final Comparator<Float> FLOAT_COMPARATOR = new Comparator<Float>() {
-
- public int compare( Float o1, Float o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of double values.
- */
- public static final Comparator<Double> DOUBLE_COMPARATOR = new Comparator<Double>() {
-
- public int compare( Double o1, Double o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of decimal values.
- */
- public static final Comparator<BigDecimal> DECIMAL_COMPARATOR = new Comparator<BigDecimal>() {
-
- public int compare( BigDecimal o1, BigDecimal o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of binary values. Although {@link Binary} is {@link Comparable}, this comparator does not rely upon any
- * particular Binary implementation. Thus, Binary implementations can use this for their {@link Comparable#compareTo(Object)}
- * implementation.
- */
- public static final Comparator<Binary> BINARY_COMPARATOR = new Comparator<Binary>() {
-
- public int compare( Binary o1, Binary o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- try {
- o1.acquire();
- try {
- o2.acquire();
- final long len1 = o1.getSize();
- final long len2 = o2.getSize();
- if (len1 < len2) return -1;
- if (len1 > len2) return 1;
- // Otherwise they are the same length ...
- InputStream stream1 = null;
- InputStream stream2 = null;
- try {
- stream1 = o1.getStream();
- stream2 = o2.getStream();
- byte[] buffer1 = new byte[1024];
- byte[] buffer2 = new byte[1024];
- while (true) {
- int numRead1 = stream1.read(buffer1);
- if (numRead1 < 0) break;
- int numRead2 = stream2.read(buffer2);
- if (numRead1 != numRead2) {
- throw new ValueFormatException(SpiI18n.errorReadingPropertyValueBytes.text());
- }
- for (int i = 0; i != numRead1; ++i) {
- int diff = buffer1[i] - buffer2[i];
- if (diff != 0) return diff;
- }
- }
- return 0;
- } catch (IOException e) {
- throw new ValueFormatException(SpiI18n.errorReadingPropertyValueBytes.text());
- } finally {
- if (stream1 != null) {
- try {
- stream1.close();
- } catch (IOException e) {
- // do nothing
- }
- }
- if (stream2 != null) {
- try {
- stream2.close();
- } catch (IOException e) {
- // do nothing
- }
- }
- }
- } finally {
- o2.release();
- }
- } finally {
- o1.release();
- }
- }
- };
- /**
- * A comparator of boolean values.
- */
- public static final Comparator<Boolean> BOOLEAN_COMPARATOR = new Comparator<Boolean>() {
-
- public int compare( Boolean o1, Boolean o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of date values.
- */
- public static final Comparator<Date> DATE_COMPARATOR = new Comparator<Date>() {
-
- public int compare( Date o1, Date o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of calendar values.
- */
- public static final Comparator<Calendar> CALENDAR_COMPARATOR = new Comparator<Calendar>() {
-
- public int compare( Calendar o1, Calendar o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of name values.
- */
- public static final Comparator<Name> NAME_COMPARATOR = new Comparator<Name>() {
-
- public int compare( Name o1, Name o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of path values.
- */
- public static final Comparator<Path> PATH_COMPARATOR = new Comparator<Path>() {
-
- public int compare( Path o1, Path o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of URI values.
- */
- public static final Comparator<URI> URI_COMPARATOR = new Comparator<URI>() {
-
- public int compare( URI o1, URI o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of reference values.
- */
- public static final Comparator<Reference> REFERENCE_COMPARATOR = new Comparator<Reference>() {
-
- public int compare( Reference o1, Reference o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- return o1.compareTo(o2);
- }
- };
- /**
- * A comparator of other values.
- */
- public static final Comparator<Object> UNDEFINED_COMPARATOR = new Comparator<Object>() {
-
- @SuppressWarnings( "unchecked" )
- public int compare( Object o1, Object o2 ) {
- if (o1 == o2) return 0;
- if (o1 == null) return -1;
- if (o2 == null) return 1;
- PropertyType type1 = PropertyType.discoverType(o1);
- PropertyType type2 = PropertyType.discoverType(o2);
- if (type1 == type2) return type1.getComparator().compare(o1, o2);
- // The types are different but the classes are the same ...
- if (type1.getDeclaringClass().isAssignableFrom(type2.getDeclaringClass())) {
- return type1.getComparator().compare(o1, o2);
- }
- if (type2.getDeclaringClass().isAssignableFrom(type1.getDeclaringClass())) {
- return type2.getComparator().compare(o1, o2);
- }
- // The types are different and must be converted ...
- String value1 = PropertyValues.getString(o1);
- String value2 = PropertyValues.getString(o2);
- return value1.compareTo(value2);
- }
- };
-
- /**
- * Get the string representation of the supplied value. This method may perform an conversion that may lose information.
- * @param value the value to be interpreted as a string
- * @return the string representation
- */
- public static String getString( Object value ) {
- if (value == null) return null;
- if (value instanceof String) return (String)value;
- if (value instanceof Boolean) return getString(((Boolean)value).booleanValue());
- if (value instanceof Double) return getString(((Double)value).doubleValue());
- if (value instanceof Long) return getString(((Long)value).longValue());
- if (value instanceof Date) return getString((Date)value);
- if (value instanceof Binary) return getString((Binary)value);
- if (value instanceof Calendar) return getString((Calendar)value);
- if (value instanceof BigDecimal) return getString((BigDecimal)value);
- if (value instanceof Name) return getString((Name)value);
- if (value instanceof Path) return getString((Path)value);
- if (value instanceof URI) return getString((URI)value);
- if (value instanceof UUID) return getString((UUID)value);
- return value.toString();
- }
-
- /**
- * Get the string representation of the supplied boolean value. This method is implemented by calling
- * {@link Boolean#toString(boolean) Boolean.toString(boolean)}.
- * @param value the boolean value
- * @return the string representation
- */
- public static String getString( boolean value ) {
- return Boolean.toString(value);
- }
-
- /**
- * Get the string representation of the supplied double value. This method is implemented by calling
- * {@link Double#toString(double) Double.toString(double)}.
- * @param value the double value
- * @return the string representation
- */
- public static String getString( double value ) {
- return Double.toString(value);
- }
-
- /**
- * Get the string representation of the supplied long value. This method is implemented by calling
- * {@link Long#toString(long) Long.toString(long)}.
- * @param value the long value
- * @return the string representation
- */
- public static String getString( long value ) {
- return Long.toString(value);
- }
-
- /**
- * Get the string representation of the supplied binary value. This method attempts to interpret the binary value as a UTF-8
- * encoded string.
- * @param value the binary value
- * @return the string representation
- */
- public static String getString( Binary value ) {
- if (value == null) return null;
- try {
- value.acquire();
- byte[] bytes = value.getBytes();
- try {
- return new String(bytes, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new ValueFormatException(SpiI18n.errorConvertingBinaryValueToString.text());
- }
- } finally {
- value.release();
- }
- }
-
- /**
- * Get the ISO 8601:2004 string representation of the supplied date value.
- * @param value the date value
- * @return the string representation
- */
- public static String getString( Date value ) {
- if (value == null) return null;
- return DateUtil.getDateAsStandardString(value);
- }
-
- /**
- * Get the ISO 8601:2004 string representation of the supplied calendar value.
- * @param value the calendar value
- * @return the string representation
- */
- public static String getString( Calendar value ) {
- if (value == null) return null;
- return getString(value.getTime());
- }
-
- /**
- * Get the string representation of the supplied decimal value.
- * @param value the decimal value
- * @return the string representation
- */
- public static String getString( BigDecimal value ) {
- if (value == null) return null;
- return value.toString();
- }
-
- /**
- * Get the string representation of the supplied name. This method calls {@link Name#getString() Name.getString()}.
- * @param value the name value
- * @return the string representation
- */
- public static String getString( Name value ) {
- if (value == null) return null;
- return value.getString();
- }
-
- /**
- * Get the string representation of the supplied path. This method calls {@link Path#getString() Path.getString()}.
- * @param value the path value
- * @return the string representation
- */
- public static String getString( Path value ) {
- if (value == null) return null;
- return value.getString();
- }
-
- /**
- * Get the string representation of the supplied URI. This method calls {@link URI#toASCIIString() URI.toASCIIString()}.
- * @param value the URI value
- * @return the string representation
- */
- public static String getString( URI value ) {
- if (value == null) return null;
- return value.toASCIIString();
- }
-
- /**
- * Get the string representation of the supplied UUID.
- * @param value the UUID value
- * @return the string representation
- */
- public static String getString( UUID value ) {
- if (value == null) return null;
- return value.toString();
- }
-
- /**
- * Get the string representation of the supplied string value. This method simply returns the supplied value.
- * @param value the date value
- * @return the string representation
- */
- public static String getString( String value ) {
- return value;
- }
-}
Copied: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java (from rev 176, branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java)
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueComparators.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,279 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.impl.StringValueFactory;
+
+/**
+ * @author Randall Hauch
+ */
+public class ValueComparators {
+
+ /**
+ * A comparator of string values.
+ */
+ public static final Comparator<String> STRING_COMPARATOR = new Comparator<String>() {
+
+ public int compare( String o1, String o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of long values.
+ */
+ public static final Comparator<Long> LONG_COMPARATOR = new Comparator<Long>() {
+
+ public int compare( Long o1, Long o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of double values.
+ */
+ public static final Comparator<Double> DOUBLE_COMPARATOR = new Comparator<Double>() {
+
+ public int compare( Double o1, Double o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of decimal values.
+ */
+ public static final Comparator<BigDecimal> DECIMAL_COMPARATOR = new Comparator<BigDecimal>() {
+
+ public int compare( BigDecimal o1, BigDecimal o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of binary values. Although {@link Binary} is {@link Comparable}, this comparator does not rely upon any
+ * particular Binary implementation. Thus, Binary implementations can use this for their {@link Comparable#compareTo(Object)}
+ * implementation.
+ */
+ public static final Comparator<Binary> BINARY_COMPARATOR = new Comparator<Binary>() {
+
+ public int compare( Binary o1, Binary o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ try {
+ o1.acquire();
+ try {
+ o2.acquire();
+ final long len1 = o1.getSize();
+ final long len2 = o2.getSize();
+ if (len1 < len2) return -1;
+ if (len1 > len2) return 1;
+ // Otherwise they are the same length ...
+ InputStream stream1 = null;
+ InputStream stream2 = null;
+ try {
+ stream1 = o1.getStream();
+ stream2 = o2.getStream();
+ byte[] buffer1 = new byte[1024];
+ byte[] buffer2 = new byte[1024];
+ while (true) {
+ int numRead1 = stream1.read(buffer1);
+ if (numRead1 < 0) break;
+ int numRead2 = stream2.read(buffer2);
+ if (numRead1 != numRead2) {
+ throw new ValueFormatException(SpiI18n.errorReadingPropertyValueBytes.text());
+ }
+ for (int i = 0; i != numRead1; ++i) {
+ int diff = buffer1[i] - buffer2[i];
+ if (diff != 0) return diff;
+ }
+ }
+ return 0;
+ } catch (IOException e) {
+ throw new ValueFormatException(SpiI18n.errorReadingPropertyValueBytes.text());
+ } finally {
+ if (stream1 != null) {
+ try {
+ stream1.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ if (stream2 != null) {
+ try {
+ stream2.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+ } finally {
+ o2.release();
+ }
+ } finally {
+ o1.release();
+ }
+ }
+ };
+ /**
+ * A comparator of boolean values.
+ */
+ public static final Comparator<Boolean> BOOLEAN_COMPARATOR = new Comparator<Boolean>() {
+
+ public int compare( Boolean o1, Boolean o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of date values.
+ */
+ public static final Comparator<Date> DATE_COMPARATOR = new Comparator<Date>() {
+
+ public int compare( Date o1, Date o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of calendar values.
+ */
+ public static final Comparator<Calendar> CALENDAR_COMPARATOR = new Comparator<Calendar>() {
+
+ public int compare( Calendar o1, Calendar o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of name values.
+ */
+ public static final Comparator<Name> NAME_COMPARATOR = new Comparator<Name>() {
+
+ public int compare( Name o1, Name o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of path values.
+ */
+ public static final Comparator<Path> PATH_COMPARATOR = new Comparator<Path>() {
+
+ public int compare( Path o1, Path o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of URI values.
+ */
+ public static final Comparator<URI> URI_COMPARATOR = new Comparator<URI>() {
+
+ public int compare( URI o1, URI o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of reference values.
+ */
+ public static final Comparator<Reference> REFERENCE_COMPARATOR = new Comparator<Reference>() {
+
+ public int compare( Reference o1, Reference o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of other values.
+ */
+ public static final Comparator<Object> OBJECT_COMPARATOR = new Comparator<Object>() {
+
+ @SuppressWarnings( "unchecked" )
+ public int compare( Object o1, Object o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ PropertyType type1 = PropertyType.discoverType(o1);
+ PropertyType type2 = PropertyType.discoverType(o2);
+ if (type1 != PropertyType.OBJECT && type2 != PropertyType.OBJECT) {
+ if (type1 == type2) return type1.getComparator().compare(o1, o2);
+
+ // The types are different but the classes are the same ...
+ if (type1.getDeclaringClass().isAssignableFrom(type2.getDeclaringClass())) {
+ return type1.getComparator().compare(o1, o2);
+ }
+ if (type2.getDeclaringClass().isAssignableFrom(type1.getDeclaringClass())) {
+ return type2.getComparator().compare(o1, o2);
+ }
+ }
+
+ // The types are different and must be converted ...
+ String value1 = getStringValueFactory().create(o1);
+ String value2 = getStringValueFactory().create(o2);
+ return value1.compareTo(value2);
+ }
+ };
+
+ // This is loaded lazily so that there is not a circular dependency between PropertyType (depends on this),
+ // StringValueFactory (depends on PropertyType), and OBJECT_COMPARATOR (which depends on StringValueFactory) ...
+ private static ValueFactory<String> STRING_VALUE_FACTORY;
+
+ 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);
+ }
+ return STRING_VALUE_FACTORY;
+ }
+}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -93,7 +93,7 @@
* Get the value factory for {@link PropertyType#NAME name} properties.
* @return the factory; never null
*/
- ValueFactory<Name> getNameFactory();
+ NameFactory getNameFactory();
/**
* Get the value factory for {@link PropertyType#REFERENCE reference} properties.
@@ -105,7 +105,7 @@
* Get the value factory for {@link PropertyType#PATH path} properties.
* @return the factory; never null
*/
- ValueFactory<Path> getPathFactory();
+ PathFactory getPathFactory();
/**
* Get the value factory for {@link PropertyType#URI URI} properties.
@@ -113,4 +113,10 @@
*/
ValueFactory<URI> getUriFactory();
+ /**
+ * Get the value factory for {@link PropertyType#OBJECT object} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<Object> getObjectFactory();
+
}
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-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -71,6 +71,10 @@
* {@inheritDoc}
*/
public String getString( TextEncoder encoder ) {
+ if (this.getNamespaceUri().length() == 0) {
+ if (this.getLocalName().equals(Path.SELF)) return Path.SELF;
+ if (this.getLocalName().equals(Path.PARENT)) return Path.PARENT;
+ }
if (encoder == null) encoder = Path.DEFAULT_ENCODER;
return "{" + encoder.encode(this.namespaceUri) + "}" + encoder.encode(this.localName);
}
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,124 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+
+/**
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public class BasicNamespaceRegistry implements NamespaceRegistry {
+
+ 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>();
+
+ /**
+ *
+ */
+ public BasicNamespaceRegistry() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNamespaceForPrefix( String prefix ) {
+ ArgCheck.isNotNull(prefix, "prefix");
+ Lock lock = this.registryLock.readLock();
+ try {
+ lock.lock();
+ return this.namespacesByPrefix.get(prefix);
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPrefixForNamespaceUri( String namespaceUri ) {
+ ArgCheck.isNotNull(namespaceUri, "namespaceUri");
+ Lock lock = this.registryLock.readLock();
+ try {
+ lock.lock();
+ return this.prefixesByNamespace.get(namespaceUri);
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isRegisteredNamespaceUri( String namespaceUri ) {
+ ArgCheck.isNotNull(namespaceUri, "namespaceUri");
+ Lock lock = this.registryLock.readLock();
+ try {
+ lock.lock();
+ return this.prefixesByNamespace.containsKey(namespaceUri);
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDefaultNamespaceUri() {
+ Lock lock = this.registryLock.readLock();
+ try {
+ lock.lock();
+ return this.namespacesByPrefix.get("");
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ public String register( String prefix, String namespaceUri ) {
+ ArgCheck.isNotNull(prefix, "prefix");
+ ArgCheck.isNotEmpty(namespaceUri, "namespaceUri");
+ String previousNamespaceForPrefix = null;
+ prefix = prefix.trim();
+ namespaceUri = namespaceUri.trim();
+ Lock lock = this.registryLock.writeLock();
+ try {
+ lock.lock();
+ previousNamespaceForPrefix = this.namespacesByPrefix.put(prefix, namespaceUri);
+ String previousPrefix = this.prefixesByNamespace.put(namespaceUri, prefix);
+ if (previousPrefix != null) {
+ this.namespacesByPrefix.remove(previousPrefix);
+ }
+ } finally {
+ lock.unlock();
+ }
+ return previousNamespaceForPrefix;
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNamespaceRegistry.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -44,12 +44,12 @@
@Immutable
public class BasicPath implements Path {
- public static final Path ROOT = new BasicPath(null, true);
+ private static final List<Segment> EMPTY_SEGMENTS = Collections.emptyList();
+ public static final Path ROOT = new BasicPath(EMPTY_SEGMENTS, true);
+
protected static final Path SELF_PATH = new BasicPath(Collections.singletonList(BasicPathSegment.SELF_SEGMENT), false);
- private static final List<Segment> EMPTY_SEGMENTS = Collections.emptyList();
-
private final List<Segment> segments;
private final boolean absolute;
private final boolean normalized;
@@ -60,9 +60,10 @@
* @param absolute true if this path is absolute, or false otherwise
*/
public BasicPath( List<Segment> segments, boolean absolute ) {
- this.segments = segments != null && segments.size() > 0 ? Collections.unmodifiableList(segments) : EMPTY_SEGMENTS;
+ ArgCheck.isNotNull(segments, "segments");
+ this.segments = segments.isEmpty() ? EMPTY_SEGMENTS : Collections.unmodifiableList(segments);
this.absolute = absolute;
- this.normalized = isNormalized(segments);
+ this.normalized = isNormalized(this.segments);
}
protected boolean isNormalized( List<Segment> segments ) {
@@ -87,6 +88,7 @@
public Path getAncestor( int degree ) {
ArgCheck.isNonNegative(degree, "degree");
if (this.isRoot()) return this;
+ if (degree == 0) return this;
int endIndex = this.segments.size() - degree;
if (endIndex < 0) {
String msg = SpiI18n.pathAncestorDegreeIsInvalid.text(this.getString(), Inflector.getInstance().ordinalize(degree));
@@ -112,20 +114,21 @@
*/
public Path getCommonAncestor( Path that ) {
if (that == null) return null;
+ if (this.isRoot() || that.isRoot()) return ROOT;
Path normalizedPath = this.getNormalizedPath();
- int lastIndex = normalizedPath.size();
+ int lastIndex = 0;
Iterator<Segment> thisIter = normalizedPath.iterator();
Iterator<Segment> thatIter = that.getNormalizedPath().iterator();
while (thisIter.hasNext() && thatIter.hasNext()) {
Segment thisSeg = thisIter.next();
Segment thatSeg = thatIter.next();
if (thisSeg.equals(thatSeg)) {
- --lastIndex;
+ ++lastIndex;
} else {
break;
}
}
- if (lastIndex <= 0) return ROOT;
+ if (lastIndex == 0) return ROOT;
return normalizedPath.subpath(0, lastIndex);
}
@@ -146,12 +149,11 @@
for (Segment segment : segments) {
if (segment.isSelfReference()) continue;
if (segment.isParentReference()) {
- if (newSegments.size() <= 0) {
+ if (newSegments.isEmpty()) {
if (this.isAbsolute()) {
throw new InvalidPathException(CommonI18n.pathCannotBeNormalized.text(this));
}
- }
- if (newSegments.size() > 0 && !newSegments.getLast().isParentReference()) {
+ } else if (!newSegments.getLast().isParentReference()) {
newSegments.removeLast();
continue;
}
@@ -241,7 +243,7 @@
}
assert segment != null;
if (namespaceRegistry != null) {
- sb.append(segment.getString(encoder));
+ sb.append(segment.getString(namespaceRegistry, encoder));
} else {
sb.append(segment.getString(encoder));
}
@@ -416,8 +418,31 @@
/**
* {@inheritDoc}
*/
+ public Path subpath( int beginIndex ) {
+ if (beginIndex == 0) return this;
+ int size = size();
+ if (beginIndex >= size) {
+ throw new IndexOutOfBoundsException(SpiI18n.unbleToCreateSubpathBeginIndexGreaterThanOrEqualToSize.text(beginIndex, size));
+ }
+ if (size == 0) return ROOT;
+ return new BasicPath(this.segments.subList(beginIndex, size), this.isAbsolute());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Path subpath( int beginIndex, int endIndex ) {
- if (beginIndex == 0 && endIndex == 0) return ROOT;
+ int size = size();
+ if (beginIndex == 0) {
+ if (endIndex == 0) return ROOT;
+ if (endIndex == size) return this;
+ }
+ if (beginIndex >= size) {
+ throw new IndexOutOfBoundsException(SpiI18n.unbleToCreateSubpathBeginIndexGreaterThanOrEqualToSize.text(beginIndex, size));
+ }
+ if (beginIndex > endIndex) {
+ throw new IndexOutOfBoundsException(SpiI18n.unbleToCreateSubpathBeginIndexGreaterThanOrEqualToEndingIndex.text(beginIndex, endIndex));
+ }
// This reuses the same list, so it's pretty efficient ...
return new BasicPath(this.segments.subList(beginIndex, endIndex), this.isAbsolute());
}
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-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -25,6 +25,7 @@
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
/**
@@ -55,9 +56,9 @@
*/
public BasicPathSegment( Name name, int index ) {
ArgCheck.isNotNull(name, "name");
- ArgCheck.isNonNegative(index, "index");
+ ArgCheck.isNotLessThan(index, Path.NO_INDEX, "index");
this.name = name;
- this.index = index;
+ this.index = (this.isSelfReference() || this.isParentReference()) ? Path.NO_INDEX : index;
}
/**
@@ -85,14 +86,14 @@
* {@inheritDoc}
*/
public boolean isParentReference() {
- return this.hasIndex() == false && this.name.getNamespaceUri().length() == 0 && this.name.getLocalName().equals(Path.PARENT);
+ return this.name.getNamespaceUri().length() == 0 && this.name.getLocalName().equals(Path.PARENT);
}
/**
* {@inheritDoc}
*/
public boolean isSelfReference() {
- return this.hasIndex() == false && this.name.getNamespaceUri().length() == 0 && this.name.getLocalName().equals(Path.SELF);
+ return this.name.getNamespaceUri().length() == 0 && this.name.getLocalName().equals(Path.SELF);
}
/**
@@ -122,7 +123,7 @@
if (obj instanceof Path.Segment) {
Path.Segment that = (Path.Segment)obj;
if (!this.getName().equals(that.getName())) return false;
- return this.getIndex() != that.getIndex();
+ return this.getIndex() == that.getIndex();
}
return false;
}
@@ -157,4 +158,24 @@
return encodedName;
}
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ return getString(namespaceRegistry, Path.DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ if (encoder == null) encoder = Path.DEFAULT_ENCODER;
+ String encodedName = this.getName().getString(namespaceRegistry, encoder);
+ if (this.hasIndex()) {
+ return encodedName + "[" + this.getIndex() + "]";
+ }
+ return encodedName;
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -29,7 +29,7 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
-import org.jboss.dna.spi.graph.PropertyValues;
+import org.jboss.dna.spi.graph.ValueComparators;
/**
* An implementation of {@link Binary} that keeps the binary data in-memory.
@@ -84,7 +84,7 @@
* {@inheritDoc}
*/
public int compareTo( Binary o ) {
- return PropertyValues.BINARY_COMPARATOR.compare(this, o);
+ return ValueComparators.BINARY_COMPARATOR.compare(this, o);
}
/**
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-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -36,6 +36,7 @@
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.NamespaceException;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
@@ -83,8 +84,8 @@
// First see whether the value fits the internal pattern ...
Matcher matcher = FULLY_QUALIFIED_NAME_PATTERN.matcher(value);
if (matcher.matches()) {
- String namespaceUri = matcher.group(2);
- String localName = matcher.group(3);
+ String namespaceUri = matcher.group(1);
+ String localName = matcher.group(2);
// Decode the parts ...
namespaceUri = decoder.decode(namespaceUri);
localName = decoder.decode(localName);
@@ -93,15 +94,20 @@
// Second, see whether the value fits the prefixed name pattern ...
matcher = PREFIXED_NAME_PATTERN.matcher(value);
if (matcher.matches()) {
- String prefix = matcher.group(1);
- String localName = matcher.group(2);
+ String prefix = matcher.group(2);
+ String localName = matcher.group(3);
// Decode the parts ...
prefix = decoder.decode(prefix);
localName = decoder.decode(localName);
// Look for a namespace match ...
- String namespaceUri = this.namespaceRegistry.getNamespaceForPrefix(prefix);
- // If no namespace is found, use the prefix ...
- if (namespaceUri == null) namespaceUri = prefix;
+ 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));
+ }
+ }
return new BasicName(namespaceUri, localName);
}
} catch (Throwable t) {
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,183 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+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.util.ArgCheck;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#OBJECT} values.
+ * @author Randall Hauch
+ */
+@Immutable
+public class ObjectValueFactory extends AbstractValueFactory<Object> {
+
+ private final ValueFactory<Binary> binaryValueFactory;
+
+ public ObjectValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory, ValueFactory<Binary> binaryValueFactory ) {
+ super(PropertyType.OBJECT, encoder, stringValueFactory);
+ ArgCheck.isNotNull(binaryValueFactory, "binaryValueFactory");
+ this.binaryValueFactory = binaryValueFactory;
+ }
+
+ /**
+ * @return binaryValueFactory
+ */
+ protected ValueFactory<Binary> getBinaryValueFactory() {
+ return this.binaryValueFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( String value ) {
+ return this.getStringValueFactory().create(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( String value, TextEncoder decoder ) {
+ return this.getStringValueFactory().create(value, decoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( int value ) {
+ return Integer.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( long value ) {
+ return Long.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( boolean value ) {
+ return Boolean.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( float value ) {
+ return Float.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( double value ) {
+ return Double.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( BigDecimal value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( Calendar value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( Date value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( Name value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( Path value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( Reference value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( URI value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( byte[] value ) throws ValueFormatException {
+ return getBinaryValueFactory().create(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( InputStream stream, int approximateLength ) throws IOException {
+ return getBinaryValueFactory().create(stream, approximateLength);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object create( Reader reader, int approximateLength ) throws IOException {
+ return getBinaryValueFactory().create(reader, approximateLength);
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -32,10 +32,10 @@
import java.util.List;
import java.util.regex.Pattern;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.jcr.InvalidPathException;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.InvalidPathException;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathFactory;
@@ -79,7 +79,7 @@
private final ValueFactory<Name> nameValueFactory;
public PathValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory, ValueFactory<Name> nameValueFactory ) {
- super(PropertyType.NAME, encoder, stringValueFactory);
+ super(PropertyType.PATH, encoder, stringValueFactory);
ArgCheck.isNotNull(nameValueFactory, "nameValueFactory");
this.nameValueFactory = nameValueFactory;
}
@@ -108,7 +108,7 @@
int length = trimmedValue.length();
boolean absolute = false;
if (length == 0) {
- throw new ValueFormatException(SpiI18n.unableToCreatePathFromEmptyString.text());
+ return BasicPath.ROOT;
}
// Remove the leading delimiter ...
@@ -123,12 +123,15 @@
length = trimmedValue.length();
}
if (length == 0) {
- throw new ValueFormatException(SpiI18n.unableToCreatePathFromEmptyString.text());
+ 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 InvalidPathException(SpiI18n.validPathMayNotContainEmptySegment.text(value));
+ }
assert pathSegments.length != 0;
for (String segment : pathSegments) {
assert segment != null;
@@ -345,6 +348,22 @@
/**
* {@inheritDoc}
*/
+ public Segment createSegment( String segmentName ) {
+ ArgCheck.isNotNull(segmentName, "segment name");
+ return new BasicPathSegment(this.nameValueFactory.create(segmentName));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Segment createSegment( String segmentName, int index ) {
+ ArgCheck.isNotNull(segmentName, "segment name");
+ 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));
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -29,13 +29,12 @@
import java.util.Iterator;
import java.util.Map;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.SystemFailureException;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.Binary;
-import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
-import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
import org.jboss.dna.spi.graph.PropertyType;
import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactories;
@@ -56,12 +55,16 @@
private final ValueFactory<BigDecimal> decimalFactory;
private final ValueFactory<Double> doubleFactory;
private final ValueFactory<Long> longFactory;
- private final ValueFactory<Name> nameFactory;
- private final ValueFactory<Path> pathFactory;
+ private final NameFactory nameFactory;
+ private final PathFactory pathFactory;
private final ValueFactory<Reference> referenceFactory;
private final ValueFactory<URI> uriFactory;
+ private final ValueFactory<Object> objectFactory;
private final Map<PropertyType, ValueFactory<?>> factories;
+ private final NamespaceRegistry namespaceRegistry;
+ private final TextEncoder encoder;
+
/**
* Create a standard set of value factories, using the {@link ValueFactory#DEFAULT_ENCODER default encoder/decoder}.
* @param namespaceRegistry the namespace registry
@@ -80,7 +83,9 @@
* @throws IllegalArgumentException if the namespace registry is null
*/
public StandardValueFactories( NamespaceRegistry namespaceRegistry, TextEncoder encoder, ValueFactory<?>... extraFactories ) {
- if (encoder == null) encoder = ValueFactory.DEFAULT_ENCODER;
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ this.namespaceRegistry = namespaceRegistry;
+ this.encoder = encoder != null ? encoder : ValueFactory.DEFAULT_ENCODER;
Map<PropertyType, ValueFactory<?>> factories = new HashMap<PropertyType, ValueFactory<?>>();
// Put the extra factories into the map first ...
@@ -90,23 +95,19 @@
}
// Now assign the members, using the factories in the map or (if null) the supplied default ...
- this.stringFactory = getFactory(factories, new StringValueFactory(encoder));
- this.binaryFactory = getFactory(factories, new InMemoryBinaryValueFactory(encoder, this.stringFactory));
- this.booleanFactory = getFactory(factories, new BooleanValueFactory(encoder, this.stringFactory));
- this.dateFactory = getFactory(factories, new DateValueFactory(encoder, this.stringFactory));
- this.decimalFactory = getFactory(factories, new DecimalValueFactory(encoder, this.stringFactory));
- this.doubleFactory = getFactory(factories, new DoubleValueFactory(encoder, this.stringFactory));
- this.longFactory = getFactory(factories, new LongValueFactory(encoder, this.stringFactory));
- this.nameFactory = getFactory(factories, new NameValueFactory(namespaceRegistry, encoder, this.stringFactory));
- this.pathFactory = getFactory(factories, new PathValueFactory(encoder, this.stringFactory, this.nameFactory));
- this.referenceFactory = getFactory(factories, new UuidReferenceValueFactory(encoder, this.stringFactory));
- this.uriFactory = getFactory(factories, new UriValueFactory(namespaceRegistry, encoder, this.stringFactory));
+ 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 = getFactory(factories, new DateValueFactory(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));
- // Make sure there is a PropertyType.UNDEFINED factory ...
- if (factories.get(PropertyType.UNDEFINED) == null) {
- factories.put(PropertyType.UNDEFINED, this.stringFactory);
- }
-
// Wrap the factories with an unmodifiable ...
this.factories = Collections.unmodifiableMap(factories);
}
@@ -123,6 +124,27 @@
}
/**
+ * @return encoder
+ */
+ public TextEncoder getTextEncoder() {
+ return this.encoder;
+ }
+
+ /**
+ * @return namespaceRegistry
+ */
+ public NamespaceRegistry getNamespaceRegistry() {
+ return this.namespaceRegistry;
+ }
+
+ /**
+ * @return factories
+ */
+ public Map<PropertyType, ValueFactory<?>> getMapOfValueFactories() {
+ return this.factories;
+ }
+
+ /**
* {@inheritDoc}
*/
public ValueFactory<Binary> getBinaryFactory() {
@@ -160,29 +182,6 @@
/**
* {@inheritDoc}
*/
- public ValueFactory<?> getValueFactory( PropertyType type ) {
- ArgCheck.isNotNull(type, "type");
- ValueFactory<?> factory = this.factories.get(type);
- if (factory == null) {
- // Should never happen
- throw new SystemFailureException("Unexpected PropertyType");
- }
- return factory;
- }
-
- /**
- * {@inheritDoc}
- */
- public ValueFactory<?> getValueFactory( Object prototype ) {
- ArgCheck.isNotNull(prototype, "prototype");
- PropertyType inferredType = PropertyType.discoverType(prototype);
- if (inferredType == null) inferredType = PropertyType.STRING;
- return getValueFactory(inferredType);
- }
-
- /**
- * {@inheritDoc}
- */
public ValueFactory<Long> getLongFactory() {
return this.longFactory;
}
@@ -190,14 +189,14 @@
/**
* {@inheritDoc}
*/
- public ValueFactory<Name> getNameFactory() {
+ public NameFactory getNameFactory() {
return this.nameFactory;
}
/**
* {@inheritDoc}
*/
- public ValueFactory<Path> getPathFactory() {
+ public PathFactory getPathFactory() {
return this.pathFactory;
}
@@ -225,8 +224,33 @@
/**
* {@inheritDoc}
*/
+ public ValueFactory<Object> getObjectFactory() {
+ return this.objectFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Iterator<ValueFactory<?>> iterator() {
return this.factories.values().iterator();
}
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<?> getValueFactory( PropertyType type ) {
+ ArgCheck.isNotNull(type, "type");
+ return this.factories.get(type);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<?> getValueFactory( Object prototype ) {
+ ArgCheck.isNotNull(prototype, "prototype");
+ PropertyType inferredType = PropertyType.discoverType(prototype);
+ assert inferredType != null;
+ return this.factories.get(inferredType);
+ }
+
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -26,8 +26,8 @@
import java.io.ObjectOutput;
import java.util.UUID;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.jcr.Path;
import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.Reference;
/**
Modified: branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties
===================================================================
--- branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties 2008-05-23 16:12:06 UTC (rev 185)
@@ -1,17 +1,19 @@
-unableToDiscoverPropertyType = Unable to discover property type for {0}
+unableToDiscoverPropertyTypeForNullValue = Unable to discover property type for null value
errorReadingPropertyValueBytes = Error reading bytes
valueJavaTypeNotCompatibleWithPropertyType = Value is instance of Java type "{0}" and is not compatible with the "{1}" property type
errorConvertingBinaryValueToString = Error while interpretting binary value as a UTF-8 string
errorCreatingValue = Error creating {0} value from {1} '{2}'
unableToCreateValue = Unable to create {0} value from {1} '{2}': undefined type conversion
-unableToCreatePathFromEmptyString = Unable to create a path from an empty string
validPathMayNotContainEmptySegment = The path '{0}' is not valid because it contains an empty segment
+noNamespaceRegisteredForPrefix = There is no namespace registered for the prefix '{0}'
pathAncestorDegreeIsInvalid = Unable to obtain the {1} ancestor for {0}
pathIsAlreadyAbsolute = The path {0} is already an absolute path
pathIsNotAbsolute = The path {0} is not an absolute path
pathIsNotRelative = The path {0} is not a relative path
pathCannotBeNormalized = The path {0} is invalid and cannot be normalized
+unbleToCreateSubpathBeginIndexGreaterThanOrEqualToSize = Unable to create subpath: fromIndex({0}) >= size({1})
+unbleToCreateSubpathBeginIndexGreaterThanOrEqualToEndingIndex = Unable to create subpath: fromIndex({0}) >= toIndex({1})
invalidQualifiedNameString = Unable to parse qualified name from "{0}"
\ No newline at end of file
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/AbstractValueComparatorsTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/AbstractValueComparatorsTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/AbstractValueComparatorsTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,136 @@
+/*
+ * 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;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.impl.BasicNamespaceRegistry;
+import org.jboss.dna.spi.graph.impl.StandardValueFactories;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ * @param <T>
+ */
+public abstract class AbstractValueComparatorsTest<T> {
+
+ public static final BasicNamespaceRegistry NAMESPACE_REGISTRY = new BasicNamespaceRegistry();
+ public static final ValueFactories VALUE_FACTORIES = new StandardValueFactories(NAMESPACE_REGISTRY);
+
+ protected final Comparator<T> comparator;
+ protected final T[] validNonNullValues;
+
+ protected AbstractValueComparatorsTest( Comparator<T> comparator, T... validNonNullValues ) {
+ ArgCheck.isNotNull(comparator, "comparator");
+ ArgCheck.isNotEmpty(validNonNullValues, "validNonNullValues");
+ this.comparator = comparator;
+ this.validNonNullValues = validNonNullValues;
+ }
+
+ protected Comparator<T> getComparator() {
+ return this.comparator;
+ }
+
+ @Test
+ public void shouldConsiderNullLessThanValidNonNull() {
+ assertThat(comparator.compare(validNonNullValues[0], null) > 0, is(true));
+ assertThat(comparator.compare(null, validNonNullValues[0]) < 0, is(true));
+ }
+
+ @Test
+ public void shouldConsiderTwoNullsToBeEquivalent() {
+ assertThat(comparator.compare(null, null), is(0));
+ }
+
+ @Test
+ public void shouldConsiderSameInstanceToBeEquivalent() {
+ for (T validNonNullValue : validNonNullValues) {
+ assertThat(comparator.compare(validNonNullValue, validNonNullValue), is(0));
+ }
+ }
+
+ protected List<T> getValues( boolean includeNull ) {
+ List<T> values = new ArrayList<T>(validNonNullValues.length);
+ for (T validNonNullValue : validNonNullValues) {
+ assertThat(validNonNullValue, is(notNullValue()));
+ values.add(validNonNullValue);
+ }
+ if (includeNull) values.add(null);
+ return values;
+ }
+
+ protected List<T> getSortedValues( boolean includeNull ) {
+ List<T> values = getValues(includeNull);
+ Collections.sort(values, comparator);
+ return values;
+ }
+
+ // protected void assertSortsSimilarTo( Comparator<T> otherComparator ) {
+ // assertThat(otherComparator, is(notNullValue()));
+ // List<T> values = getValues(true);
+ // List<T> otherValues = getValues(true);
+ // Collections.sort(values, comparator);
+ // Collections.sort(otherValues, comparator);
+ // assertThat(values, is(otherValues));
+ //
+ // values = getValues(false);
+ // otherValues = getValues(false);
+ // Collections.sort(values, comparator);
+ // Collections.sort(otherValues, comparator);
+ // assertThat(values, is(otherValues));
+ // }
+
+ @SuppressWarnings( "unchecked" )
+ @Test
+ public void shouldBeCompatibleWithCompareTo() {
+ List<T> values = getValues(false);
+ Collections.sort(values, comparator);
+ for (int i = 0; i != (values.size() - 1); ++i) {
+ T value1 = values.get(i);
+ T value2 = values.get(i + 1);
+ assertThat(value1, is(instanceOf(Comparable.class)));
+ Comparable<T> comparable1 = (Comparable<T>)value1;
+ int result = comparable1.compareTo(value2);
+ assertThat(result < 0 || result == 0, is(true));
+ assertThat(comparable1.compareTo(value1), is(0));
+ }
+ }
+
+ protected void assertValuesCompareUsing( T value1, T value2 ) {
+ int value1ToValue2 = comparator.compare(value1, value2);
+ int value2ToValue1 = comparator.compare(value2, value1);
+ if (value1ToValue2 == 0) {
+ assertThat(value2ToValue1, is(0));
+ } else if (value1ToValue2 < 0) {
+ assertThat(value2ToValue1 > 0, is(true));
+ } else { // if ( value1ToValue2 > 0 )
+ assertThat(value2ToValue1 < 0, is(true));
+ }
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/AbstractValueComparatorsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BinaryValueComparatorTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BinaryValueComparatorTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BinaryValueComparatorTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public class BinaryValueComparatorTest extends AbstractValueComparatorsTest<Binary> {
+
+ private static final ValueFactory<Binary> FACTORY;
+ private static final Binary BINARY1;
+ private static final Binary BINARY2;
+ private static final Binary BINARY3;
+
+ static {
+ FACTORY = VALUE_FACTORIES.getBinaryFactory();
+ BINARY1 = FACTORY.create("This is the binary 1 value");
+ BINARY2 = FACTORY.create("This is the binary 2 value");
+ BINARY3 = FACTORY.create("This is the binary 3 value");
+ }
+
+ public BinaryValueComparatorTest() {
+ super(ValueComparators.BINARY_COMPARATOR, BINARY1, BINARY2, BINARY3);
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BinaryValueComparatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BooleanValueComparatorTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BooleanValueComparatorTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BooleanValueComparatorTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public class BooleanValueComparatorTest extends AbstractValueComparatorsTest<Boolean> {
+
+ public BooleanValueComparatorTest() {
+ super(ValueComparators.BOOLEAN_COMPARATOR, Boolean.TRUE, Boolean.FALSE);
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/BooleanValueComparatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DateValueComparatorTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DateValueComparatorTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DateValueComparatorTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+import java.util.Calendar;
+
+/**
+ * @author Randall Hauch
+ */
+public class DateValueComparatorTest extends AbstractValueComparatorsTest<Calendar> {
+
+ private static final Calendar TODAY = Calendar.getInstance();
+ private static final Calendar YESTERDAY;
+ private static final Calendar TOMORROW;
+
+ static {
+ YESTERDAY = (Calendar)TODAY.clone();
+ YESTERDAY.roll(Calendar.DAY_OF_YEAR, false);
+
+ TOMORROW = (Calendar)TODAY.clone();
+ TOMORROW.roll(Calendar.DAY_OF_YEAR, true);
+ }
+
+ public DateValueComparatorTest() {
+ super(ValueComparators.CALENDAR_COMPARATOR, TODAY, TOMORROW, YESTERDAY);
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DateValueComparatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DecimalValueComparatorTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DecimalValueComparatorTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DecimalValueComparatorTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import java.math.BigDecimal;
+
+/**
+ * @author Randall Hauch
+ */
+public class DecimalValueComparatorTest extends AbstractValueComparatorsTest<BigDecimal> {
+
+ public DecimalValueComparatorTest() {
+ super(ValueComparators.DECIMAL_COMPARATOR, new BigDecimal(100), new BigDecimal(200.0), new BigDecimal(300.0), new BigDecimal(-1.0), new BigDecimal(0.0));
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DecimalValueComparatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DoubleValueComparatorTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DoubleValueComparatorTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DoubleValueComparatorTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public class DoubleValueComparatorTest extends AbstractValueComparatorsTest<Double> {
+
+ public DoubleValueComparatorTest() {
+ super(ValueComparators.DOUBLE_COMPARATOR, 100.0d, 200.0d, 300.0d, -1.0d, 0.0d);
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/DoubleValueComparatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/LongValueComparatorTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/LongValueComparatorTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/LongValueComparatorTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public class LongValueComparatorTest extends AbstractValueComparatorsTest<Long> {
+
+ public LongValueComparatorTest() {
+ super(ValueComparators.LONG_COMPARATOR, 100l, 200l, 300l, -1l, 0l);
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/LongValueComparatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/NameValueComparatorTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/NameValueComparatorTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/NameValueComparatorTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class NameValueComparatorTest extends AbstractValueComparatorsTest<Name> {
+
+ private static final ValueFactory<Name> FACTORY;
+ private static final Name NAME1;
+ private static final Name NAME2;
+ private static final Name NAME3;
+ private static final Name NAME4;
+ private static final Name NAME5;
+ private static final Name NAME6;
+
+ static {
+ NAMESPACE_REGISTRY.register("dna", "http://www.jboss.org/dna/namespaces/Test");
+ NAMESPACE_REGISTRY.register("acme", "http://www.acme.com/");
+ NAMESPACE_REGISTRY.register("dna-b", "http://www.jboss.org/dna/namespaces/Test/b");
+ NAMESPACE_REGISTRY.register("dna-c", "http://www.jboss.org/dna/namespaces/TEST");
+ FACTORY = VALUE_FACTORIES.getNameFactory();
+ NAME1 = FACTORY.create("dna:alpha");
+ NAME2 = FACTORY.create("dna:beta");
+ NAME3 = FACTORY.create("acme:beta");
+ NAME4 = FACTORY.create("dna:beta");
+ NAME5 = FACTORY.create("dna:ALPHA");
+ NAME6 = FACTORY.create("dna-c:ALPHA");
+ }
+
+ public NameValueComparatorTest() {
+ super(ValueComparators.NAME_COMPARATOR, NAME1, NAME2, NAME3, NAME4, NAME5, NAME6);
+ }
+
+ @Test
+ public void shouldConsiderNamesWithSameNamespaceUriAndLocalPartToBeComparable() {
+ System.out.println(NAME2);
+ System.out.println(NAME4);
+ assertThat(comparator.compare(NAME2, NAME4), is(0));
+ }
+
+ @Test
+ public void shouldBeCaseSensitive() {
+ assertThat(comparator.compare(NAME2, NAME4), is(0));
+ assertThat(comparator.compare(NAME1, NAME5), is(not(0)));
+ assertThat(comparator.compare(NAME6, NAME5), is(not(0)));
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/NameValueComparatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/StringValueComparatorTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/StringValueComparatorTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/StringValueComparatorTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class StringValueComparatorTest extends AbstractValueComparatorsTest<String> {
+
+ public StringValueComparatorTest() {
+ super(ValueComparators.STRING_COMPARATOR, "valid value 1", "Valid valid 2");
+ }
+
+ @Test
+ public void shouldBeCaseInsensitive() {
+ assertThat(comparator.compare(validNonNullValues[0].toUpperCase(), validNonNullValues[0].toLowerCase()), is(not(0)));
+ }
+
+ @Test
+ public void shouldMatchStringCompareToMethod() {
+ assertThat(comparator.compare(validNonNullValues[0], validNonNullValues[1]), is(validNonNullValues[0].compareTo(validNonNullValues[1])));
+ assertThat(comparator.compare(validNonNullValues[1], validNonNullValues[0]), is(validNonNullValues[1].compareTo(validNonNullValues[0])));
+ assertThat(comparator.compare(validNonNullValues[1], validNonNullValues[1]), is(validNonNullValues[1].compareTo(validNonNullValues[1])));
+ assertThat(comparator.compare(validNonNullValues[0], validNonNullValues[0]), is(validNonNullValues[0].compareTo(validNonNullValues[0])));
+ }
+
+ @Test
+ public void shouldSortValues() {
+ assertThat(getSortedValues(false), hasItems(validNonNullValues[0], validNonNullValues[1]));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/StringValueComparatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,158 @@
+/*
+ * 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.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.containsString;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicNameTest {
+
+ private BasicNamespaceRegistry namespaceRegistry;
+ private Name name;
+ private String validNamespaceUri;
+ private String validLocalName;
+ private TextEncoder encoder;
+ private String validNamespacePrefix;
+
+ @Before
+ public void beforeEach() throws Exception {
+ this.validNamespaceUri = "http://www.jboss.org/dna";
+ this.validLocalName = "localPart";
+ this.validNamespacePrefix = "dna";
+ this.name = new BasicName(validNamespaceUri, validLocalName);
+ this.encoder = Path.URL_ENCODER;
+ this.namespaceRegistry = new BasicNamespaceRegistry();
+ this.namespaceRegistry.register(validNamespacePrefix, validNamespaceUri);
+ }
+
+ @Test
+ public void shouldAllowNullNamespaceUriInConstructorAndConvertToEmptyString() {
+ name = new BasicName(null, validLocalName);
+ assertThat(name.getNamespaceUri(), is(""));
+ }
+
+ @Test
+ public void shouldAllowEmptyNamespaceUriInConstructor() {
+ name = new BasicName("", validLocalName);
+ assertThat(name.getNamespaceUri(), is(""));
+ }
+
+ @Test
+ public void shouldTrimNamespaceUriInConstructor() {
+ name = new BasicName(" " + validNamespaceUri + "\t \t", validLocalName);
+ assertThat(name.getNamespaceUri(), is(validNamespaceUri.trim()));
+
+ name = new BasicName(" \t \t", validLocalName);
+ assertThat(name.getNamespaceUri(), is(""));
+ }
+
+ @Test
+ public void shouldAllowNullLocalNameInConstructorAndConvertToEmptyString() {
+ name = new BasicName(validNamespaceUri, null);
+ assertThat(name.getLocalName(), is(""));
+ }
+
+ @Test
+ public void shouldAllowEmptyLocalNameInConstructorAndConvertToEmptyString() {
+ name = new BasicName(validNamespaceUri, "");
+ assertThat(name.getLocalName(), is(""));
+ }
+
+ @Test
+ public void shouldAcceptLocalNameWithColon() {
+ validLocalName = "some:name:with:colons";
+ name = new BasicName(validNamespaceUri, validLocalName);
+ assertThat(name.getLocalName(), is(validLocalName));
+ }
+
+ @Test
+ public void shouldReturnSameHashCodeForNamesWithSameNamespaceUriAndLocalPart() {
+ Name other = new BasicName(name.getNamespaceUri(), name.getLocalName());
+ assertThat(name.hashCode(), is(other.hashCode()));
+ }
+
+ @Test
+ public void shouldConsiderNamesEqualIfTheyHaveTheSameNamespaceUriAndLocalPart() {
+ Name other = new BasicName(name.getNamespaceUri(), name.getLocalName());
+ assertThat(name.equals(other), is(true));
+ assertThat(name.compareTo(other), is(0));
+ }
+
+ @Test
+ public void shouldConsiderSameInstanceEqualToItself() {
+ assertThat(name.equals(name), is(true));
+ assertThat(name.compareTo(name), is(0));
+ }
+
+ @Test( expected = NullPointerException.class )
+ public void shouldNotSupportNullInCompareTo() {
+ name.compareTo(null);
+ }
+
+ @Test
+ public void shouldSupportNullInEquals() {
+ assertThat(name.equals(null), is(false));
+ }
+
+ @Test
+ public void shouldUseFullNamespaceUriInResultFromGetStringWithoutNamespaceRegistry() {
+ String encodedNamespaceUri = Path.DEFAULT_ENCODER.encode(validNamespaceUri);
+ String encodedLocalName = Path.DEFAULT_ENCODER.encode(validLocalName);
+ String result = name.getString();
+ assertThat(result, containsString(encodedNamespaceUri));
+ assertThat(result, containsString(encodedLocalName));
+ assertThat(result, is("{" + encodedNamespaceUri + "}" + encodedLocalName));
+ }
+
+ @Test
+ public void shouldEncodeColonInLocalNameAndNamespaceUriInResultFromGetStringWithoutNamespaceRegistry() {
+ validLocalName = "some:name:with:colons";
+ name = new BasicName(validNamespaceUri, validLocalName);
+ String encodedNamespaceUri = encoder.encode(validNamespaceUri);
+ String encodedLocalName = encoder.encode(validLocalName);
+ String result = name.getString(encoder);
+ assertThat(result, is("{" + encodedNamespaceUri + "}" + encodedLocalName));
+ assertThat(encodedNamespaceUri, is("http%3a%2f%2fwww.jboss.org%2fdna"));
+ assertThat(encodedLocalName, is("some%3aname%3awith%3acolons"));
+ }
+
+ @Test
+ public void shouldUseNamespacePrefixInResultFromGetStringWithNamespaceRegistry() {
+ String result = name.getString(namespaceRegistry, encoder);
+ assertThat(result, is("dna:" + validLocalName));
+
+ validLocalName = "some:name:with:colons";
+ name = new BasicName(validNamespaceUri, validLocalName);
+ result = name.getString(namespaceRegistry, encoder);
+ assertThat(result, is("dna:some%3aname%3awith%3acolons"));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicNameTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,145 @@
+/*
+ * 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.junit.Assert.assertThat;
+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.ValueFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicPathSegmentTest {
+
+ public static final TextEncoder NO_OP_ENCODER = Path.NO_OP_ENCODER;
+
+ private BasicNamespaceRegistry registry;
+ private ValueFactory<String> stringValueFactory;
+ private NameValueFactory nameFactory;
+ private PathValueFactory factory;
+ private TextEncoder encoder;
+ private Name validName;
+ private Path.Segment segment;
+ private Path.Segment segment2;
+
+ @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.nameFactory = new NameValueFactory(registry, encoder, stringValueFactory);
+ this.validName = nameFactory.create("dna:something");
+ this.factory = new PathValueFactory(encoder, stringValueFactory, nameFactory);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNegativeIndex() {
+ new BasicPathSegment(validName, -2);
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoSegmentsWithSameNameAndIndex() {
+ segment = new BasicPathSegment(validName);
+ segment2 = new BasicPathSegment(validName);
+ assertThat(segment.equals(segment2), is(true));
+ assertThat(segment.isSelfReference(), is(false));
+ assertThat(segment.isParentReference(), is(false));
+ assertThat(segment.getName(), is(validName));
+ }
+
+ @Test
+ public void shouldHaveIndexSpecifiedInConstructor() {
+ segment = new BasicPathSegment(validName, 3);
+ assertThat(segment.getIndex(), is(3));
+ assertThat(segment.hasIndex(), is(true));
+ assertThat(segment.isSelfReference(), is(false));
+ assertThat(segment.isParentReference(), is(false));
+ assertThat(segment.getName(), is(validName));
+ }
+
+ @Test
+ public void shouldNotHaveIndexByDefault() {
+ segment = new BasicPathSegment(validName);
+ assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.hasIndex(), is(false));
+ assertThat(segment.isSelfReference(), is(false));
+ assertThat(segment.isParentReference(), is(false));
+ assertThat(segment.getName(), is(validName));
+ }
+
+ @Test
+ public void shouldCreateSelfReferenceSegmentIfPassedSelfReferenceStringRegardlessOfIndex() {
+ segment = factory.createSegment(Path.SELF);
+ assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.hasIndex(), is(false));
+ assertThat(segment.isSelfReference(), is(true));
+ assertThat(segment.isParentReference(), is(false));
+ assertThat(segment.getName().getLocalName(), is(Path.SELF));
+ assertThat(segment.getName().getNamespaceUri().length(), is(0));
+
+ segment = factory.createSegment(Path.SELF, 1);
+ assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.hasIndex(), is(false));
+ assertThat(segment.isSelfReference(), is(true));
+ assertThat(segment.isParentReference(), is(false));
+ assertThat(segment.getName().getLocalName(), is(Path.SELF));
+ assertThat(segment.getName().getNamespaceUri().length(), is(0));
+ }
+
+ @Test
+ public void shouldCreateParentReferenceSegmentIfPassedParentReferenceStringRegardlessOfIndex() {
+ segment = factory.createSegment(Path.PARENT);
+ assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.hasIndex(), is(false));
+ assertThat(segment.isSelfReference(), is(false));
+ assertThat(segment.isParentReference(), is(true));
+ assertThat(segment.getName().getLocalName(), is(Path.PARENT));
+ assertThat(segment.getName().getNamespaceUri().length(), is(0));
+
+ segment = factory.createSegment(Path.PARENT, 1);
+ assertThat(segment.getIndex(), is(Path.NO_INDEX));
+ assertThat(segment.hasIndex(), is(false));
+ assertThat(segment.isSelfReference(), is(false));
+ assertThat(segment.isParentReference(), is(true));
+ assertThat(segment.getName().getLocalName(), is(Path.PARENT));
+ assertThat(segment.getName().getNamespaceUri().length(), is(0));
+ }
+
+ @Test
+ public void shouldConsiderSegmentCreatedWithSelfReferenceToBeEqualToStaticSingleton() {
+ segment = factory.createSegment(Path.SELF);
+ assertThat(segment.equals(BasicPathSegment.SELF_SEGMENT), is(true));
+ }
+
+ @Test
+ public void shouldConsiderSegmentCreatedWithParentReferenceToBeEqualToStaticSingleton() {
+ segment = factory.createSegment(Path.PARENT);
+ assertThat(segment.equals(BasicPathSegment.PARENT_SEGMENT), is(true));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,761 @@
+/*
+ * 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.core.IsNot.not;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.jboss.dna.spi.graph.impl.IsPathContaining.hasSegments;
+import static org.junit.Assert.assertThat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.InvalidPathException;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathNotFoundException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicPathTest {
+
+ 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;
+
+ @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);
+ }
+
+ @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 shouldCreateAbsolutePathWithParentSegment() {
+ validSegmentsList.add(BasicPathSegment.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(BasicPathSegment.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(BasicPathSegment.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(BasicPathSegment.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 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));
+
+ 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));
+
+ 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( expected = InvalidPathException.class )
+ public void shouldNotConstructPathWithSuccessiveDelimiters() {
+ pathFactory.create("///a/b///c//d//");
+ }
+
+ @Test( expected = InvalidPathException.class )
+ public void shouldNotConstructPathWithOnlyDelimiters() {
+ pathFactory.create("///");
+ }
+
+ @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 shouldConstructRelativePathIfSuppliedPathHasNoLeadingDelimiter() {
+ assertThat(pathFactory.create("a"), hasSegments(pathFactory, "a"));
+ }
+
+ @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()));
+ }
+
+ 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 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( expected = PathNotFoundException.class )
+ public void shouldNotAllowAncestorDegreeLargerThanSize() {
+ path.getAncestor(path.size() + 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 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 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/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 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));
+ }
+ }
+
+ @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));
+ }
+ }
+
+ @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 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 shouldNotConsiderRootToBeAncestorOfItself() {
+ assertThat(ROOT.isAncestorOf(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 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 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));
+ }
+
+ @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( 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 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 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
+ 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());
+ }
+
+ 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/../{}d/./{http://www.jboss.org/dna}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 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 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
+ 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, ".."));
+
+ 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, ".."));
+
+ 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( 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 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 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)));
+
+ // 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 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 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"));
+ }
+
+ public void shouldResolveNonAbsolutePaths() {
+ path = pathFactory.create("a/b/c");
+ assertThat(path, hasSegments(pathFactory, "a", "b", "c"));
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/IsPathContaining.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/IsPathContaining.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/IsPathContaining.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,106 @@
+/*
+ * 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.AllOf.allOf;
+import static org.hamcrest.core.IsEqual.equalTo;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.hamcrest.Description;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.Path.Segment;
+import org.junit.matchers.TypeSafeMatcher;
+
+/**
+ * @author Randall Hauch
+ */
+public class IsPathContaining extends TypeSafeMatcher<Iterable<Segment>> {
+
+ private final Matcher<? super Segment> elementMatcher;
+
+ public IsPathContaining( Matcher<? super Segment> elementMatcher ) {
+ this.elementMatcher = elementMatcher;
+ }
+
+ @Override
+ public boolean matchesSafely( Iterable<Segment> collection ) {
+ for (Segment item : collection) {
+ if (elementMatcher.matches(item)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void describeTo( Description description ) {
+ description.appendText("a path containing ").appendDescriptionOf(elementMatcher);
+ }
+
+ @Factory
+ public static Matcher<Iterable<Segment>> hasSegment( Matcher<? super Segment> elementMatcher ) {
+ return new IsPathContaining(elementMatcher);
+ }
+
+ @Factory
+ public static Matcher<Iterable<Segment>> hasSegment( Segment element ) {
+ return hasSegment(equalTo(element));
+ }
+
+ @Factory
+ public static Matcher<Iterable<Segment>> hasSegments( Matcher<Path.Segment>... elementMatchers ) {
+ Collection<Matcher<? extends Iterable<Path.Segment>>> all = new ArrayList<Matcher<? extends Iterable<Path.Segment>>>(elementMatchers.length);
+
+ for (Matcher<Path.Segment> elementMatcher : elementMatchers) {
+ Matcher<Iterable<Path.Segment>> itemMatcher = hasSegment(elementMatcher);
+ all.add(itemMatcher);
+ }
+
+ return allOf(all);
+ }
+
+ @Factory
+ public static Matcher<Iterable<Segment>> hasSegments( Segment... elements ) {
+ Collection<Matcher<? extends Iterable<Segment>>> all = new ArrayList<Matcher<? extends Iterable<Segment>>>(elements.length);
+ for (Segment element : elements) {
+ all.add(hasSegment(element));
+ }
+ return allOf(all);
+ }
+
+ @Factory
+ public static Matcher<Iterable<Segment>> hasSegment( PathFactory pathFactory, String element ) {
+ Path.Segment segment = pathFactory.createSegment(element);
+ return hasSegment(equalTo(segment));
+ }
+
+ @Factory
+ public static Matcher<Iterable<Segment>> hasSegments( PathFactory pathFactory, String... segments ) {
+ Collection<Matcher<? extends Iterable<Segment>>> all = new ArrayList<Matcher<? extends Iterable<Segment>>>(segments.length);
+ for (String element : segments) {
+ all.add(hasSegment(pathFactory, element));
+ }
+ return allOf(all);
+ }
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/IsPathContaining.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,87 @@
+/*
+ * 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.junit.Assert.assertThat;
+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.ValueFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class NameValueFactoryTest {
+
+ public static final TextEncoder NO_OP_ENCODER = Path.NO_OP_ENCODER;
+
+ private BasicNamespaceRegistry registry;
+ private ValueFactory<String> stringValueFactory;
+ private NameValueFactory factory;
+ private TextEncoder encoder;
+ 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);
+ }
+
+ @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 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"));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/NameValueFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -0,0 +1,121 @@
+/*
+ * 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.jboss.dna.spi.graph.impl.IsPathContaining.hasSegments;
+import static org.junit.Assert.assertThat;
+import java.util.ArrayList;
+import java.util.List;
+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.ValueFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class PathValueFactoryTest {
+
+ public static final TextEncoder NO_OP_ENCODER = Path.NO_OP_ENCODER;
+
+ private BasicNamespaceRegistry registry;
+ private ValueFactory<String> stringValueFactory;
+ private NameValueFactory nameFactory;
+ private PathValueFactory factory;
+ private TextEncoder encoder;
+ private Path path;
+ private Path path2;
+
+ @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.nameFactory = new NameValueFactory(registry, encoder, stringValueFactory);
+ this.factory = new PathValueFactory(encoder, stringValueFactory, nameFactory);
+ }
+
+ protected List<Path.Segment> getSegments( String... segments ) {
+ List<Path.Segment> result = new ArrayList<Path.Segment>();
+ for (String segmentStr : segments) {
+ Name name = nameFactory.create(segmentStr);
+ BasicPathSegment segment = new BasicPathSegment(name);
+ result.add(segment);
+ }
+ return result;
+ }
+
+ @Test
+ public void shouldCreateFromStringWithAbsolutePathAndNoParentOrSelfReferences() {
+ path = factory.create("/a/b/c/d/dna:e/dna:f");
+ assertThat(path, hasSegments(factory, "a", "b", "c", "d", "dna:e", "dna:f"));
+ }
+
+ @Test
+ public void shouldCreateFromStringWithRelativePathAndNoParentOrSelfReferences() {
+ path = factory.create("a/b/c/d/dna:e/dna:f");
+ assertThat(path, hasSegments(factory, "a", "b", "c", "d", "dna:e", "dna:f"));
+ }
+
+ @Test
+ public void shouldCreateFromStringWithAbsolutePathAndParentReference() {
+ path = factory.create("/a/b/c/../dna:e/dna:f");
+ assertThat(path, hasSegments(factory, "a", "b", "c", "..", "dna:e", "dna:f"));
+ }
+
+ @Test
+ public void shouldCreateFromStringWithRelativePathAndParentReference() {
+ path = factory.create("a/b/c/../dna:e/dna:f");
+ assertThat(path, hasSegments(factory, "a", "b", "c", "..", "dna:e", "dna:f"));
+ }
+
+ @Test
+ public void shouldCreateFromStringWithAbsolutePathAndSelfReference() {
+ path = factory.create("/a/b/c/./dna:e/dna:f");
+ assertThat(path, hasSegments(factory, "a", "b", "c", ".", "dna:e", "dna:f"));
+ }
+
+ @Test
+ public void shouldCreateFromStringWithRelativePathAndSelfReference() {
+ path = factory.create("a/b/c/./dna:e/dna:f");
+ assertThat(path, hasSegments(factory, "a", "b", "c", ".", "dna:e", "dna:f"));
+ }
+
+ @Test
+ public void shouldCreateFromStringWithRelativePathBeginningWithSelfReference() {
+ path = factory.create("./a/b/c/./dna:e/dna:f");
+ assertThat(path, hasSegments(factory, ".", "a", "b", "c", ".", "dna:e", "dna:f"));
+ }
+
+ @Test
+ public void shouldCreateEquivalentPathsWhetherOrNotThereIsATrailingDelimiter() {
+ path = factory.create("/a/b/c/d/dna:e/dna:f");
+ path2 = factory.create("/a/b/c/d/dna:e/dna:f/");
+ assertThat(path.equals(path2), is(true));
+ assertThat(path.compareTo(path2), is(0));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/PathValueFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/federation/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java
===================================================================
--- branches/federation/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java 2008-05-22 20:22:50 UTC (rev 184)
+++ branches/federation/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java 2008-05-23 16:12:06 UTC (rev 185)
@@ -200,13 +200,14 @@
// for the DNA services which knows about the JCR repositories, workspaces, and credentials used to
// establish sessions to these workspaces. This example uses the SimpleExecutionContext, but there is
// implementation for use with JCR repositories registered in JNDI.
+ final String repositoryWorkspaceName = this.repositoryName + "/" + this.workspaceName;
SimpleSessionFactory sessionFactory = new SimpleSessionFactory();
sessionFactory.registerRepository(this.repositoryName, this.repository);
if (this.username != null) {
Credentials credentials = new SimpleCredentials(this.username, this.password);
- sessionFactory.registerCredentials(this.repositoryName + "/" + this.workspaceName, credentials);
+ sessionFactory.registerCredentials(repositoryWorkspaceName, credentials);
}
- this.executionContext = new SimpleExecutionContext(sessionFactory);
+ this.executionContext = new SimpleExecutionContext(sessionFactory, repositoryWorkspaceName);
// Create the sequencing service, passing in the execution context ...
this.sequencingService = new SequencingService();
@@ -247,7 +248,7 @@
this.observationService = new ObservationService(this.executionContext.getSessionFactory());
this.observationService.getAdministrator().start();
this.observationService.addListener(this.sequencingService);
- this.observationService.monitor(this.repositoryName + "/" + this.workspaceName, Event.NODE_ADDED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED);
+ this.observationService.monitor(repositoryWorkspaceName, Event.NODE_ADDED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED);
}
// Start up the sequencing service ...
this.sequencingService.getAdministrator().start();
17 years, 11 months
DNA SVN: r184 - trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3.
by dna-commits@lists.jboss.org
Author: maeste
Date: 2008-05-22 16:22:50 -0400 (Thu, 22 May 2008)
New Revision: 184
Modified:
trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
Log:
minor fix in javadoc
Modified: trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java
===================================================================
--- trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-05-22 16:38:28 UTC (rev 183)
+++ trunk/sequencers/dna-sequencer-mp3/src/main/java/org/jboss/dna/sequencer/mp3/Mp3MetadataSequencer.java 2008-05-22 20:22:50 UTC (rev 184)
@@ -34,8 +34,6 @@
* <ul>
* <li><strong>mp3:metadata</strong> node of type <code>mp3:metadata</code>
* <ul>
- * <li><strong>jcr:mimeType</strong> - optional string property for the mime type of the image</li>
- * <li><strong>jcr:encoding</strong> - optional string property for the encoding of the image</li>
* <li><strong>mp3:title</strong> - optional string property for the name of the audio file or recording</li>
* <li><strong>mp3:author</strong> - optional string property for the author of the recording</li>
* <li><strong>mp3:album</strong> - optional string property for the name of the album</li>
@@ -67,9 +65,7 @@
if (metadata != null) {
// Place the image metadata into the output map ...
output.setProperty(METADATA_NODE, MP3_PRIMARY_TYPE, "mp3:metadata");
- // output.psetProperty(METADATA_NODE, IMAGE_MIXINS, "");
output.setProperty(METADATA_NODE, MP3_TITLE, metadata.getTitle());
- // output.setProperty(METADATA_NODE, IMAGE_ENCODING, "");
output.setProperty(METADATA_NODE, MP3_AUTHOR, metadata.getAuthor());
output.setProperty(METADATA_NODE, MP3_ALBUM, metadata.getAlbum());
output.setProperty(METADATA_NODE, MP3_YEAR, metadata.getYear());
17 years, 11 months
DNA SVN: r182 - trunk.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-22 12:36:45 -0400 (Thu, 22 May 2008)
New Revision: 182
Modified:
trunk/pom.xml
Log:
Updated POM with developers and repositories
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-05-19 20:30:04 UTC (rev 181)
+++ trunk/pom.xml 2008-05-22 16:36:45 UTC (rev 182)
@@ -12,6 +12,48 @@
<scm>
<connection>scm:svn:https://svn.jboss.org/repos/dna/trunk</connection>
</scm>
+ <developers>
+ <developer>
+ <name>Randall Hauch</name>
+ <id>randall</id>
+ <email>rhauch(a)redhat.com</email>
+ <organization>Red Hat</organization>
+ <roles>
+ <role>Project Lead</role>
+ <role>Developer</role>
+ </roles>
+ <timezone>-6</timezone>
+ </developer>
+ <developer>
+ <name>John Verhaeg</name>
+ <id>johnny</id>
+ <email>jverhaeg(a)redhat.com</email>
+ <organization>Red Hat</organization>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>-6</timezone>
+ </developer>
+ <developer>
+ <name>Dan Florian</name>
+ <id>dan</id>
+ <email>dflorian(a)redhat.com</email>
+ <organization>Red Hat</organization>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>-6</timezone>
+ </developer>
+ <developer>
+ <name>Stefano Maestri</name>
+ <id>stefano</id>
+ <email>stefano.maestri(a)javalinux.it</email>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>-6</timezone>
+ </developer>
+ </developers>
<modules>
<module>dna-common</module>
<module>dna-spi</module>
@@ -25,6 +67,7 @@
<properties>
<dna-version>0.2-SNAPSHOT</dna-version>
</properties>
+
<profiles>
<profile>
<id>release</id>
@@ -81,23 +124,23 @@
</execution>
</executions>
<configuration>
- <finalName>
- jboss-dna-${project.version}
- </finalName>
- <descriptors>
- <descriptor>
- build/assembly/examples.xml
- </descriptor>
- <descriptor>
- build/assembly/javadoc.xml
- </descriptor>
- <descriptor>
- build/assembly/dist.xml
- </descriptor>
- <descriptor>
- build/assembly/src.xml
- </descriptor>
- </descriptors>
+ <finalName>
+ jboss-dna-${project.version}
+ </finalName>
+ <descriptors>
+ <descriptor>
+ build/assembly/examples.xml
+ </descriptor>
+ <descriptor>
+ build/assembly/javadoc.xml
+ </descriptor>
+ <descriptor>
+ build/assembly/dist.xml
+ </descriptor>
+ <descriptor>
+ build/assembly/src.xml
+ </descriptor>
+ </descriptors>
</configuration>
</plugin>
</plugins>
@@ -366,12 +409,24 @@
</plugin>
</plugins>
</reporting>
- <distributionManagement>
- <repository>
- <!-- Copy the distribution jar file to a local checkout of the maven repository
- - This variable can be set in $MAVEN_HOME/conf/settings.xml -->
- <id>repository.jboss.org</id>
- <url>file://${jboss.repository.root}</url>
- </repository>
- </distributionManagement>
+
+ <repositories>
+ <repository>
+ <id>jboss</id>
+ <url>http://repository.jboss.com/maven2/</url>
+ </repository>
+
+ <repository>
+ <id>jboss-snapshot</id>
+ <url>http://snapshots.jboss.org/maven2</url>
+ </repository>
+ </repositories>
+ <distributionManagement>
+ <repository>
+ <!-- Copy the distribution jar file to a local checkout of the maven repository
+ - This variable can be set in $MAVEN_HOME/conf/settings.xml -->
+ <id>repository.jboss.org</id>
+ <url>file://${jboss.repository.root}</url>
+ </repository>
+ </distributionManagement>
</project>
\ No newline at end of file
17 years, 11 months
DNA SVN: r181 - branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-19 16:30:04 -0400 (Mon, 19 May 2008)
New Revision: 181
Added:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnPath.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnProperties.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/CreateNodeCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/DeleteBranchCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/MoveBranchCommand.java
Removed:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java
Log:
DNA-68: Create connector API
http://jira.jboss.org/jira/browse/DNA-68
Restructured the repository command interfaces by making the inheritance hierarchy more shallow and by adding orthogonal interfaces (e.g, "ActsAs...") that add behavior to the commands.
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnPath.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnPath.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnPath.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -0,0 +1,38 @@
+/*
+ * 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.connector.commands;
+
+import org.jboss.dna.spi.graph.Path;
+
+/**
+ * Aspect interface for any repository command that acts upon a specific path. This aspect adds a method that can be used by the
+ * recipient to obtain the path that the command applies to.
+ * @author Randall Hauch
+ */
+public interface ActsOnPath extends RepositoryCommand {
+
+ /**
+ * Get the path to which this command applies.
+ * @return the path; never null
+ */
+ Path getPath();
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnPath.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnProperties.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnProperties.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnProperties.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -0,0 +1,43 @@
+/*
+ * 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.connector.commands;
+
+import org.jboss.dna.spi.cache.Cacheable;
+import org.jboss.dna.spi.graph.Name;
+
+/**
+ * Aspect interface for any repository command that acts upon or updates properties on a given node. This aspect also allows for
+ * the recipient to {@link Cacheable#setCachePolicy(org.jboss.dna.spi.cache.CachePolicy) update the cache policy} for the updated
+ * information.
+ * @author Randall Hauch
+ */
+public interface ActsOnProperties extends ActsOnPath, Cacheable {
+
+ /**
+ * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
+ * no property vlaues or if all of the property values are null, the property will be removed.
+ * @param propertyName the name of the property
+ * @param values the property values
+ */
+ void setProperty( Name propertyName, Object... values );
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/ActsOnProperties.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/CreateNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/CreateNodeCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/CreateNodeCommand.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -0,0 +1,48 @@
+/*
+ * 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.connector.commands;
+
+import java.util.Iterator;
+import org.jboss.dna.spi.cache.Cacheable;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+
+/**
+ * A command to get the children of a single node given its path.
+ * @author Randall Hauch
+ */
+public interface CreateNodeCommand extends RepositoryCommand, ActsOnPath, Cacheable, ActsOnProperties {
+
+ /**
+ * Get the names of the children for this new node. The recipient of the command should {@link Iterator#remove() remove} any
+ * child name that will not be stored.
+ * @return the names of the node's children; never null, but possibly empty
+ */
+ Iterator<Name> getChildren();
+
+ /**
+ * Get the properties for this new node. The recipient of the command should {@link Iterator#remove() remove} any property
+ * that will not be stored.
+ * @return the property iterator; never null, but possibly empty
+ */
+ Iterator<Property> getProperties();
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/CreateNodeCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/DeleteBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/DeleteBranchCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/DeleteBranchCommand.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -0,0 +1,29 @@
+/*
+ * 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.connector.commands;
+
+/**
+ * Command that deletes a branch given by a specified path.
+ * @author Randall Hauch
+ */
+public interface DeleteBranchCommand extends RepositoryCommand, ActsOnPath {
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/DeleteBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java 2008-05-19 20:27:57 UTC (rev 180)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -22,13 +22,14 @@
package org.jboss.dna.spi.connector.commands;
import java.util.Iterator;
+import org.jboss.dna.spi.cache.Cacheable;
import org.jboss.dna.spi.graph.Name;
/**
- * A command to get the children of a single node.
+ * A command to get the children of a single node given its path.
* @author Randall Hauch
*/
-public interface GetChildrenCommand extends GetNodeInformationCommand {
+public interface GetChildrenCommand extends RepositoryCommand, ActsOnPath, Cacheable {
/**
* Set the children of this node using an iterator of names. Any existing child references already set on this command will be
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetCommand.java 2008-05-19 20:27:57 UTC (rev 180)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetCommand.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -1,45 +0,0 @@
-/*
- * 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.connector.commands;
-
-import org.jboss.dna.spi.cache.CachePolicy;
-
-/**
- * Base interface for any repository command that retrieves information.
- * @author Randall Hauch
- */
-public interface GetCommand extends RepositoryCommand {
-
- /**
- * Get the caching policy to be used for this command's results. Note that the values of the policy are relative to the time
- * the information was obtained, so the same instance can be used repeatedly.
- * </p>
- * @return cachePolicy the caching policy, which may not be null if no caching policy is defined
- */
- public CachePolicy getCachePolicy();
-
- /**
- * Set the caching policy for this command's results.
- * @param cachePolicy the caching policy to use for this command's results
- */
- public void setCachePolicy( CachePolicy cachePolicy );
-}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeCommand.java 2008-05-19 20:27:57 UTC (rev 180)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeCommand.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -22,7 +22,7 @@
package org.jboss.dna.spi.connector.commands;
/**
- * A command to get the properties and children for a single node.
+ * A command to get the properties and children for a single node given its path.
* @author Randall Hauch
*/
public interface GetNodeCommand extends GetChildrenCommand, GetPropertiesCommand {
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java 2008-05-19 20:27:57 UTC (rev 180)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -1,50 +0,0 @@
-/*
- * 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.connector.commands;
-
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.Property;
-
-/**
- * A command to get information about a single node.
- * @author Randall Hauch
- */
-public interface GetNodeInformationCommand extends GetCommand {
-
- /**
- * Get the path of the node for which the children are to be obtained.
- * @return the node's path
- */
- Path getPath();
-
- /**
- * Get the property with the given name. This method is useful when the source has previously saved node-specific information
- * in properties, and that information is required to process commands. As the node may not have yet been obtained from the
- * source, the source should not expect properties to always exist on the supplied node.
- * @param propertyName the name of the property to retrieve
- * @return the property with the supplied name, or null if that property is not already known to the component that created
- * this command
- */
- Property getProperty( Name propertyName );
-
-}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java 2008-05-19 20:27:57 UTC (rev 180)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -21,20 +21,12 @@
*/
package org.jboss.dna.spi.connector.commands;
-import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.cache.Cacheable;
/**
- * A command to get the properties for a single node.
+ * A command to obtain from the source the properties for a single node given its path.
* @author Randall Hauch
*/
-public interface GetPropertiesCommand extends GetNodeInformationCommand {
+public interface GetPropertiesCommand extends RepositoryCommand, ActsOnPath, Cacheable, ActsOnProperties {
- /**
- * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
- * no property vlaues or if all of the property values are null, the property will be removed.
- * @param propertyName the name of the property
- * @param values the property values
- */
- void setProperty( Name propertyName, Object... values );
-
}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/MoveBranchCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/MoveBranchCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/MoveBranchCommand.java 2008-05-19 20:30:04 UTC (rev 181)
@@ -0,0 +1,37 @@
+/*
+ * 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.connector.commands;
+
+import org.jboss.dna.spi.graph.Path;
+
+/**
+ * Command that moves a branch from one path to another.
+ * @author Randall Hauch
+ */
+public interface MoveBranchCommand extends RepositoryCommand, ActsOnPath {
+
+ /**
+ * Get the new path to which the branch is to be moved.
+ * @return the new path; never null
+ */
+ Path getNewPath();
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/MoveBranchCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
17 years, 11 months
DNA SVN: r180 - in branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph: impl and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-19 16:27:57 -0400 (Mon, 19 May 2008)
New Revision: 180
Removed:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Added a create(Object) method on ValueFactory, and added an implementation of the method to the AbstractValueFactory. Also removed the unused "Values" interface.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-05-19 20:26:50 UTC (rev 179)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-05-19 20:27:57 UTC (rev 180)
@@ -189,4 +189,14 @@
*/
T create( Reader reader, int approximateLength ) throws ValueFormatException, IOException;
+ /**
+ * 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)}.
+ * @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
+ */
+ T create( Object value ) throws ValueFormatException;
+
}
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java 2008-05-19 20:26:50 UTC (rev 179)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java 2008-05-19 20:27:57 UTC (rev 180)
@@ -1,31 +0,0 @@
-/*
- * 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;
-
-
-/**
- *
- * @author Randall Hauch
- */
-public class Values {
-
-}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-05-19 20:26:50 UTC (rev 179)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-05-19 20:27:57 UTC (rev 180)
@@ -21,11 +21,19 @@
*/
package org.jboss.dna.spi.graph.impl;
+import java.math.BigDecimal;
+import java.net.URI;
+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.util.ArgCheck;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
/**
* Abstract {@link ValueFactory}.
@@ -77,4 +85,25 @@
return propertyType;
}
+ /**
+ * {@inheritDoc}
+ */
+ public T create( Object value ) throws ValueFormatException {
+ if (value == null) return null;
+ if (value instanceof String) return create((String)value);
+ if (value instanceof Integer) return create(((Integer)value).intValue());
+ if (value instanceof Long) return create(((Long)value).longValue());
+ if (value instanceof Double) return create(((Double)value).doubleValue());
+ if (value instanceof Float) return create(((Float)value).floatValue());
+ if (value instanceof Boolean) return create(((Boolean)value).booleanValue());
+ if (value instanceof BigDecimal) return create((BigDecimal)value);
+ if (value instanceof Calendar) return create((Calendar)value);
+ if (value instanceof Date) return create((Date)value);
+ if (value instanceof Name) return create((Name)value);
+ if (value instanceof Path) return create((Path)value);
+ if (value instanceof Reference) return create((Reference)value);
+ if (value instanceof URI) return create((URI)value);
+ return create(value.toString());
+ }
+
}
17 years, 11 months
DNA SVN: r179 - branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-19 16:26:50 -0400 (Mon, 19 May 2008)
New Revision: 179
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Corrected the class defined for the PropertyType.REFERENCE.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-19 20:25:53 UTC (rev 178)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-19 20:26:50 UTC (rev 179)
@@ -25,7 +25,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Comparator;
-import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.SpiI18n;
@@ -46,7 +45,7 @@
BOOLEAN("Boolean", PropertyValues.BOOLEAN_COMPARATOR, Boolean.class),
NAME("Name", PropertyValues.NAME_COMPARATOR, Name.class),
PATH("Path", PropertyValues.PATH_COMPARATOR, Path.class),
- REFERENCE("Reference", PropertyValues.REFERENCE_COMPARATOR, UUID.class),
+ REFERENCE("Reference", PropertyValues.REFERENCE_COMPARATOR, Reference.class),
URI("URI", PropertyValues.URI_COMPARATOR, URI.class),
UNDEFINED("undefined", PropertyValues.UNDEFINED_COMPARATOR, Comparable.class);
17 years, 11 months
DNA SVN: r178 - in branches/federation/dna-spi/src/test/java/org/jboss/dna/spi: graph and 1 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-19 16:25:53 -0400 (Mon, 19 May 2008)
New Revision: 178
Added:
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Added a test case for AbstractValueFactory.
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-05-19 20:25:53 UTC (rev 178)
@@ -0,0 +1,172 @@
+/*
+ * 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.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+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.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class AbstractValueFactoryTest {
+
+ public static final TextEncoder CUSTOM_ENCODER = new NoOpEncoder();
+
+ private static class MockFactory extends AbstractValueFactory<String> {
+
+ protected MockFactory( TextEncoder encoder, StringValueFactory stringValueFactory ) {
+ super(PropertyType.STRING, encoder, stringValueFactory);
+ }
+
+ public String create( String value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( String value, TextEncoder decoder ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( int value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( long value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( boolean value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( float value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( double value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( BigDecimal value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( Calendar value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( Date value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( Name value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( Path value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( Reference value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( URI value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( byte[] value ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( InputStream stream, int approximateLength ) throws ValueFormatException {
+ return null;
+ }
+
+ public String create( Reader reader, int approximateLength ) throws ValueFormatException {
+ return null;
+ }
+ }
+
+ private AbstractValueFactory factory;
+
+ @Before
+ public void beforeEach() throws Exception {
+ factory = new MockFactory(null, null);
+ }
+
+ @Test
+ public void shouldHaveDefaultEncoderIfNullPassedIntoConstructor() {
+ assertThat(factory.getEncoder(), is(notNullValue()));
+ assertThat(factory.getEncoder(), is(sameInstance(ValueFactory.DEFAULT_ENCODER)));
+ }
+
+ @Test
+ public void shouldReturnTextEncoderPassedIntoConstructor() {
+ factory = new MockFactory(CUSTOM_ENCODER, null);
+ assertThat(factory.getEncoder(), is(notNullValue()));
+ assertThat(factory.getEncoder(), is(sameInstance(CUSTOM_ENCODER)));
+ }
+
+ @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)));
+ }
+
+ @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)));
+ }
+
+ @Test
+ public void shouldHaveNullStringValueFactoryIfNullPassedIntoConstructor() {
+ assertThat(factory.getStringValueFactory(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldHaveExpectedPropertyType() {
+ assertThat(factory.getPropertyType(), is(sameInstance(PropertyType.STRING)));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
17 years, 11 months
DNA SVN: r177 - branches/federation/dna-spi/src/main/java/org/jboss/dna/spi.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-19 13:04:17 -0400 (Mon, 19 May 2008)
New Revision: 177
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java
Log:
Corrected test case.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java 2008-05-19 16:32:40 UTC (rev 176)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java 2008-05-19 17:04:17 UTC (rev 177)
@@ -21,6 +21,9 @@
*/
package org.jboss.dna.spi;
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dna.common.CommonI18n;
import org.jboss.dna.common.i18n.I18n;
/**
@@ -28,14 +31,6 @@
*/
public final class SpiI18n {
- static {
- try {
- I18n.initialize(SpiI18n.class);
- } catch (final Exception err) {
- System.err.println(err);
- }
- }
-
public static I18n unableToDiscoverPropertyType;
public static I18n errorReadingPropertyValueBytes;
public static I18n valueJavaTypeNotCompatibleWithPropertyType;
@@ -53,4 +48,24 @@
public static I18n pathCannotBeNormalized;
public static I18n invalidQualifiedNameString;
+
+ static {
+ try {
+ I18n.initialize(SpiI18n.class);
+ } catch (final Exception err) {
+ System.err.println(err);
+ }
+ }
+
+ public static Set<Locale> getLocalizationProblemLocales() {
+ return I18n.getLocalizationProblemLocales(CommonI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems() {
+ return I18n.getLocalizationProblems(CommonI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems( Locale locale ) {
+ return I18n.getLocalizationProblems(CommonI18n.class, locale);
+ }
}
17 years, 11 months
DNA SVN: r176 - in branches/federation/dna-spi/src/main: java/org/jboss/dna/spi/connector and 4 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-19 12:32:40 -0400 (Mon, 19 May 2008)
New Revision: 176
Added:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.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/Reference.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.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/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
Removed:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java
Modified:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.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/PathFactory.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/PropertyType.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.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/BasicPath.java
branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties
Log:
DNA-67: Create graph API for federation engine
http://jira.jboss.org/jira/browse/DNA-67
Updated the graph API by removing the concept of a PropertyValue and instead simply defined Property to store raw values (e.g., String, long, double, boolean, Calendar, Reference, Path, Name, URI). Created a ValueFactory<T> interface along with a ValueFactories interface that maintains access to the different ValueFactory<T> interfaces. These value factories can be used to create raw value instances as well as convert instances from one type to another. Also provide a basic implementation of all these interfaces, which all should be usable in most environments (except for InMemoryBinaryValueFactory, which assumes an InMemoryBinary implementation). The StandardValueFactories interface is a highly-flexible container for other value factories, and can easily be provided with other value factory implementations that override the default implementations.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -41,6 +41,10 @@
public static I18n valueJavaTypeNotCompatibleWithPropertyType;
public static I18n errorConvertingBinaryValueToString;
+ public static I18n errorCreatingValue;
+ public static I18n unableToCreateValue;
+ public static I18n unableToCreatePathFromEmptyString;
+ public static I18n validPathMayNotContainEmptySegment;
public static I18n pathAncestorDegreeIsInvalid;
public static I18n pathIsAlreadyAbsolute;
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -58,6 +58,10 @@
*/
boolean ping( long time, TimeUnit unit ) throws InterruptedException;
+ /**
+ * Set the listener that is to receive notifications to changes to content within this source.
+ * @param listener the new listener, or null if no component is interested in the change notifications
+ */
void setListener( RepositorySourceListener listener );
/**
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -23,8 +23,8 @@
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.NameFactory;
-import org.jboss.dna.spi.graph.PropertyValue;
-import org.jboss.dna.spi.graph.PropertyValueFactory;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.ValueFactories;
/**
* @author Randall Hauch
@@ -32,10 +32,10 @@
public interface RepositorySourceEnvironment {
/**
- * Get the factory that should be used to create {@link PropertyValue property values}.
+ * Get the factories that should be used to create values for {@link Property properties}.
* @return the property value factory; never null
*/
- PropertyValueFactory getPropertyValueFactory();
+ ValueFactories getValueFactories();
/**
* Get the factory that should be used to create {@link Name names}.
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -23,21 +23,14 @@
import java.util.Iterator;
import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
/**
* A command to get the children of a single node.
* @author Randall Hauch
*/
-public interface GetChildrenCommand extends GetCommand {
+public interface GetChildrenCommand extends GetNodeInformationCommand {
/**
- * Get the path of the node for which the children are to be obtained.
- * @return the node's path
- */
- Path getPath();
-
- /**
* Set the children of this node using an iterator of names. Any existing child references already set on this command will be
* replaced by those supplied to this method.
* <p>
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,50 @@
+/*
+ * 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.connector.commands;
+
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+
+/**
+ * A command to get information about a single node.
+ * @author Randall Hauch
+ */
+public interface GetNodeInformationCommand extends GetCommand {
+
+ /**
+ * Get the path of the node for which the children are to be obtained.
+ * @return the node's path
+ */
+ Path getPath();
+
+ /**
+ * Get the property with the given name. This method is useful when the source has previously saved node-specific information
+ * in properties, and that information is required to process commands. As the node may not have yet been obtained from the
+ * source, the source should not expect properties to always exist on the supplied node.
+ * @param propertyName the name of the property to retrieve
+ * @return the property with the supplied name, or null if that property is not already known to the component that created
+ * this command
+ */
+ Property getProperty( Name propertyName );
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeInformationCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -22,27 +22,19 @@
package org.jboss.dna.spi.connector.commands;
import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.PropertyValue;
/**
* A command to get the properties for a single node.
* @author Randall Hauch
*/
-public interface GetPropertiesCommand extends GetCommand {
+public interface GetPropertiesCommand extends GetNodeInformationCommand {
/**
- * Get the path of the node for which the properties are to be obtained.
- * @return the node's path
- */
- Path getPath();
-
- /**
* Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
* no property vlaues or if all of the property values are null, the property will be removed.
* @param propertyName the name of the property
* @param values the property values
*/
- void setProperty( Name propertyName, PropertyValue... values );
+ void setProperty( Name propertyName, Object... values );
}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -59,4 +59,28 @@
* @see #getString()
*/
public String getString( TextEncoder encoder );
+
+ /**
+ * Get the string form of the name, using the supplied namespace registry to convert the
+ * {@link #getNamespaceUri() namespace URI} to a prefix. The {@link Path#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}
+ * @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 name, using the supplied namespace registry to convert the
+ * {@link #getNamespaceUri() namespace URI} to a prefix.
+ * @param namespaceRegistry the namespace registry that should be used to obtain the prefix for the
+ * {@link Name#getNamespaceUri() namespace URI}
+ * @param encoder the encoder to use, or null if the {@link Path#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: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -27,29 +27,9 @@
* A factory for creating {@link Name names}.
* @author Randall Hauch
*/
-public interface NameFactory {
+public interface NameFactory extends ValueFactory<Name> {
/**
- * Create a name from the qualified name, which must be of the same form as returned by {@link Name#getString()}.
- * <p>
- * This method is equivalent to calling {@link #create(String, TextEncoder)} with a null encoder.
- * </p>
- * @param qualifiedName
- * @return the new name.
- * @throws IllegalArgumentException if the qualified name is null or invalid
- */
- Name create( String qualifiedName );
-
- /**
- * Create a name from the qualified name, which must be of the same form as returned by {@link Name#getString()}.
- * @param qualifiedName
- * @param encoder the encoder that should be used to decode the qualified name
- * @return the new name
- * @throws IllegalArgumentException if the qualified name is null or invalid
- */
- Name create( String qualifiedName, TextEncoder encoder );
-
- /**
* 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.
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public interface NamespaceRegistry {
+
+ String getNamespaceForPrefix( String prefix );
+
+ String getPrefixForNamespaceUri( String namespaceUri );
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NamespaceRegistry.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -358,4 +358,27 @@
*/
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: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -25,7 +25,7 @@
* A factory for creating {@link Path paths}.
* @author Randall Hauch
*/
-public interface PathFactory {
+public interface PathFactory extends ValueFactory<Path> {
/**
* Create an absolute path with the supplied segment names, in order. If no segments are provided, the result will be the root
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-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -21,17 +21,207 @@
*/
package org.jboss.dna.spi.graph;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
import java.util.Iterator;
/**
+ * Representation of a property consisting of a name and value(s).
* @author Randall Hauch
*/
-public interface Property extends Iterable<PropertyValue> {
+public interface Property extends Iterable<Object>, Comparable<Property> {
+ /**
+ * Get the name of the property.
+ * @return the property name; never null
+ */
Name getName();
+ /**
+ * Get the name of the property's definition.
+ * @return the property definition's name; never null
+ */
+ Name getDefinitionName();
+
+ /**
+ * Determine whether the property is defined to allow multiple values.
+ * @return true if the property has multiple values, or false otherwise.
+ * @see #isSingle()
+ */
boolean isMultiple();
- Iterator<PropertyValue> getValues();
+ /**
+ * Determine whether the property is defined to allow a single value. This is a convenience method that is equivalent to
+ * calling <code>!isMultiple()</code>.
+ * @return true if the property has multiple values, or false otherwise.
+ * @see #isMultiple()
+ */
+ boolean isSingle();
+ /**
+ * Get the number of actual values in this property. If the property allows {@link #isMultiple() multiple values}, then this
+ * method may return a value greater than 1. If the property only allows a {@link #isSingle() single value}, then this method
+ * will return either 0 or 1. This method may return 0 regardless of whether the property allows a
+ * {@link #isSingle() single value}, or {@link #isMultiple() multiple values}.
+ * @return the number of actual values in this property; always non-negative
+ */
+ int size();
+
+ /**
+ * Determine whether this property has no actual values. This method may return <code>true</code> regardless of whether the
+ * property allows a {@link #isSingle() single value}, or {@link #isMultiple() multiple values}.
+ * <p>
+ * This method is a convenience method that is equivalent to <code>size() == 0</code>.
+ * </p>
+ * @return the number of actual values in this property; always non-negative
+ */
+ boolean isEmpty();
+
+ /**
+ * Get the type for this property.
+ * @return the property's type, which is never null
+ */
+ PropertyType getPropertyType();
+
+ /**
+ * Obtain the property's values in their natural form, as defined by {@link #getPropertyType()}. This is equivalent to
+ * calling {@link Iterable#iterator() iterator()}.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the values; never null
+ * @see Iterable#iterator()
+ */
+ Iterator<?> getValues();
+
+ /**
+ * Obtain the property's values in their natural form, converting the values to the supplied {@link PropertyType} if it is
+ * different than this property's {@link #getPropertyType() property type}. Note that it is not always possible to convert
+ * between PropertyTypes.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </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
+ */
+ Iterator<?> getValues( PropertyType type );
+
+ /**
+ * Obtain the property's values as String objects, converting the values if the {@link #getPropertyType() property type} is
+ * not {@link PropertyType#STRING}. Note that it is always possible to convert to a String value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the String values; never null
+ */
+ Iterator<String> getStringValues();
+
+ /**
+ * Obtain the property's values as Binary objects, converting the values if the {@link #getPropertyType() property type} is
+ * not {@link PropertyType#BINARY}. Note that it is always possible to convert to a {@link Binary} value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the {@link Binary} values; never null
+ */
+ Iterator<Binary> getBinaryValues();
+
+ /**
+ * Obtain the property's values as longs, converting the values if the {@link #getPropertyType() property type} is not
+ * {@link PropertyType#LONG}. Note that it is not always possible to convert to a {@link PropertyType#LONG long} value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the long values; never null
+ */
+ Iterator<Long> getLongValues();
+
+ /**
+ * Obtain the property's values as doubles, converting the values if the {@link #getPropertyType() property type} is not
+ * {@link PropertyType#DOUBLE}. Note that it is not always possible to convert to a {@link PropertyType#DOUBLE double} value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the double values; never null
+ */
+ Iterator<Double> getDoubleValues();
+
+ /**
+ * Obtain the property's values as decimal values, converting the values if the {@link #getPropertyType() property type} is
+ * not {@link PropertyType#DECIMAL}. Note that it is not always possible to convert to a {@link PropertyType#DECIMAL decimal}
+ * value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the decimal values; never null
+ */
+ Iterator<BigDecimal> getDecimalValues();
+
+ /**
+ * Obtain the property's values as {@link Calendar dates}, converting the values if the
+ * {@link #getPropertyType() property type} is not {@link PropertyType#DATE}. Note that it is not always possible to convert
+ * to a {@link PropertyType#DATE date} value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the Calendar values; never null
+ */
+ Iterator<Calendar> getDateValues();
+
+ /**
+ * Obtain the property's values as booleans, converting the values if the {@link #getPropertyType() property type} is not
+ * {@link PropertyType#BOOLEAN}. Note that it is not always possible to convert to a {@link PropertyType#BOOLEAN boolean}
+ * value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the Boolean values; never null
+ */
+ Iterator<Boolean> getBooleanValues();
+
+ /**
+ * Obtain the property's values as {@link Name names}, converting the values if the {@link #getPropertyType() property type}
+ * is not {@link PropertyType#NAME}. Note that it is not always possible to convert to a {@link PropertyType#NAME long}
+ * value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the Name values; never null
+ */
+ Iterator<Name> getNameValues();
+
+ /**
+ * Obtain the property's values as {@link Path paths}, converting the values if the {@link #getPropertyType() property type}
+ * is not {@link PropertyType#PATH}. Note that it is not always possible to convert to a {@link PropertyType#PATH path}
+ * value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the Path values; never null
+ */
+ Iterator<Path> getPathValues();
+
+ /**
+ * Obtain the property's values as references, converting the values if the {@link #getPropertyType() property type} is not
+ * {@link PropertyType#REFERENCE}. Note that it is not always possible to convert to a
+ * {@link PropertyType#REFERENCE reference} value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </p>
+ * @return an iterator over the Reference values; never null
+ */
+ Iterator<Reference> getReferenceValues();
+
+ /**
+ * Obtain the property's values as {@link URI URIs}, converting the values if the {@link #getPropertyType() property type} is
+ * not {@link PropertyType#URI}. Note that it is not always possible to convert to a {@link PropertyType#URI URI} value.
+ * <p>
+ * A valid iterator is returned if the property has {@link #isSingle() single valued} or {@link #isMultiple() multi-valued}.
+ * </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/PropertyType.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -23,8 +23,8 @@
import java.math.BigDecimal;
import java.net.URI;
+import java.util.Calendar;
import java.util.Comparator;
-import java.util.Date;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.StringUtil;
@@ -42,7 +42,7 @@
LONG("Long", PropertyValues.LONG_COMPARATOR, Long.class),
DOUBLE("Double", PropertyValues.DOUBLE_COMPARATOR, Double.class),
DECIMAL("Decimal", PropertyValues.DECIMAL_COMPARATOR, BigDecimal.class),
- DATE("Date", PropertyValues.DATE_COMPARATOR, Date.class),
+ DATE("Date", PropertyValues.DATE_COMPARATOR, Calendar.class),
BOOLEAN("Boolean", PropertyValues.BOOLEAN_COMPARATOR, Boolean.class),
NAME("Name", PropertyValues.NAME_COMPARATOR, Name.class),
PATH("Path", PropertyValues.PATH_COMPARATOR, Path.class),
@@ -85,5 +85,4 @@
}
throw new ValueFormatException(SpiI18n.unableToDiscoverPropertyType.text(StringUtil.readableString(value)));
}
-
}
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -1,42 +0,0 @@
-/*
- * 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;
-
-import java.io.Serializable;
-
-/**
- * @author Randall Hauch
- */
-public interface PropertyValue extends Comparable<PropertyValue>, Cloneable, Serializable {
-
- /**
- * Determine whether the property value is null.
- * @return true if the property value is null, or false otherwise
- */
- boolean isNull();
-
- String getValueAsString();
-
- PropertyType getPropertyType();
-
- boolean isEquivalentTo( PropertyValue value );
-}
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -1,68 +0,0 @@
-/*
- * 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;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.net.URI;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.UUID;
-import net.jcip.annotations.ThreadSafe;
-
-/**
- * @author Randall Hauch
- */
-@ThreadSafe
-public interface PropertyValueFactory {
-
- PropertyValue create( String value ) throws ValueFormatException;
-
- PropertyValue create( int value ) throws ValueFormatException;
-
- PropertyValue create( long value ) throws ValueFormatException;
-
- PropertyValue create( boolean value ) throws ValueFormatException;
-
- PropertyValue create( float value ) throws ValueFormatException;
-
- PropertyValue create( double value ) throws ValueFormatException;
-
- PropertyValue create( Calendar value ) throws ValueFormatException;
-
- PropertyValue create( Date value ) throws ValueFormatException;
-
- PropertyValue create( Name value ) throws ValueFormatException;
-
- PropertyValue create( Path value ) throws ValueFormatException;
-
- PropertyValue create( UUID value ) throws ValueFormatException;
-
- PropertyValue create( URI value ) throws ValueFormatException;
-
- PropertyValue create( byte[] value ) throws ValueFormatException;
-
- PropertyValue create( InputStream value, int approximateLength ) throws ValueFormatException;
-
- PropertyValue create( Reader reader, int approximateLength ) throws ValueFormatException;
-
-}
Modified: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -44,6 +44,9 @@
public static final Comparator<String> STRING_COMPARATOR = new Comparator<String>() {
public int compare( String o1, String o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -53,6 +56,9 @@
public static final Comparator<Integer> INTEGER_COMPARATOR = new Comparator<Integer>() {
public int compare( Integer o1, Integer o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -62,6 +68,9 @@
public static final Comparator<Long> LONG_COMPARATOR = new Comparator<Long>() {
public int compare( Long o1, Long o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -71,6 +80,9 @@
public static final Comparator<Float> FLOAT_COMPARATOR = new Comparator<Float>() {
public int compare( Float o1, Float o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -80,6 +92,9 @@
public static final Comparator<Double> DOUBLE_COMPARATOR = new Comparator<Double>() {
public int compare( Double o1, Double o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -89,6 +104,9 @@
public static final Comparator<BigDecimal> DECIMAL_COMPARATOR = new Comparator<BigDecimal>() {
public int compare( BigDecimal o1, BigDecimal o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -164,6 +182,9 @@
public static final Comparator<Boolean> BOOLEAN_COMPARATOR = new Comparator<Boolean>() {
public int compare( Boolean o1, Boolean o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -173,6 +194,9 @@
public static final Comparator<Date> DATE_COMPARATOR = new Comparator<Date>() {
public int compare( Date o1, Date o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -182,6 +206,9 @@
public static final Comparator<Calendar> CALENDAR_COMPARATOR = new Comparator<Calendar>() {
public int compare( Calendar o1, Calendar o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -191,6 +218,9 @@
public static final Comparator<Name> NAME_COMPARATOR = new Comparator<Name>() {
public int compare( Name o1, Name o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -200,6 +230,9 @@
public static final Comparator<Path> PATH_COMPARATOR = new Comparator<Path>() {
public int compare( Path o1, Path o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
@@ -209,15 +242,21 @@
public static final Comparator<URI> URI_COMPARATOR = new Comparator<URI>() {
public int compare( URI o1, URI o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
/**
* A comparator of reference values.
*/
- public static final Comparator<UUID> REFERENCE_COMPARATOR = new Comparator<UUID>() {
+ public static final Comparator<Reference> REFERENCE_COMPARATOR = new Comparator<Reference>() {
- public int compare( UUID o1, UUID o2 ) {
+ public int compare( Reference o1, Reference o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
return o1.compareTo(o2);
}
};
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import java.io.Externalizable;
+import org.jboss.dna.common.text.TextEncoder;
+
+/**
+ * @author Randall Hauch
+ */
+public interface Reference extends Comparable<Reference>, Externalizable {
+
+ /**
+ * Get the string form of the Reference. The {@link Path#DEFAULT_ENCODER default encoder} is used to encode characters in the
+ * reference.
+ * @return the encoded string
+ * @see #getString(TextEncoder)
+ */
+ public String getString();
+
+ /**
+ * Get the encoded string form of the Reference, using the supplied encoder to encode characters in the reference.
+ * @param encoder the encoder to use, or null if the {@link Path#DEFAULT_ENCODER default encoder} should be used
+ * @return the encoded string
+ * @see #getString()
+ */
+ public String getString( TextEncoder encoder );
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Reference.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,116 @@
+/*
+ * 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;
+
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+
+/**
+ * The set of standard {@link ValueFactory} instances.
+ * @author Randall Hauch
+ */
+public interface ValueFactories extends Iterable<ValueFactory<?>> {
+
+ /**
+ * Get the value factory that creates values of the supplied {@link PropertyType type}.
+ * @param type the type for the values
+ * @return the factory; never null
+ * @throws IllegalArgumentException if the property type is null
+ */
+ ValueFactory<?> getValueFactory( PropertyType type );
+
+ /**
+ * Get the value factory that is best able to create values with the most natural type given by the supplied value.
+ * @param prototype the value that should be used to determine the best value factory
+ * @return the factory; never null
+ * @throws IllegalArgumentException if the prototype value is null
+ */
+ ValueFactory<?> getValueFactory( Object prototype );
+
+ /**
+ * Get the value factory for {@link PropertyType#STRING string} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<String> getStringFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#BINARY binary} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<Binary> getBinaryFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#LONG long} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<Long> getLongFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#DOUBLE double} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<Double> getDoubleFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#DECIMAL decimal} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<BigDecimal> getDecimalFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#DATE date} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<Calendar> getDateFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#BOOLEAN boolean} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<Boolean> getBooleanFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#NAME name} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<Name> getNameFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#REFERENCE reference} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<Reference> getReferenceFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#PATH path} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<Path> getPathFactory();
+
+ /**
+ * Get the value factory for {@link PropertyType#URI URI} properties.
+ * @return the factory; never null
+ */
+ ValueFactory<URI> getUriFactory();
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactories.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,192 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+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 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)
+ */
+ 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
+ * @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;
+
+ /**
+ * 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
+ */
+ T create( int value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( long value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( boolean value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( float value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( double value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( BigDecimal value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( Calendar value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( Date value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( Name value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( Path value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( Reference value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( URI value ) throws ValueFormatException;
+
+ /**
+ * 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
+ */
+ T create( byte[] value ) throws ValueFormatException;
+
+ /**
+ * 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
+ * @throws ValueFormatException if the value could not be created from the supplied stream
+ * @throws IOException if there is a problem reading the stream
+ */
+ T create( InputStream stream, int approximateLength ) throws ValueFormatException, IOException;
+
+ /**
+ * 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
+ * @throws ValueFormatException if the value could not be created from the supplied reader
+ * @throws IOException if there is a problem reading the stream
+ */
+ T create( Reader reader, int approximateLength ) throws ValueFormatException, IOException;
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+
+/**
+ *
+ * @author Randall Hauch
+ */
+public class Values {
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Values.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,80 @@
+/*
+ * 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 net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.ValueFactory;
+
+/**
+ * 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 PropertyType propertyType;
+ private final ValueFactory<String> stringValueFactory;
+
+ protected AbstractValueFactory( PropertyType type, TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+ ArgCheck.isNotNull(type, "type");
+ this.propertyType = type;
+ this.encoder = encoder != null ? encoder : DEFAULT_ENCODER;
+ this.stringValueFactory = stringValueFactory;
+ }
+
+ /**
+ * @return stringValueFactory
+ */
+ protected ValueFactory<String> getStringValueFactory() {
+ return this.stringValueFactory;
+ }
+
+ /**
+ * Get the text encoder/decoder.
+ * @return encoder/decoder
+ */
+ public TextEncoder getEncoder() {
+ return this.encoder;
+ }
+
+ /**
+ * 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
+ */
+ protected TextEncoder getEncoder( TextEncoder encoder ) {
+ return encoder != null ? encoder : this.getEncoder();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PropertyType getPropertyType() {
+ return propertyType;
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -23,8 +23,10 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
/**
@@ -76,6 +78,30 @@
/**
* {@inheritDoc}
*/
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri);
+ if (prefix != null) {
+ return prefix + ":" + this.localName;
+ }
+ return this.localName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ String prefix = namespaceRegistry.getPrefixForNamespaceUri(this.namespaceUri);
+ if (prefix != null) {
+ return encoder.encode(prefix) + ":" + encoder.encode(this.localName);
+ }
+ return this.localName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public int compareTo( Name that ) {
if (that == this) return 0;
int diff = this.getNamespaceUri().compareTo(that.getNamespaceUri());
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -1,83 +0,0 @@
-/*
- * 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 java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.jboss.dna.common.text.TextEncoder;
-import org.jboss.dna.common.util.ArgCheck;
-import org.jboss.dna.spi.SpiI18n;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.NameFactory;
-import org.jboss.dna.spi.graph.Path;
-
-/**
- * @author Randall Hauch
- */
-public class BasicNameFactory implements NameFactory {
-
- // Non-escaped pattern: (\{([^}]*)\})?(.*)
- protected static final String QUALFIED_NAME_PATTERN_STRING = "(\\{([^}]*)\\})?(.*)";
- protected static final Pattern QUALIFIED_NAME_PATTERN = Pattern.compile(QUALFIED_NAME_PATTERN_STRING);
-
- /**
- * {@inheritDoc}
- */
- public Name create( String qualifiedName ) {
- return create(qualifiedName, Path.DEFAULT_ENCODER);
- }
-
- /**
- * {@inheritDoc}
- */
- public Name create( String qualifiedName, TextEncoder encoder ) {
- ArgCheck.isNotNull(qualifiedName, "qualifiedName");
- if (encoder == null) encoder = Path.DEFAULT_ENCODER;
- String decodedQualifiedName = encoder.decode(qualifiedName.trim());
- Matcher matcher = QUALIFIED_NAME_PATTERN.matcher(decodedQualifiedName);
- if (!matcher.matches()) {
- throw new IllegalArgumentException(SpiI18n.invalidQualifiedNameString.text(qualifiedName));
- }
- String namespaceUri = matcher.group(2);
- String localName = matcher.group(3);
- return new BasicName(namespaceUri, localName);
- }
-
- /**
- * {@inheritDoc}
- */
- public Name create( String namespaceUri, String localName ) {
- return create(namespaceUri, localName, Path.DEFAULT_ENCODER);
- }
-
- /**
- * {@inheritDoc}
- */
- public Name create( String namespaceUri, String localName, TextEncoder encoder ) {
- ArgCheck.isNotNull(localName, "localName");
- if (encoder == null) encoder = Path.DEFAULT_ENCODER;
- namespaceUri = namespaceUri != null ? encoder.decode(namespaceUri.trim()) : null;
- localName = encoder.decode(localName.trim());
- return new BasicName(namespaceUri, localName);
- }
-
-}
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-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -33,6 +33,7 @@
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.SpiI18n;
import org.jboss.dna.spi.graph.InvalidPathException;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.PathNotFoundException;
@@ -190,13 +191,40 @@
* {@inheritDoc}
*/
public String getString() {
- return getString(DEFAULT_ENCODER);
+ return doGetString(null, DEFAULT_ENCODER);
}
/**
* {@inheritDoc}
*/
public String getString( TextEncoder encoder ) {
+ return doGetString(null, encoder);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry ) {
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ return doGetString(namespaceRegistry, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ return doGetString(namespaceRegistry, encoder);
+ }
+
+ /**
+ * Method that creates the string representation. This method works two different ways depending upon whether the namespace
+ * registry is provided.
+ * @param namespaceRegistry
+ * @param encoder
+ * @return
+ */
+ protected String doGetString( NamespaceRegistry namespaceRegistry, TextEncoder encoder ) {
if (encoder == null) encoder = DEFAULT_ENCODER;
if (encoder == DEFAULT_ENCODER && this.path != null) return this.path;
@@ -212,7 +240,11 @@
sb.append(DELIMITER);
}
assert segment != null;
- sb.append(segment.getString(encoder));
+ if (namespaceRegistry != null) {
+ sb.append(segment.getString(encoder));
+ } else {
+ sb.append(segment.getString(encoder));
+ }
}
String result = sb.toString();
// Save the result to the internal string if this the default encoder is used.
@@ -415,7 +447,6 @@
* {@inheritDoc}
*/
public int compareTo( Path that ) {
- if (that == null) return 1;
if (this == that) return 0;
Iterator<Segment> thisIter = this.segments.iterator();
Iterator<Segment> thatIter = that.iterator();
Deleted: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -1,167 +0,0 @@
-/*
- * 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 java.util.ArrayList;
-import java.util.List;
-import org.jboss.dna.common.util.ArgCheck;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.PathFactory;
-import org.jboss.dna.spi.graph.Path.Segment;
-
-/**
- * @author Randall Hauch
- */
-public class BasicPathFactory implements PathFactory {
-
- /**
- *
- */
- public BasicPathFactory() {
- }
-
- /**
- * {@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 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 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;
-
- 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;
-
- 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");
- return new BasicPathSegment(segmentName);
- }
-
- /**
- * {@inheritDoc}
- */
- public Segment createSegment( Name segmentName, int index ) {
- ArgCheck.isNotNull(segmentName, "segment name");
- return new BasicPathSegment(segmentName, index);
- }
-
-}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,176 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * 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);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( String value ) {
+ if (value == null) return null;
+ return Boolean.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( String value, TextEncoder 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));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( int value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Integer.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( long value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Long.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( boolean value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( float value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Float.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( double value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Double.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( BigDecimal value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), BigDecimal.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( Calendar value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Calendar.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( Date value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( Name value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( Path value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( Reference value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( URI value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( byte[] value ) throws ValueFormatException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(stream, approximateLength));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Boolean create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+ // First create a string and then create the boolean from the string value ...
+ return create(getStringValueFactory().create(reader, approximateLength));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,187 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.text.ParseException;
+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.util.DateUtil;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#DATE} values.
+ * @author Randall Hauch
+ */
+@Immutable
+public class DateValueFactory extends AbstractValueFactory<Calendar> {
+
+ public DateValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+ super(PropertyType.DATE, encoder, stringValueFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( String value ) throws ValueFormatException {
+ if (value == null) return null;
+ try {
+ return DateUtil.getCalendarFromStandardString(value);
+ } catch (ParseException e) {
+ throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( String value, TextEncoder 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));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( int value ) {
+ return create((long)value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( long value ) {
+ Calendar result = Calendar.getInstance();
+ result.setTimeInMillis(value);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( boolean value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( float value ) throws ValueFormatException {
+ return create((long)value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( double value ) throws ValueFormatException {
+ return create((long)value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( BigDecimal value ) throws ValueFormatException {
+ if (value == null) return null;
+ return create(value.longValue());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( Calendar value ) throws ValueFormatException {
+ if (value == null) return null;
+ return create(value.getTimeInMillis());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( Date value ) throws ValueFormatException {
+ if (value == null) return null;
+ return create(value.getTime());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( Name value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( Path value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( Reference value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar create( URI value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar 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 Calendar 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 Calendar 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));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DateValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,182 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * 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);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( String value ) throws ValueFormatException {
+ if (value == null) return null;
+ try {
+ return new BigDecimal(value);
+ } catch (NumberFormatException e) {
+ throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( String value, TextEncoder 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));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( int value ) {
+ return BigDecimal.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( long value ) {
+ return BigDecimal.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( boolean value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Boolean.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( float value ) {
+ return BigDecimal.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( double value ) {
+ return BigDecimal.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( BigDecimal value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( Calendar value ) {
+ if (value == null) return null;
+ return create(value.getTimeInMillis());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( Date value ) {
+ if (value == null) return null;
+ return create(value.getTime());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( Name value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( Path value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( Reference value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal create( URI value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal 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 BigDecimal 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 BigDecimal 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));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,187 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * 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);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( String value ) throws ValueFormatException {
+ if (value == null) return null;
+ try {
+ return Double.valueOf(value);
+ } catch (NumberFormatException e) {
+ throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( String value, TextEncoder 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));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( int value ) {
+ return Double.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( long value ) {
+ return new Double(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( boolean value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Double.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( float value ) {
+ return Double.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( double value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( BigDecimal value ) throws ValueFormatException {
+ if (value == null) return null;
+ double result = value.doubleValue();
+ if (result == Double.NEGATIVE_INFINITY || result == Double.POSITIVE_INFINITY) {
+ throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value));
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( Calendar value ) {
+ if (value == null) return null;
+ return create(value.getTimeInMillis());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( Date value ) {
+ if (value == null) return null;
+ return create(value.getTime());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( Name value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( Path value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( Reference value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double create( URI value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Double 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 Double 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 Double 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));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,199 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.net.URI;
+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.util.IoUtil;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * Teh standard {@link ValueFactory} for {@link PropertyType#BINARY} values.
+ * @author Randall Hauch
+ */
+@Immutable
+public class InMemoryBinaryValueFactory extends AbstractValueFactory<Binary> {
+
+ private static final String CHAR_SET_NAME = "UTF-8";
+
+ public InMemoryBinaryValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+ super(PropertyType.BINARY, encoder, stringValueFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( String value ) throws ValueFormatException {
+ if (value == null) return null;
+ try {
+ return create(value.getBytes(CHAR_SET_NAME));
+ } catch (UnsupportedEncodingException e) {
+ throw new ValueFormatException(SpiI18n.errorConvertingBinaryValueToString.text());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( String value, TextEncoder decoder ) throws ValueFormatException {
+ if (value == null) return null;
+ return create(getEncoder(decoder).decode(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( int value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( long value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( boolean value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( float value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( double value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( BigDecimal value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( Calendar value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( Date value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( Name value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( Path value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( Reference value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( URI value ) throws ValueFormatException {
+ // Convert the value to a string, then to a binary ...
+ return create(this.getStringValueFactory().create(value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( byte[] value ) throws ValueFormatException {
+ return new InMemoryBinary(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( InputStream stream, int approximateLength ) throws IOException {
+ if (stream == null) return null;
+ byte[] value = IoUtil.readBytes(stream);
+ return create(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary create( Reader reader, int approximateLength ) throws IOException {
+ if (reader == null) return null;
+ // Convert the value to a string, then to a binary ...
+ String value = IoUtil.read(reader);
+ return create(this.getStringValueFactory().create(value));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,183 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * 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);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( String value ) throws ValueFormatException {
+ if (value == null) return null;
+ try {
+ return Long.valueOf(value);
+ } catch (NumberFormatException e) {
+ throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( String value, TextEncoder 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));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( int value ) {
+ return Long.valueOf(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( long value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( boolean value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Long.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( float value ) throws ValueFormatException {
+ return (long)value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( double value ) throws ValueFormatException {
+ return (long)value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( BigDecimal value ) throws ValueFormatException {
+ if (value == null) return null;
+ return value.longValue();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( Calendar value ) throws ValueFormatException {
+ if (value == null) return null;
+ return value.getTimeInMillis();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( Date value ) throws ValueFormatException {
+ if (value == null) return null;
+ return value.getTime();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( Name value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Name.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( Path value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( Reference value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( URI value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), URI.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long 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 Long create( InputStream stream, int approximateLength ) throws IOException, ValueFormatException {
+ // First attempt to create a string from the value, then a long from the string ...
+ return create(getStringValueFactory().create(stream, approximateLength));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Long create( Reader reader, int approximateLength ) throws IOException, ValueFormatException {
+ // First attempt to create a string from the value, then a long from the string ...
+ return create(getStringValueFactory().create(reader, approximateLength));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,253 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+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.util.ArgCheck;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * 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);
+
+ // 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;
+
+ public NameValueFactory( NamespaceRegistry namespaceRegistry, TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+ super(PropertyType.NAME, encoder, stringValueFactory);
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ this.namespaceRegistry = namespaceRegistry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( String value ) {
+ return create(value, getEncoder());
+ }
+
+ /**
+ * {@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(2);
+ String localName = matcher.group(3);
+ // 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(1);
+ String localName = matcher.group(2);
+ // Decode the parts ...
+ prefix = decoder.decode(prefix);
+ localName = decoder.decode(localName);
+ // Look for a namespace match ...
+ String namespaceUri = this.namespaceRegistry.getNamespaceForPrefix(prefix);
+ // If no namespace is found, use the prefix ...
+ if (namespaceUri == null) namespaceUri = 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, TextEncoder decoder ) {
+ ArgCheck.isNotNull(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( 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( 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( 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( 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( 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( 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( 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( 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));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,392 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.regex.Pattern;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.jcr.InvalidPathException;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#NAME} values.
+ * @author Randall Hauch
+ */
+@Immutable
+public class PathValueFactory extends AbstractValueFactory<Path> implements PathFactory {
+
+ protected static final char DELIMITER = Path.DELIMITER;
+
+ /**
+ * 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+)])?");
+
+ private final ValueFactory<Name> nameValueFactory;
+
+ public PathValueFactory( TextEncoder encoder, ValueFactory<String> stringValueFactory, ValueFactory<Name> nameValueFactory ) {
+ super(PropertyType.NAME, encoder, stringValueFactory);
+ ArgCheck.isNotNull(nameValueFactory, "nameValueFactory");
+ this.nameValueFactory = nameValueFactory;
+ }
+
+ /**
+ * @return nameValueFactory
+ */
+ protected ValueFactory<Name> getNameValueFactory() {
+ return this.nameValueFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path create( String value ) {
+ return create(value, getEncoder());
+ }
+
+ /**
+ * {@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) {
+ throw new ValueFormatException(SpiI18n.unableToCreatePathFromEmptyString.text());
+ }
+
+ // Remove the leading delimiter ...
+ if (trimmedValue.charAt(0) == DELIMITER) {
+ trimmedValue = length > 1 ? trimmedValue.substring(1) : "";
+ --length;
+ absolute = true;
+ }
+ // remove the trailing delimiter ...
+ if (length > 0 && trimmedValue.charAt(length - 1) == DELIMITER) {
+ trimmedValue = length > 1 ? trimmedValue.substring(0, length - 1) : "";
+ length = trimmedValue.length();
+ }
+ if (length == 0) {
+ throw new ValueFormatException(SpiI18n.unableToCreatePathFromEmptyString.text());
+ }
+
+ // Parse the path into its segments ...
+ List<Segment> segments = new ArrayList<Segment>();
+ String[] pathSegments = DELIMITER_PATTERN.split(trimmedValue);
+ assert pathSegments.length != 0;
+ for (String segment : pathSegments) {
+ assert segment != null;
+ segment = segment.trim();
+ if (segment.length() == 0) {
+ throw new InvalidPathException(SpiI18n.validPathMayNotContainEmptySegment.text(value));
+ }
+ // Create the name and add a segment with it ...
+ Name segmentName = this.getNameValueFactory().create(segment, decoder);
+ segments.add(new BasicPathSegment(segmentName));
+ }
+
+ // 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( 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( 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( 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( 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( 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( 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 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 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;
+
+ 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;
+
+ 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");
+ return new BasicPathSegment(segmentName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Segment createSegment( Name segmentName, int index ) {
+ ArgCheck.isNotNull(segmentName, "segment name");
+ return new BasicPathSegment(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( 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( 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));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,232 @@
+/*
+ * 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 java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.SystemFailureException;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactories;
+import org.jboss.dna.spi.graph.ValueFactory;
+
+/**
+ * The standard set of {@link ValueFactory value factories}.
+ * @author Randall Hauch
+ */
+@Immutable
+public class StandardValueFactories implements ValueFactories {
+
+ // This class is implemented with separate members for each factory so that the typical usage is optimized.
+ private final ValueFactory<String> stringFactory;
+ private final ValueFactory<Binary> binaryFactory;
+ private final ValueFactory<Boolean> booleanFactory;
+ private final ValueFactory<Calendar> dateFactory;
+ private final ValueFactory<BigDecimal> decimalFactory;
+ private final ValueFactory<Double> doubleFactory;
+ private final ValueFactory<Long> longFactory;
+ private final ValueFactory<Name> nameFactory;
+ private final ValueFactory<Path> pathFactory;
+ private final ValueFactory<Reference> referenceFactory;
+ private final ValueFactory<URI> uriFactory;
+ private final Map<PropertyType, ValueFactory<?>> factories;
+
+ /**
+ * Create a standard set of value factories, using the {@link ValueFactory#DEFAULT_ENCODER default encoder/decoder}.
+ * @param namespaceRegistry the namespace registry
+ * @throws IllegalArgumentException if the namespace registry is null
+ */
+ public StandardValueFactories( NamespaceRegistry namespaceRegistry ) {
+ this(namespaceRegistry, null);
+ }
+
+ /**
+ * Create a standard set of value factories, using the supplied encoder/decoder.
+ * @param namespaceRegistry the namespace registry
+ * @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 ) {
+ if (encoder == null) encoder = ValueFactory.DEFAULT_ENCODER;
+ Map<PropertyType, ValueFactory<?>> factories = new HashMap<PropertyType, ValueFactory<?>>();
+
+ // Put the extra factories into the map first ...
+ for (ValueFactory<?> factory : extraFactories) {
+ if (factory == null) continue;
+ factories.put(factory.getPropertyType(), factory);
+ }
+
+ // Now assign the members, using the factories in the map or (if null) the supplied default ...
+ this.stringFactory = getFactory(factories, new StringValueFactory(encoder));
+ this.binaryFactory = getFactory(factories, new InMemoryBinaryValueFactory(encoder, this.stringFactory));
+ this.booleanFactory = getFactory(factories, new BooleanValueFactory(encoder, this.stringFactory));
+ this.dateFactory = getFactory(factories, new DateValueFactory(encoder, this.stringFactory));
+ this.decimalFactory = getFactory(factories, new DecimalValueFactory(encoder, this.stringFactory));
+ this.doubleFactory = getFactory(factories, new DoubleValueFactory(encoder, this.stringFactory));
+ this.longFactory = getFactory(factories, new LongValueFactory(encoder, this.stringFactory));
+ this.nameFactory = getFactory(factories, new NameValueFactory(namespaceRegistry, encoder, this.stringFactory));
+ this.pathFactory = getFactory(factories, new PathValueFactory(encoder, this.stringFactory, this.nameFactory));
+ this.referenceFactory = getFactory(factories, new UuidReferenceValueFactory(encoder, this.stringFactory));
+ this.uriFactory = getFactory(factories, new UriValueFactory(namespaceRegistry, encoder, this.stringFactory));
+
+ // Make sure there is a PropertyType.UNDEFINED factory ...
+ if (factories.get(PropertyType.UNDEFINED) == null) {
+ factories.put(PropertyType.UNDEFINED, this.stringFactory);
+ }
+
+ // Wrap the factories with an unmodifiable ...
+ this.factories = Collections.unmodifiableMap(factories);
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private static <T> ValueFactory<T> getFactory( Map<PropertyType, ValueFactory<?>> factories, ValueFactory<T> defaultFactory ) {
+ PropertyType type = defaultFactory.getPropertyType();
+ ValueFactory<?> factory = factories.get(type);
+ if (factory == null) {
+ factory = defaultFactory;
+ factories.put(type, factory);
+ }
+ return (ValueFactory<T>)factory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<Binary> getBinaryFactory() {
+ return this.binaryFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<Boolean> getBooleanFactory() {
+ return this.booleanFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<Calendar> getDateFactory() {
+ return this.dateFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<BigDecimal> getDecimalFactory() {
+ return this.decimalFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<Double> getDoubleFactory() {
+ return this.doubleFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<?> getValueFactory( PropertyType type ) {
+ ArgCheck.isNotNull(type, "type");
+ ValueFactory<?> factory = this.factories.get(type);
+ if (factory == null) {
+ // Should never happen
+ throw new SystemFailureException("Unexpected PropertyType");
+ }
+ return factory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<?> getValueFactory( Object prototype ) {
+ ArgCheck.isNotNull(prototype, "prototype");
+ PropertyType inferredType = PropertyType.discoverType(prototype);
+ if (inferredType == null) inferredType = PropertyType.STRING;
+ return getValueFactory(inferredType);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<Long> getLongFactory() {
+ return this.longFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<Name> getNameFactory() {
+ return this.nameFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<Path> getPathFactory() {
+ return this.pathFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<Reference> getReferenceFactory() {
+ return this.referenceFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<String> getStringFactory() {
+ return this.stringFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactory<URI> getUriFactory() {
+ return this.uriFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<ValueFactory<?>> iterator() {
+ return this.factories.values().iterator();
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StandardValueFactories.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,203 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.net.URI;
+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.util.DateUtil;
+import org.jboss.dna.common.util.IoUtil;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * 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);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ValueFactory<String> getStringValueFactory() {
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( String value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( String value, TextEncoder decoder ) {
+ if (value == null) return value;
+ if (decoder == null) decoder = getEncoder();
+ return decoder.decode(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( int value ) {
+ return Integer.toString(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( long value ) {
+ return Long.toString(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( boolean value ) {
+ return Boolean.toString(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( float value ) {
+ return Float.toString(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( double value ) {
+ return Double.toString(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( BigDecimal value ) {
+ if (value == null) return null;
+ return value.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( Calendar value ) {
+ if (value == null) return null;
+ return DateUtil.getDateAsStandardString(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( Date value ) {
+ if (value == null) return null;
+ return DateUtil.getDateAsStandardString(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( Name value ) {
+ if (value == null) return null;
+ return value.getString(getEncoder());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( Path value ) {
+ if (value == null) return null;
+ return value.getString(getEncoder());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( Reference value ) {
+ if (value == null) return null;
+ return value.getString(getEncoder());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( URI value ) {
+ if (value == null) return null;
+ return value.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( byte[] value ) throws ValueFormatException {
+ if (value == null) return null;
+ try {
+ return new String(value, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new ValueFormatException(SpiI18n.errorConvertingBinaryValueToString.text());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( InputStream stream, int approximateLength ) throws IOException {
+ if (stream == null) return null;
+ byte[] value = IoUtil.readBytes(stream);
+ try {
+ return new String(value, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new ValueFormatException(SpiI18n.errorConvertingBinaryValueToString.text());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String create( Reader reader, int approximateLength ) throws IOException {
+ if (reader == null) return null;
+ return IoUtil.read(reader);
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,192 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.net.URISyntaxException;
+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.util.ArgCheck;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * The standard {@link ValueFactory} for {@link PropertyType#URI} values.
+ * @author Randall Hauch
+ */
+@Immutable
+public class UriValueFactory extends AbstractValueFactory<URI> {
+
+ private final NamespaceRegistry namespaceRegistry;
+
+ public UriValueFactory( NamespaceRegistry namespaceRegistry, TextEncoder encoder, ValueFactory<String> stringValueFactory ) {
+ super(PropertyType.URI, encoder, stringValueFactory);
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ this.namespaceRegistry = namespaceRegistry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( String value ) throws ValueFormatException {
+ if (value == null) return null;
+ try {
+ return new URI(value);
+ } catch (URISyntaxException t) {
+ throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), t);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( String value, TextEncoder 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));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( int value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( long value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( boolean value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( float value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( double value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( BigDecimal value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( Calendar value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( Date value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( Name value ) {
+ if (value == null) return null;
+ return create("./" + value.getString(this.namespaceRegistry));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( Path value ) throws ValueFormatException {
+ if (value == null) return null;
+ if (value.isAbsolute()) {
+ return create("/" + value.getString(this.namespaceRegistry));
+ }
+ return create("./" + value.getString(this.namespaceRegistry));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( Reference value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Reference.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI create( URI value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI 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 URI 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 URI 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));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,118 @@
+/*
+ * 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 java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.jcr.Path;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.graph.Reference;
+
+/**
+ * @author Randall Hauch
+ */
+@Immutable
+public class UuidReference implements Reference {
+
+ private UUID uuid;
+
+ public UuidReference( UUID uuid ) {
+ this.uuid = uuid;
+ }
+
+ /**
+ * @return uuid
+ */
+ public UUID getUuid() {
+ return this.uuid;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return this.uuid.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ if (encoder == null) encoder = Path.DEFAULT_ENCODER;
+ return encoder.encode(getString());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Reference that ) {
+ if (this == that) return 0;
+ if (that instanceof UuidReference) {
+ return this.uuid.compareTo(((UuidReference)that).getUuid());
+ }
+ return this.getString().compareTo(that.getString());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof UuidReference) {
+ return this.uuid.equals(((UuidReference)obj).getUuid());
+ }
+ if (obj instanceof Reference) {
+ return this.getString().equals(((Reference)obj).getString());
+ }
+ return super.equals(obj);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return this.uuid.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void readExternal( ObjectInput in ) throws IOException {
+ long lsb = in.readLong();
+ long msb = in.readLong();
+ this.uuid = new UUID(msb, lsb);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void writeExternal( ObjectOutput out ) throws IOException {
+ out.writeLong(this.uuid.getLeastSignificantBits());
+ out.writeLong(this.uuid.getMostSignificantBits());
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReference.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-05-19 16:32:40 UTC (rev 176)
@@ -0,0 +1,182 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyType;
+import org.jboss.dna.spi.graph.Reference;
+import org.jboss.dna.spi.graph.ValueFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+
+/**
+ * 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);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( String value ) throws ValueFormatException {
+ if (value == null) return null;
+ try {
+ UUID uuid = UUID.fromString(value);
+ return new UuidReference(uuid);
+ } catch (IllegalArgumentException t) {
+ throw new ValueFormatException(SpiI18n.errorCreatingValue.text(getPropertyType().getName(), String.class.getSimpleName(), value), t);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( String value, TextEncoder 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));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( int value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( long value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( boolean value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( float value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( double value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( BigDecimal value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( Calendar value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( Date value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( Name value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( Path value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( Reference value ) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference create( URI value ) throws ValueFormatException {
+ throw new ValueFormatException(SpiI18n.unableToCreateValue.text(getPropertyType().getName(), Date.class.getSimpleName(), value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Reference 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 Reference 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 Reference 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));
+ }
+
+}
Property changes on: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties
===================================================================
--- branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties 2008-05-15 20:21:25 UTC (rev 175)
+++ branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties 2008-05-19 16:32:40 UTC (rev 176)
@@ -3,6 +3,10 @@
valueJavaTypeNotCompatibleWithPropertyType = Value is instance of Java type "{0}" and is not compatible with the "{1}" property type
errorConvertingBinaryValueToString = Error while interpretting binary value as a UTF-8 string
+errorCreatingValue = Error creating {0} value from {1} '{2}'
+unableToCreateValue = Unable to create {0} value from {1} '{2}': undefined type conversion
+unableToCreatePathFromEmptyString = Unable to create a path from an empty string
+validPathMayNotContainEmptySegment = The path '{0}' is not valid because it contains an empty segment
pathAncestorDegreeIsInvalid = Unable to obtain the {1} ancestor for {0}
pathIsAlreadyAbsolute = The path {0} is already an absolute path
17 years, 11 months
DNA SVN: r175 - in branches/federation/dna-spi/src: main/java/org/jboss/dna/spi/cache and 10 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-05-15 16:21:25 -0400 (Thu, 15 May 2008)
New Revision: 175
Added:
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/cache/
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/cache/CachePolicy.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/cache/Cacheable.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceException.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceListener.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/RepositoryCommand.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/
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/InvalidPathException.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.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/PathFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.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/PropertyType.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFormatException.java
branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/
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/BasicNameFactory.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/BasicPathFactory.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/InMemoryBinary.java
branches/federation/dna-spi/src/main/resources/org/
branches/federation/dna-spi/src/main/resources/org/jboss/
branches/federation/dna-spi/src/main/resources/org/jboss/dna/
branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/
branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties
branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/SpiI18nTest.java
Log:
Added preliminary SPI interfaces, including start of connector and graph.
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/SpiI18n.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * @author Randall Hauch
+ */
+public final class SpiI18n {
+
+ static {
+ try {
+ I18n.initialize(SpiI18n.class);
+ } catch (final Exception err) {
+ System.err.println(err);
+ }
+ }
+
+ public static I18n unableToDiscoverPropertyType;
+ public static I18n errorReadingPropertyValueBytes;
+ public static I18n valueJavaTypeNotCompatibleWithPropertyType;
+
+ public static I18n errorConvertingBinaryValueToString;
+
+ public static I18n pathAncestorDegreeIsInvalid;
+ public static I18n pathIsAlreadyAbsolute;
+ public static I18n pathIsNotAbsolute;
+ public static I18n pathIsNotRelative;
+ public static I18n pathCannotBeNormalized;
+
+ public static I18n invalidQualifiedNameString;
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/cache/CachePolicy.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/cache/CachePolicy.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/cache/CachePolicy.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,47 @@
+/*
+ * 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.cache;
+
+import java.io.Serializable;
+import net.jcip.annotations.Immutable;
+
+/**
+ * The specification of how node data is to be cached. The time values provided are relative, allowing the same cache policy
+ * instance to be shared among multiple {@link Cacheable} objects.
+ * @author Randall Hauch
+ */
+@Immutable
+public interface CachePolicy extends Serializable {
+
+ /**
+ * Get the system time in milliseconds before which the node data remains valid.
+ * @return the number of milliseconds that the cached data should be used before consulting the original source.
+ */
+ public long getTimeToCache();
+
+ /**
+ * Get the relative time after which the cached data should expire and no longer be used.
+ * @return the number of milliseconds until the cached data expires
+ */
+ public long getTimeToExpire();
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/cache/Cacheable.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/cache/Cacheable.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/cache/Cacheable.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,55 @@
+/*
+ * 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.cache;
+
+import java.io.Serializable;
+
+/**
+ * Interface defining an object that can be cached according to a {@link CachePolicy}.
+ * @author Randall Hauch
+ */
+public interface Cacheable extends Serializable {
+
+ /**
+ * Get the time that this node data was originally loaded.
+ * @return the system time (in milliseconds) that the node data was loaded
+ */
+ long getTimeLoaded();
+
+ /**
+ * Get the caching policy to be used for this object.
+ * <p>
+ * Note that the values of the policy are relative to the {@link #getTimeLoaded() time the node was loaded}, so the same
+ * instance can be used for many nodes.
+ * </p>
+ * @return cachePolicy the caching policy, which may not be null
+ */
+ public CachePolicy getCachePolicy();
+
+ /**
+ * Set the caching policy for this object.
+ * @param cachePolicy the caching policy to use for this object
+ * @throws IllegalArgumentException if the cachePolicy is null
+ */
+ public void setCachePolicy( CachePolicy cachePolicy );
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnection.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,76 @@
+/*
+ * 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.connector;
+
+import java.util.concurrent.TimeUnit;
+import javax.transaction.xa.XAResource;
+import org.jboss.dna.spi.connector.commands.RepositoryCommand;
+
+/**
+ * A connection to a repository source.
+ * <p>
+ * These connections need not support concurrent operations by multiple threads, since the federation engine never uses them this
+ * way.
+ * </p>
+ * @author Randall Hauch
+ */
+public interface RepositoryConnection {
+
+ /**
+ * Get the name for this repository source. This value should be the same as that {@link RepositorySource#getName() returned}
+ * by the same {@link RepositorySource} that created this connection.
+ * @return the identifier; never null or empty
+ */
+ String getSourceName();
+
+ /**
+ * Return the transactional resource associated with this connection. The transaction manager will use this resource to manage
+ * the participation of this connection in a distributed transaction.
+ * @return the XA resource, or null if this connection is not aware of distributed transactions
+ */
+ XAResource getXAResource();
+
+ /**
+ * Ping the underlying system to determine if the connection is still valid and alive.
+ * @param time the length of time to wait before timing out
+ * @param unit the time unit to use; may not be null
+ * @return true if this connection is still valid and can still be used, or false otherwise
+ * @throws InterruptedException if the thread has been interrupted during the operation
+ */
+ boolean ping( long time, TimeUnit unit ) throws InterruptedException;
+
+ void setListener( RepositorySourceListener listener );
+
+ /**
+ * Execute the supplied commands against this repository source.
+ * @param env the environment in which the commands are being executed; never null
+ * @param commands the commands to be executed; never null
+ * @throws RepositorySourceException if there is a problem loading the node data
+ */
+ void execute( RepositorySourceEnvironment env, RepositoryCommand... commands ) throws RepositorySourceException;
+
+ /**
+ * Close this connection to signal that it is no longer needed and that any accumulated resources are to be released.
+ * @throws InterruptedException if the thread has been interrupted while the close was in progress
+ */
+ void close() throws InterruptedException;
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryConnectionFactory.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,37 @@
+/*
+ * 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.connector;
+
+/**
+ * @author Randall Hauch
+ */
+public interface RepositoryConnectionFactory {
+
+ /**
+ * Get a connection from this factory.
+ * @return a connection
+ * @throws RepositorySourceException if there is a problem obtaining a connection
+ * @throws InterruptedException if the thread is interrupted while attempting to get a connection
+ * @throws IllegalStateException if the factory is not in a state to create or return connections
+ */
+ RepositoryConnection getConnection() throws RepositorySourceException, InterruptedException;
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,74 @@
+/*
+ * 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.connector;
+
+import java.io.Serializable;
+import javax.naming.Referenceable;
+import org.jboss.dna.spi.cache.CachePolicy;
+
+/**
+ * A repository source is a description of a resource that can be used to access or store repository information. This class
+ * serves as a factory for {@link RepositoryConnection} instances and provides some basic configuration information.
+ * <p>
+ * Typically this interface is implemented by classes that provide standard-style getters and setters for the various properties
+ * necessary for proper configuration via reflection or introspection. This interface expects nor defines any such properties,
+ * leaving that entirely to the implementation classes.
+ * </p>
+ * <p>
+ * Objects that implement this <code>RepositorySource</code> interface are typically registered with a naming service such as
+ * Java Naming and Directory Interface<sup><font size=-3>TM</font></sup> (JNDI). This interface extends both
+ * {@link Referenceable} and {@link Serializable} so that such objects can be stored in any JNDI naming context and enable proper
+ * system recovery,
+ * </p>
+ * @author Randall Hauch
+ */
+public interface RepositorySource extends RepositoryConnectionFactory, Referenceable, Serializable {
+
+ /**
+ * Get the name for this repository source.
+ * @return the name; never null or empty
+ */
+ String getName();
+
+ /**
+ * Get the maximum number of retries that may be performed on a given operation when using
+ * {@link #getConnection() connections} created by this source. This value does not constitute a minimum number of retries; in
+ * fact, the connection user is not required to retry any operations.
+ * @return the maximum number of allowable retries, or 0 if the source has no limit
+ */
+ int getRetryLimit();
+
+ /**
+ * Set the maximum number of retries that may be performed on a given operation when using
+ * {@link #getConnection() connections} created by this source. This value does not constitute a minimum number of retries; in
+ * fact, the connection user is not required to retry any operations.
+ * @param limit the maximum number of allowable retries, or 0 if the source has no limit
+ */
+ void setRetryLimit( int limit );
+
+ /**
+ * Get the default cache policy for this source. If none is provided, a global cache policy will be used.
+ * @return the default cache policy
+ */
+ CachePolicy getDefaultCachePolicy();
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceEnvironment.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,53 @@
+/*
+ * 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.connector;
+
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.PropertyValue;
+import org.jboss.dna.spi.graph.PropertyValueFactory;
+
+/**
+ * @author Randall Hauch
+ */
+public interface RepositorySourceEnvironment {
+
+ /**
+ * Get the factory that should be used to create {@link PropertyValue property values}.
+ * @return the property value factory; never null
+ */
+ PropertyValueFactory getPropertyValueFactory();
+
+ /**
+ * Get the factory that should be used to create {@link Name names}.
+ * @return the name factory; never null
+ */
+ NameFactory getNameFactory();
+
+ /**
+ * Get the {@link RepositorySource} instance that this environment represents. This instance will be the same instance that
+ * created the {@link RepositoryConnection} for which this environment was created and is being used.
+ * @return the repository source; never null
+ */
+ RepositorySource getRepositorySource();
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceException.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceException.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceException.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,73 @@
+/*
+ * 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.connector;
+
+/**
+ * @author Randall Hauch
+ */
+public class RepositorySourceException extends RuntimeException {
+
+ private final String sourceName;
+
+ /**
+ * @param sourceName the identifier of the source from which this exception eminates
+ */
+ public RepositorySourceException( String sourceName ) {
+ this.sourceName = sourceName;
+ }
+
+ /**
+ * @param sourceName the identifier of the source from which this exception eminates
+ * @param message
+ */
+ public RepositorySourceException( String sourceName, String message ) {
+ super(message);
+ this.sourceName = sourceName;
+ }
+
+ /**
+ * @param sourceName the identifier of the source from which this exception eminates
+ * @param cause
+ */
+ public RepositorySourceException( String sourceName, Throwable cause ) {
+ super(cause);
+ this.sourceName = sourceName;
+ }
+
+ /**
+ * @param sourceName the identifier of the source from which this exception eminates
+ * @param message
+ * @param cause
+ */
+ public RepositorySourceException( String sourceName, String message, Throwable cause ) {
+ super(message, cause);
+ this.sourceName = sourceName;
+ }
+
+ /**
+ * @return sourceName
+ */
+ public String getSourceName() {
+ return this.sourceName;
+ }
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceListener.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceListener.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySourceListener.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,30 @@
+/*
+ * 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.connector;
+
+/**
+ * @author Randall Hauch
+ */
+public interface RepositorySourceListener {
+
+ void notify( String sourceName, Object... events );
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetChildrenCommand.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,75 @@
+/*
+ * 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.connector.commands;
+
+import java.util.Iterator;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+
+/**
+ * A command to get the children of a single node.
+ * @author Randall Hauch
+ */
+public interface GetChildrenCommand extends GetCommand {
+
+ /**
+ * Get the path of the node for which the children are to be obtained.
+ * @return the node's path
+ */
+ Path getPath();
+
+ /**
+ * Set the children of this node using an iterator of names. Any existing child references already set on this command will be
+ * replaced by those supplied to this method.
+ * <p>
+ * The indexes of the same-name siblings will be determined by the order in which they appear in the iterator.
+ * </p>
+ * <p>
+ * The caller may supply a custom iterator implementation, which will be called on this same connection within the same
+ * transaction when the node data is processed and consumed.
+ * </p>
+ * @param namesOfChildren the iterator over the names of children; may be null if there are no children
+ */
+ void setChildren( Iterator<Name> namesOfChildren );
+
+ /**
+ * Set the children of this node using the array of names. Any existing child references already set on this command will be
+ * replaced by those supplied to this method.
+ * <p>
+ * The indexes of the same-name siblings will be determined by the order in which they appear in the iterator.
+ * </p>
+ * @param namesOfChildren the names of children; may be null if there are no children
+ */
+ void setChildren( Name... namesOfChildren );
+
+ /**
+ * Set the child of this node using the supplied name. Any existing child references already set on this command will be
+ * replaced by those supplied to this method.
+ * @param nameOfChild
+ */
+ void setChild( Name nameOfChild );
+
+ /**
+ * Set that this node has no children. Any existing child references already set on this command will be removed.
+ */
+ void setNoChildren();
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetCommand.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,45 @@
+/*
+ * 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.connector.commands;
+
+import org.jboss.dna.spi.cache.CachePolicy;
+
+/**
+ * Base interface for any repository command that retrieves information.
+ * @author Randall Hauch
+ */
+public interface GetCommand extends RepositoryCommand {
+
+ /**
+ * Get the caching policy to be used for this command's results. Note that the values of the policy are relative to the time
+ * the information was obtained, so the same instance can be used repeatedly.
+ * </p>
+ * @return cachePolicy the caching policy, which may not be null if no caching policy is defined
+ */
+ public CachePolicy getCachePolicy();
+
+ /**
+ * Set the caching policy for this command's results.
+ * @param cachePolicy the caching policy to use for this command's results
+ */
+ public void setCachePolicy( CachePolicy cachePolicy );
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetNodeCommand.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,30 @@
+/*
+ * 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.connector.commands;
+
+/**
+ * A command to get the properties and children for a single node.
+ * @author Randall Hauch
+ */
+public interface GetNodeCommand extends GetChildrenCommand, GetPropertiesCommand {
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/GetPropertiesCommand.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,48 @@
+/*
+ * 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.connector.commands;
+
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PropertyValue;
+
+/**
+ * A command to get the properties for a single node.
+ * @author Randall Hauch
+ */
+public interface GetPropertiesCommand extends GetCommand {
+
+ /**
+ * Get the path of the node for which the properties are to be obtained.
+ * @return the node's path
+ */
+ Path getPath();
+
+ /**
+ * Set the values for the named property. Any existing property values, if previously set, will be overwritten. If there are
+ * no property vlaues or if all of the property values are null, the property will be removed.
+ * @param propertyName the name of the property
+ * @param values the property values
+ */
+ void setProperty( Name propertyName, PropertyValue... values );
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/RepositoryCommand.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/RepositoryCommand.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/connector/commands/RepositoryCommand.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,36 @@
+/*
+ * 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.connector.commands;
+
+/**
+ * The base interface for all repository commands
+ * @author Randall Hauch
+ */
+public interface RepositoryCommand {
+
+ /**
+ * Return whether this command has been cancelled.
+ * @return true if this command has been cancelled, or false otherwise.
+ */
+ boolean isCancelled();
+
+}
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Binary.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,63 @@
+/*
+ * 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;
+
+import java.io.Externalizable;
+import java.io.InputStream;
+import net.jcip.annotations.ThreadSafe;
+
+/**
+ * Value holder for binary data.
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public interface Binary extends Comparable<Binary>, Externalizable {
+
+ /**
+ * Get the length of this binary data.
+ * @return the number of bytes in this binary data
+ */
+ public long getSize();
+
+ /**
+ * Get the contents of this data as a stream.
+ * @return the stream to this data's contents
+ */
+ public InputStream getStream();
+
+ /**
+ * Get the contents of this data as a byte array.
+ * @return the data as an array
+ */
+ public byte[] getBytes();
+
+ /**
+ * Acquire any resources for this data. This method must be called before any other method on this object.
+ */
+ public void acquire();
+
+ /**
+ * Release any acquired resources. This method must be called after a client is finished with this value.
+ */
+ public void release();
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/InvalidPathException.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/InvalidPathException.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/InvalidPathException.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public class InvalidPathException extends RuntimeException {
+
+ /**
+ *
+ */
+ public InvalidPathException() {
+ }
+
+ /**
+ * @param message
+ */
+ public InvalidPathException( String message ) {
+ super(message);
+
+ }
+
+ /**
+ * @param cause
+ */
+ public InvalidPathException( Throwable cause ) {
+ super(cause);
+
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public InvalidPathException( String message, Throwable cause ) {
+ super(message, cause);
+
+ }
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Name.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+
+/**
+ * A qualified name consisting of a namespace and a local name.
+ * @author Randall Hauch
+ */
+@Immutable
+public interface Name extends Comparable<Name>, Serializable {
+
+ /**
+ * Get the local name part of this qualified name.
+ * @return the local name; never null
+ */
+ String getLocalName();
+
+ /**
+ * Get the URI for the namespace used in this qualified name.
+ * @return the URI; never null but possibly empty
+ */
+ String getNamespaceUri();
+
+ /**
+ * Get the string form of the name. The {@link Path#DEFAULT_ENCODER default encoder} is used to encode characters in the local
+ * name and namespace.
+ * @return the encoded string
+ * @see #getString(TextEncoder)
+ */
+ public String getString();
+
+ /**
+ * Get the encoded string form of the name, using the supplied encoder to encode characters in the local name and namespace.
+ * @param encoder the encoder to use, or null if the {@link Path#DEFAULT_ENCODER default encoder} should be used
+ * @return the encoded string
+ * @see #getString()
+ */
+ public String getString( TextEncoder encoder );
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/NameFactory.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import org.jboss.dna.common.text.TextEncoder;
+
+/**
+ * A factory for creating {@link Name names}.
+ * @author Randall Hauch
+ */
+public interface NameFactory {
+
+ /**
+ * Create a name from the qualified name, which must be of the same form as returned by {@link Name#getString()}.
+ * <p>
+ * This method is equivalent to calling {@link #create(String, TextEncoder)} with a null encoder.
+ * </p>
+ * @param qualifiedName
+ * @return the new name.
+ * @throws IllegalArgumentException if the qualified name is null or invalid
+ */
+ Name create( String qualifiedName );
+
+ /**
+ * Create a name from the qualified name, which must be of the same form as returned by {@link Name#getString()}.
+ * @param qualifiedName
+ * @param encoder the encoder that should be used to decode the qualified name
+ * @return the new name
+ * @throws IllegalArgumentException if the qualified name is null or invalid
+ */
+ Name create( String qualifiedName, TextEncoder encoder );
+
+ /**
+ * 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 null
+ */
+ 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 null
+ */
+ Name create( String namespaceUri, String localName, TextEncoder encoder );
+}
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Path.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,361 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+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.TextEncoder;
+import org.jboss.dna.common.text.UrlEncoder;
+
+/**
+ * An object representation of a node path within a repository.
+ * <p>
+ * A path consists of zero or more segments that can contain any characters, although the string representation may require some
+ * characters to be encoded. For example, if a path contains a segment with a forward slash, then this forward slash must be
+ * escaped when writing the whole path to a string (since a forward slash is used as the {@link #DELIMITER delimiter} between
+ * segments).
+ * </p>
+ * <p>
+ * Because of this encoding and decoding issue, there is no standard representation of a path as a string. Instead, this class
+ * uses {@link TextEncoder text encoders} to escape certain characters when writing to a string or unescaping the string
+ * representation. These encoders and used only with individual segments, and therefore are not used to encode the
+ * {@link #DELIMITER delimiter}. Three standard encoders are provided, although others can certainly be used:
+ * <ul>
+ * <li>{@link #JSR283_ENCODER Jsr283Encoder} - an encoder and decoder that is compliant with <a
+ * href="http://jcp.org/en/jsr/detail?id=283">JSR-283</a> by converting the reserved characters (namely '*', '/', ':', '[', ']'
+ * and '|') to their unicode equivalent.</td>
+ * </li>
+ * <li>{@link #URL_ENCODER UrlEncoder} - an encoder and decoder that is 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>. This encoder does encode many characters
+ * (including '`', '@', '#', '$', '^', '&', '{', '[', '}', ']', '|', ':', ';', '\', '"', '<', ',', '>', '?', '/', and ' '), while
+ * others are not encoded (including '-', '_', '.', '!', '~', '*', '\', ''', '(', and ')'). Note that only the '*' character is
+ * the only character reserved by JSR-283 that is not encoded by the URL encoder.</li>
+ * <li>{@link #NO_OP_ENCODER NoOpEncoder} - an {@link TextEncoder encoder} implementation that does nothing.</li>
+ * </ul>
+ * </p>
+ * <p>
+ * This class simplifies working with paths and using a <code>Path</code> is often more efficient that processing and
+ * manipulating the equivalent <code>String</code>. This class can easily {@link #iterator() iterate} over the segments, return
+ * the {@link #size() number of segments}, {@link #compareTo(Path) compare} with other paths, {@link #resolve(Path) resolve}
+ * relative paths, return the {@link #getAncestor() ancestor (or parent)}, determine whether one path is an
+ * {@link #isAncestorOf(Path) ancestor} or {@link #isDecendantOf(Path) decendent} of another path, and
+ * {@link #getCommonAncestor(Path) finding a common ancestor}.
+ * </p>
+ * @author Randall Hauch
+ */
+@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 encodes and decodes 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 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 delimiter character used to separate segments within a path.
+ */
+ public static final char DELIMITER = '/';
+
+ /**
+ * String form of the delimiter used to separate segments within a path.
+ */
+ public static final String DELIMITER_STR = new String(new char[] {DELIMITER});
+
+ /**
+ * String representation of the segment that references a parent.
+ */
+ public static final String PARENT = "..";
+
+ /**
+ * String representation of the segment that references the same segment.
+ */
+ public static final String SELF = ".";
+
+ /**
+ * The index that will be returned for a {@link Segment} that {@link Segment#hasIndex() has no index}.
+ */
+ public static final int NO_INDEX = 0;
+
+ /**
+ * Representation of the segments that occur within a path.
+ * @author Randall Hauch
+ */
+ @Immutable
+ public static interface Segment extends Cloneable, Comparable<Segment>, Serializable {
+
+ /**
+ * Get the name component of this segment.
+ * @return the segment's name
+ */
+ public Name getName();
+
+ /**
+ * 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();
+
+ /**
+ * Return whether this segment has an index.
+ * @return true if this segment has an index, or false otherwise.
+ */
+ public boolean hasIndex();
+
+ /**
+ * Return whether this segment is a self-reference.
+ * @return true if the segment is a self-reference, or false otherwise.
+ */
+ public boolean isSelfReference();
+
+ /**
+ * 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 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 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 the number of segments in this path.
+ * @return the number of path segments
+ */
+ public int size();
+
+ /**
+ * Return whether this path represents the root path.
+ * @return true if this path is the root path, or false otherwise
+ */
+ public boolean isRoot();
+
+ /**
+ * 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 );
+
+ /**
+ * 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 );
+
+ /**
+ * 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 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 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 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();
+
+ /**
+ * 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();
+
+ /**
+ * 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 );
+
+ /**
+ * 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 );
+
+ /**
+ * 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 );
+
+ /**
+ * 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();
+
+ /**
+ * 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 );
+
+ /**
+ * 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 );
+
+ /**
+ * 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 last segment in this path.
+ * @return the last segment, or null if the path is empty
+ */
+ public Segment getLastSegment();
+
+ /**
+ * 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 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 substring.
+ * @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 );
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Segment> iterator();
+
+ /**
+ * 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 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 );
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathFactory.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,112 @@
+/*
+ * 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;
+
+/**
+ * A factory for creating {@link Path paths}.
+ * @author Randall Hauch
+ */
+public interface PathFactory {
+
+ /**
+ * 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 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 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 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 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 );
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PathNotFoundException.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public class PathNotFoundException extends RuntimeException {
+
+ /**
+ *
+ */
+ public PathNotFoundException() {
+ }
+
+ /**
+ * @param message
+ */
+ public PathNotFoundException( String message ) {
+ super(message);
+
+ }
+
+ /**
+ * @param cause
+ */
+ public PathNotFoundException( Throwable cause ) {
+ super(cause);
+
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public PathNotFoundException( String message, Throwable cause ) {
+ super(message, cause);
+
+ }
+
+}
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/Property.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import java.util.Iterator;
+
+/**
+ * @author Randall Hauch
+ */
+public interface Property extends Iterable<PropertyValue> {
+
+ Name getName();
+
+ boolean isMultiple();
+
+ Iterator<PropertyValue> getValues();
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyType.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,89 @@
+/*
+ * 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;
+
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.spi.SpiI18n;
+import com.sun.tools.javac.tree.Tree.Binary;
+
+/**
+ * @author Randall Hauch
+ */
+@Immutable
+public enum PropertyType {
+
+ STRING("String", PropertyValues.STRING_COMPARATOR, String.class),
+ BINARY("Binary", PropertyValues.BINARY_COMPARATOR, Binary.class),
+ LONG("Long", PropertyValues.LONG_COMPARATOR, Long.class),
+ DOUBLE("Double", PropertyValues.DOUBLE_COMPARATOR, Double.class),
+ DECIMAL("Decimal", PropertyValues.DECIMAL_COMPARATOR, BigDecimal.class),
+ DATE("Date", PropertyValues.DATE_COMPARATOR, Date.class),
+ BOOLEAN("Boolean", PropertyValues.BOOLEAN_COMPARATOR, Boolean.class),
+ NAME("Name", PropertyValues.NAME_COMPARATOR, Name.class),
+ PATH("Path", PropertyValues.PATH_COMPARATOR, Path.class),
+ REFERENCE("Reference", PropertyValues.REFERENCE_COMPARATOR, UUID.class),
+ URI("URI", PropertyValues.URI_COMPARATOR, URI.class),
+ UNDEFINED("undefined", PropertyValues.UNDEFINED_COMPARATOR, Comparable.class);
+
+ private final String name;
+ private final Comparator comparator;
+ private final Class valueClass;
+
+ private PropertyType( String name, Comparator comparator, Class valueClass ) {
+ this.name = name;
+ this.comparator = comparator;
+ this.valueClass = valueClass;
+ }
+
+ public Class getValueClass() {
+ return this.valueClass;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public Comparator getComparator() {
+ return this.comparator;
+ }
+
+ public boolean isInstance( Object value ) {
+ return this.valueClass.isInstance(value);
+ }
+
+ public static PropertyType discoverType( Object value ) {
+ if (value == null) {
+ throw new ValueFormatException(SpiI18n.unableToDiscoverPropertyType.text(value));
+ }
+ for (PropertyType type : PropertyType.values()) {
+ if (type.isInstance(value)) return type;
+ }
+ throw new ValueFormatException(SpiI18n.unableToDiscoverPropertyType.text(StringUtil.readableString(value)));
+ }
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValue.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+
+/**
+ * @author Randall Hauch
+ */
+public interface PropertyValue extends Comparable<PropertyValue>, Cloneable, Serializable {
+
+ /**
+ * Determine whether the property value is null.
+ * @return true if the property value is null, or false otherwise
+ */
+ boolean isNull();
+
+ String getValueAsString();
+
+ PropertyType getPropertyType();
+
+ boolean isEquivalentTo( PropertyValue value );
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValueFactory.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,68 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+import net.jcip.annotations.ThreadSafe;
+
+/**
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public interface PropertyValueFactory {
+
+ PropertyValue create( String value ) throws ValueFormatException;
+
+ PropertyValue create( int value ) throws ValueFormatException;
+
+ PropertyValue create( long value ) throws ValueFormatException;
+
+ PropertyValue create( boolean value ) throws ValueFormatException;
+
+ PropertyValue create( float value ) throws ValueFormatException;
+
+ PropertyValue create( double value ) throws ValueFormatException;
+
+ PropertyValue create( Calendar value ) throws ValueFormatException;
+
+ PropertyValue create( Date value ) throws ValueFormatException;
+
+ PropertyValue create( Name value ) throws ValueFormatException;
+
+ PropertyValue create( Path value ) throws ValueFormatException;
+
+ PropertyValue create( UUID value ) throws ValueFormatException;
+
+ PropertyValue create( URI value ) throws ValueFormatException;
+
+ PropertyValue create( byte[] value ) throws ValueFormatException;
+
+ PropertyValue create( InputStream value, int approximateLength ) throws ValueFormatException;
+
+ PropertyValue create( Reader reader, int approximateLength ) throws ValueFormatException;
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/PropertyValues.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,402 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.UUID;
+import org.jboss.dna.common.util.DateUtil;
+import org.jboss.dna.spi.SpiI18n;
+
+/**
+ * @author Randall Hauch
+ */
+public class PropertyValues {
+
+ /**
+ * A comparator of string values.
+ */
+ public static final Comparator<String> STRING_COMPARATOR = new Comparator<String>() {
+
+ public int compare( String o1, String o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of integer values.
+ */
+ public static final Comparator<Integer> INTEGER_COMPARATOR = new Comparator<Integer>() {
+
+ public int compare( Integer o1, Integer o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of long values.
+ */
+ public static final Comparator<Long> LONG_COMPARATOR = new Comparator<Long>() {
+
+ public int compare( Long o1, Long o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of float values.
+ */
+ public static final Comparator<Float> FLOAT_COMPARATOR = new Comparator<Float>() {
+
+ public int compare( Float o1, Float o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of double values.
+ */
+ public static final Comparator<Double> DOUBLE_COMPARATOR = new Comparator<Double>() {
+
+ public int compare( Double o1, Double o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of decimal values.
+ */
+ public static final Comparator<BigDecimal> DECIMAL_COMPARATOR = new Comparator<BigDecimal>() {
+
+ public int compare( BigDecimal o1, BigDecimal o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of binary values. Although {@link Binary} is {@link Comparable}, this comparator does not rely upon any
+ * particular Binary implementation. Thus, Binary implementations can use this for their {@link Comparable#compareTo(Object)}
+ * implementation.
+ */
+ public static final Comparator<Binary> BINARY_COMPARATOR = new Comparator<Binary>() {
+
+ public int compare( Binary o1, Binary o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ try {
+ o1.acquire();
+ try {
+ o2.acquire();
+ final long len1 = o1.getSize();
+ final long len2 = o2.getSize();
+ if (len1 < len2) return -1;
+ if (len1 > len2) return 1;
+ // Otherwise they are the same length ...
+ InputStream stream1 = null;
+ InputStream stream2 = null;
+ try {
+ stream1 = o1.getStream();
+ stream2 = o2.getStream();
+ byte[] buffer1 = new byte[1024];
+ byte[] buffer2 = new byte[1024];
+ while (true) {
+ int numRead1 = stream1.read(buffer1);
+ if (numRead1 < 0) break;
+ int numRead2 = stream2.read(buffer2);
+ if (numRead1 != numRead2) {
+ throw new ValueFormatException(SpiI18n.errorReadingPropertyValueBytes.text());
+ }
+ for (int i = 0; i != numRead1; ++i) {
+ int diff = buffer1[i] - buffer2[i];
+ if (diff != 0) return diff;
+ }
+ }
+ return 0;
+ } catch (IOException e) {
+ throw new ValueFormatException(SpiI18n.errorReadingPropertyValueBytes.text());
+ } finally {
+ if (stream1 != null) {
+ try {
+ stream1.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ if (stream2 != null) {
+ try {
+ stream2.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+ } finally {
+ o2.release();
+ }
+ } finally {
+ o1.release();
+ }
+ }
+ };
+ /**
+ * A comparator of boolean values.
+ */
+ public static final Comparator<Boolean> BOOLEAN_COMPARATOR = new Comparator<Boolean>() {
+
+ public int compare( Boolean o1, Boolean o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of date values.
+ */
+ public static final Comparator<Date> DATE_COMPARATOR = new Comparator<Date>() {
+
+ public int compare( Date o1, Date o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of calendar values.
+ */
+ public static final Comparator<Calendar> CALENDAR_COMPARATOR = new Comparator<Calendar>() {
+
+ public int compare( Calendar o1, Calendar o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of name values.
+ */
+ public static final Comparator<Name> NAME_COMPARATOR = new Comparator<Name>() {
+
+ public int compare( Name o1, Name o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of path values.
+ */
+ public static final Comparator<Path> PATH_COMPARATOR = new Comparator<Path>() {
+
+ public int compare( Path o1, Path o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of URI values.
+ */
+ public static final Comparator<URI> URI_COMPARATOR = new Comparator<URI>() {
+
+ public int compare( URI o1, URI o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of reference values.
+ */
+ public static final Comparator<UUID> REFERENCE_COMPARATOR = new Comparator<UUID>() {
+
+ public int compare( UUID o1, UUID o2 ) {
+ return o1.compareTo(o2);
+ }
+ };
+ /**
+ * A comparator of other values.
+ */
+ public static final Comparator<Object> UNDEFINED_COMPARATOR = new Comparator<Object>() {
+
+ @SuppressWarnings( "unchecked" )
+ public int compare( Object o1, Object o2 ) {
+ if (o1 == o2) return 0;
+ if (o1 == null) return -1;
+ if (o2 == null) return 1;
+ PropertyType type1 = PropertyType.discoverType(o1);
+ PropertyType type2 = PropertyType.discoverType(o2);
+ if (type1 == type2) return type1.getComparator().compare(o1, o2);
+ // The types are different but the classes are the same ...
+ if (type1.getDeclaringClass().isAssignableFrom(type2.getDeclaringClass())) {
+ return type1.getComparator().compare(o1, o2);
+ }
+ if (type2.getDeclaringClass().isAssignableFrom(type1.getDeclaringClass())) {
+ return type2.getComparator().compare(o1, o2);
+ }
+ // The types are different and must be converted ...
+ String value1 = PropertyValues.getString(o1);
+ String value2 = PropertyValues.getString(o2);
+ return value1.compareTo(value2);
+ }
+ };
+
+ /**
+ * Get the string representation of the supplied value. This method may perform an conversion that may lose information.
+ * @param value the value to be interpreted as a string
+ * @return the string representation
+ */
+ public static String getString( Object value ) {
+ if (value == null) return null;
+ if (value instanceof String) return (String)value;
+ if (value instanceof Boolean) return getString(((Boolean)value).booleanValue());
+ if (value instanceof Double) return getString(((Double)value).doubleValue());
+ if (value instanceof Long) return getString(((Long)value).longValue());
+ if (value instanceof Date) return getString((Date)value);
+ if (value instanceof Binary) return getString((Binary)value);
+ if (value instanceof Calendar) return getString((Calendar)value);
+ if (value instanceof BigDecimal) return getString((BigDecimal)value);
+ if (value instanceof Name) return getString((Name)value);
+ if (value instanceof Path) return getString((Path)value);
+ if (value instanceof URI) return getString((URI)value);
+ if (value instanceof UUID) return getString((UUID)value);
+ return value.toString();
+ }
+
+ /**
+ * Get the string representation of the supplied boolean value. This method is implemented by calling
+ * {@link Boolean#toString(boolean) Boolean.toString(boolean)}.
+ * @param value the boolean value
+ * @return the string representation
+ */
+ public static String getString( boolean value ) {
+ return Boolean.toString(value);
+ }
+
+ /**
+ * Get the string representation of the supplied double value. This method is implemented by calling
+ * {@link Double#toString(double) Double.toString(double)}.
+ * @param value the double value
+ * @return the string representation
+ */
+ public static String getString( double value ) {
+ return Double.toString(value);
+ }
+
+ /**
+ * Get the string representation of the supplied long value. This method is implemented by calling
+ * {@link Long#toString(long) Long.toString(long)}.
+ * @param value the long value
+ * @return the string representation
+ */
+ public static String getString( long value ) {
+ return Long.toString(value);
+ }
+
+ /**
+ * Get the string representation of the supplied binary value. This method attempts to interpret the binary value as a UTF-8
+ * encoded string.
+ * @param value the binary value
+ * @return the string representation
+ */
+ public static String getString( Binary value ) {
+ if (value == null) return null;
+ try {
+ value.acquire();
+ byte[] bytes = value.getBytes();
+ try {
+ return new String(bytes, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new ValueFormatException(SpiI18n.errorConvertingBinaryValueToString.text());
+ }
+ } finally {
+ value.release();
+ }
+ }
+
+ /**
+ * Get the ISO 8601:2004 string representation of the supplied date value.
+ * @param value the date value
+ * @return the string representation
+ */
+ public static String getString( Date value ) {
+ if (value == null) return null;
+ return DateUtil.getDateAsStandardString(value);
+ }
+
+ /**
+ * Get the ISO 8601:2004 string representation of the supplied calendar value.
+ * @param value the calendar value
+ * @return the string representation
+ */
+ public static String getString( Calendar value ) {
+ if (value == null) return null;
+ return getString(value.getTime());
+ }
+
+ /**
+ * Get the string representation of the supplied decimal value.
+ * @param value the decimal value
+ * @return the string representation
+ */
+ public static String getString( BigDecimal value ) {
+ if (value == null) return null;
+ return value.toString();
+ }
+
+ /**
+ * Get the string representation of the supplied name. This method calls {@link Name#getString() Name.getString()}.
+ * @param value the name value
+ * @return the string representation
+ */
+ public static String getString( Name value ) {
+ if (value == null) return null;
+ return value.getString();
+ }
+
+ /**
+ * Get the string representation of the supplied path. This method calls {@link Path#getString() Path.getString()}.
+ * @param value the path value
+ * @return the string representation
+ */
+ public static String getString( Path value ) {
+ if (value == null) return null;
+ return value.getString();
+ }
+
+ /**
+ * Get the string representation of the supplied URI. This method calls {@link URI#toASCIIString() URI.toASCIIString()}.
+ * @param value the URI value
+ * @return the string representation
+ */
+ public static String getString( URI value ) {
+ if (value == null) return null;
+ return value.toASCIIString();
+ }
+
+ /**
+ * Get the string representation of the supplied UUID.
+ * @param value the UUID value
+ * @return the string representation
+ */
+ public static String getString( UUID value ) {
+ if (value == null) return null;
+ return value.toString();
+ }
+
+ /**
+ * Get the string representation of the supplied string value. This method simply returns the supplied value.
+ * @param value the date value
+ * @return the string representation
+ */
+ public static String getString( String value ) {
+ return value;
+ }
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFormatException.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFormatException.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFormatException.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+/**
+ * @author Randall Hauch
+ */
+public class ValueFormatException extends RuntimeException {
+
+ /**
+ *
+ */
+ public ValueFormatException() {
+ }
+
+ /**
+ * @param message
+ */
+ public ValueFormatException( String message ) {
+ super(message);
+
+ }
+
+ /**
+ * @param cause
+ */
+ public ValueFormatException( Throwable cause ) {
+ super(cause);
+
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public ValueFormatException( String message, Throwable cause ) {
+ super(message, cause);
+
+ }
+
+}
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicName.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,117 @@
+/*
+ * 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 net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.HashCode;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+
+/**
+ * A basic implementation of {@link Name}.
+ * @author Randall Hauch
+ */
+@Immutable
+public class BasicName implements Name {
+
+ private final String namespaceUri;
+ private final String localName;
+ private final int hc;
+
+ public BasicName( String namespaceUri, String localName ) {
+ this.namespaceUri = namespaceUri != null ? namespaceUri.trim() : "";
+ this.localName = localName != null ? localName.trim() : "";
+ this.hc = HashCode.compute(this.namespaceUri, this.localName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getLocalName() {
+ return this.localName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getNamespaceUri() {
+ return this.namespaceUri;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return getString(Path.DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ if (encoder == null) encoder = Path.DEFAULT_ENCODER;
+ return "{" + encoder.encode(this.namespaceUri) + "}" + encoder.encode(this.localName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Name that ) {
+ if (that == this) return 0;
+ int diff = this.getNamespaceUri().compareTo(that.getNamespaceUri());
+ if (diff != 0) return diff;
+ diff = this.getLocalName().compareTo(that.getLocalName());
+ return diff;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return this.hc;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof Name) {
+ Name that = (Name)obj;
+ if (!this.getNamespaceUri().equals(that.getNamespaceUri())) return false;
+ return this.getLocalName().equals(that.getLocalName());
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "{" + this.namespaceUri + "}" + this.localName;
+ }
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicNameFactory.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,83 @@
+/*
+ * 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 java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NameFactory;
+import org.jboss.dna.spi.graph.Path;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicNameFactory implements NameFactory {
+
+ // Non-escaped pattern: (\{([^}]*)\})?(.*)
+ protected static final String QUALFIED_NAME_PATTERN_STRING = "(\\{([^}]*)\\})?(.*)";
+ protected static final Pattern QUALIFIED_NAME_PATTERN = Pattern.compile(QUALFIED_NAME_PATTERN_STRING);
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( String qualifiedName ) {
+ return create(qualifiedName, Path.DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( String qualifiedName, TextEncoder encoder ) {
+ ArgCheck.isNotNull(qualifiedName, "qualifiedName");
+ if (encoder == null) encoder = Path.DEFAULT_ENCODER;
+ String decodedQualifiedName = encoder.decode(qualifiedName.trim());
+ Matcher matcher = QUALIFIED_NAME_PATTERN.matcher(decodedQualifiedName);
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException(SpiI18n.invalidQualifiedNameString.text(qualifiedName));
+ }
+ String namespaceUri = matcher.group(2);
+ String localName = matcher.group(3);
+ return new BasicName(namespaceUri, localName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( String namespaceUri, String localName ) {
+ return create(namespaceUri, localName, Path.DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name create( String namespaceUri, String localName, TextEncoder encoder ) {
+ ArgCheck.isNotNull(localName, "localName");
+ if (encoder == null) encoder = Path.DEFAULT_ENCODER;
+ namespaceUri = namespaceUri != null ? encoder.decode(namespaceUri.trim()) : null;
+ localName = encoder.decode(localName.trim());
+ return new BasicName(namespaceUri, localName);
+ }
+
+}
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPath.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,441 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.CommonI18n;
+import org.jboss.dna.common.text.Inflector;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.SpiI18n;
+import org.jboss.dna.spi.graph.InvalidPathException;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathNotFoundException;
+
+/**
+ * A basic implementation of {@link Path}.
+ * @author Randall Hauch
+ */
+@Immutable
+public class BasicPath implements Path {
+
+ public static final Path ROOT = new BasicPath(null, true);
+
+ protected static final Path SELF_PATH = new BasicPath(Collections.singletonList(BasicPathSegment.SELF_SEGMENT), false);
+
+ private static final List<Segment> EMPTY_SEGMENTS = Collections.emptyList();
+
+ private final List<Segment> segments;
+ private final boolean absolute;
+ private final boolean normalized;
+ private transient String path;
+
+ /**
+ * @param segments the segments
+ * @param absolute true if this path is absolute, or false otherwise
+ */
+ public BasicPath( List<Segment> segments, boolean absolute ) {
+ this.segments = segments != null && segments.size() > 0 ? Collections.unmodifiableList(segments) : EMPTY_SEGMENTS;
+ this.absolute = absolute;
+ this.normalized = isNormalized(segments);
+ }
+
+ protected boolean isNormalized( List<Segment> segments ) {
+ for (Segment segment : segments) {
+ if (segment.isSelfReference() || segment.isParentReference()) return false;
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getAncestor() {
+ if (this.isRoot()) return this;
+ if (this.segments.size() == 1) return ROOT;
+ return subpath(0, this.segments.size() - 1);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getAncestor( int degree ) {
+ ArgCheck.isNonNegative(degree, "degree");
+ if (this.isRoot()) return this;
+ int endIndex = this.segments.size() - degree;
+ if (endIndex < 0) {
+ String msg = SpiI18n.pathAncestorDegreeIsInvalid.text(this.getString(), Inflector.getInstance().ordinalize(degree));
+ throw new PathNotFoundException(msg);
+ }
+ return subpath(0, endIndex);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getCanonicalPath() {
+ if (!this.isAbsolute()) {
+ String msg = SpiI18n.pathIsNotAbsolute.text(this);
+ throw new InvalidPathException(msg);
+ }
+ if (this.isNormalized()) return this;
+ return this.getNormalizedPath();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getCommonAncestor( Path that ) {
+ if (that == null) return null;
+ Path normalizedPath = this.getNormalizedPath();
+ int lastIndex = normalizedPath.size();
+ Iterator<Segment> thisIter = normalizedPath.iterator();
+ Iterator<Segment> thatIter = that.getNormalizedPath().iterator();
+ while (thisIter.hasNext() && thatIter.hasNext()) {
+ Segment thisSeg = thisIter.next();
+ Segment thatSeg = thatIter.next();
+ if (thisSeg.equals(thatSeg)) {
+ --lastIndex;
+ } else {
+ break;
+ }
+ }
+ if (lastIndex <= 0) return ROOT;
+ return normalizedPath.subpath(0, lastIndex);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path.Segment getLastSegment() {
+ if (this.isRoot()) return null;
+ return this.segments.get(size() - 1);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path getNormalizedPath() {
+ if (this.isNormalized()) return this; // ROOT is normalized already
+ LinkedList<Segment> newSegments = new LinkedList<Segment>();
+ for (Segment segment : segments) {
+ if (segment.isSelfReference()) continue;
+ if (segment.isParentReference()) {
+ if (newSegments.size() <= 0) {
+ if (this.isAbsolute()) {
+ throw new InvalidPathException(CommonI18n.pathCannotBeNormalized.text(this));
+ }
+ }
+ if (newSegments.size() > 0 && !newSegments.getLast().isParentReference()) {
+ newSegments.removeLast();
+ continue;
+ }
+ }
+ newSegments.add(segment);
+ }
+ if (newSegments.isEmpty()) {
+ if (this.isAbsolute()) return ROOT;
+ // Otherwise relative and it had contained nothing but self references ...
+ return SELF_PATH;
+ }
+ return new BasicPath(newSegments, this.isAbsolute());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Segment getSegment( int index ) {
+ return this.segments.get(index);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Segment[] getSegmentsArray() {
+ return this.segments.toArray(new Path.Segment[this.segments.size()]);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Segment> getSegmentsList() {
+ return this.segments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return getString(DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ if (encoder == null) encoder = DEFAULT_ENCODER;
+ if (encoder == DEFAULT_ENCODER && this.path != null) return this.path;
+
+ // Since the segments are immutable, this code need not be synchronized because concurrent threads
+ // may just compute the same value (with no harm done)
+ StringBuilder sb = new StringBuilder();
+ if (this.isAbsolute()) sb.append(DELIMITER);
+ boolean first = true;
+ for (Segment segment : this.segments) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(DELIMITER);
+ }
+ assert segment != null;
+ sb.append(segment.getString(encoder));
+ }
+ String result = sb.toString();
+ // Save the result to the internal string if this the default encoder is used.
+ // This is not synchronized, but it's okay
+ if (encoder == DEFAULT_ENCODER && this.path == null) this.path = result;
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasSameAncestor( Path that ) {
+ if (that == null) return false;
+ if (that.size() != this.size()) return false;
+ if (this.size() == 1) return false;
+ for (int i = this.size() - 2; i < 0; --i) {
+ Path.Segment thisSegment = this.getSegment(i);
+ Path.Segment thatSegment = that.getSegment(i);
+ if (!thisSegment.equals(thatSegment)) return false;
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAbsolute() {
+ return this.absolute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAncestorOf( Path decendant ) {
+ if (decendant == null) return false;
+ if (this == decendant) return false;
+ if (this.size() >= decendant.size()) return false;
+
+ Iterator<Path.Segment> thisIter = this.iterator();
+ Iterator<Path.Segment> thatIter = decendant.iterator();
+ while (thisIter.hasNext()) {
+ Path.Segment thisSeg = thisIter.next();
+ Path.Segment thatSeg = thatIter.next();
+ if (!thisSeg.equals(thatSeg)) return false;
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isDecendantOf( Path ancestor ) {
+ if (ancestor == null) return false;
+ return ancestor.isAncestorOf(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isNormalized() {
+ return this.normalized;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isRoot() {
+ return this == ROOT || this.segments.isEmpty();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSame( Path other ) {
+ return this.compareTo(other) == 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Segment> iterator() {
+ return this.segments.iterator();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path relativeTo( Path startingPath ) {
+ ArgCheck.isNotNull(startingPath, "to");
+ if (!this.isAbsolute()) {
+ String msg = SpiI18n.pathIsNotAbsolute.text(this);
+ throw new InvalidPathException(msg);
+ }
+ if (!startingPath.isAbsolute()) {
+ String msg = SpiI18n.pathIsNotAbsolute.text(startingPath);
+ throw new InvalidPathException(msg);
+ }
+
+ // Count the number of segments up to the common ancestor (relative path is what remains) ...
+ int lengthOfCommonAncestor = 0;
+ Iterator<Segment> thisIter = this.getNormalizedPath().iterator();
+ Iterator<Segment> toIter = startingPath.getNormalizedPath().iterator();
+ while (thisIter.hasNext() && toIter.hasNext()) {
+ Segment thisSeg = thisIter.next();
+ Segment toSeg = toIter.next();
+ if (thisSeg.equals(toSeg)) {
+ ++lengthOfCommonAncestor;
+ } else {
+ break;
+ }
+ }
+ // Create the relative path, starting with parent references to the common ancestor ...
+ int numberOfParentReferences = startingPath.size() - lengthOfCommonAncestor;
+ List<Segment> relativeSegments = new ArrayList<Segment>();
+ for (int i = 0; i != numberOfParentReferences; ++i) {
+ relativeSegments.add(BasicPathSegment.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);
+ }
+ return new BasicPath(relativeSegments, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path resolve( Path relativePath ) {
+ ArgCheck.isNotNull(relativePath, "relative path");
+ if (!this.isAbsolute()) {
+ String msg = SpiI18n.pathIsAlreadyAbsolute.text(this.path);
+ throw new InvalidPathException(msg);
+ }
+ if (relativePath.isAbsolute()) {
+ String msg = SpiI18n.pathIsNotRelative.text(relativePath);
+ throw new InvalidPathException(msg);
+ }
+ // If the relative path is the self or parent reference ...
+ relativePath = relativePath.getNormalizedPath();
+ if (relativePath.size() == 1) {
+ Segment onlySegment = relativePath.getSegment(0);
+ if (onlySegment.isSelfReference()) return this;
+ if (onlySegment.isParentReference()) return this.getAncestor();
+ }
+ List<Segment> segments = new ArrayList<Segment>(this.size() + relativePath.size());
+ segments.addAll(this.segments);
+ segments.addAll(relativePath.getSegmentsList());
+ return new BasicPath(segments, true).getNormalizedPath();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path resolveAgainst( Path absolutePath ) {
+ ArgCheck.isNotNull(absolutePath, "absolute path");
+ return absolutePath.resolve(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int size() {
+ return this.segments.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Path subpath( int beginIndex, int endIndex ) {
+ if (beginIndex == 0 && endIndex == 0) return ROOT;
+ // This reuses the same list, so it's pretty efficient ...
+ return new BasicPath(this.segments.subList(beginIndex, endIndex), this.isAbsolute());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return this.segments.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof Path) {
+ Path that = (Path)obj;
+ return this.segments.equals(that.getSegmentsList());
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Path that ) {
+ if (that == null) return 1;
+ if (this == that) return 0;
+ Iterator<Segment> thisIter = this.segments.iterator();
+ Iterator<Segment> thatIter = that.iterator();
+ while (thisIter.hasNext() && thatIter.hasNext()) {
+ Segment thisSegment = thisIter.next();
+ Segment thatSegment = thatIter.next();
+ int diff = thisSegment.compareTo(thatSegment);
+ if (diff != 0) return diff;
+ }
+ if (thisIter.hasNext()) return 1;
+ if (thatIter.hasNext()) return -1;
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return getString(Path.URL_ENCODER);
+ }
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathFactory.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,167 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathFactory;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * @author Randall Hauch
+ */
+public class BasicPathFactory implements PathFactory {
+
+ /**
+ *
+ */
+ public BasicPathFactory() {
+ }
+
+ /**
+ * {@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 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 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;
+
+ 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;
+
+ 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");
+ return new BasicPathSegment(segmentName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Segment createSegment( Name segmentName, int index ) {
+ ArgCheck.isNotNull(segmentName, "segment name");
+ return new BasicPathSegment(segmentName, index);
+ }
+
+}
Added: 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 (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,160 @@
+/*
+ * 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 net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+
+/**
+ * A basic implementation of {@link Path.Segment}.
+ * @author Randall Hauch
+ */
+@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;
+
+ /**
+ * @param name the segment name
+ * @throws IllegalArgumentException if the name is null or if the index is invalid
+ */
+ public BasicPathSegment( Name name ) {
+ this(name, Path.NO_INDEX);
+ }
+
+ /**
+ * @param name the segment name
+ * @param index the segment index
+ * @throws IllegalArgumentException if the name is null or if the index is invalid
+ */
+ public BasicPathSegment( Name name, int index ) {
+ ArgCheck.isNotNull(name, "name");
+ ArgCheck.isNonNegative(index, "index");
+ this.name = name;
+ this.index = index;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getIndex() {
+ return this.index;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Name getName() {
+ return this.name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasIndex() {
+ return this.index != Path.NO_INDEX;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isParentReference() {
+ return this.hasIndex() == false && this.name.getNamespaceUri().length() == 0 && this.name.getLocalName().equals(Path.PARENT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSelfReference() {
+ return this.hasIndex() == false && this.name.getNamespaceUri().length() == 0 && this.name.getLocalName().equals(Path.SELF);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Path.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 int hashCode() {
+ return this.name.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof Path.Segment) {
+ Path.Segment that = (Path.Segment)obj;
+ if (!this.getName().equals(that.getName())) return false;
+ return this.getIndex() != that.getIndex();
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ if (this.hasIndex()) {
+ return this.getName().toString() + "[" + this.getIndex() + "]";
+ }
+ return this.getName().toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString() {
+ return getString(Path.DEFAULT_ENCODER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getString( TextEncoder encoder ) {
+ if (encoder == null) encoder = Path.DEFAULT_ENCODER;
+ String encodedName = this.getName().getString(encoder);
+ if (this.hasIndex()) {
+ return encodedName + "[" + this.getIndex() + "]";
+ }
+ return encodedName;
+ }
+
+}
Added: branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java
===================================================================
--- branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java (rev 0)
+++ branches/federation/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinary.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,107 @@
+/*
+ * 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 java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.spi.graph.Binary;
+import org.jboss.dna.spi.graph.PropertyValues;
+
+/**
+ * An implementation of {@link Binary} that keeps the binary data in-memory.
+ * @author Randall Hauch
+ */
+@Immutable
+public class InMemoryBinary implements Binary {
+
+ private byte[] bytes;
+
+ public InMemoryBinary( byte[] bytes ) {
+ ArgCheck.isNotNull(bytes, "bytes");
+ this.bytes = bytes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getSize() {
+ return this.bytes.length;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getBytes() {
+ return this.bytes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public InputStream getStream() {
+ return new ByteArrayInputStream(this.bytes);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void acquire() {
+ // do nothing
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void release() {
+ // do nothing
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compareTo( Binary o ) {
+ return PropertyValues.BINARY_COMPARATOR.compare(this, o);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void readExternal( ObjectInput in ) throws IOException {
+ int length = in.readInt();
+ this.bytes = new byte[length];
+ in.read(this.bytes);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void writeExternal( ObjectOutput out ) throws IOException {
+ out.write(this.bytes.length);
+ out.write(this.bytes);
+ }
+
+}
Added: branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties
===================================================================
--- branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties (rev 0)
+++ branches/federation/dna-spi/src/main/resources/org/jboss/dna/spi/SpiI18n.properties 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,13 @@
+unableToDiscoverPropertyType = Unable to discover property type for {0}
+errorReadingPropertyValueBytes = Error reading bytes
+valueJavaTypeNotCompatibleWithPropertyType = Value is instance of Java type "{0}" and is not compatible with the "{1}" property type
+
+errorConvertingBinaryValueToString = Error while interpretting binary value as a UTF-8 string
+
+pathAncestorDegreeIsInvalid = Unable to obtain the {1} ancestor for {0}
+pathIsAlreadyAbsolute = The path {0} is already an absolute path
+pathIsNotAbsolute = The path {0} is not an absolute path
+pathIsNotRelative = The path {0} is not a relative path
+pathCannotBeNormalized = The path {0} is invalid and cannot be normalized
+
+invalidQualifiedNameString = Unable to parse qualified name from "{0}"
\ No newline at end of file
Added: branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/SpiI18nTest.java
===================================================================
--- branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/SpiI18nTest.java (rev 0)
+++ branches/federation/dna-spi/src/test/java/org/jboss/dna/spi/SpiI18nTest.java 2008-05-15 20:21:25 UTC (rev 175)
@@ -0,0 +1,16 @@
+/*
+ *
+ */
+package org.jboss.dna.spi;
+
+import org.jboss.dna.common.AbstractI18nTest;
+
+/**
+ * @author Randall Hauch
+ */
+public class SpiI18nTest extends AbstractI18nTest {
+
+ public SpiI18nTest() {
+ super(SpiI18n.class);
+ }
+}
17 years, 11 months