DNA SVN: r533 - in trunk: dna-graph and 18 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-09-18 12:00:42 -0400 (Thu, 18 Sep 2008)
New Revision: 533
Added:
trunk/dna-graph/
Removed:
trunk/dna-spi/
Modified:
trunk/dna-graph/.project
trunk/dna-graph/pom.xml
trunk/dna-jcr/pom.xml
trunk/dna-repository/pom.xml
trunk/dna-repository/src/test/resources/master.xml
trunk/docs/examples/gettingstarted/pom.xml
trunk/docs/gettingstarted/src/main/docbook/en-US/content/custom_sequencers.xml
trunk/docs/reference/en/master.xml
trunk/docs/reference/src/main/docbook/en-US/content/introduction.xml
trunk/extensions/dna-connector-federation/pom.xml
trunk/extensions/dna-connector-inmemory/pom.xml
trunk/extensions/dna-connector-jbosscache/pom.xml
trunk/extensions/dna-mimetype-detector-aperture/pom.xml
trunk/extensions/dna-sequencer-cnd/pom.xml
trunk/extensions/dna-sequencer-esbMessage/pom.xml
trunk/extensions/dna-sequencer-images/pom.xml
trunk/extensions/dna-sequencer-java/pom.xml
trunk/extensions/dna-sequencer-mp3/pom.xml
trunk/extensions/dna-sequencer-msoffice/dna-sequencer-msoffice.iml
trunk/extensions/dna-sequencer-msoffice/pom.xml
trunk/extensions/dna-sequencer-zip/pom.xml
trunk/pom.xml
Log:
Restructured the 'dna-spi' project to 'dna-graph' so that it's possible to be a home for the graph API in the upcoming release.
Copied: trunk/dna-graph (from rev 532, trunk/dna-spi)
Modified: trunk/dna-graph/.project
===================================================================
--- trunk/dna-spi/.project 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/dna-graph/.project 2008-09-18 16:00:42 UTC (rev 533)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>dna-spi</name>
+ <name>dna-graph</name>
<comment></comment>
<projects>
</projects>
Modified: trunk/dna-graph/pom.xml
===================================================================
--- trunk/dna-spi/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/dna-graph/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -6,10 +6,10 @@
<version>0.2-SNAPSHOT</version>
</parent>
<!-- The groupId and version values are inherited from parent -->
- <artifactId>dna-spi</artifactId>
- <description>The JBoss DNA Service Provider Interface (SPI) used to create extensions</description>
+ <artifactId>dna-graph</artifactId>
+ <description>The JBoss DNA Graph API and SPI interfaces</description>
<packaging>jar</packaging>
- <name>JBoss DNA Service Provider Interface (SPI)</name>
+ <name>JBoss DNA Graph</name>
<url>http://labs.jboss.org/dna</url>
<properties>
Modified: trunk/dna-jcr/pom.xml
===================================================================
--- trunk/dna-jcr/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/dna-jcr/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -34,11 +34,11 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>${dna-version}</version>
<type>test-jar</type>
<scope>test</scope>
Modified: trunk/dna-repository/pom.xml
===================================================================
--- trunk/dna-repository/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/dna-repository/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -34,11 +34,11 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>${dna-version}</version>
<type>test-jar</type>
<scope>test</scope>
Modified: trunk/dna-repository/src/test/resources/master.xml
===================================================================
--- trunk/dna-repository/src/test/resources/master.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/dna-repository/src/test/resources/master.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -1532,7 +1532,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>0.1</version>
</dependency>
<dependency>
Modified: trunk/docs/examples/gettingstarted/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/docs/examples/gettingstarted/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -26,7 +26,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>${dna-version}</version>
</dependency>
<dependency>
Modified: trunk/docs/gettingstarted/src/main/docbook/en-US/content/custom_sequencers.xml
===================================================================
--- trunk/docs/gettingstarted/src/main/docbook/en-US/content/custom_sequencers.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/docs/gettingstarted/src/main/docbook/en-US/content/custom_sequencers.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -76,7 +76,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>0.1</version>
</dependency>
<dependency>
Modified: trunk/docs/reference/en/master.xml
===================================================================
--- trunk/docs/reference/en/master.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/docs/reference/en/master.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -182,9 +182,9 @@
</listitem>
<listitem>
<para>
- <emphasis role="strong">dna-spi</emphasis>
- defines the Service Provider Interface (SPI) for DNA, including the repository connectors, sequencers, graph
- interfaces, and MIME type detectors.
+ <emphasis role="strong">dna-graph</emphasis>
+ defines the graph Application Programming Interface (API) and Service Provider Interface (SPI) for DNA,
+ including the repository connectors, sequencers, graph interfaces, and MIME type detectors.
</para>
</listitem>
<listitem>
Modified: trunk/docs/reference/src/main/docbook/en-US/content/introduction.xml
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/content/introduction.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/docs/reference/src/main/docbook/en-US/content/introduction.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -135,9 +135,9 @@
</listitem>
<listitem>
<para>
- <emphasis role="strong">dna-spi</emphasis>
- defines the Service Provider Interface (SPI) for DNA, including the repository connectors, sequencers, graph
- interfaces, and MIME type detectors.
+ <emphasis role="strong">dna-graph</emphasis>
+ defines the graph Application Programming Interface (API) and Service Provider Interface (SPI) for DNA,
+ including the repository connectors, sequencers, graph interfaces, and MIME type detectors.
</para>
</listitem>
<listitem>
Modified: trunk/extensions/dna-connector-federation/pom.xml
===================================================================
--- trunk/extensions/dna-connector-federation/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-connector-federation/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -31,7 +31,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
@@ -42,7 +42,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>${dna-version}</version>
<type>test-jar</type>
<scope>test</scope>
Modified: trunk/extensions/dna-connector-inmemory/pom.xml
===================================================================
--- trunk/extensions/dna-connector-inmemory/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-connector-inmemory/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -31,7 +31,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
@@ -42,7 +42,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>${dna-version}</version>
<type>test-jar</type>
<scope>test</scope>
Modified: trunk/extensions/dna-connector-jbosscache/pom.xml
===================================================================
--- trunk/extensions/dna-connector-jbosscache/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-connector-jbosscache/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -31,7 +31,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
@@ -42,7 +42,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>${dna-version}</version>
<type>test-jar</type>
<scope>test</scope>
Modified: trunk/extensions/dna-mimetype-detector-aperture/pom.xml
===================================================================
--- trunk/extensions/dna-mimetype-detector-aperture/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-mimetype-detector-aperture/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
Modified: trunk/extensions/dna-sequencer-cnd/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-cnd/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-sequencer-cnd/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -20,7 +20,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
<dependency>
Modified: trunk/extensions/dna-sequencer-esbMessage/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-esbMessage/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-sequencer-esbMessage/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -19,7 +19,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
Modified: trunk/extensions/dna-sequencer-images/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-images/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-sequencer-images/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -30,7 +30,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
@@ -41,7 +41,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>${dna-version}</version>
<type>test-jar</type>
<scope>test</scope>
Modified: trunk/extensions/dna-sequencer-java/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-java/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-sequencer-java/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -34,7 +34,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
@@ -45,7 +45,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>${dna-version}</version>
<type>test-jar</type>
<scope>test</scope>
Modified: trunk/extensions/dna-sequencer-mp3/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-mp3/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-sequencer-mp3/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -19,7 +19,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.jaudiotagger</groupId>
Modified: trunk/extensions/dna-sequencer-msoffice/dna-sequencer-msoffice.iml
===================================================================
--- trunk/extensions/dna-sequencer-msoffice/dna-sequencer-msoffice.iml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-sequencer-msoffice/dna-sequencer-msoffice.iml 2008-09-18 16:00:42 UTC (rev 533)
@@ -43,7 +43,7 @@
</SOURCES>
</library>
</orderEntry>
- <orderEntry type="module" module-name="dna-spi" exported="" />
+ <orderEntry type="module" module-name="dna-graph" exported="" />
<orderEntry type="module-library" exported="">
<library name="joda-time:joda-time:1.4">
<CLASSES>
Modified: trunk/extensions/dna-sequencer-msoffice/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-msoffice/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-sequencer-msoffice/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -26,7 +26,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
Modified: trunk/extensions/dna-sequencer-zip/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-zip/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/extensions/dna-sequencer-zip/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -26,7 +26,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
+++ trunk/pom.xml 2008-09-18 16:00:42 UTC (rev 533)
@@ -112,7 +112,7 @@
</contributors>
<modules>
<module>dna-common</module>
- <module>dna-spi</module>
+ <module>dna-graph</module>
<module>dna-repository</module>
<module>dna-jcr</module>
<module>extensions/dna-classloader-maven</module>
@@ -354,7 +354,7 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-spi</artifactId>
+ <artifactId>dna-graph</artifactId>
<version>${dna-version}</version>
</dependency>
<dependency>
15 years, 7 months
DNA SVN: r532 - in trunk/docs/examples/gettingstarted: sequencers and 10 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-09-17 19:03:19 -0400 (Wed, 17 Sep 2008)
New Revision: 532
Added:
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ContentInfo.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/JavaInfo.java
trunk/docs/examples/gettingstarted/sequencers/workspace/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/MySource.java
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java
trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/package-info.java
Removed:
trunk/docs/examples/gettingstarted/dna-example-java-sequencer/
Modified:
trunk/docs/examples/gettingstarted/pom.xml
trunk/docs/examples/gettingstarted/sequencers/pom.xml
trunk/docs/examples/gettingstarted/sequencers/src/main/assembly/basic.xml
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ConsoleInput.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/MediaInfo.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/UserInterface.java
trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/MockUserInterface.java
trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/SequencingClientTest.java
Log:
DNA-222 Create Getting Started example application for repositories
Refactored the java sequencer example project so that it's included in the 'sequencer' example. Most of the code was duplicated, and this makes the Getting Started document much easier to understand as well, since all sequencing code is in the one example.
Modified: trunk/docs/examples/gettingstarted/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/pom.xml 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
@@ -10,7 +10,7 @@
<modules>
<module>sequencers</module>
- <module>dna-example-java-sequencer</module>
+ <module>repositories</module>
</modules>
<properties>
@@ -36,6 +36,11 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
+ <artifactId>dna-jcr</artifactId>
+ <version>${dna-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
<artifactId>dna-maven-classloader</artifactId>
<version>${dna-version}</version>
</dependency>
@@ -44,6 +49,27 @@
<artifactId>dna-sequencer-images</artifactId>
<version>${dna-version}</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-sequencer-java</artifactId>
+ <version>${dna-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-connector-inmemory</artifactId>
+ <version>${dna-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-connector-jbosscache</artifactId>
+ <version>${dna-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-connector-federation</artifactId>
+ <version>${dna-version}</version>
+ <scope>runtime</scope>
+ </dependency>
<!-- Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing) -->
<dependency>
<groupId>org.slf4j</groupId>
@@ -109,6 +135,12 @@
<version>4.4</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.5</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
Modified: trunk/docs/examples/gettingstarted/sequencers/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/pom.xml 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/pom.xml 2008-09-17 23:03:19 UTC (rev 532)
@@ -44,6 +44,12 @@
<version>${dna-version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-sequencer-java</artifactId>
+ <version>${dna-version}</version>
+ <scope>runtime</scope>
+ </dependency>
<!--
Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing)
-->
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/assembly/basic.xml
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/assembly/basic.xml 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/assembly/basic.xml 2008-09-17 23:03:19 UTC (rev 532)
@@ -23,6 +23,11 @@
<include>*.mp3</include>
</includes>
</fileSet>
+ <fileSet>
+ <directory>workspace/</directory>
+ <outputDirectory/>
+ <useDefaultExcludes>true</useDefaultExcludes>
+ </fileSet>
</fileSets>
<files>
<file>
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ConsoleInput.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ConsoleInput.java 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ConsoleInput.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -27,7 +27,6 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.util.List;
-import java.util.Map;
import org.jboss.dna.repository.sequencers.SequencingService;
/**
@@ -173,27 +172,22 @@
return path;
}
- public void displaySearchResults( List<MediaInfo> medias ) {
+ public void displaySearchResults( List<ContentInfo> contentInfos ) {
System.out.println();
- if (medias.isEmpty()) {
+ if (contentInfos.isEmpty()) {
System.out.println("No results were found.");
System.out.println();
return;
}
- if (medias.size() == 1) {
- System.out.println("1 image was found:");
+ if (contentInfos.size() == 1) {
+ System.out.println("1 result was found:");
} else {
- System.out.println("" + medias.size() + " images were found:");
+ System.out.println("" + contentInfos.size() + " results were found:");
}
int counter = 1;
- for (MediaInfo media : medias) {
- System.out.println(" Media " + counter++);
- System.out.println(" Name: " + media.getName());
- System.out.println(" Path: " + media.getPath());
- System.out.println(" Type: " + media.getMediaType());
- for (Map.Entry<Object, Object> entry : media.getProperties().entrySet()) {
- System.out.println(" " + entry.getKey() + ": " + entry.getValue());
- }
+ for (ContentInfo info : contentInfos) {
+ System.out.println(" " + info.getInfoType() + " " + counter++);
+ System.out.println(info.toString());
}
System.out.println();
}
Added: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ContentInfo.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ContentInfo.java (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/ContentInfo.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -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.example.dna.sequencers;
+
+import java.util.Map;
+import java.util.Properties;
+import net.jcip.annotations.Immutable;
+
+/**
+ * @author Randall Hauch
+ */
+@Immutable
+public class ContentInfo {
+
+ private final Properties properties = new Properties();
+ private final String name;
+ private final String path;
+
+ protected ContentInfo( String path,
+ String name,
+ Properties props ) {
+ this.name = name;
+ this.path = path;
+ if (props != null) this.properties.putAll(props);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getPath() {
+ return this.path;
+ }
+
+ public Properties getProperties() {
+ return this.properties;
+ }
+
+ public String getInfoType() {
+ return this.getClass().getSimpleName().replaceAll("Info$", "");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(" Name: " + getName() + "\n");
+ sb.append(" Path: " + getPath() + "\n");
+ for (Map.Entry<Object, Object> entry : getProperties().entrySet()) {
+ sb.append(" " + entry.getKey() + ": " + entry.getValue() + "\n");
+ }
+ return sb.toString();
+ }
+
+}
Added: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/JavaInfo.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/JavaInfo.java (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/JavaInfo.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.example.dna.sequencers;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import net.jcip.annotations.Immutable;
+
+/**
+ * @author Serge Pagop
+ * @author Randall Hauch
+ */
+@Immutable
+public class JavaInfo extends ContentInfo {
+
+ private final Map<String, List<Properties>> javaElements;
+ private final String type;
+
+ protected JavaInfo( String path,
+ String name,
+ String type,
+ Map<String, List<Properties>> javaElements ) {
+ super(path, name, null);
+ this.type = type;
+ this.javaElements = javaElements != null ? new TreeMap<String, List<Properties>>(javaElements) : new TreeMap<String, List<Properties>>();
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ /**
+ * @return javaElements
+ */
+ public Map<String, List<Properties>> getJavaElements() {
+ return javaElements;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(" Name: " + getName() + "\n");
+ sb.append(" Path: " + getPath() + "\n");
+ sb.append(" Type: " + getType() + "\n");
+ for (Map.Entry<Object, Object> entry : getProperties().entrySet()) {
+ sb.append(" " + entry.getKey() + ": " + entry.getValue() + "\n");
+ }
+ for (Map.Entry<String, List<Properties>> javaElement : getJavaElements().entrySet()) {
+ sb.append("\n ------ " + javaElement.getKey() + " ------\n");
+ for (Properties props : javaElement.getValue()) {
+ for (Map.Entry<Object, Object> entry : props.entrySet()) {
+ if (!entry.getKey().equals("jcr:primaryType")) {
+ sb.append(" " + entry.getKey() + " => " + entry.getValue() + "\n");
+ }
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+}
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/MediaInfo.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/MediaInfo.java 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/MediaInfo.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -23,53 +23,38 @@
import java.util.Map;
import java.util.Properties;
+import net.jcip.annotations.Immutable;
/**
* @author Randall Hauch
*/
-public class MediaInfo {
+@Immutable
+public class MediaInfo extends ContentInfo {
- private final Properties properties = new Properties();
- private final String name;
- private final String path;
private final String mediaType;
- protected MediaInfo( String path, String name, String mediaType, Properties props ) {
- this.name = name;
- this.path = path;
+ protected MediaInfo( String path,
+ String name,
+ String mediaType,
+ Properties props ) {
+ super(path, name, props);
this.mediaType = mediaType;
- if (props != null) this.properties.putAll(props);
}
- public String getName() {
- return this.name;
- }
-
- public String getPath() {
- return this.path;
- }
-
public String getMediaType() {
return this.mediaType;
}
- public Properties getProperties() {
- return this.properties;
- }
-
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (Map.Entry<Object, Object> entry : this.properties.entrySet()) {
- sb.append(entry.getKey()).append("=>").append(entry.getValue());
- if (first) {
- first = false;
- } else {
- sb.append(", ");
- }
+ sb.append(" Name: " + getName() + "\n");
+ sb.append(" Path: " + getPath() + "\n");
+ sb.append(" Type: " + getMediaType() + "\n");
+ for (Map.Entry<Object, Object> entry : getProperties().entrySet()) {
+ sb.append(" " + entry.getKey() + ": " + entry.getValue() + "\n");
}
- return this.name + " (at " + this.path + ") of type \"" + this.mediaType + "\" with properties {" + sb.toString() + "}";
+ return sb.toString();
}
}
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -26,7 +26,9 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import javax.jcr.Credentials;
import javax.jcr.Node;
@@ -253,6 +255,14 @@
SequencerConfig mp3SequencerConfig = new SequencerConfig(name, desc, classname, classpath, mp3PathExpressions);
this.sequencingService.addSequencer(mp3SequencerConfig);
+ // Set up the MP3 sequencer ...
+ name = "Java Sequencer";
+ desc = "Sequences java files to extract the characteristics of the java sources";
+ classname = "org.jboss.dna.sequencer.java.JavaMetadataSequencer";
+ String[] javaPathExpressions = {"//(*.java[*])/jcr:content[@jcr:data] => /compilationUnits/$1"};
+ SequencerConfig javaSequencerConfig = new SequencerConfig(name, desc, classname, classpath, javaPathExpressions);
+ this.sequencingService.addSequencer(javaSequencerConfig);
+
// Use the DNA observation service to listen to the JCR repository (or multiple ones), and
// then register the sequencing service as a listener to this observation service...
this.observationService = new ObservationService(this.executionContext.getSessionFactory());
@@ -330,10 +340,10 @@
*/
public void search() throws Exception {
// Use JCR to search the repository for image metadata ...
- List<MediaInfo> medias = new ArrayList<MediaInfo>();
+ List<ContentInfo> infos = new ArrayList<ContentInfo>();
Session session = createSession();
try {
- // Find the image node ...
+ // Find the node ...
Node root = session.getRootNode();
if (root.hasNode("images") || root.hasNode("mp3s")) {
@@ -344,7 +354,7 @@
for (NodeIterator iter = mediasNode.getNodes(); iter.hasNext();) {
Node mediaNode = iter.nextNode();
if (mediaNode.hasNode("image:metadata")) {
- medias.add(extractMediaInfo("image:metadata", "image", mediaNode));
+ infos.add(extractMediaInfo("image:metadata", "image", mediaNode));
}
}
}
@@ -354,18 +364,118 @@
for (NodeIterator iter = mediasNode.getNodes(); iter.hasNext();) {
Node mediaNode = iter.nextNode();
if (mediaNode.hasNode("mp3:metadata")) {
- medias.add(extractMediaInfo("mp3:metadata", "mp3", mediaNode));
+ infos.add(extractMediaInfo("mp3:metadata", "mp3", mediaNode));
}
}
}
+ } else if (root.hasNode("compilationUnits")) {
+ Map<String, List<Properties>> tree = new TreeMap<String, List<Properties>>();
+ // Find the compilation unit node ...
+ List<Properties> javaElements;
+ if (root.hasNode("compilationUnits")) {
+ Node javaSourcesNode = root.getNode("compilationUnits");
+ for (NodeIterator i = javaSourcesNode.getNodes(); i.hasNext();) {
+
+ Node javaSourceNode = i.nextNode();
+
+ if (javaSourceNode.hasNodes()) {
+ Node javaCompilationUnit = javaSourceNode.getNodes().nextNode();
+ // package informations
+
+ javaElements = new ArrayList<Properties>();
+ try {
+ Node javaPackageDeclarationNode = javaCompilationUnit.getNode("java:package/java:packageDeclaration");
+ javaElements.add(extractJavaInfo(javaPackageDeclarationNode));
+ tree.put("Class package", javaElements);
+ } catch (PathNotFoundException e) {
+ // do nothing
+ }
+
+ // import informations
+ javaElements = new ArrayList<Properties>();
+ try {
+ for (NodeIterator singleImportIterator = javaCompilationUnit.getNode("java:import/java:importDeclaration/java:singleImport").getNodes(); singleImportIterator.hasNext();) {
+ Node javasingleTypeImportDeclarationNode = singleImportIterator.nextNode();
+ javaElements.add(extractJavaInfo(javasingleTypeImportDeclarationNode));
+ }
+ tree.put("Class single Imports", javaElements);
+ } catch (PathNotFoundException e) {
+ // do nothing
+ }
+
+ javaElements = new ArrayList<Properties>();
+ try {
+ for (NodeIterator javaImportOnDemandIterator = javaCompilationUnit.getNode("java:import/java:importDeclaration/java:importOnDemand").getNodes(); javaImportOnDemandIterator.hasNext();) {
+ Node javaImportOnDemandtDeclarationNode = javaImportOnDemandIterator.nextNode();
+ javaElements.add(extractJavaInfo(javaImportOnDemandtDeclarationNode));
+ }
+ tree.put("Class on demand imports", javaElements);
+
+ } catch (PathNotFoundException e) {
+ // do nothing
+ }
+ // class head informations
+ javaElements = new ArrayList<Properties>();
+ Node javaNormalDeclarationClassNode = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration");
+ javaElements.add(extractJavaInfo(javaNormalDeclarationClassNode));
+ tree.put("Class head information", javaElements);
+
+ // field member informations
+ javaElements = new ArrayList<Properties>();
+ for (NodeIterator javaFieldTypeIterator = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:field/java:fieldType").getNodes(); javaFieldTypeIterator.hasNext();) {
+ Node rootFieldTypeNode = javaFieldTypeIterator.nextNode();
+ if (rootFieldTypeNode.hasNode("java:primitiveType")) {
+ Node javaPrimitiveTypeNode = rootFieldTypeNode.getNode("java:primitiveType");
+ javaElements.add(extractJavaInfo(javaPrimitiveTypeNode));
+ // more informations
+ }
+
+ if (rootFieldTypeNode.hasNode("java:simpleType")) {
+ Node javaSimpleTypeNode = rootFieldTypeNode.getNode("java:simpleType");
+ javaElements.add(extractJavaInfo(javaSimpleTypeNode));
+ }
+ if (rootFieldTypeNode.hasNode("java:parameterizedType")) {
+ Node javaParameterizedType = rootFieldTypeNode.getNode("java:parameterizedType");
+ javaElements.add(extractJavaInfo(javaParameterizedType));
+ }
+ if (rootFieldTypeNode.hasNode("java:arrayType")) {
+ Node javaArrayType = rootFieldTypeNode.getNode("java:arrayType[2]");
+ javaElements.add(extractJavaInfo(javaArrayType));
+ }
+ }
+ tree.put("Class field members", javaElements);
+
+ // constructor informations
+ javaElements = new ArrayList<Properties>();
+ for (NodeIterator javaConstructorIterator = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:constructor").getNodes(); javaConstructorIterator.hasNext();) {
+ Node javaConstructor = javaConstructorIterator.nextNode();
+ javaElements.add(extractJavaInfo(javaConstructor));
+ }
+ tree.put("Class constructors", javaElements);
+
+ // method informations
+ javaElements = new ArrayList<Properties>();
+ for (NodeIterator javaMethodIterator = javaCompilationUnit.getNode("java:unitType/java:classDeclaration/java:normalClass/java:normalClassDeclaration/java:method").getNodes(); javaMethodIterator.hasNext();) {
+ Node javaMethod = javaMethodIterator.nextNode();
+ javaElements.add(extractJavaInfo(javaMethod));
+ }
+ tree.put("Class member functions", javaElements);
+
+ JavaInfo javaInfo = new JavaInfo(javaCompilationUnit.getPath(), javaCompilationUnit.getName(),
+ "java source", tree);
+ infos.add(javaInfo);
+ }
+ }
+ }
+
}
} finally {
session.logout();
}
// Display the search results ...
- this.userInterface.displaySearchResults(medias);
+ this.userInterface.displaySearchResults(infos);
}
private MediaInfo extractMediaInfo( String metadataNodeName,
@@ -402,6 +512,29 @@
}
/**
+ * Extract informations from a specific node.
+ *
+ * @param node - node, that contains informations.
+ * @return a properties of keys/values.
+ * @throws RepositoryException
+ * @throws IllegalStateException
+ * @throws ValueFormatException
+ */
+ private Properties extractJavaInfo( Node node ) throws ValueFormatException, IllegalStateException, RepositoryException {
+ if (node.hasProperties()) {
+ Properties properties = new Properties();
+ for (PropertyIterator propertyIter = node.getProperties(); propertyIter.hasNext();) {
+ Property property = propertyIter.nextProperty();
+ String name = property.getName();
+ String stringValue = property.getValue().getString();
+ properties.put(name, stringValue);
+ }
+ return properties;
+ }
+ return null;
+ }
+
+ /**
* Utility method to create a new JCR session from the execution context's {@link SessionFactory}.
*
* @return the session
@@ -422,6 +555,7 @@
if (filename.endsWith(".jpeg")) return "image/jpeg";
if (filename.endsWith(".ras")) return "image/x-cmu-raster";
if (filename.endsWith(".mp3")) return "audio/mpeg";
+ if (filename.endsWith(".java")) return "text/x-java-source";
throw new SystemFailureException("Unknown mime type for " + file);
}
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/UserInterface.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/UserInterface.java 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/UserInterface.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -34,5 +34,5 @@
public String getRepositoryPath( String defaultPath ) throws IllegalArgumentException, IOException;
- public void displaySearchResults( List<MediaInfo> images ) throws IOException;
+ public void displaySearchResults( List<ContentInfo> contentInfo ) throws IOException;
}
Modified: trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/src/main/resources/jackrabbitNodeTypes.cnd 2008-09-17 23:03:19 UTC (rev 532)
@@ -3,6 +3,8 @@
<mix='http://www.jcp.org/jcr/mix/1.0'>
<image='http://jboss.org/dna/images/1.0'>
<mp3='http://jboss.org/dna/mp3/1.0'>
+<java='http://www.jboss.org/dna/java/1.0'>
+
// ----------------------------------------------------------
// JCR Pre-defined Mixin Types that are not loaded by default
// ----------------------------------------------------------
@@ -32,6 +34,10 @@
- image:physicalWidthInches (long)
- image:physicalHeightInches (long)
+// -------------------
+// DNA MP3 Sequencer
+// -------------------
+
/**
* Node type that defines the metadata for an MP3 audio file
*/
@@ -42,4 +48,217 @@
- mp3:year (long)
- mp3:comment (string)
+// -------------------
+// DNA Java Sequencer
+// -------------------
+/**
+ * Node types that define metadata for a Java source file
+ */
+/**
+ * Element-value
+ */
+[java:elementValue] > nt:unstructured
+ + java:kindOfvalues (java:conditionalExpression, java:annotationDeclaration, java:elementValueArrayInitializer) mandatory
+
+/**
+ * Modifiers
+ */
+[java:modifierDeclaration] > nt:unstructured
+ - java:modifierName (string) mandatory
+
+/**
+ * Expression element-value type
+ */
+[java:conditionalExpression] > nt:unstructured
+ - java:expression (string)
+
+/**
+ * Array initializer element-value type
+ */
+[java:elementValueArrayInitializer] > nt:unstructured
+ + java:elementValue (java:elementValue) = java:elementValue multiple
+
+/**
+ * Identifier
+ */
+[java:identifier] > nt:unstructured
+ - java:identifierName (String) mandatory
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Element-value pair
+ */
+[java:elementValuePair] > nt:unstructured
+ + java:identifier (java:identifier) mandatory
+
+/**
+ * Annotation type
+ */
+[java:annotationDeclaration] > nt:unstructured
+ + java:annotationType (java:normalAnnotation, java:markerAnnotation, java:singleElementAnnotation) mandatory
+
+/**
+ * Normal annotation e.g. @Entity(name="Customer")
+ */
+[java:normalAnnotation] > nt:unstructured
+ - java:normalAnnotationName (string) mandatory
+ + java:elementValuePair (java:elementValuePair)
+
+/**
+ * Marker annotation e.g. @GET
+ */
+[java:markerAnnotation] > nt:unstructured
+ - java:markerAnnotationName (string) mandatory
+
+/**
+ * Single element annotation e.g. @Path("/book")
+ */
+[java:singleElementAnnotation] > nt:unstructured
+ - java:singleElementAnnotationNam
+ + java:value (java:elementValue) = java:elementValue mandatory
+
+/**
+ * Formal parameter
+ */
+[java:formalParameter] > nt:unstructured
+ + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType)
+
+/**
+ * Primitive type:
+ * - Integral type ('byte', 'short', 'int', 'long', 'char')
+ * - Floating point type ('float', 'double')
+ * - Boolean type ('boolean')
+ * - No return type ('void')
+ */
+[java:primitiveType] > nt:unstructured
+ - java:primitiveTypeDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:primitiveTypeName (string) mandatory
+ + java:primitiveVariable (java:variable) = java:variable
+
+ [java:variable] > nt:unstructured
+ - java:variableName (string) mandatory
+
+/**
+ * java:arrayType
+ */
+[java:arrayType] > nt:unstructured
+ - java:arrayTypeDescription (string)
+ + java:arrayTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:arrayTypeName (string) mandatory
+ + java:arrayTypeVariable (java:variable) = java:variable
+
+[java:simpleType] > nt:unstructured
+ - java:simpleTypeDescription (string)
+ + java:simpleTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:simpleTypeName (string) mandatory
+ + java:simpleTypeVariable (java:variable) = java:variable
+
+[java:qualifiedType] > nt:unstructured
+ - java:qualifiedTypeDescription (string)
+ + java:qualifiedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:qualifiedTypeName (string) mandatory
+ + java:qualifiedTypeVariable (java:variable) = java:variable
+
+[java:wildcardType] > nt:unstructured
+ - java:wildcardTypeDescription (string)
+ + java:wildcardTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:wildcardTypeName (string) mandatory
+ + java:wildcardTypeVariable (java:variable) = java:variable
+
+[java:parameterizedType] > nt:unstructured
+ - java:parameterizedTypeDescription (string)
+ + java:parameterizedTypeModifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:parameterizedTypeName (string) mandatory
+ + java:parameterizedTypeVariable (java:variable) = java:variable
+
+/**
+ * Field type
+ */
+[java:fieldType] > nt:unstructured
+ + java:type (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory multiple
+
+ /**
+ * Method declaration
+ */
+[java:methodDeclaration] > nt:unstructured
+ - java:methodDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ + java:resultType (java:primitiveType, java:arrayType, java:simpleType, java:qualifiedType, java:wildcardType, java:parameterizedType) mandatory
+ - java:methodName (string) mandatory
+ + java:parameter (java:formalParameter) multiple
+
+/**
+ * Constructor declarations
+ */
+[java:constructorDeclaration] > nt:unstructured
+ - java:constructorDescription (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:constructorName (string) mandatory
+ + java:parameter (java:formalParameter)
+
+
+/**
+ * Package declarations
+ */
+[java:packageDeclaration] > nt:unstructured
+ + java:annotation (java:annotationDeclaration) = java:annotationDeclaration
+ - java:packageKeyword (string)
+ < 'package'
+ - java:packageName (string) mandatory
+
+/**
+ * Import declarations
+ */
+[java:singleTypeImportDeclaration] > nt:unstructured
+ - java:singleTypeImportkeyword (string) mandatory
+ < 'import'
+ - java:singleImportName (string) mandatory
+
+[java:typeImportOnDemandDeclaration] > nt:unstructured
+ - java:onDemandImportKeyword (string) mandatory
+ < 'import'
+ - java:onDemandImportName (string) mandatory
+
+ [java:importDeclaration] > nt:unstructured
+ + java:singleImport (java:singleTypeImportDeclaration) = java:singleTypeImportDeclaration
+ + java:importOnDemand (java:typeImportOnDemandDeclaration) = java:typeImportOnDemandDeclaration
+
+
+/**
+ * Class declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+[java:normalClassDeclaration] > nt:unstructured
+ - java:description (string)
+ + java:modifier (java:modifierDeclaration) = java:modifierDeclaration
+ - java:normalClassName (string) mandatory
+ + java:field (java:fieldType) = java:fieldType multiple
+ + java:method (java:methodDeclaration) = java:methodDeclaration multiple
+ + java:constructor (java:constructorDeclaration) = java:constructorDeclaration multiple
+
+[java:enumDeclaration] > nt:unstructured // TODO
+
+[java:classDeclaration] > nt:unstructured
+ + java:normalClass (java:normalClassDeclaration) = java:normalClassDeclaration
+ + java:enum (java:enumDeclaration) = java:enumDeclaration
+
+/**
+ * Interface declaration
+ *
+ * The body of class declares members (fields and methods and nested classes and interfaces),
+ * instance and static initializers, and constructors
+ */
+[java:interfaceDeclaration] > nt:unstructured
+
+
+/**
+ * Compilation unit
+ */
+[java:compilationUnit] > nt:unstructured
+ + java:package (java:packageDeclaration) = java:packageDeclaration
+ + java:import (java:importDeclaration) = java:importDeclaration
+ + java:unitType (java:classDeclaration, java:interfaceDeclaration)
Modified: trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/MockUserInterface.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/MockUserInterface.java 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/MockUserInterface.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -46,10 +46,11 @@
/**
* {@inheritDoc}
*/
- public void displaySearchResults( List<MediaInfo> images ) {
- assertThat(images.size(), is(this.numberOfSearchResults));
- for (MediaInfo image : images) {
- System.out.println("Image: " + image);
+ public void displaySearchResults( List<ContentInfo> infos ) {
+ assertThat(infos.size(), is(this.numberOfSearchResults));
+ for (ContentInfo info : infos) {
+ System.out.println("Info: ");
+ System.out.println(info);
}
}
Modified: trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/SequencingClientTest.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/SequencingClientTest.java 2008-09-17 22:56:29 UTC (rev 531)
+++ trunk/docs/examples/gettingstarted/sequencers/src/test/java/org/jboss/example/dna/sequencers/SequencingClientTest.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -24,6 +24,9 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import org.jboss.dna.common.util.FileUtil;
import org.junit.After;
@@ -39,14 +42,18 @@
private URL pictImageUrl;
private URL jpegImageUrl;
private URL mp3Url;
+ private URL javaSourceUrl;
private SequencingClient client;
@Before
- public void beforeEach() {
+ public void beforeEach() throws MalformedURLException {
this.pngImageUrl = Thread.currentThread().getContextClassLoader().getResource("caution.png");
this.pictImageUrl = Thread.currentThread().getContextClassLoader().getResource("caution.pict");
this.jpegImageUrl = Thread.currentThread().getContextClassLoader().getResource("caution.jpg");
this.mp3Url = Thread.currentThread().getContextClassLoader().getResource("sample1.mp3");
+ // Get the URL of source (MySource.java), that have to be sequencing
+ this.javaSourceUrl = FileUtil.convertFileToURL("workspace/project1/src/org/acme/MySource.java");
+
client = new SequencingClient();
client.setWorkingDirectory("target/repositoryData");
client.setJackrabbitConfigPath("src/main/resources/jackrabbitConfig.xml");
@@ -159,4 +166,35 @@
assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1l));
}
+ @Test
+ public void shouldFindCompilationUnitSource() throws IOException {
+ assertThat(this.javaSourceUrl, is(notNullValue()));
+ InputStream stream = this.javaSourceUrl.openStream();
+ try {
+ byte[] buffer = new byte[1024];
+ while (stream.read(buffer) != -1) {
+ }
+ } finally {
+ stream.close();
+ }
+ }
+
+ @Test
+ public void shouldUploadAndSequenceJavaSourceFile() throws Exception {
+ client.setUserInterface(new MockUserInterface(this.javaSourceUrl, "/a/b/MySource.java", 1));
+ client.startRepository();
+ client.startDnaServices();
+ client.uploadFile();
+
+ // Use a trick to wait until the sequencing has been done by sleeping (to give the sequencing time to start)
+ // and to then shut down the DNA services (which will block until all sequencing has been completed) ...
+ Thread.sleep(1000);
+ client.shutdownDnaServices();
+
+ // The sequencers should have run, so perform the search.
+ // The mock user interface checks the results.
+ client.search();
+ assertThat(client.getStatistics().getNumberOfNodesSequenced(), is(1L));
+ }
+
}
Added: trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/MySource.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/MySource.java (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/MySource.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -0,0 +1,111 @@
+/*
+ * 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.acme;
+
+import org.acme.annotation.MyClassAnnotation;
+import java.util.*;
+
+/**
+ * @author Serge Pagop
+ */
+@MyClassAnnotation
+public class MySource {
+
+ private int i, j;
+ private static double a;
+ private List<String> l;
+ private A<Integer> o;
+ private X x;
+ private int[] ia;
+ private Object[] oa;
+ private Collection[] ca;
+
+ MySource() {
+ }
+
+ public MySource( int i,
+ int j,
+ Object o ) {
+ this.i = i;
+ this.j = j;
+ }
+
+ public int getI() {
+ return this.i;
+ }
+
+ public void setI( int i ) {
+ this.i = i;
+ }
+
+ public void setJ( int j ) {
+ this.j = j;
+ }
+
+ public void doSomething( int p1,
+ double p2,
+ Object o ) {
+ l = new ArrayList<String>();
+ l.add("N1");
+ }
+
+ private double doSomething2( Object[] oa,
+ int[] ia ) {
+ System.out.println("genial");
+ }
+
+ public Object doSomething3() {
+ return null;
+ }
+
+ // nested class
+ class A<E> {
+ E e;
+
+ A( E e ) {
+ this.e = e;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(this.e);
+ }
+
+ class B<T> {
+ T t;
+
+ B( T t ) {
+ this.t = t;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(this.t);
+ }
+ }
+ }
+
+ class X {
+
+ }
+}
+
\ No newline at end of file
Added: trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyClassAnnotation.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -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.acme.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Randall Hauch
+ */
+@Retention( RetentionPolicy.CLASS )
+@Target( ElementType.TYPE )
+public @interface MyClassAnnotation {
+
+}
Added: trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/annotation/MyPackageAnnotation.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -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.acme.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Randall Hauch
+ */
+@Retention( RetentionPolicy.CLASS )
+@Target( ElementType.PACKAGE )
+public @interface MyPackageAnnotation {
+
+}
Added: trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/package-info.java
===================================================================
--- trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/package-info.java (rev 0)
+++ trunk/docs/examples/gettingstarted/sequencers/workspace/project1/src/org/acme/package-info.java 2008-09-17 23:03:19 UTC (rev 532)
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+@MyPackageAnnotation
+package org.acme;
+
+import org.acme.annotation.MyPackageAnnotation;
+
15 years, 7 months
DNA SVN: r531 - in trunk: docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository and 6 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-09-17 18:56:29 -0400 (Wed, 17 Sep 2008)
New Revision: 531
Added:
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientUsingJcrTest.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/PlaceholderContribution.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/MergeStrategy.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategy.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategyTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategyTest.java
Removed:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
Log:
DNA-222 - Create Getting Started example application for repositories
http://jira.jboss.com/jira/browse/DNA-222
More testing with several fixes. DNA-225 is still an issue.
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2008-09-17 22:56:21 UTC (rev 530)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -32,6 +32,7 @@
import javax.jcr.NodeIterator;
import javax.jcr.PropertyIterator;
import javax.jcr.Session;
+import javax.jcr.Value;
import javax.naming.NamingException;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
@@ -258,13 +259,26 @@
pathToNode = pathToNode.replaceAll("^/+", "");
// Get the node by path ...
Node root = session.getRootNode();
- Node node = root.getNode(pathToNode);
+ Node node = root;
+ if (pathToNode.length() != 0) {
+ if (!pathToNode.endsWith("]")) pathToNode = pathToNode + "[1]";
+ node = pathToNode.equals("") ? root : root.getNode(pathToNode);
+ }
// Now populate the properties and children ...
if (properties != null) {
for (PropertyIterator iter = node.getProperties(); iter.hasNext();) {
javax.jcr.Property property = iter.nextProperty();
- Object[] values = property.getDefinition().isMultiple() ? property.getValues() : new Object[] {property.getValue()};
+ Object[] values = null;
+ if (property.getDefinition().isMultiple()) {
+ Value[] jcrValues = property.getValues();
+ values = new String[jcrValues.length];
+ for (int i = 0; i < jcrValues.length; i++) {
+ values[i] = jcrValues[i].getString();
+ }
+ } else {
+ values = new Object[] {property.getValue().getString()};
+ }
properties.put(property.getName(), values);
}
}
Modified: trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java 2008-09-17 22:56:21 UTC (rev 530)
+++ trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -32,7 +32,6 @@
import java.util.Map;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -44,6 +43,7 @@
private RepositoryClient client;
private Map<String, Object[]> properties;
+ private Map<String, Object> uuids;
private List<String> children;
@Mock
private UserInterface userInterface;
@@ -51,6 +51,7 @@
@Before
public void beforeEach() {
MockitoAnnotations.initMocks(this);
+ uuids = new HashMap<String, Object>();
properties = new HashMap<String, Object[]>();
children = new ArrayList<String>();
client = new RepositoryClient();
@@ -74,6 +75,22 @@
assertThat(actualValues, is(values));
}
+ protected void getNodeInfo( String source,
+ String path ) throws Throwable {
+ properties.clear();
+ children.clear();
+ assertThat(client.getNodeInfo(source, path, properties, children), is(true));
+ // Record the UUID of the node ...
+ final Object uuid = properties.get("dna:uuid");
+ final String key = source + "\n" + path;
+ final Object existingUuid = uuids.get(key);
+ if (existingUuid != null) {
+ assertThat(uuid, is(existingUuid));
+ } else {
+ uuids.put(key, uuid);
+ }
+ }
+
@Test
public void shouldStartupWithoutError() throws Exception {
client.startRepositories();
@@ -89,23 +106,20 @@
@Test
public void shouldHaveContentFromConfigurationRepository() throws Throwable {
client.startRepositories();
- assertThat(client.getNodeInfo("Configuration", "/dna:system", properties, children), is(true));
+
+ getNodeInfo("Configuration", "/dna:system");
assertThat(children, hasItems("dna:sources", "dna:federatedRepositories"));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(2));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Configuration", "/dna:system/dna:sources", properties, children), is(true));
+ getNodeInfo("Configuration", "/dna:system/dna:sources");
assertThat(children, hasItems("SourceA", "SourceB", "SourceC", "SourceD"));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(2));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Configuration", "/dna:system/dna:sources/SourceA", properties, children), is(true));
+ getNodeInfo("Configuration", "/dna:system/dna:sources/SourceA");
assertThat(children.size(), is(0));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
@@ -116,25 +130,22 @@
}
@Test
- public void shouldLoadCarsRepository() throws Throwable {
+ public void shouldHaveContentFromCarsRepository() throws Throwable {
client.startRepositories();
- assertThat(client.getNodeInfo("Cars", "/Cars", properties, children), is(true));
+
+ getNodeInfo("Cars", "/Cars");
assertThat(children, hasItems("Hybrid", "Sports", "Luxury", "Utility"));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(2));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Cars", "/Cars/Hybrid", properties, children), is(true));
+ getNodeInfo("Cars", "/Cars/Hybrid");
assertThat(children, hasItems("Toyota Prius", "Toyota Highlander", "Nissan Altima"));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(2));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Cars", "/Cars/Sports/Aston Martin DB9", properties, children), is(true));
+ getNodeInfo("Cars", "/Cars/Sports/Aston Martin DB9");
assertThat(children.size(), is(0));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
@@ -153,17 +164,16 @@
}
@Test
- public void shouldLoadAircraftRepository() throws Throwable {
+ public void shouldHaveContentFromAircraftRepository() throws Throwable {
client.startRepositories();
- assertThat(client.getNodeInfo("Aircraft", "/Aircraft", properties, children), is(true));
+
+ getNodeInfo("Aircraft", "/Aircraft");
assertThat(children, hasItems("Business", "Commercial", "Vintage", "Homebuilt"));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(2));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Aircraft", "/Aircraft/Commercial", properties, children), is(true));
+ getNodeInfo("Aircraft", "/Aircraft/Commercial");
assertThat(children, hasItems("Boeing 777",
"Boeing 767",
"Boeing 787",
@@ -176,9 +186,7 @@
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(2));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Aircraft", "/Aircraft/Vintage/Wright Flyer", properties, children), is(true));
+ getNodeInfo("Aircraft", "/Aircraft/Vintage/Wright Flyer");
assertThat(children.size(), is(0));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
@@ -191,41 +199,32 @@
assertThat(properties.size(), is(8));
}
- @Ignore
@Test
- public void shouldLoadVehiclesRepository() throws Throwable {
+ public void shouldHaveContentFromVehiclesRepository() throws Throwable {
client.startRepositories();
- assertThat(client.getNodeInfo("Vehicles", "/", properties, children), is(true));
+
+ getNodeInfo("Vehicles", "/");
assertThat(children, hasItems("Vehicles"));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(1));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Vehicles", "/Vehicles", properties, children), is(true));
+ getNodeInfo("Vehicles", "/Vehicles");
assertThat(children, hasItems("Cars", "Aircraft"));
- assertThat(properties.containsKey("jcr:primaryType"), is(false));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(1));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Vehicles", "/", properties, children), is(true));
+ getNodeInfo("Vehicles", "/");
assertThat(children, hasItems("Vehicles"));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(1));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Vehicles", "/Vehicles/Cars/Hybrid", properties, children), is(true));
+ getNodeInfo("Vehicles", "/Vehicles/Cars/Hybrid");
assertThat(children, hasItems("Toyota Prius", "Toyota Highlander", "Nissan Altima"));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(2));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Vehicles", "/Vehicles/Cars/Sports/Aston Martin DB9", properties, children), is(true));
+ getNodeInfo("Vehicles", "/Vehicles/Cars/Sports/Aston Martin DB9");
assertThat(children.size(), is(0));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
@@ -242,9 +241,7 @@
assertProperty("engine", "5,935 cc 5.9 liters V 12");
assertThat(properties.size(), is(12));
- properties.clear();
- children.clear();
- assertThat(client.getNodeInfo("Vehicles", "/Vehicles/Aircraft/Vintage/Wright Flyer", properties, children), is(true));
+ getNodeInfo("Vehicles", "/Vehicles/Aircraft/Vintage/Wright Flyer");
assertThat(children.size(), is(0));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
@@ -262,4 +259,14 @@
client.startRepositories();
assertThat(client.getNodeInfo("Cars", "/Cars/Sports/Non Existant Car", properties, children), is(false));
}
+
+ @Test
+ public void shouldBeAbleToExecuteTestsRepeatedly() throws Throwable {
+ for (int i = 0; i != 10; ++i) {
+ shouldHaveContentFromConfigurationRepository();
+ shouldHaveContentFromCarsRepository();
+ shouldHaveContentFromAircraftRepository();
+ // shouldHaveContentFromVehiclesRepository();
+ }
+ }
}
Added: trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientUsingJcrTest.java
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientUsingJcrTest.java (rev 0)
+++ trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientUsingJcrTest.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -0,0 +1,40 @@
+/*
+ * 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.example.dna.repository;
+
+import org.jboss.example.dna.repository.RepositoryClient.Api;
+
+/**
+ * @author Randall Hauch
+ */
+public class RepositoryClientUsingJcrTest extends RepositoryClientTest {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.example.dna.repository.RepositoryClientTest#getApi()
+ */
+ @Override
+ protected Api getApi() {
+ return RepositoryClient.Api.JCR;
+ }
+}
Property changes on: trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientUsingJcrTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java 2008-09-17 22:56:21 UTC (rev 530)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -23,6 +23,7 @@
import java.io.Serializable;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
@@ -179,6 +180,46 @@
}
/**
+ * Create a placeholder contribution of a single child from the named source.
+ *
+ * @param sourceName the name of the source, which may not be null or blank
+ * @param pathInSource the path in the source for this contributed information; may not be null
+ * @param expirationTime the time (in UTC) after which this contribution should be considered expired, or null if there is no
+ * expiration time
+ * @param child the child from the source; may not be null or empty
+ * @return the contribution
+ */
+ public static Contribution createPlaceholder( String sourceName,
+ Path pathInSource,
+ DateTime expirationTime,
+ Segment child ) {
+ if (child == null) {
+ return new EmptyContribution(sourceName, expirationTime);
+ }
+ return new PlaceholderContribution(sourceName, pathInSource, expirationTime, Collections.singletonList(child));
+ }
+
+ /**
+ * Create a placeholder contribution of the supplied properties and children from the named source.
+ *
+ * @param sourceName the name of the source, which may not be null or blank
+ * @param pathInSource the path in the source for this contributed information; may not be null
+ * @param expirationTime the time (in UTC) after which this contribution should be considered expired, or null if there is no
+ * expiration time
+ * @param children the children from the source; may not be null or empty
+ * @return the contribution
+ */
+ public static Contribution createPlaceholder( String sourceName,
+ Path pathInSource,
+ DateTime expirationTime,
+ List<Segment> children ) {
+ if (children == null || children.isEmpty()) {
+ return new EmptyContribution(sourceName, expirationTime);
+ }
+ return new PlaceholderContribution(sourceName, pathInSource, expirationTime, children);
+ }
+
+ /**
* This is the first version of this class. See the documentation of BasicMergePlan.serialVersionUID.
*/
private static final long serialVersionUID = 1L;
@@ -299,6 +340,16 @@
}
/**
+ * Determine whether this contribution is considered a placeholder necessary solely because the same source has contributions
+ * at or below the children.
+ *
+ * @return true if a placeholder contribution, or false otherwise
+ */
+ public boolean isPlaceholder() {
+ return false;
+ }
+
+ /**
* {@inheritDoc}
* <p>
* This implementation returns the hash code of the {@link #getSourceName() source name}, and is compatible with the
Added: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/PlaceholderContribution.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/PlaceholderContribution.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/PlaceholderContribution.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -0,0 +1,67 @@
+/*
+ * 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.connector.federation.contribution;
+
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.spi.graph.DateTime;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * A placeholder contribution needed because of a source's contribution below the specified children.
+ *
+ * @author Randall Hauch
+ */
+@Immutable
+public class PlaceholderContribution extends MultiChildContribution {
+
+ /**
+ * This is the first version of this class. See the documentation of MergePlan.serialVersionUID.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Create a contribution of children from the source with the supplied name.
+ *
+ * @param sourceName the name of the source, which may not be null or blank
+ * @param pathInSource the path in the source for this contributed information; may not be null
+ * @param expirationTime the time (in UTC) after which this contribution should be considered expired, or null if there is no
+ * expiration time
+ * @param children the children from the source; may not be null or empty
+ */
+ public PlaceholderContribution( String sourceName,
+ Path pathInSource,
+ DateTime expirationTime,
+ Iterable<Segment> children ) {
+ super(sourceName, pathInSource, expirationTime, children);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.federation.contribution.Contribution#isPlaceholder()
+ */
+ @Override
+ public boolean isPlaceholder() {
+ return true;
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/PlaceholderContribution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-09-17 22:56:21 UTC (rev 530)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -40,9 +40,9 @@
import org.jboss.dna.connector.federation.contribution.Contribution;
import org.jboss.dna.connector.federation.merge.FederatedNode;
import org.jboss.dna.connector.federation.merge.MergePlan;
-import org.jboss.dna.connector.federation.merge.MergeStrategy;
-import org.jboss.dna.connector.federation.merge.OneContributionMergeStrategy;
-import org.jboss.dna.connector.federation.merge.SimpleMergeStrategy;
+import org.jboss.dna.connector.federation.merge.strategy.MergeStrategy;
+import org.jboss.dna.connector.federation.merge.strategy.OneContributionMergeStrategy;
+import org.jboss.dna.connector.federation.merge.strategy.SimpleMergeStrategy;
import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.cache.CachePolicy;
@@ -315,7 +315,7 @@
Path pathToLoad = path.getParent();
while (!pathToLoad.equals(lowestExistingAncestor)) {
loadContributionsFromSources(pathToLoad, null, contributions); // sourceNames may be null or empty
- FederatedNode mergedNode = createFederatedNode(pathToLoad, contributions, true);
+ FederatedNode mergedNode = createFederatedNode(null, pathToLoad, contributions, true);
if (mergedNode == null) {
// No source had a contribution ...
I18n msg = FederationI18n.nodeDoesNotExistAtPath;
@@ -361,7 +361,7 @@
// Get the contributions from the sources given their names ...
loadContributionsFromSources(path, sourceNames, contributions); // sourceNames may be null or empty
- FederatedNode mergedNode = createFederatedNode(path, contributions, true);
+ FederatedNode mergedNode = createFederatedNode(fromCache, path, contributions, true);
if (mergedNode == null) {
// No source had a contribution ...
Path ancestor = path.getParent();
@@ -372,7 +372,8 @@
return mergedNode;
}
- protected FederatedNode createFederatedNode( Path path,
+ protected FederatedNode createFederatedNode( BasicGetNodeCommand fromCache,
+ Path path,
List<Contribution> contributions,
boolean updateCache ) throws RepositorySourceException {
@@ -394,11 +395,21 @@
}
}
- // Merge the results into a single set of results ...
- FederatedNode mergedNode = new FederatedNode(path, UUID.randomUUID());
+ // Create the node, and use the existing UUID if one is found in the cache ...
ExecutionContext context = getExecutionContext();
- assert contributions.size() > 0;
assert context != null;
+ UUID uuid = null;
+ if (fromCache != null) {
+ Property uuidProperty = fromCache.getPropertiesByName().get(DnaLexicon.UUID);
+ if (uuidProperty != null && !uuidProperty.isEmpty()) {
+ uuid = context.getValueFactories().getUuidFactory().create(uuidProperty.getValues().next());
+ }
+ }
+ if (uuid == null) uuid = UUID.randomUUID();
+ FederatedNode mergedNode = new FederatedNode(path, uuid);
+
+ // Merge the results into a single set of results ...
+ assert contributions.size() > 0;
mergingStrategy.merge(mergedNode, contributions, context);
if (mergedNode.getCachePolicy() == null) {
mergedNode.setCachePolicy(defaultCachePolicy);
@@ -455,7 +466,7 @@
if (path.isAncestorOf(topLevelPath)) {
assert topLevelPath.size() > path.size();
Path.Segment child = topLevelPath.getSegment(path.size());
- contribution = Contribution.create(source, path, expirationTime, null, child);
+ contribution = Contribution.createPlaceholder(source, path, expirationTime, child);
}
break;
}
@@ -470,7 +481,7 @@
}
}
if (children.size() > 0) {
- contribution = Contribution.create(source, path, expirationTime, null, children);
+ contribution = Contribution.createPlaceholder(source, path, expirationTime, children);
}
}
}
@@ -549,37 +560,4 @@
}
cacheConnection.execute(context, intoCache);
}
-
- /**
- * Determine if the supplied plan is considered current
- *
- * @param path the path of the node at which (or below which) the merge plan applies
- * @param plan the merge plan
- * @return true if the merge plan is current, or false if it needs to be (at least partially) rebuilt
- */
- protected boolean isCurrent( Path path,
- MergePlan plan ) {
- // First check the time ...
- DateTime now = getCurrentTimeInUtc();
- if (plan.isExpired(now)) return false;
-
- // Does the plan have any contributions from sources that don't exist ?
- for (Contribution contribution : plan) {
- if (!sourceNames.contains(contribution.getSourceName())) return false;
- }
- //
- // // Determine if any new source projections exists that aren't part of the plan ...
- // for (String sourceName : sourceNames) {
- // if (plan.isSource(sourceName)) continue;
- // // The source is new ... see whether there are any regions that apply ...
- // // for (FederatedRegion region : this.regionsBySourceName.get(sourceName)) {
- // // // If the region's path is not at/above the path, the region doesn't matter
- // // if (!region.appliesTo(path)) continue;
- // // // The region applies to the path ...
- // // return false;
- // // }
- // }
- return true;
- }
-
}
Deleted: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java 2008-09-17 22:56:21 UTC (rev 530)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -1,44 +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.connector.federation.merge;
-
-import java.util.List;
-import org.jboss.dna.connector.federation.contribution.Contribution;
-import org.jboss.dna.spi.ExecutionContext;
-
-/**
- * @author Randall Hauch
- */
-public interface MergeStrategy {
-
- /**
- * Merge the contributions into a single
- *
- * @param federatedNode the federated node into which the contributions are to be merged; never null
- * @param contributions the contributions to the node; never null, never empty, and never containing nulls
- * @param context the context in which this operation is to be performed; never null
- */
- public void merge( FederatedNode federatedNode,
- List<Contribution> contributions,
- ExecutionContext context );
-
-}
Deleted: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java 2008-09-17 22:56:21 UTC (rev 530)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -1,118 +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.connector.federation.merge;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.connector.federation.contribution.Contribution;
-import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Property;
-import org.jboss.dna.spi.graph.UuidFactory;
-import org.jboss.dna.spi.graph.ValueFormatException;
-import org.jboss.dna.spi.graph.Path.Segment;
-
-/**
- * A merge strategy that is optimized for merging when there is a single contribution.
- *
- * @author Randall Hauch
- */
-@ThreadSafe
-public class OneContributionMergeStrategy implements MergeStrategy {
-
- public static final boolean DEFAULT_REUSE_UUID_FROM_CONTRIBUTION = true;
-
- private boolean useUuidFromContribution = DEFAULT_REUSE_UUID_FROM_CONTRIBUTION;
-
- /**
- * @return reuseUuidFromContribution
- */
- public boolean isContributionUuidUsedForFederatedNode() {
- return useUuidFromContribution;
- }
-
- /**
- * @param useUuidFromContribution Sets useUuidFromContribution to the specified value.
- */
- public void setContributionUuidUsedForFederatedNode( boolean useUuidFromContribution ) {
- this.useUuidFromContribution = useUuidFromContribution;
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * This method only uses the one and only one non-null {@link Contribution} in the <code>contributions</code>.
- * </p>
- *
- * @see org.jboss.dna.connector.federation.merge.MergeStrategy#merge(org.jboss.dna.connector.federation.merge.FederatedNode,
- * java.util.List, org.jboss.dna.spi.ExecutionContext)
- */
- public void merge( FederatedNode federatedNode,
- List<Contribution> contributions,
- ExecutionContext context ) {
- assert federatedNode != null;
- assert context != null;
- assert contributions != null;
- assert contributions.size() > 0;
- Contribution contribution = contributions.get(0);
- assert contribution != null;
- final boolean findUuid = isContributionUuidUsedForFederatedNode();
- // Copy the children ...
- List<Segment> children = federatedNode.getChildren();
- children.clear();
- Iterator<Segment> childIterator = contribution.getChildren();
- while (childIterator.hasNext()) {
- Segment child = childIterator.next();
- children.add(child);
- }
- // Copy the properties ...
- Map<Name, Property> properties = federatedNode.getPropertiesByName();
- properties.clear();
- UUID uuid = null;
- UuidFactory uuidFactory = null;
- Iterator<Property> propertyIterator = contribution.getProperties();
- while (propertyIterator.hasNext()) {
- Property property = propertyIterator.next();
- properties.put(property.getName(), property);
- if (findUuid && uuid == null && property.getName().getLocalName().equals("uuid") && property.isSingle()) {
- if (uuidFactory == null) uuidFactory = context.getValueFactories().getUuidFactory();
- try {
- uuid = uuidFactory.create(property.getValues().next());
- } catch (ValueFormatException e) {
- // Ignore conversion exceptions
- }
- }
- }
- // If we found a single "uuid" property whose value is a valid UUID ..
- if (uuid != null) {
- // then set the UUID on the federated node ...
- federatedNode.setUuid(uuid);
- }
- // Assign the merge plan ...
- MergePlan mergePlan = MergePlan.create(contributions);
- federatedNode.setMergePlan(mergePlan);
- }
-
-}
Deleted: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java 2008-09-17 22:56:21 UTC (rev 530)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -1,275 +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.connector.federation.merge;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.UUID;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.connector.federation.contribution.Contribution;
-import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.graph.IoException;
-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.Property;
-import org.jboss.dna.spi.graph.PropertyFactory;
-import org.jboss.dna.spi.graph.UuidFactory;
-import org.jboss.dna.spi.graph.ValueComparators;
-import org.jboss.dna.spi.graph.Path.Segment;
-
-/**
- * This merge strategy simply merges all of the contributions' properties and combines the children according to the order of the
- * contributions. No children are merged, and all properties are used (except if they are deemed to be duplicates of the property
- * in other contributions).
- *
- * @author Randall Hauch
- */
-@ThreadSafe
-public class SimpleMergeStrategy implements MergeStrategy {
-
- private boolean removeDuplicateProperties = true;
-
- /**
- * @return removeDuplicateProperties
- */
- public boolean isRemoveDuplicateProperties() {
- return removeDuplicateProperties;
- }
-
- /**
- * @param removeDuplicateProperties Sets removeDuplicateProperties to the specified value.
- */
- public void setRemoveDuplicateProperties( boolean removeDuplicateProperties ) {
- this.removeDuplicateProperties = removeDuplicateProperties;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.connector.federation.merge.MergeStrategy#merge(org.jboss.dna.connector.federation.merge.FederatedNode,
- * java.util.List, org.jboss.dna.spi.ExecutionContext)
- */
- public void merge( FederatedNode federatedNode,
- List<Contribution> contributions,
- ExecutionContext context ) {
- assert federatedNode != null;
- assert context != null;
- assert contributions != null;
- assert contributions.size() > 0;
- PathFactory pathFactory = context.getValueFactories().getPathFactory();
- // Prepare the federated node ...
- List<Segment> children = federatedNode.getChildren();
- children.clear();
- Map<Name, Integer> childNames = new HashMap<Name, Integer>();
- Map<Name, Property> properties = federatedNode.getPropertiesByName();
- properties.clear();
- UUID uuid = null;
- UuidFactory uuidFactory = null;
- final boolean removeDuplicateProperties = isRemoveDuplicateProperties();
- // Iterate over the set of contributions (in order) ...
- for (Contribution contribution : contributions) {
- // Copy the children ...
- int childListIndex = 0;
- Iterator<Segment> childIterator = contribution.getChildren();
- while (childIterator.hasNext()) {
- Segment child = childIterator.next();
- int index = Path.NO_INDEX;
- Integer previous = childNames.put(child.getName(), 1);
- if (previous != null) {
- int previousValue = previous.intValue();
- if (previousValue == 1) {
- // If the previous value was 1, then go back and look for the child that has no index but that should ...
- // Walk backwards, just in case the previous same-name-sibling is closer to the end
- for (int i = children.size() - 1; i >= 0; --i) {
- Path.Segment childSegment = children.get(i);
- if (childSegment.getName().equals(child.getName())) {
- children.set(i, pathFactory.createSegment(child.getName(), 1));
- break;
- }
- }
- }
- // Add the previous value back in ...
- childNames.put(child.getName(), ++previousValue);
- index = previousValue;
- }
- children.add(pathFactory.createSegment(child.getName(), index));
- ++childListIndex;
- }
-
- // Copy the properties ...
- Iterator<Property> propertyIterator = contribution.getProperties();
- while (propertyIterator.hasNext()) {
- Property property = propertyIterator.next();
- Property existing = properties.put(property.getName(), property);
- if (existing != null) {
- // There's already an existing property, so we need to merge them ...
- Property merged = merge(existing, property, context.getPropertyFactory(), removeDuplicateProperties);
- properties.put(property.getName(), merged);
- }
-
- if (uuid == null && property.getName().getLocalName().equals("uuid") && property.isSingle()) {
- if (uuidFactory == null) uuidFactory = context.getValueFactories().getUuidFactory();
- try {
- uuid = uuidFactory.create(property.getValues().next());
- } catch (IoException e) {
- // Ignore conversion exceptions
- assert uuid == null;
- }
- }
- }
- }
- // If we found a single "uuid" property whose value is a valid UUID ..
- if (uuid != null) {
- // then set the UUID on the federated node ...
- federatedNode.setUuid(uuid);
- }
- // Assign the merge plan ...
- MergePlan mergePlan = MergePlan.create(contributions);
- federatedNode.setMergePlan(mergePlan);
- }
-
- /**
- * Merge the values from the two properties with the same name, returning a new property with the newly merged values.
- * <p>
- * The current algorithm merges the values by concatenating the values from <code>property1</code> and <code>property2</code>,
- * and if <code>removeDuplicates</code> is true any values in <code>property2</code> that are identical to values found in
- * <code>property1</code> are skipped.
- * </p>
- *
- * @param property1 the first property; may not be null, and must have the same {@link Property#getName() name} as
- * <code>property2</code>
- * @param property2 the second property; may not be null, and must have the same {@link Property#getName() name} as
- * <code>property1</code>
- * @param factory the property factory, used to create the result
- * @param removeDuplicates true if this method removes any values in the second property that duplicate values found in the
- * first property.
- * @return the property that contains the same {@link Property#getName() name} as the input properties, but with values that
- * are merged from both of the input properties
- */
- protected Property merge( Property property1,
- Property property2,
- PropertyFactory factory,
- boolean removeDuplicates ) {
- assert property1 != null;
- assert property2 != null;
- assert property1.getName().equals(property2.getName());
- if (property1.isEmpty()) return property2;
- if (property2.isEmpty()) return property1;
-
- // If they are both single-valued, then we can use a more efficient algorithm ...
- if (property1.isSingle() && property2.isSingle()) {
- Object value1 = property1.getValues().next();
- Object value2 = property2.getValues().next();
- if (removeDuplicates && ValueComparators.OBJECT_COMPARATOR.compare(value1, value2) == 0) return property1;
- return factory.create(property1.getName(), new Object[] {value1, value2});
- }
-
- // One or both properties are multi-valued, so use an algorithm that works with in all cases ...
- if (!removeDuplicates) {
- Iterator<?> valueIterator = new DualIterator(property1.getValues(), property2.getValues());
- return factory.create(property1.getName(), valueIterator);
- }
-
- // First copy all the values from property 1 ...
- Object[] values = new Object[property1.size() + property2.size()];
- int index = 0;
- for (Object property1Value : property1) {
- values[index++] = property1Value;
- }
- assert index == property1.size();
- // Now add any values of property2 that don't match a value in property1 ...
- for (Object property2Value : property2) {
- // Brute force, go through the values of property1 and compare ...
- boolean matched = false;
- for (Object property1Value : property1) {
- if (ValueComparators.OBJECT_COMPARATOR.compare(property1Value, property2Value) == 0) {
- // The values are the same ...
- matched = true;
- break;
- }
- }
- if (!matched) values[index++] = property2Value;
- }
- if (index != values.length) {
- Object[] newValues = new Object[index];
- System.arraycopy(values, 0, newValues, 0, index);
- values = newValues;
- }
- return factory.create(property1.getName(), values);
- }
-
- protected static class DualIterator implements Iterator<Object> {
-
- private final Iterator<?>[] iterators;
- private Iterator<?> current;
- private int index = 0;
-
- protected DualIterator( Iterator<?>... iterators ) {
- assert iterators != null;
- assert iterators.length > 0;
- this.iterators = iterators;
- this.current = this.iterators[0];
- }
-
- /**
- * {@inheritDoc}
- *
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- if (this.current != null) return this.current.hasNext();
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see java.util.Iterator#next()
- */
- public Object next() {
- while (this.current != null) {
- if (this.current.hasNext()) return this.current.next();
- // Get the next iterator ...
- if (++this.index < iterators.length) {
- this.current = this.iterators[this.index];
- } else {
- this.current = null;
- }
- }
- throw new NoSuchElementException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- }
-}
Copied: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/MergeStrategy.java (from rev 522, trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/MergeStrategy.java)
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/MergeStrategy.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/MergeStrategy.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -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.connector.federation.merge.strategy;
+
+import java.util.List;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.connector.federation.merge.FederatedNode;
+import org.jboss.dna.spi.ExecutionContext;
+
+/**
+ * @author Randall Hauch
+ */
+public interface MergeStrategy {
+
+ /**
+ * Merge the contributions into a single
+ *
+ * @param federatedNode the federated node into which the contributions are to be merged; never null
+ * @param contributions the contributions to the node; never null, never empty, and never containing nulls
+ * @param context the context in which this operation is to be performed; never null
+ */
+ public void merge( FederatedNode federatedNode,
+ List<Contribution> contributions,
+ ExecutionContext context );
+
+}
Property changes on: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/MergeStrategy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategy.java (from rev 522, trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategy.java)
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategy.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategy.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -0,0 +1,128 @@
+/*
+ * 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.connector.federation.merge.strategy;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.connector.federation.merge.FederatedNode;
+import org.jboss.dna.connector.federation.merge.MergePlan;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.UuidFactory;
+import org.jboss.dna.spi.graph.ValueFormatException;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * A merge strategy that is optimized for merging when there is a single contribution.
+ *
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public class OneContributionMergeStrategy implements MergeStrategy {
+
+ public static final boolean DEFAULT_REUSE_UUID_FROM_CONTRIBUTION = true;
+
+ private boolean useUuidFromContribution = DEFAULT_REUSE_UUID_FROM_CONTRIBUTION;
+
+ /**
+ * @return reuseUuidFromContribution
+ */
+ public boolean isContributionUuidUsedForFederatedNode() {
+ return useUuidFromContribution;
+ }
+
+ /**
+ * @param useUuidFromContribution Sets useUuidFromContribution to the specified value.
+ */
+ public void setContributionUuidUsedForFederatedNode( boolean useUuidFromContribution ) {
+ this.useUuidFromContribution = useUuidFromContribution;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * This method only uses the one and only one non-null {@link Contribution} in the <code>contributions</code>.
+ * </p>
+ *
+ * @see org.jboss.dna.connector.federation.merge.strategy.MergeStrategy#merge(org.jboss.dna.connector.federation.merge.FederatedNode,
+ * java.util.List, org.jboss.dna.spi.ExecutionContext)
+ */
+ public void merge( FederatedNode federatedNode,
+ List<Contribution> contributions,
+ ExecutionContext context ) {
+ assert federatedNode != null;
+ assert context != null;
+ assert contributions != null;
+ assert contributions.size() > 0;
+ Contribution contribution = contributions.get(0);
+ assert contribution != null;
+ final boolean findUuid = isContributionUuidUsedForFederatedNode();
+ // Copy the children ...
+ List<Segment> children = federatedNode.getChildren();
+ children.clear();
+ Iterator<Segment> childIterator = contribution.getChildren();
+ while (childIterator.hasNext()) {
+ Segment child = childIterator.next();
+ children.add(child);
+ }
+ // Copy the properties ...
+ Map<Name, Property> properties = federatedNode.getPropertiesByName();
+ properties.clear();
+ UUID uuid = null;
+ UuidFactory uuidFactory = null;
+ Iterator<Property> propertyIterator = contribution.getProperties();
+ while (propertyIterator.hasNext()) {
+ Property property = propertyIterator.next();
+ if (findUuid && uuid == null && property.getName().getLocalName().equals("uuid")) {
+ if (property.isSingle()) {
+ if (uuidFactory == null) uuidFactory = context.getValueFactories().getUuidFactory();
+ try {
+ uuid = uuidFactory.create(property.getValues().next());
+ } catch (ValueFormatException e) {
+ // Ignore conversion exceptions
+ }
+ }
+ } else {
+ properties.put(property.getName(), property);
+ }
+ }
+ // If we found a single "uuid" property whose value is a valid UUID ..
+ if (uuid != null) {
+ // then set the UUID on the federated node ...
+ federatedNode.setUuid(uuid);
+ }
+ // Set the UUID as a property ...
+ Property uuidProperty = context.getPropertyFactory().create(DnaLexicon.UUID, federatedNode.getUuid());
+ properties.put(uuidProperty.getName(), uuidProperty);
+
+ // Assign the merge plan ...
+ MergePlan mergePlan = MergePlan.create(contributions);
+ federatedNode.setMergePlan(mergePlan);
+ }
+
+}
Property changes on: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java (from rev 522, trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategy.java)
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -0,0 +1,285 @@
+/*
+ * 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.connector.federation.merge.strategy;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.UUID;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.connector.federation.merge.FederatedNode;
+import org.jboss.dna.connector.federation.merge.MergePlan;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.IoException;
+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.Property;
+import org.jboss.dna.spi.graph.PropertyFactory;
+import org.jboss.dna.spi.graph.UuidFactory;
+import org.jboss.dna.spi.graph.ValueComparators;
+import org.jboss.dna.spi.graph.Path.Segment;
+
+/**
+ * This merge strategy simply merges all of the contributions' properties and combines the children according to the order of the
+ * contributions. No children are merged, and all properties are used (except if they are deemed to be duplicates of the property
+ * in other contributions).
+ *
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public class SimpleMergeStrategy implements MergeStrategy {
+
+ private boolean removeDuplicateProperties = true;
+
+ /**
+ * @return removeDuplicateProperties
+ */
+ public boolean isRemoveDuplicateProperties() {
+ return removeDuplicateProperties;
+ }
+
+ /**
+ * @param removeDuplicateProperties Sets removeDuplicateProperties to the specified value.
+ */
+ public void setRemoveDuplicateProperties( boolean removeDuplicateProperties ) {
+ this.removeDuplicateProperties = removeDuplicateProperties;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.connector.federation.merge.strategy.MergeStrategy#merge(org.jboss.dna.connector.federation.merge.FederatedNode,
+ * java.util.List, org.jboss.dna.spi.ExecutionContext)
+ */
+ public void merge( FederatedNode federatedNode,
+ List<Contribution> contributions,
+ ExecutionContext context ) {
+ assert federatedNode != null;
+ assert context != null;
+ assert contributions != null;
+ assert contributions.size() > 0;
+ PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ // Prepare the federated node ...
+ List<Segment> children = federatedNode.getChildren();
+ children.clear();
+ Map<Name, Integer> childNames = new HashMap<Name, Integer>();
+ Map<Name, Property> properties = federatedNode.getPropertiesByName();
+ properties.clear();
+ UUID uuid = null;
+ UuidFactory uuidFactory = null;
+ final boolean removeDuplicateProperties = isRemoveDuplicateProperties();
+ // Iterate over the set of contributions (in order) ...
+ for (Contribution contribution : contributions) {
+ // If the contribution is a placeholder contribution, then the children should be merged into other children ...
+ if (contribution.isPlaceholder()) {
+ // Iterate over the children and add only if there is not already one ...
+ Iterator<Segment> childIterator = contribution.getChildren();
+ while (childIterator.hasNext()) {
+ Segment child = childIterator.next();
+ if (!childNames.containsKey(child)) {
+ childNames.put(child.getName(), 1);
+ children.add(pathFactory.createSegment(child.getName()));
+ }
+ }
+
+ } else {
+ // Copy the children ...
+ Iterator<Segment> childIterator = contribution.getChildren();
+ while (childIterator.hasNext()) {
+ Segment child = childIterator.next();
+ int index = Path.NO_INDEX;
+ Integer previous = childNames.put(child.getName(), 1);
+ if (previous != null) {
+ int previousValue = previous.intValue();
+ // Correct the index in the child name map ...
+ childNames.put(child.getName(), ++previousValue);
+ index = previousValue;
+ }
+ children.add(pathFactory.createSegment(child.getName(), index));
+ }
+
+ // Copy the properties ...
+ Iterator<Property> propertyIterator = contribution.getProperties();
+ while (propertyIterator.hasNext()) {
+ Property property = propertyIterator.next();
+ // Skip the "uuid" property on all root nodes ...
+ if (federatedNode.getPath().isRoot() && property.getName().getLocalName().equals("uuid")) continue;
+ Property existing = properties.put(property.getName(), property);
+ if (existing != null) {
+ // There's already an existing property, so we need to merge them ...
+ Property merged = merge(existing, property, context.getPropertyFactory(), removeDuplicateProperties);
+ properties.put(property.getName(), merged);
+ }
+
+ if (uuid == null && property.getName().getLocalName().equals("uuid") && property.isSingle()) {
+ if (uuidFactory == null) uuidFactory = context.getValueFactories().getUuidFactory();
+ try {
+ uuid = uuidFactory.create(property.getValues().next());
+ } catch (IoException e) {
+ // Ignore conversion exceptions
+ assert uuid == null;
+ }
+ }
+ }
+ }
+ }
+ // If we found a single "uuid" property whose value is a valid UUID ..
+ if (uuid != null) {
+ // then set the UUID on the federated node ...
+ federatedNode.setUuid(uuid);
+ }
+ // Set the UUID as a property ...
+ Property uuidProperty = context.getPropertyFactory().create(DnaLexicon.UUID, federatedNode.getUuid());
+ properties.put(uuidProperty.getName(), uuidProperty);
+
+ // Assign the merge plan ...
+ MergePlan mergePlan = MergePlan.create(contributions);
+ federatedNode.setMergePlan(mergePlan);
+ }
+
+ /**
+ * Merge the values from the two properties with the same name, returning a new property with the newly merged values.
+ * <p>
+ * The current algorithm merges the values by concatenating the values from <code>property1</code> and <code>property2</code>,
+ * and if <code>removeDuplicates</code> is true any values in <code>property2</code> that are identical to values found in
+ * <code>property1</code> are skipped.
+ * </p>
+ *
+ * @param property1 the first property; may not be null, and must have the same {@link Property#getName() name} as
+ * <code>property2</code>
+ * @param property2 the second property; may not be null, and must have the same {@link Property#getName() name} as
+ * <code>property1</code>
+ * @param factory the property factory, used to create the result
+ * @param removeDuplicates true if this method removes any values in the second property that duplicate values found in the
+ * first property.
+ * @return the property that contains the same {@link Property#getName() name} as the input properties, but with values that
+ * are merged from both of the input properties
+ */
+ protected Property merge( Property property1,
+ Property property2,
+ PropertyFactory factory,
+ boolean removeDuplicates ) {
+ assert property1 != null;
+ assert property2 != null;
+ assert property1.getName().equals(property2.getName());
+ if (property1.isEmpty()) return property2;
+ if (property2.isEmpty()) return property1;
+
+ // If they are both single-valued, then we can use a more efficient algorithm ...
+ if (property1.isSingle() && property2.isSingle()) {
+ Object value1 = property1.getValues().next();
+ Object value2 = property2.getValues().next();
+ if (removeDuplicates && ValueComparators.OBJECT_COMPARATOR.compare(value1, value2) == 0) return property1;
+ return factory.create(property1.getName(), new Object[] {value1, value2});
+ }
+
+ // One or both properties are multi-valued, so use an algorithm that works with in all cases ...
+ if (!removeDuplicates) {
+ Iterator<?> valueIterator = new DualIterator(property1.getValues(), property2.getValues());
+ return factory.create(property1.getName(), valueIterator);
+ }
+
+ // First copy all the values from property 1 ...
+ Object[] values = new Object[property1.size() + property2.size()];
+ int index = 0;
+ for (Object property1Value : property1) {
+ values[index++] = property1Value;
+ }
+ assert index == property1.size();
+ // Now add any values of property2 that don't match a value in property1 ...
+ for (Object property2Value : property2) {
+ // Brute force, go through the values of property1 and compare ...
+ boolean matched = false;
+ for (Object property1Value : property1) {
+ if (ValueComparators.OBJECT_COMPARATOR.compare(property1Value, property2Value) == 0) {
+ // The values are the same ...
+ matched = true;
+ break;
+ }
+ }
+ if (!matched) values[index++] = property2Value;
+ }
+ if (index != values.length) {
+ Object[] newValues = new Object[index];
+ System.arraycopy(values, 0, newValues, 0, index);
+ values = newValues;
+ }
+ return factory.create(property1.getName(), values);
+ }
+
+ protected static class DualIterator implements Iterator<Object> {
+
+ private final Iterator<?>[] iterators;
+ private Iterator<?> current;
+ private int index = 0;
+
+ protected DualIterator( Iterator<?>... iterators ) {
+ assert iterators != null;
+ assert iterators.length > 0;
+ this.iterators = iterators;
+ this.current = this.iterators[0];
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.current != null) return this.current.hasNext();
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ while (this.current != null) {
+ if (this.current.hasNext()) return this.current.next();
+ // Get the next iterator ...
+ if (++this.index < iterators.length) {
+ this.current = this.iterators[this.index];
+ } else {
+ this.current = null;
+ }
+ }
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+}
Property changes on: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java 2008-09-17 22:56:21 UTC (rev 530)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -1,205 +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.connector.federation.merge;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNot.not;
-import static org.hamcrest.core.IsSame.sameInstance;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.stub;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import org.jboss.dna.connector.federation.contribution.Contribution;
-import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.connector.BasicExecutionContext;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.Property;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.MockitoAnnotations;
-import org.mockito.MockitoAnnotations.Mock;
-
-/**
- * @author Randall Hauch
- */
-public class OneContributionMergeStrategyTest {
-
- private OneContributionMergeStrategy strategy;
- private List<Contribution> contributions;
- private ExecutionContext context;
- private FederatedNode node;
- private Map<Name, Property> properties;
- private List<Path.Segment> children;
- @Mock
- private Contribution contribution;
-
- @Before
- public void beforeEach() throws Exception {
- MockitoAnnotations.initMocks(this);
- Path path = mock(Path.class);
- node = new FederatedNode(path, UUID.randomUUID());
- strategy = new OneContributionMergeStrategy();
- contributions = new LinkedList<Contribution>();
- contributions.add(contribution);
- context = new BasicExecutionContext();
- context.getNamespaceRegistry().register("dna", "http://www.jboss.org/dna/something");
- context.getNamespaceRegistry().register("jcr", "http://www.jcr.org");
- stub(contribution.getSourceName()).toReturn("source name");
- children = new LinkedList<Path.Segment>();
- for (int i = 0; i != 10; ++i) {
- children.add(context.getValueFactories().getPathFactory().createSegment("a" + i));
- }
- properties = new HashMap<Name, Property>();
- for (int i = 0; i != 10; ++i) {
- Name propertyName = context.getValueFactories().getNameFactory().create("property" + i);
- properties.put(propertyName, context.getPropertyFactory().create(propertyName, "value"));
- }
- }
-
- @Test
- public void shouldMergeTheChildrenFromTheFirstContribution() {
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- strategy.merge(node, contributions, context);
- assertThat(node.getChildren(), is(children));
- }
-
- @Test
- public void shouldMergeThePropertiesFromTheFirstContribution() {
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- strategy.merge(node, contributions, context);
- assertThat(node.getPropertiesByName(), is(properties));
- }
-
- @Test
- public void shouldCreateMergePlanInTheFederatedNode() {
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- strategy.merge(node, contributions, context);
- MergePlan mergePlan = node.getMergePlan();
- assertThat(mergePlan.getContributionFrom(contribution.getSourceName()), is(sameInstance(contribution)));
- assertThat(mergePlan.getContributionCount(), is(1));
- }
-
- @Test
- public void shouldSetTheUuidOnTheNodeIfThereIsASingleValuedPropertyNamedUuidWithValueThatConvertsToUuidInstance() {
- // Test the "dna:uuid" property ...
- Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
- UUID uuid = UUID.randomUUID();
- Property uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
- properties.put(uuidProperty.getName(), uuidProperty);
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- assertThat(node.getUuid(), is(not(uuid)));
- strategy.merge(node, contributions, context);
- assertThat(node.getUuid(), is(uuid));
- properties.remove(uuidProperty.getName());
-
- // Test the "jcr:uuid" property ...
- uuidName = context.getValueFactories().getNameFactory().create("jcr:uuid");
- uuid = UUID.randomUUID();
- uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
- properties.put(uuidProperty.getName(), uuidProperty);
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- assertThat(node.getUuid(), is(not(uuid)));
- strategy.merge(node, contributions, context);
- assertThat(node.getUuid(), is(uuid));
- properties.remove(uuidProperty.getName());
-
- // Test the "uuid" property ...
- uuidName = context.getValueFactories().getNameFactory().create("uuid");
- uuid = UUID.randomUUID();
- uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
- properties.put(uuidProperty.getName(), uuidProperty);
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- assertThat(node.getUuid(), is(not(uuid)));
- strategy.merge(node, contributions, context);
- assertThat(node.getUuid(), is(uuid));
- properties.remove(uuidProperty.getName());
-
- // Test the "uuid" property whose value is a String ...
- uuidName = context.getValueFactories().getNameFactory().create("uuid");
- uuid = UUID.randomUUID();
- uuidProperty = context.getPropertyFactory().create(uuidName, uuid.toString());
- properties.put(uuidProperty.getName(), uuidProperty);
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- assertThat(node.getUuid(), is(not(uuid)));
- strategy.merge(node, contributions, context);
- assertThat(node.getUuid(), is(uuid));
- properties.remove(uuidProperty.getName());
- }
-
- @Test
- public void shouldNotSetTheUuidOnTheNodeIfThereIsNoPropertyNamedUuid() {
- // Test the "dna:uuid" property ...
- Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
- UUID uuid = UUID.randomUUID();
- Property uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
- properties.put(uuidProperty.getName(), uuidProperty);
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- assertThat(node.getUuid(), is(not(uuid)));
- strategy.merge(node, contributions, context);
- assertThat(node.getUuid(), is(uuid));
- properties.remove(uuidProperty.getName());
- }
-
- @Test
- public void shouldNotSetTheUuidOnTheNodeIfThereIsAMultiValuedPropertyNamedUuid() {
- final UUID originalUuid = node.getUuid();
- // Test the "dna:uuid" property ...
- Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
- Property uuidProperty = context.getPropertyFactory().create(uuidName,
- UUID.randomUUID(),
- UUID.randomUUID(),
- UUID.randomUUID());
- properties.put(uuidProperty.getName(), uuidProperty);
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- strategy.merge(node, contributions, context);
- assertThat(node.getUuid(), is(originalUuid));
- }
-
- @Test
- public void shouldNotSetTheUuidOnTheNodeIfThereIsASingleValuedPropertyNamedUuidWithValueThatDoesNotConvertToUuidInstance() {
- final UUID originalUuid = node.getUuid();
- // Test the "dna:uuid" property ...
- Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
- Property uuidProperty = context.getPropertyFactory().create(uuidName, 3.33d);
- properties.put(uuidProperty.getName(), uuidProperty);
- stub(contribution.getChildren()).toReturn(children.iterator());
- stub(contribution.getProperties()).toReturn(properties.values().iterator());
- strategy.merge(node, contributions, context);
- assertThat(node.getUuid(), is(originalUuid));
- }
-
-}
Deleted: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java 2008-09-17 22:56:21 UTC (rev 530)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -1,297 +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.connector.federation.merge;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.hamcrest.core.IsSame.sameInstance;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.stub;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import org.hamcrest.Matcher;
-import org.jboss.dna.common.collection.IsIteratorContaining;
-import org.jboss.dna.connector.federation.contribution.Contribution;
-import org.jboss.dna.spi.ExecutionContext;
-import org.jboss.dna.spi.connector.BasicExecutionContext;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Path;
-import org.jboss.dna.spi.graph.Property;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-/**
- * @author Randall Hauch
- */
-public class SimpleMergeStrategyTest {
-
- private SimpleMergeStrategy strategy;
- private List<Contribution> contributions;
- private ExecutionContext context;
- private FederatedNode node;
-
- @Before
- public void beforeEach() throws Exception {
- MockitoAnnotations.initMocks(this);
- Path path = mock(Path.class);
- node = new FederatedNode(path, UUID.randomUUID());
- strategy = new SimpleMergeStrategy();
- contributions = new LinkedList<Contribution>();
- context = new BasicExecutionContext();
- context.getNamespaceRegistry().register("dna", "http://www.jboss.org/dna/something");
- context.getNamespaceRegistry().register("jcr", "http://www.jcr.org");
- }
-
- @Test
- public void shouldAddChildrenFromOneContribution() {
- addContribution("source1").addChildren("childA", "childB[1]", "childB[2]");
- strategy.merge(node, contributions, context);
- assertThat(node.getChildren(), hasSegments("childA", "childB[1]", "childB[2]"));
- }
-
- @Test
- public void shouldCombinePropertiesFromOneContribution() {
- addContribution("source1").setProperty("p1", "p1 value");
- strategy.merge(node, contributions, context);
- assertThat(node.getProperties().size(), is(1));
- assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
- }
-
- @Test
- public void shouldAddChildrenFromMultipleContributionsInOrderAndShouldNotChangeSameNameSiblingIndexesWhenChildrenDoNotShareNamesWithChildrenFromDifferentContributions() {
- addContribution("source1").addChildren("childA", "childB[1]", "childB[2]");
- addContribution("source2").addChildren("childX", "childY[1]", "childY[2]");
- strategy.merge(node, contributions, context);
- assertThat(node.getChildren(), hasSegments("childA", "childB[1]", "childB[2]", "childX", "childY[1]", "childY[2]"));
- }
-
- @Test
- public void shouldAddChildrenFromMultipleContributionsInOrderAndShouldChangeSameNameSiblingIndexesWhenChildrenDoShareNamesWithChildrenFromDifferentContributions() {
- addContribution("source1").addChildren("childA", "childB[1]", "childB[2]");
- addContribution("source2").addChildren("childX", "childB", "childY");
- addContribution("source3").addChildren("childX", "childB");
- strategy.merge(node, contributions, context);
- assertThat(node.getChildren(), hasSegments("childA",
- "childB[1]",
- "childB[2]",
- "childX[1]",
- "childB[3]",
- "childY",
- "childX[2]",
- "childB[4]"));
- }
-
- @Test
- public void shouldCombinePropertiesFromMultipleContributionsAndRemoveNoValuesWhenNoContributionsContainSameProperty() {
- addContribution("source1").setProperty("p1", "p1 value");
- addContribution("source2").setProperty("p2", "p2 value");
- strategy.merge(node, contributions, context);
- assertThat(node.getProperties().size(), is(2));
- assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
- assertThat(node.getPropertiesByName().get(name("p2")), is(property("p2", "p2 value")));
- }
-
- @Test
- public void shouldCombinePropertiesFromMultipleContributionsAndRemoveDuplicateValuesWhenContributionsContainSameProperty() {
- addContribution("source1").setProperty("p1", "p1 value").setProperty("p12", "1", "2", "3");
- addContribution("source2").setProperty("p2", "p2 value").setProperty("p12", "3", "4");
- strategy.merge(node, contributions, context);
- assertThat(node.getProperties().size(), is(3));
- assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
- assertThat(node.getPropertiesByName().get(name("p2")), is(property("p2", "p2 value")));
- assertThat(node.getPropertiesByName().get(name("p12")), is(property("p12", "1", "2", "3", "4")));
- }
-
- @Test
- public void shouldCombinePropertiesFromMultipleContributionsAndMaintainAllValuesForEveryProperty() {
- addContribution("source1").setProperty("p1", "p1 value").setProperty("p12", "1", "2", "3");
- addContribution("source2").setProperty("p2", "p2 value").setProperty("p12", "3", "4");
- strategy.merge(node, contributions, context);
- assertThat(node.getProperties().size(), is(3));
- for (Contribution contribution : contributions) {
- Iterator<Property> iter = contribution.getProperties();
- while (iter.hasNext()) {
- Property contributionProperty = iter.next();
- Property mergedProperty = node.getPropertiesByName().get(contributionProperty.getName());
- assertThat(mergedProperty, is(notNullValue()));
- // Make sure that the merged property has each value ...
- for (Object contributedValue : contributionProperty.getValuesAsArray()) {
- boolean foundValue = false;
- for (Object mergedValue : mergedProperty.getValuesAsArray()) {
- if (mergedValue.equals(contributedValue)) {
- foundValue = true;
- break;
- }
- }
- assertThat(foundValue, is(true));
- }
- }
- }
- }
-
- @Test
- public void shouldCombinePropertiesFromMultipleContributionsWhenPropertyValuesAreOfDifferentPropertyTypes() {
- addContribution("source1").setProperty("p1", "p1 value").setProperty("p12", "1", "2", "3");
- addContribution("source2").setProperty("p2", "p2 value").setProperty("p12", 3, 4);
- strategy.merge(node, contributions, context);
- assertThat(node.getProperties().size(), is(3));
- assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
- assertThat(node.getPropertiesByName().get(name("p2")), is(property("p2", "p2 value")));
- assertThat(node.getPropertiesByName().get(name("p12")), is(property("p12", "1", "2", "3", 4)));
- }
-
- @Test
- public void shouldCreateMergePlanWhenMergingContributions() {
- addContribution("source1").addChildren("childA", "childB[1]", "childB[2]").setProperty("p1", "p1 value");
- addContribution("source2").addChildren("childX", "childB", "childY").setProperty("p2", "p2 value");
- strategy.merge(node, contributions, context);
- assertThat(node.getMergePlan(), is(notNullValue()));
- assertThat(node.getMergePlan().getContributionCount(), is(2));
- assertThat(node.getMergePlan().getContributionFrom("source1"), is(sameInstance(contributions.get(0))));
- assertThat(node.getMergePlan().getContributionFrom("source2"), is(sameInstance(contributions.get(1))));
- }
-
- @Test
- public void shouldCorrectlyBuildMockUsingContributionBuilder() {
- assertThat(contributions.size(), is(0));
- addContribution("source1").addChildren("childA", "childB[1]", "childB[2]").setProperty("p1", "p1 value");
- assertThat(contributions.size(), is(1));
- assertThat(contributions.get(0).getChildren(), hasSegmentIterator("childA", "childB[1]", "childB[2]"));
- }
-
- protected Matcher<List<Path.Segment>> hasSegments( String... segment ) {
- List<Path.Segment> segments = new ArrayList<Path.Segment>();
- for (String seg : segment) {
- segments.add(context.getValueFactories().getPathFactory().createSegment(seg));
- }
- return equalTo(segments);
- }
-
- protected Matcher<Iterator<Path.Segment>> hasSegmentIterator( String... segment ) {
- Path.Segment[] segments = new Path.Segment[segment.length];
- int index = 0;
- for (String seg : segment) {
- segments[index++] = context.getValueFactories().getPathFactory().createSegment(seg);
- }
- return IsIteratorContaining.hasItems(segments);
- }
-
- protected Name name( String name ) {
- return context.getValueFactories().getNameFactory().create(name);
- }
-
- protected Property property( String name,
- Object... values ) {
- return context.getPropertyFactory().create(name(name), values);
- }
-
- protected ContributionBuilder addContribution( String sourceName ) {
- ContributionBuilder builder = new ContributionBuilder(context, sourceName, contributions);
- contributions.add(builder.getMock());
- return builder;
- }
-
- protected class ContributionBuilder {
- protected final Contribution mockContribution;
- protected final ExecutionContext context;
- protected final Map<Name, Property> properties = new HashMap<Name, Property>();
- protected final List<Path.Segment> children = new ArrayList<Path.Segment>();
-
- protected ContributionBuilder( ExecutionContext context,
- String name,
- List<Contribution> contributions ) {
- this.context = context;
- this.mockContribution = Mockito.mock(Contribution.class);
- stub(mockContribution.getSourceName()).toReturn(name);
- stub(mockContribution.getChildren()).toAnswer(new Answer<Iterator<Path.Segment>>() {
- public Iterator<Path.Segment> answer( InvocationOnMock invocation ) throws Throwable {
- return ContributionBuilder.this.children.iterator();
- }
- });
- stub(mockContribution.getChildrenCount()).toAnswer(new Answer<Integer>() {
- public Integer answer( InvocationOnMock invocation ) throws Throwable {
- return ContributionBuilder.this.children.size();
- }
- });
- stub(mockContribution.getProperties()).toAnswer(new Answer<Iterator<Property>>() {
- public Iterator<Property> answer( InvocationOnMock invocation ) throws Throwable {
- return ContributionBuilder.this.properties.values().iterator();
- }
- });
- stub(mockContribution.getPropertyCount()).toAnswer(new Answer<Integer>() {
- public Integer answer( InvocationOnMock invocation ) throws Throwable {
- return ContributionBuilder.this.properties.size();
- }
- });
- }
-
- public Contribution getMock() {
- return this.mockContribution;
- }
-
- public ContributionBuilder addChildren( String... segmentNamesForChildren ) {
- for (String childSegmentName : segmentNamesForChildren) {
- children.add(context.getValueFactories().getPathFactory().createSegment(childSegmentName));
- }
- return this;
- }
-
- public ContributionBuilder addChildren( Name... segmentNamesForChildren ) {
- for (Name childSegmentName : segmentNamesForChildren) {
- children.add(context.getValueFactories().getPathFactory().createSegment(childSegmentName));
- }
- return this;
- }
-
- public ContributionBuilder addChildren( Path.Segment... segmentNamesForChildren ) {
- for (Path.Segment childSegmentName : segmentNamesForChildren) {
- children.add(childSegmentName);
- }
- return this;
- }
-
- public ContributionBuilder setProperty( String name,
- Object... values ) {
- Name propertyName = context.getValueFactories().getNameFactory().create(name);
- Property property = context.getPropertyFactory().create(propertyName, values);
- stub(mockContribution.getProperty(propertyName)).toReturn(property);
- if (values != null && values.length > 0) {
- properties.put(propertyName, property);
- } else {
- properties.remove(propertyName);
- }
- return this;
- }
- }
-
-}
Copied: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategyTest.java (from rev 522, trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/OneContributionMergeStrategyTest.java)
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategyTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategyTest.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -0,0 +1,209 @@
+/*
+ * 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.connector.federation.merge.strategy;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.connector.federation.merge.FederatedNode;
+import org.jboss.dna.connector.federation.merge.MergePlan;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * @author Randall Hauch
+ */
+public class OneContributionMergeStrategyTest {
+
+ private OneContributionMergeStrategy strategy;
+ private List<Contribution> contributions;
+ private ExecutionContext context;
+ private FederatedNode node;
+ private Map<Name, Property> properties;
+ private List<Path.Segment> children;
+ @Mock
+ private Contribution contribution;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ Path path = mock(Path.class);
+ node = new FederatedNode(path, UUID.randomUUID());
+ strategy = new OneContributionMergeStrategy();
+ contributions = new LinkedList<Contribution>();
+ contributions.add(contribution);
+ context = new BasicExecutionContext();
+ context.getNamespaceRegistry().register("dna", "http://www.jboss.org/dna/something");
+ context.getNamespaceRegistry().register("jcr", "http://www.jcr.org");
+ stub(contribution.getSourceName()).toReturn("source name");
+ children = new LinkedList<Path.Segment>();
+ for (int i = 0; i != 10; ++i) {
+ children.add(context.getValueFactories().getPathFactory().createSegment("a" + i));
+ }
+ properties = new HashMap<Name, Property>();
+ for (int i = 0; i != 10; ++i) {
+ Name propertyName = context.getValueFactories().getNameFactory().create("property" + i);
+ properties.put(propertyName, context.getPropertyFactory().create(propertyName, "value"));
+ }
+ }
+
+ @Test
+ public void shouldMergeTheChildrenFromTheFirstContribution() {
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ assertThat(node.getChildren(), is(children));
+ }
+
+ @Test
+ public void shouldMergeThePropertiesFromTheFirstContribution() {
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ properties.put(DnaLexicon.UUID, node.getPropertiesByName().get(DnaLexicon.UUID));
+ assertThat(node.getPropertiesByName(), is(properties));
+ }
+
+ @Test
+ public void shouldCreateMergePlanInTheFederatedNode() {
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ MergePlan mergePlan = node.getMergePlan();
+ assertThat(mergePlan.getContributionFrom(contribution.getSourceName()), is(sameInstance(contribution)));
+ assertThat(mergePlan.getContributionCount(), is(1));
+ }
+
+ @Test
+ public void shouldSetTheUuidOnTheNodeIfThereIsASingleValuedPropertyNamedUuidWithValueThatConvertsToUuidInstance() {
+ // Test the "dna:uuid" property ...
+ Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
+ UUID uuid = UUID.randomUUID();
+ Property uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+
+ // Test the "jcr:uuid" property ...
+ uuidName = context.getValueFactories().getNameFactory().create("jcr:uuid");
+ uuid = UUID.randomUUID();
+ uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+
+ // Test the "uuid" property ...
+ uuidName = context.getValueFactories().getNameFactory().create("uuid");
+ uuid = UUID.randomUUID();
+ uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+
+ // Test the "uuid" property whose value is a String ...
+ uuidName = context.getValueFactories().getNameFactory().create("uuid");
+ uuid = UUID.randomUUID();
+ uuidProperty = context.getPropertyFactory().create(uuidName, uuid.toString());
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+ }
+
+ @Test
+ public void shouldNotSetTheUuidOnTheNodeIfThereIsNoPropertyNamedUuid() {
+ // Test the "dna:uuid" property ...
+ Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
+ UUID uuid = UUID.randomUUID();
+ Property uuidProperty = context.getPropertyFactory().create(uuidName, uuid);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ assertThat(node.getUuid(), is(not(uuid)));
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(uuid));
+ properties.remove(uuidProperty.getName());
+ }
+
+ @Test
+ public void shouldNotSetTheUuidOnTheNodeIfThereIsAMultiValuedPropertyNamedUuid() {
+ final UUID originalUuid = node.getUuid();
+ // Test the "dna:uuid" property ...
+ Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
+ Property uuidProperty = context.getPropertyFactory().create(uuidName,
+ UUID.randomUUID(),
+ UUID.randomUUID(),
+ UUID.randomUUID());
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(originalUuid));
+ }
+
+ @Test
+ public void shouldNotSetTheUuidOnTheNodeIfThereIsASingleValuedPropertyNamedUuidWithValueThatDoesNotConvertToUuidInstance() {
+ final UUID originalUuid = node.getUuid();
+ // Test the "dna:uuid" property ...
+ Name uuidName = context.getValueFactories().getNameFactory().create("dna:uuid");
+ Property uuidProperty = context.getPropertyFactory().create(uuidName, 3.33d);
+ properties.put(uuidProperty.getName(), uuidProperty);
+ stub(contribution.getChildren()).toReturn(children.iterator());
+ stub(contribution.getProperties()).toReturn(properties.values().iterator());
+ strategy.merge(node, contributions, context);
+ assertThat(node.getUuid(), is(originalUuid));
+ }
+
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategyTest.java (from rev 522, trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/SimpleMergeStrategyTest.java)
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategyTest.java (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategyTest.java 2008-09-17 22:56:29 UTC (rev 531)
@@ -0,0 +1,304 @@
+/*
+ * 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.connector.federation.merge.strategy;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.hamcrest.Matcher;
+import org.jboss.dna.common.collection.IsIteratorContaining;
+import org.jboss.dna.connector.federation.contribution.Contribution;
+import org.jboss.dna.connector.federation.merge.FederatedNode;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.Property;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/**
+ * @author Randall Hauch
+ */
+public class SimpleMergeStrategyTest {
+
+ private SimpleMergeStrategy strategy;
+ private List<Contribution> contributions;
+ private ExecutionContext context;
+ private FederatedNode node;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ Path path = mock(Path.class);
+ node = new FederatedNode(path, UUID.randomUUID());
+ strategy = new SimpleMergeStrategy();
+ contributions = new LinkedList<Contribution>();
+ context = new BasicExecutionContext();
+ context.getNamespaceRegistry().register("dna", "http://www.jboss.org/dna/something");
+ context.getNamespaceRegistry().register("jcr", "http://www.jcr.org");
+ }
+
+ @Test
+ public void shouldAddChildrenFromOneContribution() {
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getChildren(), hasSegments("childA", "childB[1]", "childB[2]"));
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromOneContribution() {
+ addContribution("source1").setProperty("p1", "p1 value");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(2));
+ assertThat(node.getPropertiesByName().get(DnaLexicon.UUID), is(notNullValue()));
+ assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
+ }
+
+ @Test
+ public void shouldAddChildrenFromMultipleContributionsInOrderAndShouldNotChangeSameNameSiblingIndexesWhenChildrenDoNotShareNamesWithChildrenFromDifferentContributions() {
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]");
+ addContribution("source2").addChildren("childX", "childY[1]", "childY[2]");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getChildren(), hasSegments("childA", "childB[1]", "childB[2]", "childX", "childY[1]", "childY[2]"));
+ }
+
+ @Test
+ public void shouldAddChildrenFromMultipleContributionsInOrderAndShouldChangeSameNameSiblingIndexesWhenChildrenDoShareNamesWithChildrenFromDifferentContributions() {
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]");
+ addContribution("source2").addChildren("childX", "childB", "childY");
+ addContribution("source3").addChildren("childX", "childB");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getChildren(), hasSegments("childA",
+ "childB[1]",
+ "childB[2]",
+ "childX[1]",
+ "childB[3]",
+ "childY",
+ "childX[2]",
+ "childB[4]"));
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromMultipleContributionsAndRemoveNoValuesWhenNoContributionsContainSameProperty() {
+ addContribution("source1").setProperty("p1", "p1 value");
+ addContribution("source2").setProperty("p2", "p2 value");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(3));
+ assertThat(node.getPropertiesByName().get(DnaLexicon.UUID), is(notNullValue()));
+ assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
+ assertThat(node.getPropertiesByName().get(name("p2")), is(property("p2", "p2 value")));
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromMultipleContributionsAndRemoveDuplicateValuesWhenContributionsContainSameProperty() {
+ addContribution("source1").setProperty("p1", "p1 value").setProperty("p12", "1", "2", "3");
+ addContribution("source2").setProperty("p2", "p2 value").setProperty("p12", "3", "4");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(4));
+ assertThat(node.getPropertiesByName().get(DnaLexicon.UUID), is(notNullValue()));
+ assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
+ assertThat(node.getPropertiesByName().get(name("p2")), is(property("p2", "p2 value")));
+ assertThat(node.getPropertiesByName().get(name("p12")), is(property("p12", "1", "2", "3", "4")));
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromMultipleContributionsAndMaintainAllValuesForEveryProperty() {
+ addContribution("source1").setProperty("p1", "p1 value").setProperty("p12", "1", "2", "3");
+ addContribution("source2").setProperty("p2", "p2 value").setProperty("p12", "3", "4");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(4));
+ assertThat(node.getPropertiesByName().get(DnaLexicon.UUID), is(notNullValue()));
+ for (Contribution contribution : contributions) {
+ Iterator<Property> iter = contribution.getProperties();
+ while (iter.hasNext()) {
+ Property contributionProperty = iter.next();
+ Property mergedProperty = node.getPropertiesByName().get(contributionProperty.getName());
+ assertThat(mergedProperty, is(notNullValue()));
+ // Make sure that the merged property has each value ...
+ for (Object contributedValue : contributionProperty.getValuesAsArray()) {
+ boolean foundValue = false;
+ for (Object mergedValue : mergedProperty.getValuesAsArray()) {
+ if (mergedValue.equals(contributedValue)) {
+ foundValue = true;
+ break;
+ }
+ }
+ assertThat(foundValue, is(true));
+ }
+ }
+ }
+ }
+
+ @Test
+ public void shouldCombinePropertiesFromMultipleContributionsWhenPropertyValuesAreOfDifferentPropertyTypes() {
+ addContribution("source1").setProperty("p1", "p1 value").setProperty("p12", "1", "2", "3");
+ addContribution("source2").setProperty("p2", "p2 value").setProperty("p12", 3, 4);
+ strategy.merge(node, contributions, context);
+ assertThat(node.getProperties().size(), is(4));
+ assertThat(node.getPropertiesByName().get(DnaLexicon.UUID), is(notNullValue()));
+ assertThat(node.getPropertiesByName().get(name("p1")), is(property("p1", "p1 value")));
+ assertThat(node.getPropertiesByName().get(name("p2")), is(property("p2", "p2 value")));
+ assertThat(node.getPropertiesByName().get(name("p12")), is(property("p12", "1", "2", "3", 4)));
+ }
+
+ @Test
+ public void shouldCreateMergePlanWhenMergingContributions() {
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]").setProperty("p1", "p1 value");
+ addContribution("source2").addChildren("childX", "childB", "childY").setProperty("p2", "p2 value");
+ strategy.merge(node, contributions, context);
+ assertThat(node.getMergePlan(), is(notNullValue()));
+ assertThat(node.getMergePlan().getContributionCount(), is(2));
+ assertThat(node.getMergePlan().getContributionFrom("source1"), is(sameInstance(contributions.get(0))));
+ assertThat(node.getMergePlan().getContributionFrom("source2"), is(sameInstance(contributions.get(1))));
+ }
+
+ @Test
+ public void shouldCorrectlyBuildMockUsingContributionBuilder() {
+ assertThat(contributions.size(), is(0));
+ addContribution("source1").addChildren("childA", "childB[1]", "childB[2]").setProperty("p1", "p1 value");
+ assertThat(contributions.size(), is(1));
+ assertThat(contributions.get(0).getChildren(), hasSegmentIterator("childA", "childB[1]", "childB[2]"));
+ }
+
+ protected Matcher<List<Path.Segment>> hasSegments( String... segment ) {
+ List<Path.Segment> segments = new ArrayList<Path.Segment>();
+ for (String seg : segment) {
+ segments.add(context.getValueFactories().getPathFactory().createSegment(seg));
+ }
+ return equalTo(segments);
+ }
+
+ protected Matcher<Iterator<Path.Segment>> hasSegmentIterator( String... segment ) {
+ Path.Segment[] segments = new Path.Segment[segment.length];
+ int index = 0;
+ for (String seg : segment) {
+ segments[index++] = context.getValueFactories().getPathFactory().createSegment(seg);
+ }
+ return IsIteratorContaining.hasItems(segments);
+ }
+
+ protected Name name( String name ) {
+ return context.getValueFactories().getNameFactory().create(name);
+ }
+
+ protected Property property( String name,
+ Object... values ) {
+ return context.getPropertyFactory().create(name(name), values);
+ }
+
+ protected ContributionBuilder addContribution( String sourceName ) {
+ ContributionBuilder builder = new ContributionBuilder(context, sourceName, contributions);
+ contributions.add(builder.getMock());
+ return builder;
+ }
+
+ protected class ContributionBuilder {
+ protected final Contribution mockContribution;
+ protected final ExecutionContext context;
+ protected final Map<Name, Property> properties = new HashMap<Name, Property>();
+ protected final List<Path.Segment> children = new ArrayList<Path.Segment>();
+
+ protected ContributionBuilder( ExecutionContext context,
+ String name,
+ List<Contribution> contributions ) {
+ this.context = context;
+ this.mockContribution = Mockito.mock(Contribution.class);
+ stub(mockContribution.getSourceName()).toReturn(name);
+ stub(mockContribution.getChildren()).toAnswer(new Answer<Iterator<Path.Segment>>() {
+ public Iterator<Path.Segment> answer( InvocationOnMock invocation ) throws Throwable {
+ return ContributionBuilder.this.children.iterator();
+ }
+ });
+ stub(mockContribution.getChildrenCount()).toAnswer(new Answer<Integer>() {
+ public Integer answer( InvocationOnMock invocation ) throws Throwable {
+ return ContributionBuilder.this.children.size();
+ }
+ });
+ stub(mockContribution.getProperties()).toAnswer(new Answer<Iterator<Property>>() {
+ public Iterator<Property> answer( InvocationOnMock invocation ) throws Throwable {
+ return ContributionBuilder.this.properties.values().iterator();
+ }
+ });
+ stub(mockContribution.getPropertyCount()).toAnswer(new Answer<Integer>() {
+ public Integer answer( InvocationOnMock invocation ) throws Throwable {
+ return ContributionBuilder.this.properties.size();
+ }
+ });
+ }
+
+ public Contribution getMock() {
+ return this.mockContribution;
+ }
+
+ public ContributionBuilder addChildren( String... segmentNamesForChildren ) {
+ for (String childSegmentName : segmentNamesForChildren) {
+ children.add(context.getValueFactories().getPathFactory().createSegment(childSegmentName));
+ }
+ return this;
+ }
+
+ public ContributionBuilder addChildren( Name... segmentNamesForChildren ) {
+ for (Name childSegmentName : segmentNamesForChildren) {
+ children.add(context.getValueFactories().getPathFactory().createSegment(childSegmentName));
+ }
+ return this;
+ }
+
+ public ContributionBuilder addChildren( Path.Segment... segmentNamesForChildren ) {
+ for (Path.Segment childSegmentName : segmentNamesForChildren) {
+ children.add(childSegmentName);
+ }
+ return this;
+ }
+
+ public ContributionBuilder setProperty( String name,
+ Object... values ) {
+ Name propertyName = context.getValueFactories().getNameFactory().create(name);
+ Property property = context.getPropertyFactory().create(propertyName, values);
+ stub(mockContribution.getProperty(propertyName)).toReturn(property);
+ if (values != null && values.length > 0) {
+ properties.put(propertyName, property);
+ } else {
+ properties.remove(propertyName);
+ }
+ return this;
+ }
+ }
+
+}
Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 7 months
DNA SVN: r530 - in trunk/dna-jcr: src/main/java/org/jboss/dna/jcr and 1 other directories.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-09-17 18:56:21 -0400 (Wed, 17 Sep 2008)
New Revision: 530
Modified:
trunk/dna-jcr/pom.xml
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
Log:
Changed UUID map implementations in session to use ReferenceMap from Google collections since it provides for soft references, which is what we want, rather than weak references.
Modified: trunk/dna-jcr/pom.xml
===================================================================
--- trunk/dna-jcr/pom.xml 2008-09-17 20:13:39 UTC (rev 529)
+++ trunk/dna-jcr/pom.xml 2008-09-17 22:56:21 UTC (rev 530)
@@ -100,5 +100,10 @@
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-tests</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.code.google-collections</groupId>
+ <artifactId>google-collect</artifactId>
+ <version>snapshot-20080530</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-09-17 20:13:39 UTC (rev 529)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-09-17 22:56:21 UTC (rev 530)
@@ -21,14 +21,12 @@
*/
package org.jboss.dna.jcr;
-import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.security.AccessControlContext;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
-import java.util.WeakHashMap;
import javax.jcr.Credentials;
import javax.jcr.LoginException;
import javax.jcr.Node;
@@ -42,6 +40,8 @@
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.ExecutionContextFactory;
import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import com.google.common.base.ReferenceType;
+import com.google.common.collect.ReferenceMap;
/**
* Creates JCR {@link Session sessions} to an underlying repository (which may be a federated repository).
@@ -259,6 +259,6 @@
if (workspaceName == null) workspaceName = JcrI18n.defaultWorkspaceName.text();
// Create session
return new JcrSession(this, execContext, workspaceName, connectionFactory.createConnection(workspaceName),
- new WeakHashMap<UUID, WeakReference<Node>>());
+ new ReferenceMap<UUID, Node>(ReferenceType.STRONG, ReferenceType.SOFT));
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-17 20:13:39 UTC (rev 529)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-17 22:56:21 UTC (rev 530)
@@ -23,15 +23,12 @@
import java.io.InputStream;
import java.io.OutputStream;
-import java.lang.ref.WeakReference;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.Calendar;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import java.util.UUID;
-import java.util.WeakHashMap;
import javax.jcr.Credentials;
import javax.jcr.Item;
import javax.jcr.Node;
@@ -61,6 +58,8 @@
import org.jboss.dna.spi.graph.commands.GraphCommand;
import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
import org.xml.sax.ContentHandler;
+import com.google.common.base.ReferenceType;
+import com.google.common.collect.ReferenceMap;
/**
* @author John Verhaeg
@@ -72,8 +71,8 @@
private final Repository repository;
private final ExecutionContext executionContext;
private RepositoryConnection connection;
- private final Map<UUID, WeakReference<Node>> nodesByUuid;
- private final Map<String, WeakReference<Node>> nodesByJcrUuid;
+ private final ReferenceMap<UUID, Node> nodesByUuid;
+ private final ReferenceMap<String, Node> nodesByJcrUuid;
private boolean isLive;
private Workspace workspace;
private JcrRootNode rootNode;
@@ -82,7 +81,7 @@
ExecutionContext executionContext,
String workspaceName,
RepositoryConnection connection,
- Map<UUID, WeakReference<Node>> nodesByUuid ) throws RepositoryException {
+ ReferenceMap<UUID, Node> nodesByUuid ) throws RepositoryException {
assert repository != null;
assert executionContext != null;
assert workspaceName != null;
@@ -92,7 +91,7 @@
this.executionContext = executionContext;
this.connection = connection;
this.nodesByUuid = nodesByUuid;
- this.nodesByJcrUuid = new WeakHashMap<String, WeakReference<Node>>();
+ this.nodesByJcrUuid = new ReferenceMap<String, Node>(ReferenceType.STRONG, ReferenceType.SOFT);
this.isLive = true;
// Following must be initialized after session's state is initialized
this.workspace = new JcrWorkspace(this, workspaceName);
@@ -315,8 +314,7 @@
}
Node getNode( UUID uuid ) {
- WeakReference<Node> ref = nodesByUuid.get(uuid);
- return (ref == null ? null : ref.get());
+ return nodesByUuid.get(uuid);
}
/**
@@ -554,12 +552,12 @@
if (dnaUuidProp == null || !referenceable) uuid = UUID.randomUUID();
else {
uuid = uuidFactory.create(dnaUuidProp.getValues()).next();
- nodesByJcrUuid.put(uuid.toString(), new WeakReference<Node>(node));
+ nodesByJcrUuid.put(uuid.toString(), node);
}
}
node.setInternalUuid(uuid);
// Setup node to be retrieved by DNA UUID
- nodesByUuid.put(new UUID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()), new WeakReference<Node>(node));
+ nodesByUuid.put(uuid, node);
}
/**
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2008-09-17 20:13:39 UTC (rev 529)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2008-09-17 22:56:21 UTC (rev 530)
@@ -29,13 +29,10 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.stub;
import java.io.InputStream;
-import java.lang.ref.WeakReference;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.Calendar;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import java.util.UUID;
import javax.jcr.Item;
import javax.jcr.NamespaceException;
@@ -59,7 +56,8 @@
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.MockitoAnnotations.Mock;
+import com.google.common.base.ReferenceType;
+import com.google.common.collect.ReferenceMap;
/**
* @author jverhaeg
@@ -91,12 +89,12 @@
}
private Session session;
- @Mock
- private Map<UUID, WeakReference<Node>> nodesByUuid;
+ private ReferenceMap<UUID, Node> nodesByUuid;
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
+ nodesByUuid = new ReferenceMap<UUID, Node>(ReferenceType.STRONG, ReferenceType.SOFT);
session = repository.login();
}
@@ -225,7 +223,7 @@
@Test
public void shouldProvideRootNode() throws Exception {
- Map<UUID, WeakReference<Node>> nodesByUuid = new HashMap<UUID, WeakReference<Node>>();
+ ReferenceMap<UUID, Node> nodesByUuid = new ReferenceMap<UUID, Node>(ReferenceType.STRONG, ReferenceType.SOFT);
Session session = new JcrSession(repository, executionContext, WORKSPACE_NAME,
connectionFactory.createConnection(WORKSPACE_NAME), nodesByUuid);
assertThat(nodesByUuid.isEmpty(), is(true));
@@ -233,9 +231,7 @@
assertThat(root, notNullValue());
UUID uuid = ((JcrRootNode)root).getInternalUuid();
assertThat(uuid, notNullValue());
- WeakReference<Node> ref = nodesByUuid.get(uuid);
- assertThat(ref, notNullValue());
- assertThat(ref.get(), is(root));
+ assertThat(nodesByUuid.get(uuid), is(root));
}
@Test
15 years, 7 months
DNA SVN: r529 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-09-17 16:13:39 -0400 (Wed, 17 Sep 2008)
New Revision: 529
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
Log:
Modified populateNode method to not filter out UUID properties from the properties within a JCR node.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-17 20:11:01 UTC (rev 528)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-17 20:13:39 UTC (rev 529)
@@ -528,22 +528,35 @@
Set<Property> properties = new HashSet<Property>();
UUID uuid = null;
Name jcrUuidName = executionContext.getValueFactories().getNameFactory().create("jcr:uuid");
+ Name jcrMixinTypesName = executionContext.getValueFactories().getNameFactory().create("jcr:mixinTypes");
UuidFactory uuidFactory = executionContext.getValueFactories().getUuidFactory();
+ org.jboss.dna.spi.graph.Property dnaUuidProp = null;
+ boolean referenceable = false;
for (org.jboss.dna.spi.graph.Property dnaProp : getNodeCommand.getProperties()) {
Name name = dnaProp.getName();
- if (uuid == null && DnaLexicon.UUID.equals(name)) uuid = uuidFactory.create(dnaProp.getValues()).next();
- else if (dnaProp.isMultiple()) properties.add(new JcrMultiValueProperty(node, executionContext, name, dnaProp));
+ if (dnaProp.isMultiple()) properties.add(new JcrMultiValueProperty(node, executionContext, name, dnaProp));
else {
- if (jcrUuidName.equals(name)) {
- uuid = uuidFactory.create(dnaProp.getValues()).next();
- nodesByJcrUuid.put(uuid.toString(), new WeakReference<Node>(node));
- } else properties.add(new JcrProperty(node, executionContext, name, dnaProp.getValues().next()));
+ if (uuid == null && DnaLexicon.UUID.equals(name)) uuid = uuidFactory.create(dnaProp.getValues()).next();
+ else if (jcrUuidName.equals(name)) dnaUuidProp = dnaProp;
+ else if (jcrMixinTypesName.equals(name)) {
+ org.jboss.dna.spi.graph.ValueFactory<String> stringFactory = executionContext.getValueFactories().getStringFactory();
+ for (String mixin : stringFactory.create(dnaProp)) {
+ if ("mix:referenceable".equals(mixin)) referenceable = true;
+ }
+ }
+ properties.add(new JcrProperty(node, executionContext, name, dnaProp.getValues().next()));
}
}
node.setProperties(properties);
// Set node's UUID, creating one if necessary
- if (uuid == null) uuid = UUID.randomUUID();
+ if (uuid == null) {
+ if (dnaUuidProp == null || !referenceable) uuid = UUID.randomUUID();
+ else {
+ uuid = uuidFactory.create(dnaUuidProp.getValues()).next();
+ nodesByJcrUuid.put(uuid.toString(), new WeakReference<Node>(node));
+ }
+ }
node.setInternalUuid(uuid);
// Setup node to be retrieved by DNA UUID
nodesByUuid.put(new UUID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()), new WeakReference<Node>(node));
15 years, 7 months
DNA SVN: r528 - in trunk/dna-spi/src: main/java/org/jboss/dna/spi/graph/impl and 1 other directories.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-09-17 16:11:01 -0400 (Wed, 17 Sep 2008)
New Revision: 528
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
Log:
DNA-226: Added method create(Iterable<?>) to ValueFactory and a corresponding impl to AbstractValueFactory. I also added a create(Iterator<?>) impl in AbstractValueFactory that allowed me to remove the impls in each concrete class.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/ValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -458,4 +458,29 @@
*/
Iterator<T> create( Iterator<?> values ) throws ValueFormatException, IoException;
+ /**
+ * Create an iterable with the values (of an unknown type). The factory converts any values as required. Note that this method
+ * will not consider {@link #create(InputStream, long)}, {@link #create(Reader, long)} and
+ * {@link #create(String, TextDecoder)}.
+ * <p>
+ * This is useful to use when converting all the {@link Property#getValues() values} of a {@link Property}.
+ * </p>
+ * Example:
+ *
+ * <pre>
+ * Property property = ...
+ * ExecutionContext executionContext = ...
+ * ValueFactory<String> stringFactory = executionContext.getValueFactories().getStringFactory();
+ * for (String token : stringFactory.create(property)) {
+ * ...
+ * }
+ * </pre>
+ *
+ * @param valueIterable the values
+ * @return the iterator of type <code>T</code> over the values, or null if the supplied parameter is null
+ * @throws ValueFormatException if the conversion from an iterator of objects could not be performed
+ * @throws IoException If an unexpected problem occurs during the conversion.
+ * @see Property#getValues()
+ */
+ Iterable<T> create( Iterable<?> valueIterable ) throws ValueFormatException, IoException;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/AbstractValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -378,6 +378,29 @@
return result;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
+ */
+ public Iterator<T> create( Iterator<?> values ) throws ValueFormatException, IoException {
+ return new ConvertingIterator<T>(values, this);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.ValueFactory#create(java.lang.Iterable)
+ */
+ public Iterable<T> create( final Iterable<?> valueIterable ) throws ValueFormatException, IoException {
+ return new Iterable<T>() {
+
+ public Iterator<T> iterator() {
+ return create(valueIterable.iterator());
+ }
+ };
+ }
+
protected static class ConvertingIterator<ValueType> implements Iterator<ValueType> {
private final Iterator<?> delegate;
private final ValueFactory<ValueType> factory;
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BooleanValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -241,16 +240,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<Boolean> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<Boolean>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected Boolean[] createEmptyArray( int length ) {
return new Boolean[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DecimalValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -236,16 +235,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<BigDecimal> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<BigDecimal>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected BigDecimal[] createEmptyArray( int length ) {
return new BigDecimal[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/DoubleValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -244,16 +243,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<Double> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<Double>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected Double[] createEmptyArray( int length ) {
return new Double[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/InMemoryBinaryValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -29,7 +29,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -250,16 +249,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<Binary> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<Binary>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected Binary[] createEmptyArray( int length ) {
return new Binary[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTimeValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -310,16 +309,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<DateTime> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<DateTime>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected DateTime[] createEmptyArray( int length ) {
return new DateTime[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/LongValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -237,16 +236,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<Long> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<Long>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected Long[] createEmptyArray( int length ) {
return new Long[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/NameValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -329,15 +328,6 @@
}
/**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
- */
- public Iterator<Name> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<Name>(values, this);
- }
-
- /**
* <p>
* {@inheritDoc}
* </p>
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/ObjectValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -239,16 +238,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<Object> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<Object>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected Object[] createEmptyArray( int length ) {
return new Object[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/PathValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -28,7 +28,6 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
@@ -631,16 +630,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<Path> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<Path>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected Path[] createEmptyArray( int length ) {
return new Path[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/StringValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -29,7 +29,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -285,16 +284,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<String> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<String>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected String[] createEmptyArray( int length ) {
return new String[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UriValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -28,7 +28,6 @@
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -257,16 +256,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<URI> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<URI>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected URI[] createEmptyArray( int length ) {
return new URI[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidReferenceValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -247,16 +246,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<Reference> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<Reference>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected Reference[] createEmptyArray( int length ) {
return new Reference[length];
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/UuidValueFactory.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -27,7 +27,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.text.TextDecoder;
@@ -263,16 +262,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<UUID> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<UUID>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected UUID[] createEmptyArray( int length ) {
return new UUID[length];
Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-09-17 18:57:47 UTC (rev 527)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/AbstractValueFactoryTest.java 2008-09-17 20:11:01 UTC (rev 528)
@@ -32,7 +32,6 @@
import java.net.URI;
import java.util.Calendar;
import java.util.Date;
-import java.util.Iterator;
import java.util.UUID;
import org.jboss.dna.common.text.NoOpEncoder;
import org.jboss.dna.common.text.TextDecoder;
@@ -147,16 +146,7 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.spi.graph.ValueFactory#create(java.util.Iterator)
*/
- public Iterator<String> create( Iterator<?> values ) throws IoException {
- return new ConvertingIterator<String>(values, this);
- }
-
- /**
- * {@inheritDoc}
- */
@Override
protected String[] createEmptyArray( int length ) {
return new String[length];
15 years, 7 months
DNA SVN: r527 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-09-17 14:57:47 -0400 (Wed, 17 Sep 2008)
New Revision: 527
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
Log:
Changed all JCR classes that call getString on a DNA name, segment, or path to provide the namespace registry so URIs get transformed into prefixes correctly.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -55,13 +55,13 @@
@NotThreadSafe
abstract class AbstractJcrNode extends AbstractJcrItem implements Node {
- private final Session session;
+ private final JcrSession session;
Set<Property> properties;
List<Name> children;
List<Integer> childNameCounts;
private UUID uuid;
- AbstractJcrNode( Session session ) {
+ AbstractJcrNode( JcrSession session ) {
assert session != null;
this.session = session;
}
@@ -423,7 +423,7 @@
int childNdx = 0;
if (children != null) {
for (Name child : children) {
- if (name.equals(child.getString())) {
+ if (name.equals(child.getString(session.getExecutionContext().getNamespaceRegistry()))) {
if (ndxNdx >= 0) {
return (Integer.parseInt(relativePath.substring(ndxNdx + 1, relativePath.length() - 1)) <= childNameCounts.get(childNdx));
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -124,7 +124,7 @@
* @see javax.jcr.Item#getName()
*/
public final String getName() {
- return name.getString();
+ return name.getString(executionContext.getNamespaceRegistry());
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -25,7 +25,6 @@
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
-import javax.jcr.Session;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.spi.graph.Path.Segment;
@@ -38,7 +37,7 @@
private final UUID parentUuid;
private final Segment segment;
- JcrNode( Session session,
+ JcrNode( JcrSession session,
UUID parentUuid,
Segment segment ) {
super(session);
@@ -72,7 +71,7 @@
* @see javax.jcr.Item#getName()
*/
public String getName() {
- return segment.getName().getString();
+ return segment.getName().getString(((JcrSession)getSession()).getExecutionContext().getNamespaceRegistry());
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeIterator.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -105,7 +105,8 @@
childNdx = 1;
}
try {
- node = parent.getNode(child.getString() + '[' + childNdx + ']');
+ node = parent.getNode(child.getString(((JcrSession)parent.getSession()).getExecutionContext().getNamespaceRegistry())
+ + '[' + childNdx + ']');
childNdx++;
ndx++;
return node;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -23,7 +23,6 @@
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
-import javax.jcr.Session;
import net.jcip.annotations.NotThreadSafe;
/**
@@ -32,7 +31,7 @@
@NotThreadSafe
final class JcrRootNode extends AbstractJcrNode {
- JcrRootNode( Session session ) {
+ JcrRootNode( JcrSession session ) {
super(session);
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -248,7 +248,7 @@
// If a node isn't found & last segment contains no index, get parent node & search for a property with the last name in
// the path
if (!lastSeg.hasIndex()) {
- return getNode(parentPath).getProperty(lastSeg.getString());
+ return getNode(parentPath).getProperty(lastSeg.getString(executionContext.getNamespaceRegistry()));
}
// If a property isn't found, throw a PathNotFoundException
throw new PathNotFoundException(JcrI18n.pathNotFound.text(path));
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -39,11 +39,12 @@
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
-import javax.jcr.Session;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
import javax.jcr.Workspace;
import javax.jcr.version.Version;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path.Segment;
import org.jboss.dna.spi.graph.impl.BasicName;
import org.junit.Before;
@@ -57,7 +58,7 @@
*/
public class AbstractJcrNodeTest {
- static MockAbstractJcrNode createChild( Session session,
+ static MockAbstractJcrNode createChild( JcrSession session,
String name,
int index,
List<Segment> children,
@@ -66,7 +67,7 @@
Segment seg = Mockito.mock(Segment.class);
stub(seg.getName()).toReturn(new BasicName(null, name));
children.add(seg);
- stub(session.getItem(parent.getPath() + "/{}" + name + '[' + index + ']')).toReturn(child);
+ stub(session.getItem(parent.getPath() + "/" + name + '[' + index + ']')).toReturn(child);
return child;
}
@@ -75,7 +76,7 @@
String name;
Node parent;
- MockAbstractJcrNode( Session session,
+ MockAbstractJcrNode( JcrSession session,
String name,
Node parent ) {
super(session);
@@ -106,13 +107,17 @@
private AbstractJcrNode node;
@Mock
- private Session session;
+ private JcrSession session;
private List<Segment> children;
private Set<Property> properties;
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
+ NamespaceRegistry registry = Mockito.mock(NamespaceRegistry.class);
+ ExecutionContext context = Mockito.mock(ExecutionContext.class);
+ stub(context.getNamespaceRegistry()).toReturn(registry);
+ stub(session.getExecutionContext()).toReturn(context);
children = new ArrayList<Segment>();
properties = new HashSet<Property>();
node = new MockAbstractJcrNode(session, "node", null);
@@ -319,7 +324,7 @@
@Test
public void shouldProvideSession() throws Exception {
- assertThat(node.getSession(), is(session));
+ assertThat((JcrSession)node.getSession(), is(session));
}
@Test
@@ -378,7 +383,7 @@
Node child = createChild(session, "child", 1, children, node);
Node child2 = createChild(session, "child2", 1, children, child);
node.setChildren(children);
- assertThat(node.hasNode("{}child"), is(true));
+ assertThat(node.hasNode("child"), is(true));
stub(session.getItem("/node/child/{}child2")).toReturn(child2);
assertThat(node.hasNode("child/{}child2"), is(true));
}
@@ -460,7 +465,7 @@
@Test
public void shouldProvideIsSame() throws Exception {
stub(session.getWorkspace()).toReturn(Mockito.mock(Workspace.class));
- Session session2 = Mockito.mock(Session.class);
+ JcrSession session2 = Mockito.mock(JcrSession.class);
Node node2 = new MockAbstractJcrNode(session2, node.getName(), node.getParent());
assertThat(node.isSame(node2), is(false));
Property prop = Mockito.mock(Property.class);
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -37,6 +37,7 @@
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -54,6 +55,8 @@
@Mock
private Node node;
@Mock
+ private NamespaceRegistry namespaceRegistry;
+ @Mock
private ExecutionContext executionContext;
@Mock
private Name name;
@@ -62,6 +65,7 @@
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
stub(node.getSession()).toReturn(session);
+ stub(executionContext.getNamespaceRegistry()).toReturn(namespaceRegistry);
prop = new MockAbstractJcrProperty(node, executionContext, name);
}
@@ -128,7 +132,7 @@
@Test
public void shouldProvideName() throws Exception {
- stub(name.getString()).toReturn("name");
+ stub(name.getString(namespaceRegistry)).toReturn("name");
assertThat(prop.getName(), is("name"));
}
@@ -140,7 +144,7 @@
@Test
public void shouldProvidePath() throws Exception {
stub(node.getPath()).toReturn("/nodeName");
- stub(name.getString()).toReturn("propertyName");
+ stub(name.getString(namespaceRegistry)).toReturn("propertyName");
assertThat(prop.getPath(), is("/nodeName/propertyName"));
}
@@ -158,11 +162,11 @@
@Test
public void shouldIndicateSameAsNodeWithSameParentAndName() throws Exception {
- stub(name.getString()).toReturn("propertyName");
+ stub(name.getString(namespaceRegistry)).toReturn("propertyName");
Node otherNode = Mockito.mock(Node.class);
stub(otherNode.getSession()).toReturn(session);
Name otherName = Mockito.mock(Name.class);
- stub(otherName.getString()).toReturn("propertyName");
+ stub(otherName.getString(namespaceRegistry)).toReturn("propertyName");
stub(node.isSame(otherNode)).toReturn(true);
Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, otherName);
assertThat(prop.isSame(otherProp), is(true));
@@ -170,11 +174,11 @@
@Test
public void shouldIndicateDifferentThanNodeWithDifferentParent() throws Exception {
- stub(name.getString()).toReturn("propertyName");
+ stub(name.getString(namespaceRegistry)).toReturn("propertyName");
Node otherNode = Mockito.mock(Node.class);
stub(otherNode.getSession()).toReturn(session);
Name otherName = Mockito.mock(Name.class);
- stub(otherName.getString()).toReturn("propertyName");
+ stub(otherName.getString(namespaceRegistry)).toReturn("propertyName");
stub(node.isSame(otherNode)).toReturn(false);
Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, otherName);
assertThat(prop.isSame(otherProp), is(false));
@@ -182,11 +186,11 @@
@Test
public void shouldIndicateDifferentThanNodeWithDifferentName() throws Exception {
- stub(name.getString()).toReturn("propertyName");
+ stub(name.getString(namespaceRegistry)).toReturn("propertyName");
Node otherNode = Mockito.mock(Node.class);
stub(otherNode.getSession()).toReturn(session);
Name otherName = Mockito.mock(Name.class);
- stub(otherName.getString()).toReturn("propertyName2");
+ stub(otherName.getString(namespaceRegistry)).toReturn("propertyName2");
stub(node.isSame(otherNode)).toReturn(true);
Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext, otherName);
assertThat(prop.isSame(otherProp), is(false));
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeIteratorTest.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -24,15 +24,18 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
import java.util.ArrayList;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
-import javax.jcr.Session;
import org.jboss.dna.jcr.AbstractJcrNodeTest.MockAbstractJcrNode;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path.Segment;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -43,12 +46,16 @@
private AbstractJcrNode node;
@Mock
- private Session session;
+ private JcrSession session;
private List<Segment> children;
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
+ NamespaceRegistry registry = Mockito.mock(NamespaceRegistry.class);
+ ExecutionContext context = Mockito.mock(ExecutionContext.class);
+ stub(context.getNamespaceRegistry()).toReturn(registry);
+ stub(session.getExecutionContext()).toReturn(context);
children = new ArrayList<Segment>();
node = new MockAbstractJcrNode(session, "node", null);
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -23,6 +23,7 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.stub;
import java.util.ArrayList;
import java.util.HashSet;
@@ -30,7 +31,9 @@
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.Property;
+import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Path.Segment;
import org.junit.Before;
import org.junit.Test;
@@ -54,11 +57,13 @@
root = new JcrRootNode(session);
Segment segment = Mockito.mock(Segment.class);
Name name = Mockito.mock(Name.class);
- stub(name.getString()).toReturn("name");
+ stub(name.getString((NamespaceRegistry)anyObject())).toReturn("name");
stub(segment.getName()).toReturn(name);
stub(segment.getIndex()).toReturn(2);
UUID uuid = UUID.randomUUID();
node = new JcrNode(session, uuid, segment);
+ ExecutionContext context = Mockito.mock(ExecutionContext.class);
+ stub(session.getExecutionContext()).toReturn(context);
stub(session.getNode(uuid)).toReturn(root);
node.setProperties(new HashSet<Property>());
node.setChildren(new ArrayList<Segment>());
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -28,7 +28,6 @@
import java.util.Set;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
-import javax.jcr.Session;
import org.jboss.dna.jcr.AbstractJcrNodeTest.MockAbstractJcrNode;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +42,7 @@
private AbstractJcrNode node;
@Mock
- private Session session;
+ private JcrSession session;
private Set<Property> properties;
@Before
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java 2008-09-17 16:01:02 UTC (rev 526)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java 2008-09-17 18:57:47 UTC (rev 527)
@@ -28,7 +28,6 @@
import java.util.Set;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Property;
-import javax.jcr.Session;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
@@ -41,7 +40,7 @@
private JcrRootNode root;
@Mock
- private Session session;
+ private JcrSession session;
private Set<Property> properties;
@Before
15 years, 7 months
DNA SVN: r526 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-09-17 12:01:02 -0400 (Wed, 17 Sep 2008)
New Revision: 526
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
Log:
Corrected JcrNode's getParent() method to use new getNode(UUID) method on JcrSession instead of getNodeByUUID(String), which is currently an unsupported operation.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-09-17 15:37:31 UTC (rev 525)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-09-17 16:01:02 UTC (rev 526)
@@ -22,6 +22,7 @@
package org.jboss.dna.jcr;
import java.util.UUID;
+import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -79,8 +80,12 @@
*
* @see javax.jcr.Item#getParent()
*/
- public Node getParent() throws RepositoryException {
- return getSession().getNodeByUUID(parentUuid.toString());
+ public Node getParent() throws ItemNotFoundException {
+ Node node = ((JcrSession)getSession()).getNode(parentUuid);
+ if (node == null) {
+ throw new ItemNotFoundException();
+ }
+ return node;
}
/**
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-17 15:37:31 UTC (rev 525)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-17 16:01:02 UTC (rev 526)
@@ -67,7 +67,7 @@
* @author Randall Hauch
*/
@NotThreadSafe
-final class JcrSession implements Session {
+class JcrSession implements Session {
private final Repository repository;
private final ExecutionContext executionContext;
@@ -300,12 +300,9 @@
if (dnaUuidProp == null) dnaUuidProp = command.getPropertiesByName().get(DnaLexicon.UUID);
if (dnaUuidProp != null) {
UUID uuid = executionContext.getValueFactories().getUuidFactory().create(dnaUuidProp.getValues()).next();
- WeakReference<Node> ref = nodesByUuid.get(uuid);
- if (ref != null) {
- Node node = ref.get();
- if (node != null) {
- return node;
- }
+ Node node = getNode(uuid);
+ if (node != null) {
+ return node;
}
}
// If not create a new one & populate it
@@ -317,6 +314,11 @@
return node;
}
+ Node getNode( UUID uuid ) {
+ WeakReference<Node> ref = nodesByUuid.get(uuid);
+ return (ref == null ? null : ref.get());
+ }
+
/**
* {@inheritDoc}
*
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-09-17 15:37:31 UTC (rev 525)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-09-17 16:01:02 UTC (rev 526)
@@ -30,7 +30,6 @@
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.Property;
-import javax.jcr.Session;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path.Segment;
import org.junit.Before;
@@ -47,7 +46,7 @@
private JcrNode node;
private Node root;
@Mock
- private Session session;
+ private JcrSession session;
@Before
public void before() throws Exception {
@@ -60,7 +59,7 @@
stub(segment.getIndex()).toReturn(2);
UUID uuid = UUID.randomUUID();
node = new JcrNode(session, uuid, segment);
- stub(session.getNodeByUUID(uuid.toString())).toReturn(root);
+ stub(session.getNode(uuid)).toReturn(root);
node.setProperties(new HashSet<Property>());
node.setChildren(new ArrayList<Segment>());
}
15 years, 7 months
DNA SVN: r524 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: jverhaeg(a)redhat.com
Date: 2008-09-17 11:20:24 -0400 (Wed, 17 Sep 2008)
New Revision: 524
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
Log:
DNA-178: Determined we also need a minimal implementation of PropertyDefintion to determine whether a property has multiple values.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-09-17 15:20:24 UTC (rev 524)
@@ -34,7 +34,6 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
-import javax.jcr.nodetype.PropertyDefinition;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.ExecutionContext;
@@ -100,16 +99,6 @@
/**
* {@inheritDoc}
*
- * @throws UnsupportedOperationException always
- * @see javax.jcr.Property#getDefinition()
- */
- public PropertyDefinition getDefinition() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Item#getDepth()
*/
public int getDepth() throws RepositoryException {
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java 2008-09-17 15:20:24 UTC (rev 524)
@@ -0,0 +1,122 @@
+/*
+ * 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.jcr;
+
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+
+/**
+ * @author jverhaeg
+ */
+abstract class AbstractJcrPropertyDefinition implements PropertyDefinition {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see javax.jcr.nodetype.PropertyDefinition#getDefaultValues()
+ */
+ public final Value[] getDefaultValues() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see javax.jcr.nodetype.PropertyDefinition#getRequiredType()
+ */
+ public final int getRequiredType() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see javax.jcr.nodetype.PropertyDefinition#getValueConstraints()
+ */
+ public final String[] getValueConstraints() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
+ */
+ public final NodeType getDeclaringNodeType() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see javax.jcr.nodetype.ItemDefinition#getName()
+ */
+ public final String getName() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see javax.jcr.nodetype.ItemDefinition#getOnParentVersion()
+ */
+ public final int getOnParentVersion() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see javax.jcr.nodetype.ItemDefinition#isAutoCreated()
+ */
+ public final boolean isAutoCreated() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see javax.jcr.nodetype.ItemDefinition#isMandatory()
+ */
+ public final boolean isMandatory() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException always
+ * @see javax.jcr.nodetype.ItemDefinition#isProtected()
+ */
+ public final boolean isProtected() {
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2008-09-17 15:20:24 UTC (rev 524)
@@ -30,6 +30,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
@@ -82,6 +83,20 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Property#getDefinition()
+ */
+ public PropertyDefinition getDefinition() {
+ return new AbstractJcrPropertyDefinition() {
+
+ public boolean isMultiple() {
+ return true;
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @throws ValueFormatException always
* @see javax.jcr.Property#getDouble()
*/
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2008-09-17 15:20:24 UTC (rev 524)
@@ -27,6 +27,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.ValueFactories;
@@ -69,6 +70,20 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Property#getDefinition()
+ */
+ public PropertyDefinition getDefinition() {
+ return new AbstractJcrPropertyDefinition() {
+
+ public boolean isMultiple() {
+ return false;
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Property#getDouble()
*/
public double getDouble() throws RepositoryException {
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-09-17 15:20:24 UTC (rev 524)
@@ -33,6 +33,7 @@
import javax.jcr.Property;
import javax.jcr.Session;
import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
@@ -270,6 +271,15 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Property#getDefinition()
+ */
+ public PropertyDefinition getDefinition() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Property#getDouble()
*/
public double getDouble() {
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java 2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java 2008-09-17 15:20:24 UTC (rev 524)
@@ -34,6 +34,7 @@
import javax.jcr.PropertyType;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.connector.BasicExecutionContext;
import org.jboss.dna.spi.graph.Name;
@@ -49,6 +50,7 @@
*/
public class JcrMultiValuePropertyTest {
+ private Property prop;
@Mock
private Node node;
private ExecutionContext executionContext = new BasicExecutionContext();
@@ -58,6 +60,7 @@
@Before
public void before() {
MockitoAnnotations.initMocks(this);
+ prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true));
}
@Test( expected = AssertionError.class )
@@ -67,10 +70,9 @@
@Test
public void shouldProvideAppropriateType() throws Exception {
- Property prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true));
assertThat(prop.getType(), is(PropertyType.BOOLEAN));
Calendar cal = Calendar.getInstance();
- prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(cal));
+ Property prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(cal));
assertThat(prop.getType(), is(PropertyType.DATE));
prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(cal.getTime()));
assertThat(prop.getType(), is(PropertyType.DATE));
@@ -102,7 +104,7 @@
@Test( expected = ValueFormatException.class )
public void shouldNotProvideBoolean() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true)).getBoolean();
+ prop.getBoolean();
}
@Test( expected = ValueFormatException.class )
@@ -115,6 +117,63 @@
new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(Calendar.getInstance().getTime())).getDate();
}
+ @Test
+ public void shouldProvidePropertyDefinition() throws Exception {
+ assertThat(prop.getDefinition(), notNullValue());
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionDeclaringNodeType() throws Exception {
+ prop.getDefinition().getDeclaringNodeType();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionDefaultValues() throws Exception {
+ prop.getDefinition().getDefaultValues();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionName() throws Exception {
+ prop.getDefinition().getName();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionGetOnParentVersion() throws Exception {
+ prop.getDefinition().getOnParentVersion();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionGetRequiredType() throws Exception {
+ prop.getDefinition().getRequiredType();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionGetValueConstraints() throws Exception {
+ prop.getDefinition().getValueConstraints();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionIsAutoCreated() throws Exception {
+ prop.getDefinition().isAutoCreated();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionIsMandatory() throws Exception {
+ prop.getDefinition().isMandatory();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionIsProtected() throws Exception {
+ prop.getDefinition().isProtected();
+ }
+
+ @Test
+ public void shouldIndicateHasMultipleValues() throws Exception {
+ PropertyDefinition def = prop.getDefinition();
+ assertThat(def, notNullValue());
+ assertThat(def.isMultiple(), is(true));
+ }
+
@Test( expected = ValueFormatException.class )
public void shouldNotProvideDoubleForDouble() throws Exception {
new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1.0)).getDouble();
@@ -147,12 +206,11 @@
@Test( expected = ValueFormatException.class )
public void shouldNotProvideValue() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true)).getValue();
+ prop.getValue();
}
@Test
public void shouldProvideValues() throws Exception {
- Property prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true));
Value[] vals = prop.getValues();
assertThat(vals, notNullValue());
assertThat(vals.length, is(1));
@@ -161,14 +219,18 @@
@Test( expected = ValueFormatException.class )
public void shouldNotProvideLength() throws Exception {
- new JcrMultiValueProperty(node, executionContext, name, Arrays.asList("value")).getLength();
+ prop.getLength();
}
@Test
public void shouldProvideLengths() throws Exception {
- long[] lengths = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList("value")).getLengths();
+ long[] lengths = prop.getLengths();
assertThat(lengths, notNullValue());
assertThat(lengths.length, is(1));
+ assertThat(lengths[0], is(4L));
+ lengths = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList("value")).getLengths();
+ assertThat(lengths, notNullValue());
+ assertThat(lengths.length, is(1));
assertThat(lengths[0], is(5L));
Object obj = new Object();
lengths = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(obj)).getLengths();
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-09-17 15:20:24 UTC (rev 524)
@@ -33,6 +33,7 @@
import javax.jcr.PropertyType;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.connector.BasicExecutionContext;
import org.jboss.dna.spi.graph.Name;
@@ -48,6 +49,7 @@
*/
public class JcrPropertyTest {
+ private Property prop;
@Mock
private Node node;
private ExecutionContext executionContext = new BasicExecutionContext();
@@ -57,6 +59,7 @@
@Before
public void before() {
MockitoAnnotations.initMocks(this);
+ prop = new JcrProperty(node, executionContext, name, true);
}
@Test( expected = AssertionError.class )
@@ -66,7 +69,6 @@
@Test
public void shouldProvideBoolean() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, true);
assertThat(prop.getBoolean(), is(true));
assertThat(prop.getType(), is(PropertyType.BOOLEAN));
}
@@ -83,6 +85,63 @@
}
@Test
+ public void shouldProvidePropertyDefinition() throws Exception {
+ assertThat(prop.getDefinition(), notNullValue());
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionDeclaringNodeType() throws Exception {
+ prop.getDefinition().getDeclaringNodeType();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionDefaultValues() throws Exception {
+ prop.getDefinition().getDefaultValues();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionName() throws Exception {
+ prop.getDefinition().getName();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionGetOnParentVersion() throws Exception {
+ prop.getDefinition().getOnParentVersion();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionGetRequiredType() throws Exception {
+ prop.getDefinition().getRequiredType();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionGetValueConstraints() throws Exception {
+ prop.getDefinition().getValueConstraints();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionIsAutoCreated() throws Exception {
+ prop.getDefinition().isAutoCreated();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionIsMandatory() throws Exception {
+ prop.getDefinition().isMandatory();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowPropertyDefinitionIsProtected() throws Exception {
+ prop.getDefinition().isProtected();
+ }
+
+ @Test
+ public void shouldIndicateHasSingleValue() throws Exception {
+ PropertyDefinition def = prop.getDefinition();
+ assertThat(def, notNullValue());
+ assertThat(def.isMultiple(), is(false));
+ }
+
+ @Test
public void shouldProvideDouble() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, 1.0);
assertThat(prop.getDouble(), is(1.0));
@@ -155,7 +214,6 @@
@Test
public void shouldProvideValue() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name, true);
Value val = prop.getValue();
assertThat(val, notNullValue());
assertThat(val.getBoolean(), is(true));
@@ -163,11 +221,12 @@
@Test( expected = ValueFormatException.class )
public void shouldNotProvideValues() throws Exception {
- new JcrProperty(node, executionContext, name, true).getValues();
+ prop.getValues();
}
@Test
public void shouldProvideLength() throws Exception {
+ assertThat(prop.getLength(), is(4L));
assertThat(new JcrProperty(node, executionContext, name, "value").getLength(), is(5L));
Object obj = new Object();
assertThat(new JcrProperty(node, executionContext, name, obj).getLength(), is((long)obj.toString().length()));
@@ -175,6 +234,6 @@
@Test( expected = ValueFormatException.class )
public void shouldNotProvideLengths() throws Exception {
- new JcrProperty(node, executionContext, name, "value").getLengths();
+ prop.getLengths();
}
}
15 years, 7 months
DNA SVN: r523 - in trunk: docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-09-17 11:08:00 -0400 (Wed, 17 Sep 2008)
New Revision: 523
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/config/run.sh
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/UserInterface.java
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
Log:
DNA-222 - Create Getting Started example application for repositories
http://jira.jboss.com/jira/browse/DNA-222
Additional changes after more testing. Mostly working now, except for DNA-225.
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/config/run.sh
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/config/run.sh 2008-09-16 20:26:44 UTC (rev 522)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/config/run.sh 2008-09-17 15:08:00 UTC (rev 523)
@@ -1,3 +1,3 @@
#!/bin/sh
-java -Djava.ext.dirs=`pwd`/lib -cp .:dna-example-sequencers-0.1-SNAPSHOT.jar org.jboss.example.dna.repository.RepositoryClient $1
\ No newline at end of file
+java -Djava.ext.dirs=`pwd`/lib -cp .:dna-example-repositories-0.1-SNAPSHOT.jar org.jboss.example.dna.repository.RepositoryClient $1
\ No newline at end of file
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java 2008-09-16 20:26:44 UTC (rev 522)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java 2008-09-17 15:08:00 UTC (rev 523)
@@ -29,7 +29,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.security.auth.callback.CallbackHandler;
import org.jboss.dna.common.util.StringUtil;
+import com.sun.security.auth.callback.TextCallbackHandler;
/**
* @author Randall Hauch
@@ -41,17 +43,37 @@
private final RepositoryClient repositoryClient;
private final Map<Integer, String> selectionToSourceName = new HashMap<Integer, String>();
+ /**
+ * Construct the console input and prompt for user input to interact with the RepositoryClient.
+ *
+ * @param client the client that should be used; may not be null
+ * @param args the command-line arguments; may not be null but may be empty
+ */
public ConsoleInput( final RepositoryClient client,
final String[] args ) {
+ assert client != null;
this.repositoryClient = client;
+ for (String arg : args) {
+ arg = arg.trim().toLowerCase();
+ if (arg.equals("--help")) {
+ System.out.println();
+ System.out.println("Usage: run.sh [options]");
+ System.out.println();
+ System.out.println("Options:");
+ System.out.println(" --api=value Specify which API should be used to obtain the content.");
+ System.out.println(" The 'value' must be either 'jcr' or 'dna', and defaults");
+ System.out.println(" to 'jcr'.");
+ System.out.println(" --jaas Specify that JAAS should be used to authenticate the user.");
+ System.out.println(" --jaas=name With no 'name', use JAAS with an application context");
+ System.out.println(" named \"" + RepositoryClient.JAAS_LOGIN_CONTEXT_NAME + "\".");
+ System.out.println(" If another application context is to be used, then specify");
+ System.out.println(" the name.");
+ System.out.println(" --help Print these instructions and exit.");
+ System.out.println();
+ return;
+ }
+ }
try {
- System.out.println();
- System.out.print("Starting repositories ... ");
- client.startRepositories();
- System.out.println("done.");
- System.out.println();
-
- System.out.println(getMenu());
Thread eventThread = new Thread(new Runnable() {
private boolean quit = false;
@@ -59,34 +81,30 @@
@SuppressWarnings( "synthetic-access" )
public void run() {
try {
+ System.out.println();
+ System.out.print("Starting repositories ... ");
+ client.startRepositories();
+ System.out.println("done.");
+ System.out.println();
+ displayMainMenu();
+
while (!quit) {
System.out.print(">");
try {
- String input = in.readLine();
- if (input.length() != 1) {
- System.out.println("Please enter a valid option.");
- continue;
+ String input = in.readLine().trim();
+ if ("?".equals(input) || "h".equals(input)) displayMainMenu();
+ else if ("q".equals(input)) quit = true;
+ else {
+ try {
+ int selection = Integer.parseInt(input);
+ String sourceName = selectionToSourceName.get(selection);
+ displayNavigationMenu(sourceName);
+ displayMainMenu();
+ } catch (NumberFormatException e) {
+ System.out.println("Invalid option.");
+ displayMainMenu();
+ }
}
-
- char option = input.charAt(0);
- switch (option) {
- case '?':
- case 'h':
- System.out.println(getMenu());
- break;
- case 'q':
- quit = true;
- break;
- default:
- try {
- int selection = Integer.parseInt("" + option);
- String sourceName = selectionToSourceName.get(selection);
- navigate(sourceName);
- } catch (NumberFormatException e) {
- System.out.println("Invalid option.");
- break;
- }
- }
} catch (NumberFormatException e) {
System.out.println("Invalid integer " + e.getMessage());
} catch (IllegalArgumentException e) {
@@ -97,6 +115,9 @@
e.printStackTrace();
}
}
+ } catch (Exception err) {
+ System.out.println("Error: " + err.getLocalizedMessage());
+ err.printStackTrace(System.err);
} finally {
try {
// Terminate ...
@@ -122,72 +143,98 @@
}
}
- protected String getMenu() {
+ /**
+ * Generate the main menu for the console-based application.
+ */
+ protected void displayMainMenu() {
selectionToSourceName.clear();
- StringBuilder buffer = new StringBuilder();
- buffer.append("-----------------------------------\n");
- buffer.append("Menu:\n");
- buffer.append("\n");
- buffer.append(" Select a repository to view:\n");
+ System.out.println("-----------------------------------");
+ System.out.println("Menu:");
+ System.out.println();
+ System.out.println("Select a repository to view:");
int selection = 1;
- for (String sourceName : this.repositoryClient.getNamesOfRepositories()) {
+ for (String sourceName : repositoryClient.getNamesOfRepositories()) {
selectionToSourceName.put(selection, sourceName);
- buffer.append(" " + selection + ") " + sourceName + "\n");
+ System.out.println(StringUtil.justifyRight("" + selection++, 3, ' ') + ") " + sourceName);
}
- buffer.append(" or\n");
- buffer.append(" ?) Show this menu\n");
- buffer.append(" q) Quit");
- return buffer.toString();
+ System.out.println("or");
+ System.out.println(" ?) Show this menu");
+ System.out.println(" q) Quit");
}
- protected void navigate( String sourceName ) {
+ /**
+ * Display the menu for navigating the source with the supplied name. This method returns as soon as the user exits the
+ * source.
+ *
+ * @param sourceName the source to be navigated; may not be null
+ */
+ protected void displayNavigationMenu( String sourceName ) {
+ assert sourceName != null;
String currentPath = "/";
+ System.out.println();
+ System.out.println("Entering the \"" + sourceName + "\" repository.");
+ displayNavigationHelp();
while (true) {
-
- // Ask for the command ...
- System.out.print("> ");
try {
+ // Print the prompt and read the input command ...
+ System.out.print(sourceName + "> ");
String input = in.readLine().trim();
- if (input.length() == 0) {
- continue;
- }
+ // Process the command ...
+ if (input.length() == 0) continue;
if ("?".equals(input) || "help".equals(input) || "h".equals(input)) {
- System.out.println(" Enter a command:");
- System.out.println(" pwd print the current node's path");
- System.out.println(" ls [path] to list the details of the node at the specified absolute or relative path");
- System.out.println(" (or the current path if none is supplied)");
- System.out.println(" cd path to change to the node at the specified absolute or relative path");
- System.out.println(" exit to exit this repository and return to the main menu");
- System.out.println(" and press return:");
+ displayNavigationHelp();
} else if ("pwd".equals(input)) {
- System.out.println(" " + currentPath);
+ System.out.println(currentPath);
} else if ("exit".equals(input)) {
return;
- } else if (input.startsWith("ls")) {
- input = input.substring("ls".length()).trim();
- String path = currentPath;
- if (input.length() != 0) path = input;
+ } else if (input.startsWith("ls") || input.startsWith("ll")) {
+ input = input.substring(2).trim();
+ String path = repositoryClient.buildPath(currentPath, input);
displayNode(sourceName, path);
} else if (input.startsWith("cd ")) {
input = input.substring("cd ".length()).trim();
if (input.length() == 0) continue;
- // Check to see if the new path exists ...
- if (!repositoryClient.getNodeInfo(sourceName, input, null, null)) {
- System.out.println(" \"" + input + "\" does not exist");
+ // Change the current path to the new location
+ String oldPath = currentPath;
+ currentPath = repositoryClient.buildPath(currentPath, input);
+ // If the current path does not exist, then go back to the previous path ...
+ if (!repositoryClient.getNodeInfo(sourceName, currentPath, null, null)) {
+ System.out.println("\"" + currentPath + "\" does not exist");
+ currentPath = oldPath;
} else {
- currentPath = input;
+ System.out.println(currentPath);
}
}
} catch (Throwable e) {
displayError(" processing your command", e);
}
}
+ }
+ protected void displayNavigationHelp() {
+ System.out.println();
+ System.out.println("Enter one of the following commands followed by RETURN:");
+ System.out.println(" pwd print the current node's path");
+ System.out.println(" ls [path] to list the details of the node at the specified absolute or relative path");
+ System.out.println(" (or the current path if none is supplied)");
+ System.out.println(" cd path to change to the node at the specified absolute or relative path");
+ System.out.println(" exit to exit this repository and return to the main menu");
+ System.out.println();
}
+ /**
+ * Display the node with the given path found in the supplied source.
+ *
+ * @param sourceName the name of the source; may not be null
+ * @param path the path to the node; may not be null
+ */
protected void displayNode( String sourceName,
String path ) {
+ assert sourceName != null;
+ assert path != null;
+
+ // Retrieve the node information from the client ...
Map<String, Object[]> properties = new HashMap<String, Object[]>();
List<String> children = new ArrayList<String>();
try {
@@ -196,29 +243,39 @@
displayError(" displaying node \"" + path + "\"", t);
}
- System.out.println(" Path:" + path);
- System.out.println(" Properties:");
- int maxLength = 0;
+ // Print the './' and '../' options ...
+ System.out.println(" ./");
+ System.out.println(" ../");
+
+ // Display the children ...
+ for (String childName : children) {
+ System.out.println(" " + childName + "/");
+ }
+ // Determine the maximum length of the properties so that we can left-justify the values
+ int maxLength = 5;
for (String propertyName : properties.keySet()) {
maxLength = Math.max(maxLength, propertyName.length());
}
+ // Display the properties ...
for (Map.Entry<String, Object[]> property : properties.entrySet()) {
- String name = property.getKey();
- name = StringUtil.justifyLeft(name, maxLength, ' ');
+ String name = StringUtil.justifyLeft(property.getKey(), maxLength, ' ');
Object[] values = property.getValue();
String valueStr = StringUtil.readableString(values);
- if (values.length == 1) StringUtil.readableString(values[0]);
- System.out.println(" " + name + " = " + valueStr);
+ if (values.length == 1) valueStr = StringUtil.readableString(values[0]);
+ System.out.println(" " + name + " = " + valueStr);
}
- System.out.println(" Children:");
- for (String childName : children) {
- System.out.println(" " + childName);
- }
- System.out.println();
}
+ /**
+ * Display the supplied error that happened during the activity.
+ *
+ * @param activity the activity; may not be null but may be empty
+ * @param t the exception; may not be null
+ */
protected void displayError( String activity,
Throwable t ) {
+ assert activity != null;
+ assert t != null;
System.err.println();
System.err.println("There has been an error" + activity);
System.err.println(" " + t.getMessage());
@@ -240,4 +297,14 @@
public String getLocationOfRepositoryFiles() {
return new File("").getAbsolutePath();
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.example.dna.repository.UserInterface#getCallbackHandler()
+ */
+ public CallbackHandler getCallbackHandler() {
+ return new TextCallbackHandler();
+ }
+
}
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2008-09-16 20:26:44 UTC (rev 522)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2008-09-17 15:08:00 UTC (rev 523)
@@ -22,7 +22,8 @@
package org.jboss.example.dna.repository;
import java.io.IOException;
-import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -31,11 +32,14 @@
import javax.jcr.NodeIterator;
import javax.jcr.PropertyIterator;
import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
import javax.naming.NamingException;
-import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+import net.jcip.annotations.Immutable;
import org.jboss.dna.common.component.ClassLoaderFactory;
import org.jboss.dna.common.component.StandardClassLoaderFactory;
+import org.jboss.dna.common.text.NoOpEncoder;
+import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.jcr.JcrRepository;
import org.jboss.dna.repository.RepositoryImporter;
@@ -68,7 +72,8 @@
arg = arg.trim();
if (arg.equals("--api=jcr")) client.setApi(Api.JCR);
if (arg.equals("--api=dna")) client.setApi(Api.DNA);
- if (arg.startsWith("--user=") && arg.length() > 7) client.setUsername(arg.substring(7).trim());
+ if (arg.equals("--jaas")) client.setJaasContextName(JAAS_LOGIN_CONTEXT_NAME);
+ if (arg.startsWith("--jaas=") && arg.length() > 7) client.setJaasContextName(arg.substring(7).trim());
}
client.setUserInterface(new ConsoleInput(client, args));
}
@@ -82,10 +87,11 @@
private RepositoryLibrary sources;
private ExecutionContextFactory contextFactory;
private RepositoryService repositoryService;
- private Api api = Api.DNA;
- private String username = null;
- private char[] password = null;
+ private Api api = Api.JCR;
+ private String jaasContextName;
private UserInterface userInterface;
+ private LoginContext loginContext;
+ private ExecutionContext context;
/**
* @param userInterface Sets userInterface to the specified value.
@@ -104,37 +110,15 @@
}
/**
- * Set the username that this client should use.
+ * Set the JAAS context name that should be used. If null (which is the default), then no authentication will be used.
*
- * @param username the new username, or null if no username should be used.
+ * @param jaasContextName the JAAS context name, or null if no authentication should be performed
*/
- public void setUsername( String username ) {
- this.username = username;
- this.password = null;
+ public void setJaasContextName( String jaasContextName ) {
+ this.jaasContextName = jaasContextName;
}
/**
- * Clear any cached password.
- */
- public void clearPassword() {
- password = null;
- }
-
- /**
- * Method used internally to obtain the password, which is obtained from the user (only once per process) if needed
- *
- * @return the user's password, or null if no username is known
- */
- private char[] getPassword() {
- if (username == null) return null;
- if (password == null) {
- PasswordCallback callback = new PasswordCallback("Password:", false);
- password = callback.getPassword();
- }
- return password;
- }
-
- /**
* Start up the repositories. This method creates the necessary components and services, and initializes the in-memory
* repositories.
*
@@ -152,7 +136,7 @@
// Create the execution context that we'll use for the services. If we'd want to use JAAS, we'd create the context
// by supply LoginContext, AccessControlContext, or even Subject with CallbackHandlers. But no JAAS in this example.
- ExecutionContext context = contextFactory.create();
+ context = contextFactory.create();
// Create the library for the RepositorySource instances ...
sources = new RepositoryLibrary(contextFactory);
@@ -183,16 +167,20 @@
*
* @return the repository names
*/
- public Collection<String> getNamesOfRepositories() {
- return sources.getSourceNames();
+ public List<String> getNamesOfRepositories() {
+ List<String> names = new ArrayList<String>(sources.getSourceNames());
+ Collections.sort(names);
+ return names;
}
/**
* Shut down the components and services and blocking until all resources have been released.
*
* @throws InterruptedException if the thread was interrupted before completing the shutdown.
+ * @throws LoginException
*/
- public void shutdown() throws InterruptedException {
+ public void shutdown() throws InterruptedException, LoginException {
+ logout();
if (repositoryService == null) return;
try {
// Shut down the various services ...
@@ -208,6 +196,37 @@
}
/**
+ * Get the current JAAS LoginContext (if there is one).
+ *
+ * @return the current login context, or null if no JAAS authentication is to be used.
+ * @throws LoginException if authentication was attempted but failed
+ */
+ protected LoginContext getLoginContext() throws LoginException {
+ if (loginContext == null) {
+ if (jaasContextName != null) {
+ loginContext = new LoginContext(jaasContextName, this.userInterface.getCallbackHandler());
+ loginContext.login();
+ }
+ }
+ return loginContext;
+ }
+
+ /**
+ * Calling this will lose the context
+ *
+ * @throws LoginException
+ */
+ public void logout() throws LoginException {
+ if (loginContext != null) {
+ try {
+ loginContext.logout();
+ } finally {
+ loginContext = null;
+ }
+ }
+ }
+
+ /**
* Get the information about a node, using the {@link #setApi(Api) API} method.
*
* @param sourceName the name of the repository source
@@ -223,17 +242,20 @@
String pathToNode,
Map<String, Object[]> properties,
List<String> children ) throws Throwable {
+ LoginContext loginContext = getLoginContext(); // will ask user to authenticate if needed
switch (api) {
case JCR: {
JcrRepository jcrRepository = new JcrRepository(contextFactory, sources);
Session session = null;
- if (username != null) {
- Credentials credentials = new SimpleCredentials(username, getPassword());
+ if (loginContext != null) {
+ Credentials credentials = new JaasCredentials(loginContext);
session = jcrRepository.login(credentials, sourceName);
} else {
session = jcrRepository.login(sourceName);
}
try {
+ // Make the path relative to the root by removing the leading slash(es) ...
+ pathToNode = pathToNode.replaceAll("^/+", "");
// Get the node by path ...
Node root = session.getRootNode();
Node node = root.getNode(pathToNode);
@@ -242,7 +264,8 @@
if (properties != null) {
for (PropertyIterator iter = node.getProperties(); iter.hasNext();) {
javax.jcr.Property property = iter.nextProperty();
- properties.put(property.getName(), property.getValues());
+ Object[] values = property.getDefinition().isMultiple() ? property.getValues() : new Object[] {property.getValue()};
+ properties.put(property.getName(), values);
}
}
if (children != null) {
@@ -259,12 +282,7 @@
break;
}
case DNA: {
- ExecutionContext context = null;
- if (username != null) {
- context = contextFactory.create(JAAS_LOGIN_CONTEXT_NAME);
- } else {
- context = contextFactory.create();
- }
+ ExecutionContext context = loginContext != null ? contextFactory.create(loginContext) : contextFactory.create();
PathFactory pathFactory = context.getValueFactories().getPathFactory();
// Get the node submitting a graph command to a repository connection.
@@ -303,4 +321,53 @@
}
return true;
}
+
+ /**
+ * Utility to build a path given the current path and the input path as string, where the input path could be an absolute path
+ * or relative to the current and where the input may use "." and "..".
+ *
+ * @param current the current path
+ * @param input the input path
+ * @return the resulting full and normalized path
+ */
+ protected String buildPath( String current,
+ String input ) {
+ if (current == null) current = "/";
+ if (input == null || input.length() == 0) return current;
+ PathFactory factory = context.getValueFactories().getPathFactory();
+ Path inputPath = factory.create(input);
+ if (inputPath.isAbsolute()) {
+ return inputPath.getNormalizedPath().getString(context.getNamespaceRegistry(), NoOpEncoder.getInstance());
+ }
+ Path currentPath = factory.create(current);
+ currentPath = factory.create(currentPath, inputPath);
+ currentPath = currentPath.getNormalizedPath();
+ return currentPath.getString(context.getNamespaceRegistry(), NoOpEncoder.getInstance());
+ }
+
+ /**
+ * A class that represents JCR Credentials containing the JAAS LoginContext.
+ *
+ * @author Randall Hauch
+ */
+ @Immutable
+ protected static class JaasCredentials implements Credentials {
+ private static final long serialVersionUID = 1L;
+ private final LoginContext context;
+
+ public JaasCredentials( LoginContext context ) {
+ ArgCheck.isNotNull(context, "context");
+ this.context = context;
+ }
+
+ /**
+ * JBoss DNA's JCR implementation will reflectively look for and call this method to get the JAAS LoginContext.
+ *
+ * @return the current LoginContext
+ */
+ public LoginContext getLoginContext() {
+ return context;
+ }
+
+ }
}
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/UserInterface.java
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/UserInterface.java 2008-09-16 20:26:44 UTC (rev 522)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/UserInterface.java 2008-09-17 15:08:00 UTC (rev 523)
@@ -21,6 +21,8 @@
*/
package org.jboss.example.dna.repository;
+import javax.security.auth.callback.CallbackHandler;
+
/**
* @author Randall Hauch
*/
@@ -28,4 +30,6 @@
String getLocationOfRepositoryFiles();
+ CallbackHandler getCallbackHandler();
+
}
Modified: trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java 2008-09-16 20:26:44 UTC (rev 522)
+++ trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java 2008-09-17 15:08:00 UTC (rev 523)
@@ -32,6 +32,7 @@
import java.util.Map;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -190,9 +191,17 @@
assertThat(properties.size(), is(8));
}
+ @Ignore
@Test
public void shouldLoadVehiclesRepository() throws Throwable {
client.startRepositories();
+ assertThat(client.getNodeInfo("Vehicles", "/", properties, children), is(true));
+ assertThat(children, hasItems("Vehicles"));
+ assertThat(properties.containsKey("dna:uuid"), is(true));
+ assertThat(properties.size(), is(1));
+
+ properties.clear();
+ children.clear();
assertThat(client.getNodeInfo("Vehicles", "/Vehicles", properties, children), is(true));
assertThat(children, hasItems("Cars", "Aircraft"));
assertThat(properties.containsKey("jcr:primaryType"), is(false));
@@ -201,6 +210,13 @@
properties.clear();
children.clear();
+ assertThat(client.getNodeInfo("Vehicles", "/", properties, children), is(true));
+ assertThat(children, hasItems("Vehicles"));
+ assertThat(properties.containsKey("dna:uuid"), is(true));
+ assertThat(properties.size(), is(1));
+
+ properties.clear();
+ children.clear();
assertThat(client.getNodeInfo("Vehicles", "/Vehicles/Cars/Hybrid", properties, children), is(true));
assertThat(children, hasItems("Toyota Prius", "Toyota Highlander", "Nissan Altima"));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
Modified: trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java
===================================================================
--- trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-09-16 20:26:44 UTC (rev 522)
+++ trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepository.java 2008-09-17 15:08:00 UTC (rev 523)
@@ -345,24 +345,26 @@
@Override
public void execute( CreateNodeCommand command ) {
Path path = command.getPath();
- Node parentNode = null;
+ Node node = null;
if (!path.isRoot()) {
Path parent = path.getParent();
// Look up the parent node, which must exist ...
- parentNode = getNode(parent);
+ Node parentNode = getNode(parent);
if (parentNode == null) {
Path lowestExisting = getLowestExistingPath(parent);
throw new PathNotFoundException(path, lowestExisting, InMemoryConnectorI18n.nodeDoesNotExist.text(parent));
}
- }
- UUID uuid = null;
- for (Property property : command.getProperties()) {
- if (property.getName().equals(uuidPropertyName)) {
- uuid = getExecutionContext().getValueFactories().getUuidFactory().create(property.getValues().next());
- break;
+ UUID uuid = null;
+ for (Property property : command.getProperties()) {
+ if (property.getName().equals(uuidPropertyName)) {
+ uuid = getExecutionContext().getValueFactories().getUuidFactory().create(property.getValues().next());
+ break;
+ }
}
+ node = createNode(getExecutionContext(), parentNode, path.getLastSegment().getName(), uuid);
+ } else {
+ node = getRoot();
}
- Node node = createNode(getExecutionContext(), parentNode, path.getLastSegment().getName(), uuid);
// Now add the properties to the supplied node ...
for (Property property : command.getProperties()) {
Name propName = property.getName();
15 years, 7 months