[Mulgara-svn] r1199 - in trunk: . conf lib src/jar src/jar/client-jrdf/java/org/mulgara/client/jrdf/test src/jar/client-jrdf/java/org/mulgara/client/jrdf/writer src/jar/content-n3/java/org/mulgara/content/n3 src/jar/content-rdfxml/java/org/mulgara/content/rdfxml src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer src/jar/driver src/jar/itql src/jar/jrdf/java/org/mulgara/jrdf src/jar/query/java/org src/jar/query/java/org/jrdf src/jar/query/java/org/jrdf/graph src/jar/query/java/org/jrdf/graph/mem src/jar/query/java/org/jrdf/parser src/jar/query/java/org/jrdf/parser/mem src/jar/query/java/org/jrdf/util src/jar/query/java/org/jrdf/util/param src/jar/query/java/org/jrdf/vocabulary src/jar/query/java/org/mulgara/server src/jar/resolver/java/org/mulgara/resolver src/jar/resolver/java/org/mulgara/store/exporter src/jar/resolver-relational src/jar/resolver-relational/java/org/mulgara/resolver/relational src/jar/server/java/org/mulgara/server src/jar/sparql-protocol/java/org/mulgara/sparql/protocol src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11 src/jar/store-xa src/jar/util/java/org/mulgara/util src/jar/util/java/org/mulgara/util/functional

pag at mulgara.org pag at mulgara.org
Thu Aug 28 23:44:41 UTC 2008


Author: pag
Date: 2008-08-28 16:44:40 -0700 (Thu, 28 Aug 2008)
New Revision: 1199

Added:
   trunk/src/jar/query/java/org/jrdf/
   trunk/src/jar/query/java/org/jrdf/graph/
   trunk/src/jar/query/java/org/jrdf/graph/AbstractBlankNode.java
   trunk/src/jar/query/java/org/jrdf/graph/AbstractGraphElementFactoryTest.java
   trunk/src/jar/query/java/org/jrdf/graph/AbstractGraphTest.java
   trunk/src/jar/query/java/org/jrdf/graph/AbstractLiteral.java
   trunk/src/jar/query/java/org/jrdf/graph/AbstractTriple.java
   trunk/src/jar/query/java/org/jrdf/graph/AbstractTripleFactory.java
   trunk/src/jar/query/java/org/jrdf/graph/AbstractTripleFactoryTest.java
   trunk/src/jar/query/java/org/jrdf/graph/AbstractURIReference.java
   trunk/src/jar/query/java/org/jrdf/graph/AlreadyReifiedException.java
   trunk/src/jar/query/java/org/jrdf/graph/Alternative.java
   trunk/src/jar/query/java/org/jrdf/graph/Bag.java
   trunk/src/jar/query/java/org/jrdf/graph/BlankNode.java
   trunk/src/jar/query/java/org/jrdf/graph/Collection.java
   trunk/src/jar/query/java/org/jrdf/graph/Container.java
   trunk/src/jar/query/java/org/jrdf/graph/Graph.java
   trunk/src/jar/query/java/org/jrdf/graph/GraphElementFactory.java
   trunk/src/jar/query/java/org/jrdf/graph/GraphElementFactoryException.java
   trunk/src/jar/query/java/org/jrdf/graph/GraphException.java
   trunk/src/jar/query/java/org/jrdf/graph/Literal.java
   trunk/src/jar/query/java/org/jrdf/graph/Node.java
   trunk/src/jar/query/java/org/jrdf/graph/ObjectNode.java
   trunk/src/jar/query/java/org/jrdf/graph/PredicateNode.java
   trunk/src/jar/query/java/org/jrdf/graph/Sequence.java
   trunk/src/jar/query/java/org/jrdf/graph/SubjectNode.java
   trunk/src/jar/query/java/org/jrdf/graph/Triple.java
   trunk/src/jar/query/java/org/jrdf/graph/TripleFactory.java
   trunk/src/jar/query/java/org/jrdf/graph/TripleFactoryException.java
   trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitable.java
   trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitor.java
   trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitorAdapter.java
   trunk/src/jar/query/java/org/jrdf/graph/URIReference.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/
   trunk/src/jar/query/java/org/jrdf/graph/mem/AbstractUnorderedContainer.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/BlankNodeImpl.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/EmptyClosableIterator.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/GraphElementFactoryImpl.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/GraphElementFactoryImplUnitTest.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler012.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler120.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler201.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/GraphImpl.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/GraphImplUnitTest.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/GraphIterator.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/LiteralImpl.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/MemNode.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/OneFixedIterator.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/SequenceImpl.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/ThreeFixedIterator.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/TripleFactoryImpl.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/TripleImpl.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/TwoFixedIterator.java
   trunk/src/jar/query/java/org/jrdf/graph/mem/URIReferenceImpl.java
   trunk/src/jar/query/java/org/jrdf/graph/package.html
   trunk/src/jar/query/java/org/jrdf/parser/
   trunk/src/jar/query/java/org/jrdf/parser/ParserBlankNodeFactory.java
   trunk/src/jar/query/java/org/jrdf/parser/mem/
   trunk/src/jar/query/java/org/jrdf/parser/mem/ParserBlankNodeFactoryImpl.java
   trunk/src/jar/query/java/org/jrdf/util/
   trunk/src/jar/query/java/org/jrdf/util/ClosableIterator.java
   trunk/src/jar/query/java/org/jrdf/util/EscapeUtil.java
   trunk/src/jar/query/java/org/jrdf/util/EscapeUtilUnitTest.java
   trunk/src/jar/query/java/org/jrdf/util/UIDGenerator.java
   trunk/src/jar/query/java/org/jrdf/util/UIDGeneratorUnitTest.java
   trunk/src/jar/query/java/org/jrdf/util/package.html
   trunk/src/jar/query/java/org/jrdf/util/param/
   trunk/src/jar/query/java/org/jrdf/util/param/EmtpyStringChecker.java
   trunk/src/jar/query/java/org/jrdf/util/param/EmtpyStringCheckerUnitTest.java
   trunk/src/jar/query/java/org/jrdf/util/param/NullChecker.java
   trunk/src/jar/query/java/org/jrdf/util/param/NullCheckerUnitTest.java
   trunk/src/jar/query/java/org/jrdf/util/param/ParameterChecker.java
   trunk/src/jar/query/java/org/jrdf/util/param/ParameterTestUtil.java
   trunk/src/jar/query/java/org/jrdf/util/param/ParameterUtil.java
   trunk/src/jar/query/java/org/jrdf/util/param/ParameterUtilUnitTest.java
   trunk/src/jar/query/java/org/jrdf/util/param/package.html
   trunk/src/jar/query/java/org/jrdf/vocabulary/
   trunk/src/jar/query/java/org/jrdf/vocabulary/RDF.java
   trunk/src/jar/query/java/org/jrdf/vocabulary/RDFS.java
   trunk/src/jar/query/java/org/jrdf/vocabulary/Vocabulary.java
   trunk/src/jar/query/java/org/jrdf/vocabulary/package.html
   trunk/src/jar/util/java/org/mulgara/util/ClasspathDesc.java
   trunk/src/jar/util/java/org/mulgara/util/functional/
   trunk/src/jar/util/java/org/mulgara/util/functional/C.java
   trunk/src/jar/util/java/org/mulgara/util/functional/F.java
   trunk/src/jar/util/java/org/mulgara/util/functional/Fn.java
   trunk/src/jar/util/java/org/mulgara/util/functional/Fn1.java
   trunk/src/jar/util/java/org/mulgara/util/functional/Fn1E.java
   trunk/src/jar/util/java/org/mulgara/util/functional/Fn2.java
   trunk/src/jar/util/java/org/mulgara/util/functional/Fn2E.java
   trunk/src/jar/util/java/org/mulgara/util/functional/FnE.java
   trunk/src/jar/util/java/org/mulgara/util/functional/Pair.java
Removed:
   trunk/lib/jrdf-0.3.4.3.jar
   trunk/src/jar/content-rio/
   trunk/src/jar/util/java/org/mulgara/util/C.java
   trunk/src/jar/util/java/org/mulgara/util/F.java
   trunk/src/jar/util/java/org/mulgara/util/Fn.java
   trunk/src/jar/util/java/org/mulgara/util/Fn1.java
   trunk/src/jar/util/java/org/mulgara/util/Fn1E.java
   trunk/src/jar/util/java/org/mulgara/util/Fn2.java
   trunk/src/jar/util/java/org/mulgara/util/Fn2E.java
   trunk/src/jar/util/java/org/mulgara/util/FnE.java
   trunk/src/jar/util/java/org/mulgara/util/Pair.java
Modified:
   trunk/.classpath
   trunk/build.properties
   trunk/build.xml
   trunk/common.properties
   trunk/common.xml
   trunk/conf/mulgara-config-x11.xml
   trunk/conf/mulgara-config.xml
   trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/test/ItqlGraphUnitTest.java
   trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/test/SessionGraphUnitTest.java
   trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/writer/MemoryXMLWriter.java
   trunk/src/jar/content-n3/java/org/mulgara/content/n3/N3StatementsUnitTest.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/Parser.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLContentHandler.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLStatements.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLStatementsUnitTest.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/TestResolverSession.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/AbstractWritableStatement.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/BlankNodeWritableStatement.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/LiteralWritableStatement.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/NamespaceMap.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/RDFXMLWriter.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/RDFXMLWriterUnitTest.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/TestResolverSession.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/TestStatementsComparator.java
   trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/URIReferenceWritableStatement.java
   trunk/src/jar/driver/build.xml
   trunk/src/jar/itql/build.xml
   trunk/src/jar/jrdf/java/org/mulgara/jrdf/JRDFGraphUnitTest.java
   trunk/src/jar/jrdf/java/org/mulgara/jrdf/JRDFLocalGraphUnitTest.java
   trunk/src/jar/query/java/org/mulgara/server/SessionFactoryFactory.java
   trunk/src/jar/resolver-relational/build.xml
   trunk/src/jar/resolver-relational/java/org/mulgara/resolver/relational/RelationalResolverUnitTest.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSessionListQueryUnitTest.java
   trunk/src/jar/resolver/java/org/mulgara/store/exporter/ModelXMLWriter.java
   trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java
   trunk/src/jar/sparql-protocol/java/org/mulgara/sparql/protocol/StreamAnswer.java
   trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java
   trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPXMLLiteralImpl.java
   trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPXMLLiteralUnitTest.java
   trunk/src/jar/store-xa/build.xml
   trunk/src/jar/util/java/org/mulgara/util/FileUtil.java
Log:
Imported JRDF into the source tree, removing it from the library. Added generics to remove warnings.

This import has been a common request. It will provide easy access to view the source. It will also
allow for easy modification for fixing bugs, or extension where we have a need to expand the
definition. An example of this was the need to add generics, but we have also wanted to work with
JRDF objects and other objects (like Variables) using some kind of common interface.

The import as allowable as JRDF is licensed mostly with Apache 1.1. However, the RDF/XML parsing
code was imported from Sesame and was under LGPL. This code had to be removed which in turn had
an impact on the RIO content handler. Since this content handler was only being used in the unit
tests for the Relational Resolver, the content handler was removed.

While debugging the new integration some utilities were created and updated. This included a
Classpath utility, for printing the classpath and copying out jars to a temporary file, and 
moving the "functional" classes to their own package.



Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/.classpath	2008-08-28 23:44:40 UTC (rev 1199)
@@ -6,15 +6,14 @@
 	<classpathentry kind="src" path="src/jar/content-mp3/java"/>
 	<classpathentry kind="src" path="src/jar/content-n3/java"/>
 	<classpathentry kind="src" path="src/jar/content-rdfxml/java"/>
-	<classpathentry kind="src" path="src/jar/content-rio/java"/>
 	<classpathentry kind="src" path="src/jar/demo-mp3/java"/>
 	<classpathentry kind="src" path="src/jar/descriptor/src/java"/>
 	<classpathentry kind="src" path="src/jar/driver/java"/>
 	<classpathentry kind="src" path="src/jar/dtd/java"/>
 	<classpathentry kind="src" path="src/jar/itql/java"/>
 	<classpathentry kind="src" path="src/jar/itql/sablecc"/>
-	<classpathentry kind="src" path="src/jar/jrdf/java"/>
 	<classpathentry kind="src" path="src/jar/krule/java"/>
+	<classpathentry kind="src" path="src/jar/jrdf/java"/>
 	<classpathentry kind="src" path="src/jar/query/java"/>
 	<classpathentry kind="src" path="src/jar/resolver/java"/>
 	<classpathentry kind="src" path="src/jar/resolver-distributed/java"/>
@@ -58,7 +57,7 @@
 	<classpathentry kind="src" path="src/jar/tuples-hybrid/java"/>
 	<classpathentry kind="src" path="src/jar/util/java"/>
 	<classpathentry kind="src" path="src/jar/util-xa/java"/>
-	<classpathentry kind="src" path="src/jar/webquery/java"/>
+	<classpathentry kind="src" path="src/jar/web/java"/>
 	<classpathentry kind="src" path="src/war/webui/java"/>
 	<classpathentry kind="src" path="tools/src"/>
 	<classpathentry kind="lib" path="lib/xom-1.0d21.jar"/>
@@ -115,10 +114,9 @@
 	<classpathentry kind="lib" path="lib/antlr.jar"/>
 	<classpathentry kind="lib" path="lib/activation-1.0.2.jar"/>
 	<classpathentry kind="lib" path="lib/jena-2.1.jar"/>
-	<classpathentry kind="lib" path="dist/ideSupport.jar"/>
+	<classpathentry kind="lib" path="dist/ideSupport.jar" sourcepath="obj/jar/config/java"/>
 	<classpathentry kind="lib" path="lib/xalan-2.7.0.jar"/>
 	<classpathentry kind="lib" path="lib/lucene-2.0.0.jar"/>
-	<classpathentry kind="lib" path="lib/jrdf-0.3.4.3.jar"/>
 	<classpathentry kind="lib" path="lib/ant-trax-1.7.0.jar"/>
 	<classpathentry kind="lib" path="lib/ant-nodeps-1.7.0.jar"/>
 	<classpathentry kind="lib" path="lib/ant-launcher-1.7.0.jar"/>

Modified: trunk/build.properties
===================================================================
--- trunk/build.properties	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/build.properties	2008-08-28 23:44:40 UTC (rev 1199)
@@ -127,9 +127,6 @@
 jid3.jar                 =jid3-0.34.jar
 jmdns.jar                =jmdns-0.2.jar
 joda-time.jar            =joda-time-1.5.2.jar
-jrdf.base.jar            =jrdf-base-1.1.0.jar
-jrdf-doc.jar             =jrdf-doc-0.3.3.jar
-jrdf.jar                 =jrdf-0.3.4.3.jar
 sesame-model.jar         =sesame-model-2.1.jar
 jsr.173.api.jar          =jsr173_07_api.jar
 jsr.173.ri.jar           =jsr173_07_ri.jar

Modified: trunk/build.xml
===================================================================
--- trunk/build.xml	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/build.xml	2008-08-28 23:44:40 UTC (rev 1199)
@@ -21,7 +21,6 @@
   <property file="${jar.src.dir}/content-mp3/content-mp3-build.properties"/>
   <property file="${jar.src.dir}/content-n3/content-n3-build.properties"/>
   <property file="${jar.src.dir}/content-rdfxml/content-rdfxml-build.properties"/>
-  <property file="${jar.src.dir}/content-rio/content-rio-build.properties"/>
   <property file="${jar.src.dir}/descriptor/descriptor-build.properties"/>
   <property file="${jar.src.dir}/driver/driver-build.properties"/>
   <property file="${jar.src.dir}/dtd/dtd-build.properties"/>
@@ -72,7 +71,7 @@
   <property file="${jar.src.dir}/tuples/tuples-build.properties"/>
   <property file="${jar.src.dir}/util-xa/util-xa-build.properties"/>
   <property file="${jar.src.dir}/util/util-build.properties"/>
-  <property file="${jar.src.dir}/web/webquery-build.properties"/>
+  <property file="${jar.src.dir}/web/web-build.properties"/>
 
   <property name="webui.viewer.src.dir"
       value="${webui.src.dir}/java/org/mulgara/webui/viewer"/>
@@ -94,7 +93,6 @@
   <import file="${jar.src.dir}/content-mp3/build.xml"/>
   <import file="${jar.src.dir}/content-n3/build.xml"/>
   <import file="${jar.src.dir}/content-rdfxml/build.xml"/>
-  <import file="${jar.src.dir}/content-rio/build.xml"/>
   <import file="${jar.src.dir}/descriptor/build.xml"/>
   <import file="${jar.src.dir}/driver/build.xml"/>
   <import file="${jar.src.dir}/dtd/build.xml"/>
@@ -337,7 +335,7 @@
   <target name="base-dist"
           depends="ant-task-dist,
                    client-jrdf-dist, content-mbox-dist,
-                   content-mp3-dist, content-rdfxml-dist, content-rio-dist,
+                   content-mp3-dist, content-rdfxml-dist,
                    descriptor-dist, driver-dist, dtd-dist, itql-dist, jrdf-dist,
                    store-dist, store-xa-dist, store-nodepool-dist,
                    store-nodepool-memory-dist,
@@ -512,14 +510,14 @@
           lib/${resolver-store.jar}, lib/${resolver-url.jar}, lib/${resolver-view.jar},
           lib/${tuples.jar}, lib/${tuples-hybrid.jar}, lib/${content-mp3.jar},
           lib/${content-n3.jar}, lib/${content-mbox.jar}, lib/${content-rdfxml.jar},
-          lib/${content-rio.jar}, lib/${resolver-nodetype.jar}, lib/${resolver-prefix.jar},
+          lib/${resolver-nodetype.jar}, lib/${resolver-prefix.jar},
           lib/${resolver-relational.jar}, lib/${resolver-xsd.jar}, lib/${resolver-test.jar},
           lib/${resolver-distributed.jar},
-          lib/${resolver-jar.jar}, lib/${dtd.jar}, lib/${jrdf.base.jar}
+          lib/${resolver-jar.jar}, lib/${dtd.jar},
           lib/activation-1.0.2.jar, lib/icu4j.jar, lib/jena-2.1.jar, lib/antlr.jar,
           lib/${joda-time.jar}, lib/${commons-logging.jar}, lib/beepcore-0.9.08.jar, lib/log4j-1.2.15.jar, lib/${lucene.jar}, lib/mail-1.3.jar,
           lib/${jetty.jar}, lib/${jetty.plus.jar}, lib/${jasper.compiler.jar}, lib/${servlet-jsp.jar}, lib/${servlet.jar}, lib/jargs-0.2.jar,
-          lib/${castor-xml.jar}, lib/${castor-codegen.jar}, lib/${castor-xml-schema.jar}, lib/trove-1.0.2.jar, lib/${jrdf.jar}, lib/${saaj.jar},
+          lib/${castor-xml.jar}, lib/${castor-codegen.jar}, lib/${castor-xml-schema.jar}, lib/trove-1.0.2.jar, lib/${saaj.jar},
           lib/${jakarta-oro.jar}, lib/jta-spec1_0_1.jar, lib/${jotm.jar}, lib/${jotm.jrmp.jar}, lib/${carol.jar}, lib/${howl.jar},
           lib/${jca.jar}, lib/${httpclient.jar}, lib/${commons-codec.jar}, lib/${mulgara-sparql.jar}, lib/${sesame-model.jar}"/>
       <attribute name="Embedded-Main-Class" value="org.mulgara.server.EmbeddedMulgaraServer"/>
@@ -546,7 +544,7 @@
                    resolver-store-dist, resolver-url-dist, resolver-jar-dist,
                    resolver-view-dist, resolver-xsd-dist,
                    content-mbox-dist, content-mp3-dist, content-n3-dist,
-                   content-rdfxml-dist, content-rio-dist,
+                   content-rdfxml-dist,
                    lite-create-manifest, javadoc-dist,
                    lite-dist-uptodate"
           unless="dist.lite.uptodate"
@@ -571,7 +569,7 @@
                     mulgara.policy"/>
       <zipfileset dir="${lib.dir}" prefix="lib" includes="
         ${log4j.jar}, ${icu4j.jar}, ${activation.jar}, ${beep.jar},
-        ${jargs.jar}, ${jrdf.jar}, ${jetty.jar}, ${jetty.plus.jar},
+        ${jargs.jar}, ${jetty.jar}, ${jetty.plus.jar},
         ${servlet-jsp.jar}, ${servlet.jar}, ${jasper.runtime.jar}, ${jasper.compiler.jar},
         ${lucene.jar}, ${mail.jar}, ${castor-xml.jar}, ${castor-xml-schema.jar}, ${castor-codegen.jar}, ${trove.jar},
         ${joda-time.jar}, ${commons-logging.jar}, ${commons-httpclient.jar},
@@ -598,7 +596,7 @@
           ${resolver-store.jar}, ${resolver-url.jar}, ${resolver-view.jar},
           ${tuples.jar}, ${tuples-hybrid.jar}, ${content-mp3.jar},
           ${content-n3.jar}, ${content-mbox.jar}, ${content-rdfxml.jar},
-          ${content-rio.jar}, ${resolver-nodetype.jar}, ${resolver-prefix.jar},
+          ${resolver-nodetype.jar}, ${resolver-prefix.jar},
           ${resolver-xsd.jar}, ${resolver-test.jar}, ${resolver-relational.jar},
           ${resolver-distributed.jar},
           ${resolver-jar.jar}, ${dtd.jar}, ${jrdf.base.jar}"/>
@@ -756,7 +754,7 @@
     depends="javadoc-uptodate, javadoc-overview.html,
              ant-task-jar, client-jrdf-jar, config-jar,
              content-mbox-jar, content-mp3-jar,
-             content-n3-jar, content-rdfxml-jar, content-rio-jar,
+             content-n3-jar, content-rdfxml-jar,
              itql-jar, sparql-int-jar,
              doclet.jar, jrdf-jar, store-jar,
              store-xa-jar,
@@ -851,7 +849,6 @@
       <sourcepath path="${content-mp3.src.dir}/java"/>
       <sourcepath path="${content-n3.src.dir}/java"/>
       <sourcepath path="${content-rdfxml.src.dir}/java"/>
-      <sourcepath path="${content-rio.src.dir}/java"/>
       <sourcepath path="${driver.src.dir}/java"/>
       <sourcepath path="${dtd.src.dir}/java"/>
       <sourcepath path="${itql.src.dir}/java"/>
@@ -921,7 +918,7 @@
                    client-jrdf-javadoc,
                    content-mbox-javadoc,
                    content-mp3-javadoc, content-n3-javadoc,
-                   content-rdfxml-javadoc, content-rio-javadoc,
+                   content-rdfxml-javadoc,
                    descriptor-javadoc, driver-javadoc, dtd-javadoc,
                    itql-javadoc, sparql-int-javadoc,
                    store-javadoc, store-xa-javadoc,
@@ -972,7 +969,7 @@
         <jvmarg value="${arch.bits}"/>
 
         <classpath>
-            <pathelement path="${lib.dir}/${jrdf.jar}, ${lib.dir}/${sesame-model.jar}"/>
+            <pathelement path="${lib.dir}/${sesame-model.jar}"/>
         </classpath>
       </java>
   </target>
@@ -1055,7 +1052,7 @@
                  includes="activation*.jar, beepcore-*.jar, jargs-*.jar,
                            icu4j.jar, jena*.jar, antlr*.jar,
                            ${commons-logging.jar}, log4j*.jar, lucene*.jar,
-                           xerces*.jar, xmlParserAPIs.jar, ${jrdf.jar},
+                           xerces*.jar, xmlParserAPIs.jar,
                            ${saaj.jar}, ${sesame-model.jar}"/>
       </classpath>
     </java>
@@ -1432,7 +1429,7 @@
           includes="WEB-INF/**" excludes="WEB-INF/web.xml"/>
 
       <lib dir="${lib.dir}" includes="log4j-core-*.jar, icu4j.jar, jena-*.jar, antlr*.jar, beepcore-*.jar,
-        lucene*.jar, apache-soap-*.jar, ${jrdf.jar}, ${joda-time.jar}, ${commons-logging.jar}, ${sesame-model.jar}"/>
+        lucene*.jar, apache-soap-*.jar, ${joda-time.jar}, ${commons-logging.jar}, ${sesame-model.jar}"/>
       <lib dir="${bin.dir}" includes="${query.jar},
         ${driver.jar}, ${itql.jar}, ${sparql-int.jar}, ${rules.jar}, ${rmi.jar},
           ${server.jar}, ${server-beep.jar}, ${server-rmi.jar},
@@ -1723,7 +1720,7 @@
   <target name="embedded-dist"
           depends="client-jrdf-jar, config-jar,
              content-mbox-jar, content-mp3-jar, content-n3-jar,
-             content-rdfxml-jar, content-rio-jar,
+             content-rdfxml-jar,
              create-manifest, demo-jar, dtd-jar, driver-jar, dtd-jar,
              itql-jar, sparql-int-jar,
              javadoc-dist, jrdf-jar, store-jar, store-xa-jar,
@@ -1790,7 +1787,6 @@
       <zipfileset src="${lib.dir}/${joda-time.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${jotm.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${jotm.jrmp.jar}" excludes="META-INF/**"/>
-      <zipfileset src="${lib.dir}/${jrdf.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${jsr.173.api.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${jsr.173.ri.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${jta.jar}" excludes="META-INF/**"/>
@@ -1850,7 +1846,6 @@
       <zipfileset src="${bin.dir}/${content-n3.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${content-mbox.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${content-rdfxml.jar}" excludes="META-INF/**"/>
-      <zipfileset src="${bin.dir}/${content-rio.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${resolver-nodetype.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${resolver-prefix.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${resolver-relational.jar}" excludes="META-INF/**"/>
@@ -1895,7 +1890,7 @@
   <target name="core-dist"
           depends="client-jrdf-jar, config-jar,
              content-mbox-jar, content-mp3-jar, content-n3-jar,
-             content-rdfxml-jar, content-rio-jar,
+             content-rdfxml-jar,
              demo-jar, driver-jar, dtd-jar,
              itql-jar, sparql-int-jar,
              jrdf-jar, store-jar, store-xa-jar,
@@ -1957,7 +1952,6 @@
       <zipfileset src="${bin.dir}/${content-n3.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${content-mbox.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${content-rdfxml.jar}" excludes="META-INF/**"/>
-      <zipfileset src="${bin.dir}/${content-rio.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${resolver-nodetype.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${resolver-prefix.jar}" excludes="META-INF/**"/>
       <zipfileset src="${bin.dir}/${resolver-relational.jar}" excludes="META-INF/**"/>
@@ -2042,7 +2036,7 @@
 
   <target name="resolver-api-test"
     depends="content-mbox-test, content-mp3-test, content-n3-test,
-             content-rdfxml-test, content-rio-test,
+             content-rdfxml-test,
              resolver-test, resolver-null-test, resolver-file-test,
              resolver-filesystem-test, resolver-jar-test, resolver-gis-test,
              resolver-http-test, resolver-lucene-test,

Modified: trunk/common.properties
===================================================================
--- trunk/common.properties	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/common.properties	2008-08-28 23:44:40 UTC (rev 1199)
@@ -46,7 +46,6 @@
 #java.javadoc = file:${user.home}/Documents/j2sdk1.4.2/docs/api
 #j2ee.javadoc = file:${j2ee.home}/doc/api
 j2ee.javadoc  = http://java.sun.com/j2ee/1.4/docs/api
-jrdf.javadoc  = http://jrdf.sourceforge.net/0.3.4/doc/javadoc
 
 # architecture definition. Changed on Solaris only
 arch.bits=-Dnoop

Modified: trunk/common.xml
===================================================================
--- trunk/common.xml	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/common.xml	2008-08-28 23:44:40 UTC (rev 1199)
@@ -146,7 +146,7 @@
 
     <fileset dir="${lib.dir}"
              includes="log4j-*.jar, xmlParserAPIs.jar, xercesImpl.jar,
-                       jena-*.jar, jrdf-*.jar, jxunit*.jar, castor*.jar,
+                       jena-*.jar, jxunit*.jar, castor*.jar,
                        mail-*.jar, activation-*.jar, apache-soap-*.jar,
                        axis-*.jar, saaj-*.jar, emory-*.jar, trove-*.jar,
                        jargs-*.jar, jetty-*.jar, jta-spec*.jar,
@@ -789,7 +789,6 @@
 
       <link href="${j2ee.javadoc}"/>
       <link href="${java.javadoc}"/>
-      <link href="${jrdf.javadoc}"/>
     </javadoc>
   </target>
 </project>

Modified: trunk/conf/mulgara-config-x11.xml
===================================================================
--- trunk/conf/mulgara-config-x11.xml	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/conf/mulgara-config-x11.xml	2008-08-28 23:44:40 UTC (rev 1199)
@@ -105,9 +105,6 @@
     types.
   -->
   <DefaultContentHandler type="org.mulgara.content.rdfxml.RDFXMLContentHandler"/>
-  <!--
-  <DefaultContentHandler type="org.mulgara.content.rio.RDFXMLContentHandler"/>
-  -->
   <ContentHandler type="org.mulgara.content.mp3.MP3ContentHandler"/>
   <ContentHandler type="org.mulgara.content.mbox.MBoxContentHandler"/>
   <ContentHandler type="org.mulgara.content.n3.N3ContentHandler"/>

Modified: trunk/conf/mulgara-config.xml
===================================================================
--- trunk/conf/mulgara-config.xml	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/conf/mulgara-config.xml	2008-08-28 23:44:40 UTC (rev 1199)
@@ -105,9 +105,6 @@
     types.
   -->
   <DefaultContentHandler type="org.mulgara.content.rdfxml.RDFXMLContentHandler"/>
-  <!--
-  <DefaultContentHandler type="org.mulgara.content.rio.RDFXMLContentHandler"/>
-  -->
   <ContentHandler type="org.mulgara.content.mp3.MP3ContentHandler"/>
   <ContentHandler type="org.mulgara.content.mbox.MBoxContentHandler"/>
   <ContentHandler type="org.mulgara.content.n3.N3ContentHandler"/>

Deleted: trunk/lib/jrdf-0.3.4.3.jar
===================================================================
(Binary files differ)

Modified: trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/test/ItqlGraphUnitTest.java
===================================================================
--- trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/test/ItqlGraphUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/test/ItqlGraphUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -66,7 +66,7 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class ItqlGraphUnitTest extends AbstractGraphUnitTest {
+public class ItqlGraphUnitTest extends AbstractGraphTest {
 
   /** name used for the server */
   private static String SERVER_NAME = "server1";

Modified: trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/test/SessionGraphUnitTest.java
===================================================================
--- trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/test/SessionGraphUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/test/SessionGraphUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -65,7 +65,7 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class SessionGraphUnitTest extends AbstractGraphUnitTest {
+public class SessionGraphUnitTest extends AbstractGraphTest {
 
   /** name used for the server */
   private static String SERVER_NAME = "server1";

Modified: trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/writer/MemoryXMLWriter.java
===================================================================
--- trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/writer/MemoryXMLWriter.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/client-jrdf/java/org/mulgara/client/jrdf/writer/MemoryXMLWriter.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -941,8 +941,8 @@
 
     //default namespaces
     this.namespaces = new HashMap();
-    this.namespaces.put(RDF_PREFIX, RDF.baseURI);
-    this.namespaces.put(RDFS_PREFIX, RDFS.baseURI);
+    this.namespaces.put(RDF_PREFIX, RDF.BASE_URI);
+    this.namespaces.put(RDFS_PREFIX, RDFS.BASE_URI);
     this.namespaces.put("owl", "http://www.w3.org/2002/07/owl#");
     this.namespaces.put("dc", "http://purl.org/dc/elements/1.1/");
 

Modified: trunk/src/jar/content-n3/java/org/mulgara/content/n3/N3StatementsUnitTest.java
===================================================================
--- trunk/src/jar/content-n3/java/org/mulgara/content/n3/N3StatementsUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-n3/java/org/mulgara/content/n3/N3StatementsUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -134,7 +134,7 @@
     long o1 = resolverSession.localize(new URIReferenceImpl(RDF.SEQ));
 
     long p2 = resolverSession.localize(new URIReferenceImpl(new URI(
-                                         RDF.baseURI + "_1")));
+                                         RDF.BASE_URI + "_1")));
     long o2 = resolverSession.localize(new LiteralImpl("bar"));
 
     try {

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/Parser.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/Parser.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/Parser.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -28,7 +28,6 @@
 package org.mulgara.content.rdfxml;
 
 // Java 2 standard packages
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
@@ -79,11 +78,8 @@
  *      Software Pty Ltd</a>
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-class Parser extends Thread implements ErrorHandler, StatementHandler
-{
-  /**
-   * Logger.
-   */
+class Parser extends Thread implements ErrorHandler, StatementHandler {
+  /** Logger. */
   private static final Logger logger =
     Logger.getLogger(Parser.class.getName());
 
@@ -134,7 +130,7 @@
    * The queue of <code>long[][3]</code> buffers of triples generated by the
    * RDF/XML parser.
    */
-  private LinkedList queue = new LinkedList();
+  private LinkedList<long[][]> queue = new LinkedList<long[][]>();
 
   /**
    * The number of statements parsed so far.
@@ -178,15 +174,10 @@
    */
   private final ResolverSession resolverSession;
 
-  /**
-   * The initial start time for performance
-   * metrics results.
-   */
+  /** The initial start time for performance metrics results. */
   private double startTime;
 
-  /**
-   * The time the last batch of statements inserted
-   */
+  /** The time the last batch of statements inserted */
   private double lastStatementLoadTime;
 
   private boolean isInfoEnabled = false;
@@ -199,15 +190,13 @@
   /**
    * Sole constructor.
    *
-   * @throws NotModifiedException if the <var>content</var> model is already
-   *   cached
+   * @throws NotModifiedException if the <var>content</var> model is already cached
    * @throws TuplesException if the {@link #blankNodeIdMap} or
    *   {@link #blankNodeNameMap} can't be created or the <var>content</var>
    *   can't be read
    */
   Parser(Content content, ResolverSession resolverSession)
-    throws NotModifiedException, TuplesException
-  {
+    throws NotModifiedException, TuplesException {
     // Validate "content" parameter
     if (content == null) {
       throw new IllegalArgumentException("Null \"content\" parameter");
@@ -226,15 +215,13 @@
           TempDir.createTempFile("rdfidmap", null)
       );
       this.blankNodeIdMap.clear();
-    }
-    catch (IOException e) {
+    } catch (IOException e) {
       throw new TuplesException("Unable to create blank node map", e);
     }
 
     try {
       this.inputStream  = content.newInputStream();
-    }
-    catch (IOException e) {
+    } catch (IOException e) {
       throw new TuplesException("Unable to obtain input stream from " + baseURI,
                                 e);
     }
@@ -257,8 +244,7 @@
   /**
    * @return the number of statements parsed so far
    */
-  synchronized long getStatementCount() throws TuplesException
-  {
+  synchronized long getStatementCount() throws TuplesException {
     checkForException();
     return statementCount;
   }
@@ -266,8 +252,7 @@
   /**
    * @return the total number of statements in the file
    */
-  synchronized long waitForStatementTotal() throws TuplesException
-  {
+  synchronized long waitForStatementTotal() throws TuplesException {
     while (!complete) {
       checkForException();
 
@@ -290,8 +275,7 @@
    * Returns true if getStatementCount() would return the total number
    * of statements in the file.
    */
-  synchronized boolean isStatementCountTotal() throws TuplesException
-  {
+  synchronized boolean isStatementCountTotal() throws TuplesException {
     checkForException();
     return statementCountIsTotal;
   }
@@ -300,8 +284,7 @@
   // Method implementing Runnable
   //
 
-  public void run()
-  {
+  public void run() {
     Throwable t = null;
 
     try {
@@ -338,8 +321,7 @@
 
   public void statement(AResource subject,
                         AResource predicate,
-                        ALiteral object)
-  {
+                        ALiteral object) {
 
     // Localize the statement
     long[] triple;
@@ -347,11 +329,9 @@
       triple = new long[] { toLocalNode(subject),
                             toLocalNode(predicate),
                             toLocalNode(object) };
-    }
-    catch (IOException e) {
+    } catch (IOException e) {
       throw new RuntimeException("Unable to localize parsed triple", e);
-    }
-    catch (LocalizeException e) {
+    } catch (LocalizeException e) {
       throw new RuntimeException("Unable to localize parsed triple", e);
     }
 
@@ -361,8 +341,7 @@
 
   public void statement(AResource subject,
                         AResource predicate,
-                        AResource object)
-  {
+                        AResource object) {
 
     // Localize the statement
     long[] triple;
@@ -370,11 +349,9 @@
       triple = new long[] { toLocalNode(subject),
                             toLocalNode(predicate),
                             toLocalNode(object) };
-    }
-    catch (IOException e) {
+    } catch (IOException e) {
       throw new RuntimeException("Unable to localize parsed triple", e);
-    }
-    catch (LocalizeException e) {
+    } catch (LocalizeException e) {
       throw new RuntimeException("Unable to localize parsed triple", e);
     }
 
@@ -388,11 +365,9 @@
 
   /**
    * Recoverable error.
-   *
-   * @param e PARAMETER TO DO
+   * @param e The exception being handled.
    */
-  public synchronized void error(SAXParseException e)
-  {
+  public synchronized void error(SAXParseException e) {
     exception = e;
     logger.error("Error, " + e.getLineNumber() + ", column " +
                  e.getColumnNumber() + ": " + e.getMessage(), e);
@@ -400,8 +375,7 @@
 
   /**
    * Non-recoverable error.
-   *
-   * @param e PARAMETER TO DO
+   * @param e The exception being handled
    */
   public synchronized void fatalError(SAXParseException e)
   {
@@ -412,11 +386,9 @@
 
   /**
    * Warning.
-   *
-   * @param e PARAMETER TO DO
+   * @param e The exception being warned about
    */
-  public void warning(SAXParseException e)
-  {
+  public void warning(SAXParseException e) {
     logger.warn("Warning, line " + e.getLineNumber() + ", column " +
                 e.getColumnNumber() + ": " + e.getMessage(), e);
   }
@@ -432,8 +404,7 @@
    * @return a local node corresponding to the literal
    * @throws LocalizeException if the literal can't be localized
    */
-  private long toLocalNode(ALiteral literal) throws LocalizeException
-  {
+  private long toLocalNode(ALiteral literal) throws LocalizeException {
 
     URI type = null;
     if (literal.getDatatypeURI() != null) {
@@ -446,18 +417,14 @@
 
     String lang = literal.getLang();
     if (type == null) {
-      if (lang == null) {
-        lang = "";
-      }
-    }
-    else {
+      if (lang == null) lang = "";
+    } else {
       lang = null;
     }
 
     if (type == null) {
       return resolverSession.localize(new LiteralImpl(literal.toString(), lang));
-    }
-    else {
+    } else {
       return resolverSession.localize(new LiteralImpl(literal.toString(), type));
     }
   }
@@ -503,8 +470,7 @@
     } else {
       try {
         assert resource.getURI() != null;
-        return resolverSession.localize(
-            new URIReferenceImpl(new URI(resource.getURI())));
+        return resolverSession.localize(new URIReferenceImpl(new URI(resource.getURI())));
       } catch (URISyntaxException e) {
         throw new Error("ARP generated a malformed URI", e);
       }
@@ -516,14 +482,12 @@
    * If an exception occurred in the parser, throws a TuplesException that
    * wraps the exception.
    */
-  private void checkForException() throws TuplesException
-  {
+  private void checkForException() throws TuplesException {
     if (exception != null) {
       queue.clear();
       headIndex = 0;
       headBuffer = null;
-      throw new TuplesException("Exception while reading " + baseURI,
-                                exception);
+      throw new TuplesException("Exception while reading " + baseURI, exception);
     }
   }
 
@@ -531,8 +495,7 @@
    * @return  a new <code>long[3]</code> triple from the queue or
    *   <code>null</code> if there are no more triples.
    */
-  long[] getTriple() throws TuplesException
-  {
+  long[] getTriple() throws TuplesException {
     if (headBuffer == null || headIndex >= headBuffer.length) {
       // Get another buffer from the queue.
       headIndex = 0;
@@ -553,8 +516,7 @@
     return triple;
   }
 
-  private synchronized long[][] getBufferFromQueue() throws TuplesException
-  {
+  private synchronized long[][] getBufferFromQueue() throws TuplesException {
     while (queue.isEmpty()) {
       checkForException();
       if (complete) {
@@ -572,7 +534,7 @@
     checkForException();
 
     notifyAll();
-    return (long[][]) queue.removeFirst();
+    return queue.removeFirst();
   }
 
   private void addTriple(long[] triple) {
@@ -593,9 +555,7 @@
 
   private synchronized void flushQueue(Throwable t) {
     if (interrupted()) {
-      if (t == null) {
-        t = new InterruptedException();
-      }
+      if (t == null) t = new InterruptedException();
     }
 
     if (t != null) {
@@ -622,8 +582,7 @@
     notifyAll();
   }
 
-  private synchronized void addBufferToQueue(long[][] buffer)
-  {
+  private synchronized void addBufferToQueue(long[][] buffer) {
     assert buffer != null;
     // Wait for the queue to drain a bit if it's too full
     while (queue.size() >= QUEUE_MAX_BUFFERS) {
@@ -641,8 +600,7 @@
   /**
    * Stops the thread.
    */
-  synchronized void abort()
-  {
+  synchronized void abort() {
     interrupt();
 
     // Clear the queue and notify in case ARP uses an internal thread
@@ -651,8 +609,7 @@
     notifyAll();
   }
 
-  private void logStatementActivity()
-  {
+  private void logStatementActivity() {
     // For very large documents, periodically log activity.
     if (isInfoEnabled) {
       if (statementCount % STATEMENT_COUNT_BATCH == 0) {
@@ -679,8 +636,7 @@
    * @param anonIdStr the AnonymousID string
    * @return the Id as a long
    */
-  private long parseAnonId(String anonIdStr)
-  {
+  private long parseAnonId(String anonIdStr) {
     assert anonIdStr.length() > 0;
     if (anonIdStr.charAt(0) != 'A') return -1;
     try {

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLContentHandler.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLContentHandler.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLContentHandler.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -28,11 +28,8 @@
 package org.mulgara.content.rdfxml;
 
 // Java 2 standard packages
-import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.net.URI;
-import java.util.Map;
 
 // Java 2 enterprise packages
 import javax.activation.MimeType;
@@ -69,6 +66,7 @@
   /**
    * Logger.
    */
+  @SuppressWarnings("unused")
   private static Logger logger =
     Logger.getLogger(RDFXMLContentHandler.class.getName());
 

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLStatements.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLStatements.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLStatements.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -29,39 +29,21 @@
 
 // Java 2 standard packages
 import java.io.*;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
 import java.util.*;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import org.xml.sax.*;
 
 // Third party packages
-import com.hp.hpl.jena.rdf.arp.ARP;  // ARP (Jena RDF/XML parser)
-import com.hp.hpl.jena.rdf.arp.ALiteral;
-import com.hp.hpl.jena.rdf.arp.AResource;
-import com.hp.hpl.jena.rdf.arp.StatementHandler;
-import com.hp.hpl.jena.rdf.arp.StatementHandler;
 import org.apache.log4j.Logger;      // Apache Log4J
-import org.jrdf.graph.*;             // JRDF
 
 // Locally written packages
 import org.mulgara.content.Content;
 import org.mulgara.content.NotModifiedException;
 import org.mulgara.content.NotModifiedTuplesException;
-import org.mulgara.query.Constraint;
 import org.mulgara.query.Cursor;
-import org.mulgara.query.QueryException;
 import org.mulgara.query.TuplesException;
 import org.mulgara.query.Variable;
-import org.mulgara.query.rdf.*;
-import org.mulgara.resolver.spi.LocalizeException;
 import org.mulgara.resolver.spi.ResolverSession;
 import org.mulgara.resolver.spi.Statements;
 import org.mulgara.resolver.spi.StatementsWrapperResolution;
-import org.mulgara.store.StoreException;
 import org.mulgara.store.tuples.AbstractTuples;
 import org.mulgara.store.tuples.Tuples;
 
@@ -80,8 +62,7 @@
  *      Software Pty Ltd</a>
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class RDFXMLStatements extends AbstractTuples implements Statements
-{
+public class RDFXMLStatements extends AbstractTuples implements Statements {
   /**
    * Logger.
    */
@@ -262,13 +243,11 @@
     return triple[column];
   }
 
-  public List getOperands()
-  {
-    return Collections.EMPTY_LIST;
+  public List<Tuples> getOperands() {
+    return Collections.emptyList();
   }
 
-  public int getRowCardinality() throws TuplesException
-  {
+  public int getRowCardinality() throws TuplesException {
     long statementCount;
 
     if (rowCountIsValid) {

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLStatementsUnitTest.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLStatementsUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLStatementsUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -28,12 +28,10 @@
 package org.mulgara.content.rdfxml;
 
 // Java 2 standard packages
-import java.beans.Beans;
 import java.io.File;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.net.URI;
-import java.util.HashMap;
 
 // Third party packages
 import junit.framework.*;        // JUnit unit testing framework
@@ -42,7 +40,6 @@
 
 // Locally written packages
 import org.mulgara.content.Content;
-import org.mulgara.query.TuplesException;
 import org.mulgara.query.rdf.LiteralImpl;
 import org.mulgara.query.rdf.URIReferenceImpl;
 import org.mulgara.resolver.spi.ResolverSession;
@@ -61,9 +58,8 @@
  */
 public class RDFXMLStatementsUnitTest extends TestCase
 {
-  /**
-   * Logger.
-   */
+  /** Logger. */
+  @SuppressWarnings("unused")
   private static final Logger logger =
     Logger.getLogger(RDFXMLStatementsUnitTest.class.getName());
 
@@ -133,7 +129,7 @@
     long o1 = resolverSession.localize(new URIReferenceImpl(RDF.SEQ));
 
     long p2 = resolverSession.localize(new URIReferenceImpl(new URI(
-                                         RDF.baseURI + "_1")));
+                                         RDF.BASE_URI + "_1")));
     long o2 = resolverSession.localize(new LiteralImpl("bar"));
 
     try {

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/TestResolverSession.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/TestResolverSession.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/TestResolverSession.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -71,30 +71,26 @@
    * Our pretend string pool, a map from global JRDF nodes to local
    * {@link Long}s.
    */
-  private final Map map = new HashMap();
+  private final Map<Node,Long> map = new HashMap<Node,Long>();
 
   //
   // Methods implementing ResolverSession
   //
 
-  public Node globalize(long node) throws GlobalizeException
-  {
+  public Node globalize(long node) throws GlobalizeException {
     throw new GlobalizeException(node, "Not implemented");
   }
 
-  public long lookup(Node node) throws LocalizeException
-  {
-    Object object = map.get(node);
+  public long lookup(Node node) throws LocalizeException {
+    Long object = map.get(node);
     if (object == null) {
       throw new LocalizeException(node, "No such node");
+    } else {
+      return object.longValue();
     }
-    else {
-      return ((Long) object).longValue();
-    }
   }
 
-  public long lookupPersistent(Node node) throws LocalizeException
-  {
+  public long lookupPersistent(Node node) throws LocalizeException {
     throw new LocalizeException(node, "Not implemented");
   }
 
@@ -111,8 +107,7 @@
     }
   }
 
-  public long localizePersistent(Node node) throws LocalizeException
-  {
+  public long localizePersistent(Node node) throws LocalizeException {
     throw new LocalizeException(node, "Not implemented");
   }
 

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/AbstractWritableStatement.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/AbstractWritableStatement.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/AbstractWritableStatement.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -66,8 +66,8 @@
   /**
    * Logger. This is named after the class.
    */
-  private final static Logger logger = Logger.getLogger(AbstractWritableStatement.class.
-      getName());
+  @SuppressWarnings("unused")
+  private final static Logger logger = Logger.getLogger(AbstractWritableStatement.class.getName());
 
   /** Subject of the statement to be written */
   protected SubjectNode subject = null;

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/BlankNodeWritableStatement.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/BlankNodeWritableStatement.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/BlankNodeWritableStatement.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -68,8 +68,8 @@
   /**
    * Logger. This is named after the class.
    */
-  private final static Logger logger = Logger.getLogger(
-      BlankNodeWritableStatement.class.getName());
+  @SuppressWarnings("unused")
+  private final static Logger logger = Logger.getLogger(BlankNodeWritableStatement.class.getName());
 
   /** BlankNode being writen */
   private BlankNode blankNode = null;

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/LiteralWritableStatement.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/LiteralWritableStatement.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/LiteralWritableStatement.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -69,8 +69,8 @@
   /**
    * Logger. This is named after the class.
    */
-  private final static Logger logger = Logger.getLogger(LiteralWritableStatement.class.
-      getName());
+  @SuppressWarnings("unused")
+  private final static Logger logger = Logger.getLogger(LiteralWritableStatement.class.getName());
 
   /** Literal being writen */
   private Literal literal = null;

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/NamespaceMap.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/NamespaceMap.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/NamespaceMap.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -68,16 +68,16 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class NamespaceMap extends HashMap {
+public class NamespaceMap extends HashMap<String,Object> {
 
-  /**
-   * Logger. This is named after the class.
-   */
-  private final static Logger logger = Logger.getLogger(NamespaceMap.class.
-      getName());
+  /** For serialization */
+  private static final long serialVersionUID = 1161744419591660130L;
 
+  /** Logger. This is named after the class. */
+  private final static Logger logger = Logger.getLogger(NamespaceMap.class.getName());
+
   /** A mirror of this map (where keys and values are swapped) */
-  private Map mirror = null;
+  private Map<Object,String> mirror = null;
 
   /** Prefix used to abbreviate RDF Namespace */
   private static final String RDF_PREFIX = "rdf";
@@ -92,31 +92,24 @@
    * @param session ResolverSession
    * @throws GraphException
    */
-  public NamespaceMap(Statements statements, ResolverSession session) throws
-      GraphException {
+  public NamespaceMap(Statements statements, ResolverSession session) throws GraphException {
 
-    mirror = new HashMap();
+    mirror = new HashMap<Object,String>();
 
     //add default namespaces
-    put(RDF_PREFIX, RDF.baseURI);
-    put(RDFS_PREFIX, RDFS.baseURI);
+    put(RDF_PREFIX, RDF.BASE_URI);
+    put(RDFS_PREFIX, RDFS.BASE_URI);
     put("owl", "http://www.w3.org/2002/07/owl#");
     put("dc", "http://purl.org/dc/elements/1.1/");
 
     //read namespaces from the statements
     try {
-
       populate(statements, session);
-    }
-    catch (TuplesException tuplesException) {
-
+    } catch (TuplesException tuplesException) {
       throw new GraphException("Could not read statements.", tuplesException);
+    } catch (GlobalizeException globalException) {
+      throw new GraphException("Could not globalize statements.", globalException);
     }
-    catch (GlobalizeException globalException) {
-
-      throw new GraphException("Could not globalize statements.",
-          globalException);
-    }
   }
 
   /**
@@ -132,7 +125,7 @@
   private void populate(Statements statements, ResolverSession session) throws
       TuplesException, GraphException, GlobalizeException {
 
-    Statements clonedStatements = (Statements) statements.clone();
+    Statements clonedStatements = (Statements)statements.clone();
 
     try {
 
@@ -201,19 +194,14 @@
    */
   protected void addNamespaceURI(URI uri) throws GraphException {
 
-    if (uri == null) {
+    if (uri == null) throw new IllegalArgumentException("URI argument is null.");
 
-      throw new IllegalArgumentException("URI argument is null.");
-    }
-
     //extract namespace from URI
     String uriString = uri.toString();
     String newURI = toNamespaceURI(uriString);
 
     //only add namespace if it is new
-    if ((newURI != null)
-        && (!containsValue(newURI))) {
-
+    if ((newURI != null) && !containsValue(newURI)) {
       //add to namespaces
       put("ns" + size(), newURI);
     }
@@ -228,11 +216,8 @@
    */
   private String toNamespaceURI(String uri) throws GraphException {
 
-    if (uri == null) {
+    if (uri == null) throw new IllegalArgumentException("URI argument is null.");
 
-      throw new IllegalArgumentException("URI argument is null.");
-    }
-
     //return original string by default
     String nsURI = uri;
 
@@ -251,7 +236,7 @@
       }
     }
 
-    assert nsURI != null:"Extracted namespace is null";
+    assert nsURI != null : "Extracted namespace is null";
     return nsURI;
   }
 
@@ -262,8 +247,7 @@
    * @return String
    */
   public String getRDFPrefix() {
-
-    return this.RDF_PREFIX;
+    return RDF_PREFIX;
   }
 
   /**
@@ -277,13 +261,10 @@
 
     String newURI = null;
     String nsURI = toNamespaceURI(uri);
-    Object key = mirror.get(nsURI);
+    String key = mirror.get(nsURI);
 
-    if (key == null) {
+    if (key == null) throw new GraphException("Namespace: " + nsURI + " has not been mapped.");
 
-      throw new GraphException("Namespace: " + nsURI + " has not been mapped.");
-    }
-
     //should all or part of the URI be replaced?
     if (uri.equals(nsURI)) {
 
@@ -293,8 +274,7 @@
       //this may produce invalid XML
       logger.warn("Replacing URI: " + uri + " with ENTITY: " + newURI +
           ". Namepace replacement may be invalid XML.");
-    }
-    else if (uri.startsWith(nsURI)) {
+    } else if (uri.startsWith(nsURI)) {
 
       //replace namespace part with key
       newURI = uri.replaceAll(nsURI, key + ":");
@@ -320,11 +300,8 @@
     String uri = original;
 
     //validate URI
-    if (original != null) {
+    if (original != null) uri = original.replaceAll("_[0-9]+", "li");
 
-      uri = original.replaceAll("_[0-9]+", "li");
-    }
-
     return uri;
   }
 
@@ -333,11 +310,11 @@
    * Overridden to allow for bi-directional mapping. Not intended to be called
    * outside this class.
    *
-   * @param key Object
+   * @param key String
    * @param value Object
    * @return Object
    */
-  public Object put(Object key, Object value) {
+  public Object put(String key, Object value) {
 
     mirror.put(value, key);
     return super.put(key, value);

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/RDFXMLWriter.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/RDFXMLWriter.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/RDFXMLWriter.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -39,14 +39,11 @@
 import org.jrdf.graph.Literal;
 import org.jrdf.graph.Node;
 import org.jrdf.graph.ObjectNode;
-import org.jrdf.graph.PredicateNode;
 import org.jrdf.graph.SubjectNode;
 import org.jrdf.graph.URIReference;
 
 // Local packages
-import org.mulgara.query.TuplesException;
 import org.mulgara.query.Variable;
-import org.mulgara.resolver.spi.GlobalizeException;
 import org.mulgara.resolver.spi.ResolverSession;
 import org.mulgara.resolver.spi.Statements;
 import org.mulgara.resolver.spi.StatementsWrapperTuples;
@@ -83,8 +80,7 @@
   /**
    * Logger. This is named after the class.
    */
-  private final static Logger log = Logger.getLogger(RDFXMLWriter.class.
-      getName());
+  private final static Logger log = Logger.getLogger(RDFXMLWriter.class.getName());
 
   /** Convenience reference to the new line character */
   private static final String NEWLINE = System.getProperty("line.separator");
@@ -153,24 +149,18 @@
       RDF_PREFIX = namespaces.getRDFPrefix();
 
       //write document
-      this.writeHeader(writer);
-      this.writeBody(statements, session, out);
-      this.writeFooter(out);
-    }
-    catch (Exception exception) {
+      writeHeader(writer);
+      writeBody(statements, session, out);
+      writeFooter(out);
+    } catch (Exception exception) {
 
       exception.printStackTrace();
       log.error("Failed to write Statements.", exception);
 
       throw new GraphException("Failed to write Statements.", exception);
+    } finally {
+      if (out != null) out.close();
     }
-    finally {
-
-      if (out != null) {
-
-        out.close();
-      }
-    }
   }
 
   /**
@@ -230,10 +220,10 @@
     }
 
     //print the Entities
-    this.writeXMLEntities(writer);
+    writeXMLEntities(writer);
 
     //print the opening RDF tag (including namespaces)
-    this.writeRDFHeader(writer);
+    writeRDFHeader(writer);
   }
 
   /**
@@ -250,25 +240,23 @@
     out.print(NEWLINE + "<!DOCTYPE " + RDF_PREFIX + ":RDF [");
 
     //print namespaces
-    Set keys = this.namespaces.keySet();
+    Set<String> keys = namespaces.keySet();
 
     if (keys != null) {
 
-      Iterator keyIter = keys.iterator();
-      Object currentKey = null;
+      Iterator<String> keyIter = keys.iterator();
+      String currentKey = null;
       Object currentValue = null;
 
       while (keyIter.hasNext()) {
 
         currentKey = keyIter.next();
-        currentValue = this.namespaces.get(currentKey);
+        currentValue = namespaces.get(currentKey);
 
-        if ((currentKey != null)
-            && (currentValue != null)) {
+        if ((currentKey != null) && (currentValue != null)) {
 
           //write as: <!ENTITY ns 'http://example.org/abc#'>
-          out.print(NEWLINE + "  <!ENTITY " + currentKey + " '" +
-              currentValue + "'>");
+          out.print(NEWLINE + "  <!ENTITY " + currentKey + " '" + currentValue + "'>");
         }
       }
     }
@@ -291,25 +279,24 @@
     out.print("<" + RDF_PREFIX + ":RDF ");
 
     //print namespaces
-    Set keys = this.namespaces.keySet();
+    Set<String> keys = namespaces.keySet();
 
     if (keys != null) {
 
-      Iterator keyIter = keys.iterator();
-      Object currentKey = null;
+      Iterator<String> keyIter = keys.iterator();
+      String currentKey = null;
       Object currentValue = null;
 
       while (keyIter.hasNext()) {
 
         currentKey = keyIter.next();
-        currentValue = this.namespaces.get(currentKey);
+        currentValue = namespaces.get(currentKey);
 
         if ((currentKey != null)
             && (currentValue != null)) {
 
           //use entities: xmlns:ns="&ns;"
-          out.print(NEWLINE + "  xmlns:" + currentKey + "=\"&" + currentKey +
-              ";\"");
+          out.print(NEWLINE + "  xmlns:" + currentKey + "=\"&" + currentKey + ";\"");
         }
       }
     }
@@ -410,25 +397,16 @@
 
       statement = new URIReferenceWritableStatement(subject, predicate,
           (URIReference) object);
-    }
-    else if (object instanceof BlankNode) {
-
-      statement = new BlankNodeWritableStatement(subject, predicate,
-          (BlankNode) object);
-    }
-    else if (object instanceof Literal) {
-
-      statement = new LiteralWritableStatement(subject, predicate,
-          (Literal) object);
-    }
-    else {
-
+    } else if (object instanceof BlankNode) {
+      statement = new BlankNodeWritableStatement(subject, predicate, (BlankNode)object);
+    } else if (object instanceof Literal) {
+      statement = new LiteralWritableStatement(subject, predicate, (Literal)object);
+    } else {
       assert(object != null):"Object should not be null";
-      throw new GraphException("Unknown ObjectNode type: " +
-          object.getClass().getName());
+      throw new GraphException("Unknown ObjectNode type: " + object.getClass().getName());
     }
 
-    assert statement != null:"WritableStatement should not be null";
+    assert statement != null : "WritableStatement should not be null";
     statement.write(namespaces, writer);
   }
 
@@ -439,10 +417,9 @@
    * @param out PrintWriter
    * @throws Exception
    */
-  protected void writeOpeningSubjectTag(SubjectNode subject,
-      PrintWriter out) throws Exception {
+  protected void writeOpeningSubjectTag(SubjectNode subject, PrintWriter out) throws Exception {
 
-    assert out != null:"PrintWriter is null";
+    assert out != null : "PrintWriter is null";
 
     //write
     if (subject instanceof URIReference) {
@@ -452,9 +429,7 @@
       String rdf = namespaces.getRDFPrefix();
       out.print("  <" + rdf + ":Description " + rdf + ":about=\"" +
           uri.toString() + "\">" + NEWLINE);
-    }
-    else if (subject instanceof BlankNode) {
-
+    } else if (subject instanceof BlankNode) {
       //get an identifier for the BlankNode
       String nodeString = subject.toString();
       nodeString = StringUtil.quoteAV(nodeString);
@@ -463,12 +438,9 @@
       //print as: <rdf:Description rdf:nodeID="blankNodeID">
       out.print("  <" + rdf + ":Description " + rdf + ":nodeID=\"" +
           nodeString + "\">" + NEWLINE);
+    } else {
+      throw new IllegalArgumentException("Unknown SubjectNode type: " + subject.getClass().getName());
     }
-    else {
-
-      throw new IllegalArgumentException("Unknown SubjectNode type: " +
-          subject.getClass().getName());
-    }
   }
 
   /**

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/RDFXMLWriterUnitTest.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/RDFXMLWriterUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/RDFXMLWriterUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -31,15 +31,11 @@
 
 // Third party packages
 import junit.framework.*;
-import org.jrdf.graph.*;
 import org.mulgara.content.Content;
 import org.mulgara.content.rdfxml.RDFXMLContentHandler;
 import org.mulgara.content.rdfxml.writer.TestResolverSession;
-import org.mulgara.query.rdf.*;
 import org.mulgara.resolver.file.FileContent;
 import org.mulgara.resolver.spi.*;
-import org.mulgara.store.statement.*;
-import org.mulgara.store.tuples.*;
 import org.mulgara.util.TempDir;
 
 
@@ -225,29 +221,22 @@
 
       //let superclass set up too
       super.setUp();
-    }
-    catch (Exception exception) {
-
+    } catch (Exception exception) {
       //try to tear down first
       try {
-
         tearDown();
+      } catch (Exception e2) {
+        // ignore
       }
-      finally {
-
-        throw exception;
-      }
+      throw exception;
     }
   }
 
   /**
    * The teardown method for JUnit
-   *
-   * @throws Exception EXCEPTION TO DO
    */
   public void tearDown() throws Exception {
-
-    //allow super to close down too
+    // allow super to close down too
     super.tearDown();
   }
 }

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/TestResolverSession.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/TestResolverSession.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/TestResolverSession.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -61,11 +61,8 @@
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
 
-public class TestResolverSession implements ResolverSession
-{
-  /**
-   * Our pretend node pool, a counter used to generate new local node values.
-   */
+public class TestResolverSession implements ResolverSession {
+  /** Our pretend node pool, a counter used to generate new local node values. */
   private long top = 0;
 
   /**
@@ -75,72 +72,55 @@
    */
   private long bNode = 1000000;
 
-  /**
-   * Our pretend string pool, a map from global JRDF nodes to local
-   * {@link Long}s.
-   */
-  private final Map map = new HashMap();
+  /** Our pretend string pool, a map from global JRDF nodes to local {@link Long}s. */
+  private final Map<Node,Long> map = new HashMap<Node,Long>();
 
-  /**
-   * Mirror to the string pool map that allows globalization.
-   */
-  private final Map mirrorMap = new HashMap();
+  /** Mirror to the string pool map that allows globalization. */
+  private final Map<Long,Node> mirrorMap = new HashMap<Long,Node>();
 
   //
   // Methods implementing ResolverSession
   //
 
-  public Node globalize(long node) throws GlobalizeException
-  {
-
-    Node gNode = (Node) mirrorMap.get(new Long(node));
-    return gNode;
+  public Node globalize(long node) throws GlobalizeException {
+    return mirrorMap.get(node);
   }
 
-  public long lookup(Node node) throws LocalizeException
-  {
-    Object object = map.get(node);
+  public long lookup(Node node) throws LocalizeException {
+    Long object = map.get(node);
     if (object == null) {
       throw new LocalizeException(node, "No such node");
+    } else {
+      return object.longValue();
     }
-    else {
-      return ((Long) object).longValue();
-    }
   }
 
-  public long lookupPersistent(Node node) throws LocalizeException
-  {
+  public long lookupPersistent(Node node) throws LocalizeException {
     throw new LocalizeException(node, "Not implemented");
   }
 
-  public long localize(Node node) throws LocalizeException
-  {
-    Object object = map.get(node);
+  public long localize(Node node) throws LocalizeException {
+    Long object = map.get(node);
     if (object == null) {
       top++;
-
       Long id = new Long(top);
 
       if (node instanceof BlankNodeImpl) {
-
         bNode++;
         id = new Long(bNode);
-        ((BlankNodeImpl) node).setNodeId(bNode);
+        ((BlankNodeImpl)node).setNodeId(bNode);
       }
 
       map.put(node, id);
       mirrorMap.put(id, node);
 
       return id.longValue();
+    } else {
+      return object.longValue();
     }
-    else {
-
-      return ((Long) object).longValue();
-    }
   }
 
-  public long localizePersistent(Node node) throws LocalizeException
-  {
+  public long localizePersistent(Node node) throws LocalizeException {
     throw new LocalizeException(node, "Not implemented");
   }
 
@@ -168,7 +148,6 @@
   /**
    * Retrieve the SPObject factory from the stringpool to allow for the creation
    * of new SPObjects.
-   *
    * @return The factory to allow for creation of SPObjects
    */
   public SPObjectFactory getSPObjectFactory() {

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/TestStatementsComparator.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/TestStatementsComparator.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/TestStatementsComparator.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -37,7 +37,6 @@
 // Local packages
 import java.util.Map;
 import java.util.HashMap;
-import java.util.Collections;
 import org.jrdf.graph.Node;
 import java.util.Arrays;
 
@@ -78,6 +77,7 @@
   /**
    * Logger. This is named after the class.
    */
+  @SuppressWarnings("unused")
   private final static Logger logger = Logger.getLogger(
       TestStatementsComparator.class.getName());
 
@@ -102,7 +102,7 @@
     equal = (compareReference(statements1, statements2))
         || (compareCount(statements1, statements2)
         && compareStatementNodes(statements1, session1, statements2, session2,
-        new HashMap()));
+        new HashMap<String,Object>()));
 
     return equal;
   }
@@ -148,7 +148,7 @@
    */
   private boolean compareStatementNodes(Statements statements1,
       ResolverSession session1, Statements statements2, ResolverSession session2,
-      Map environment) throws Exception {
+      Map<String,Object> environment) throws Exception {
 
     statements1 = prepareStatements(statements1);
     statements2 = prepareStatements(statements2);

Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/URIReferenceWritableStatement.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/URIReferenceWritableStatement.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/writer/URIReferenceWritableStatement.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -66,6 +66,7 @@
   /**
    * Logger. This is named after the class.
    */
+  @SuppressWarnings("unused")
   private final static Logger logger = Logger.getLogger(
       URIReferenceWritableStatement.class.getName());
 

Modified: trunk/src/jar/driver/build.xml
===================================================================
--- trunk/src/jar/driver/build.xml	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/driver/build.xml	2008-08-28 23:44:40 UTC (rev 1199)
@@ -109,7 +109,6 @@
       <zipfileset src="${server-beep.dist.dir}/${server-beep.jar}" excludes="META-INF/**"/>
       <zipfileset src="${server-rmi.dist.dir}/${server-rmi.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${log4j.jar}" excludes="META-INF/**"/>
-      <zipfileset src="${lib.dir}/${jrdf.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${sesame-model.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${saaj.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${emory-util.jar}" excludes="META-INF/**"/>

Modified: trunk/src/jar/itql/build.xml
===================================================================
--- trunk/src/jar/itql/build.xml	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/itql/build.xml	2008-08-28 23:44:40 UTC (rev 1199)
@@ -87,7 +87,7 @@
     </manifest>
     <manifest file="${obj.dir}/META-INF/MANIFEST_ITQL_BOOTSTRAP.MF">
       <attribute name="Main-Class" value="org.mulgara.util.Bootstrap"/>
-      <attribute name="Embedded-Jar" value="${query.jar}, ${driver.jar}, ${itql.jar},${util.jar}, ${server-beep.jar}, ${server-rmi.jar}, apache-soap-2.2.jar, log4j-1.2.15.jar,jargs-0.2.jar, ${jrdf.jar}, ${saaj.jar}, ${emory-util.jar}, ${sesame-model.jar}"/>
+      <attribute name="Embedded-Jar" value="${query.jar}, ${driver.jar}, ${itql.jar},${util.jar}, ${server-beep.jar}, ${server-rmi.jar}, apache-soap-2.2.jar, log4j-1.2.15.jar,jargs-0.2.jar, ${saaj.jar}, ${emory-util.jar}, ${sesame-model.jar}"/>
       <attribute name="Embedded-Main-Class" value="org.mulgara.itql.TqlSession"/>
     </manifest>
   </target>
@@ -136,7 +136,6 @@
       <zipfileset src="${lib.dir}/${commons-logging.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/concurrent-1.3.4.jar" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/jargs-0.2.jar" excludes="META-INF/**"/>
-      <zipfileset src="${lib.dir}/${jrdf.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/${sesame-model.jar}" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/jsr173_07_api.jar" excludes="META-INF/**"/>
       <zipfileset src="${lib.dir}/jsr173_07_ri.jar" excludes="META-INF/**"/>

Modified: trunk/src/jar/jrdf/java/org/mulgara/jrdf/JRDFGraphUnitTest.java
===================================================================
--- trunk/src/jar/jrdf/java/org/mulgara/jrdf/JRDFGraphUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/jrdf/java/org/mulgara/jrdf/JRDFGraphUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -61,7 +61,7 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class JRDFGraphUnitTest extends AbstractGraphUnitTest {
+public class JRDFGraphUnitTest extends AbstractGraphTest {
 
   /**
    * init the logging class

Modified: trunk/src/jar/jrdf/java/org/mulgara/jrdf/JRDFLocalGraphUnitTest.java
===================================================================
--- trunk/src/jar/jrdf/java/org/mulgara/jrdf/JRDFLocalGraphUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/jrdf/java/org/mulgara/jrdf/JRDFLocalGraphUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -61,7 +61,7 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class JRDFLocalGraphUnitTest extends AbstractGraphUnitTest {
+public class JRDFLocalGraphUnitTest extends AbstractGraphTest {
 
   /**
    * init the logging class

Added: trunk/src/jar/query/java/org/jrdf/graph/AbstractBlankNode.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/AbstractBlankNode.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/AbstractBlankNode.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,108 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import java.io.Serializable;
+
+import org.openrdf.model.BNode;
+
+/**
+ * A base implementation of an RDF {@link BlankNode}.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public abstract class AbstractBlankNode implements BlankNode, Serializable {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 3481053689307839406L;
+
+  /**
+   * Accept a call from a TypedNodeVisitor.
+   *
+   * @param visitor the object doing the visiting.
+   */
+  public void accept(TypedNodeVisitor visitor) {
+    visitor.visitBlankNode(this);
+  }
+
+  public boolean equals(Object obj) {
+    if (obj instanceof BNode)
+      return getID().equals(((BNode) obj).getID());
+    return false;
+  }
+
+  public int hashCode() {
+    return getID().hashCode();
+  }
+
+  public String stringValue() {
+    return getID();
+  }
+
+  public String toString() {
+    return "_:" + getID();
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/AbstractGraphElementFactoryTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/AbstractGraphElementFactoryTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/AbstractGraphElementFactoryTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,376 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jrdf.util.ClosableIterator;
+
+import java.net.URI;
+
+/**
+ * Abstract Test case for Graph Element Factories.
+ *
+ * Implementing packages should extend this class and implement the
+ * {@link #newGraph}, {@link #getDefaultLiteralType} and
+ * {@link #getDefaultLiteralLanguage} methods.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ *
+ * @version $Revision: 624 $
+ */
+public abstract class AbstractGraphElementFactoryTest extends TestCase {
+
+  /**
+   * Instance of a graph element factory.
+   */
+  private GraphElementFactory elementFactory;
+
+  /**
+   * Global graph object.
+   */
+  private Graph graph;
+
+  /**
+   * Hook for test runner to obtain an empty test suite from, because this test
+   * can't be run (it's abstract). This must be overridden in subclasses.
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    return suite;
+  }
+
+
+  /**
+   * Constructs a new test with the given name.
+   *
+   * @param name the name of the test
+   */
+  public AbstractGraphElementFactoryTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Create test instance.
+   * @throws Exception A generic exception - this should cause the tests to fail.
+   */
+  public void setUp() throws Exception {
+    graph = newGraph();
+    elementFactory = graph.getElementFactory();
+  }
+
+  //
+  // abstract methods specific to the implementation.
+  //
+
+  /**
+   * Create a new graph of the appropriate type.
+   *
+   * @return A new graph implementation object.
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   */
+  protected abstract Graph newGraph() throws Exception;
+
+  /**
+   * Return the default literal type from the implementation.
+   *
+   * @return The default Literal type.
+   */
+  protected abstract URI getDefaultLiteralType();
+
+  /**
+   * Get the default literal language from the implementation.
+   *
+   * @return The default Literal language.
+   */
+  public abstract String getDefaultLiteralLanguage();
+
+  //
+  // Test cases
+  //
+
+  /**
+   * Tests that each of the createLiteral methods work as expected.
+   *
+   * @throws Exception if query fails when it should have succeeded
+   */
+  public void testCreateLiterals() throws Exception {
+    final String TEST_STR1 = "A test string";
+    final String TEST_STR2 = "Another test string";
+
+    // createLiteral(String lexicalValue)
+    Literal l1 = elementFactory.createLiteral(TEST_STR1);
+    Literal l2 = elementFactory.createLiteral(TEST_STR2);
+    Literal l3 = elementFactory.createLiteral(TEST_STR1);
+    assertFalse(l1.equals(l2));
+    assertEquals(l1, l3);
+    assertEquals(getDefaultLiteralType(), l1.getDatatypeURI());
+    assertEquals(null, l1.getLanguage());
+    assertEquals(TEST_STR1, l1.getLexicalForm());
+
+    // createLiteral(String lexicalValue, String languageType)
+    l1 = elementFactory.createLiteral(TEST_STR1, "it");
+    l2 = elementFactory.createLiteral(TEST_STR2, "it");
+    l3 = elementFactory.createLiteral(TEST_STR1, "it");
+    Literal l4 = elementFactory.createLiteral(TEST_STR1);
+    assertFalse(l1.equals(l2));
+    assertFalse(l1.equals(l4));
+    assertEquals(l1, l3);
+    assertEquals(getDefaultLiteralType(), l1.getDatatypeURI());
+    assertEquals("it", l1.getLanguage());
+    assertEquals(TEST_STR1, l1.getLexicalForm());
+
+    // createLiteral(String lexicalValue, URI datatypeURI)
+    URI type = new URI("xsd:long");
+    l1 = elementFactory.createLiteral("42", type);
+    l2 = elementFactory.createLiteral("0", type);
+    l3 = elementFactory.createLiteral("42", type);
+    l4 = elementFactory.createLiteral("42");
+    assertFalse(l1.equals(l2));
+    assertFalse(l1.equals(l4));
+    assertEquals(l1, l3);
+    assertEquals(type, l1.getDatatypeURI());
+    assertEquals(null, l1.getLanguage());
+    assertEquals("42", l1.getLexicalForm());
+
+  }
+
+  /**
+   * Tests that each of the createResource methods work as expected.
+   *
+   * @throws Exception if query fails when it should have succeeded
+   */
+  public void testCreateResources() throws Exception {
+    // test blank node creation
+    BlankNode blank1 = elementFactory.createResource();
+    BlankNode blank2 = elementFactory.createResource();
+    assertFalse(blank1.equals(blank2));
+
+    // test named node creation
+    URI uri1 = new URI("http://namespace#somevalue");
+    URI uri2 = new URI("http://namespace#someothervalue");
+    URIReference ref1 = elementFactory.createResource(uri1);
+    URIReference ref2 = elementFactory.createResource(uri2);
+    URIReference ref3 = elementFactory.createResource(uri1);
+    assertFalse(ref1.equals(ref2));
+    assertEquals(ref1, ref3);
+    assertEquals(ref1.getURI(), uri1);
+  }
+
+
+  /**
+   * Tests that each of the createResource methods work as expected.
+   *
+   * @throws Exception if query fails when it should have succeeded
+   */
+  public void testCreateTriples() throws Exception {
+
+    BlankNode blank1 = elementFactory.createResource();
+    BlankNode blank2 = elementFactory.createResource();
+
+    URI uri1 = new URI("http://namespace#somevalue");
+    URI uri2 = new URI("http://namespace#someothervalue");
+    URI uri3 = new URI("http://namespace#yetanothervalue");
+    URIReference ref1 = elementFactory.createResource(uri1);
+    URIReference ref2 = elementFactory.createResource(uri2);
+    elementFactory.createResource(uri3);
+
+    final String TEST_STR1 = "A test string";
+    final String TEST_STR2 = "Another test string";
+    Literal l1 = elementFactory.createLiteral(TEST_STR1);
+    elementFactory.createLiteral(TEST_STR2);
+
+    // test ordinary creation
+    Triple triple = elementFactory.createTriple(blank1, ref1, blank2);
+    assertEquals(blank1, triple.getSubject());
+    assertEquals(ref1, triple.getPredicate());
+    assertEquals(blank2, triple.getObject());
+
+    // test inequality, particularly against differing blank nodes
+    Triple triple2 = elementFactory.createTriple(blank2, ref1, blank2);
+    assertFalse(triple.equals(triple2));
+
+    // test equality
+    triple2 = elementFactory.createTriple(blank1, ref1, blank2);
+    assertEquals(triple, triple2);
+
+    // test all types of statement creation
+    triple = elementFactory.createTriple(blank1, ref1, l1);
+    triple = elementFactory.createTriple(blank1, ref1, l1);
+    triple = elementFactory.createTriple(ref1, ref2, l1);
+    triple = elementFactory.createTriple(ref1, ref2, blank1);
+
+    // Test that the node exists from a newly created predicate - the same
+    // as an already existing predicate
+    graph.add(triple);
+    graph.add(ref2, ref1, l1);
+
+    URIReference ref4 = elementFactory.createResource(uri1);
+    URIReference ref5 = elementFactory.createResource(uri2);
+    Literal l3 = elementFactory.createLiteral(TEST_STR1);
+    assertEquals(ref4, ref1);
+    assertEquals(ref5, ref2);
+    assertEquals(l1, l3);
+    assertEquals(l1.getEscapedForm(), l3.getEscapedForm());
+    assertTrue(graph.contains(ref4, ref5, blank1));
+
+    ClosableIterator<Triple> iter = graph.find(ref2, ref1, null);
+    while (iter.hasNext()) {
+      triple = (Triple) iter.next();
+      assertEquals(l1, triple.getObject());
+      assertTrue(l1.hashCode() == triple.getObject().hashCode());
+      assertEquals(l3, triple.getObject());
+      assertTrue(l3.hashCode() == triple.getObject().hashCode());
+    }
+
+    assertTrue(graph.find(ref2, ref1, l1).hasNext());
+    assertTrue(graph.contains(ref2, ref1, l1));
+    assertTrue(graph.find(ref5, ref4, l3).hasNext());
+    assertTrue(graph.contains(ref5, ref4, l3));
+  }
+
+  /**
+   * Tests that objects are always localized before testing.
+   *
+   * @throws Exception if query fails when it should have succeeded
+   */
+  public void testTwoGraphs() throws Exception {
+
+    Graph g1 = newGraph();
+    Graph g2 = newGraph();
+
+    final String TEST_STR1 = "A test string";
+    final String TEST_STR2 = "Foo 2";
+    URI uri1 = new URI("http://namespace#somevalue1");
+    URI uri2 = new URI("http://namespace#somevalue2");
+    URI uri3 = new URI("http://namespace#foo");
+
+    GraphElementFactory gef1 = g1.getElementFactory();
+    URIReference g1u1 = gef1.createResource(uri1);
+    URIReference g1u2 = gef1.createResource(uri2);
+    URIReference g1u3 = gef1.createResource(uri3);
+
+    GraphElementFactory gef2 = g2.getElementFactory();
+    Literal g2l1 = gef2.createLiteral(TEST_STR1);
+    Literal g2l2 = gef2.createLiteral(TEST_STR2);
+    URIReference g2u1 = gef2.createResource(uri2);
+
+    // Test inserting a subject and predicate that do no exist in g2.
+    boolean isOkay = false;
+    try {
+      g2.add(g1u1, g1u1, g2l1);
+    }
+    catch (GraphException ge) {
+      isOkay = true;
+    }
+    assertTrue("Should fail to insert node", isOkay);
+
+    // Test inserting a predicate that does no exist in g2.
+    isOkay = false;
+    try {
+      g2.add(g2u1, g1u1, g2l1);
+    }
+    catch (GraphException ge) {
+      isOkay = true;
+    }
+    assertTrue("Should fail to insert node", isOkay);
+
+    // Test inserting an object that does not exist g2.
+    isOkay = false;
+    try {
+      g2.add(g2u1, g1u1, g2l2);
+    }
+    catch (GraphException ge) {
+      isOkay = true;
+    }
+    assertTrue("Should fail to insert node", isOkay);
+
+    // Test inserting a predicate and object that come from another graph but
+    // do exist.
+    try {
+      g2.add(g2u1, g1u2, g1u2);
+      assertTrue("Should contain the statemet", g2.contains(g2u1, g2u1, g2u1));
+    }
+    catch (GraphException ge) {
+      fail("Should allow nodes to be inserted from other graphs which have " +
+          "the same value but different node ids");
+    }
+
+    // Test inserting a statements using objects from the correct graph and then
+    // using find and contains with the same, by value, object from another.
+    URIReference g2u3 = gef2.createResource(uri3);
+    g2.add(g2u3, g2u3, g2u3);
+
+    assertTrue("Contains should work by value", g2.contains(g1u3, g1u3, g1u3));
+    assertTrue("Find should work by value", g2.find(g1u3, g1u3, g1u3).hasNext());
+
+    // Test the find(<foo>, null, null) works.
+    ClosableIterator<Triple> iter = g2.find(g2u3, null, null);
+    assertTrue("Should get back at least one result", iter.hasNext());
+
+    // Test the find(null, null, null) works.
+    iter = g2.find(null, null, null);
+    assertTrue("Should get back at least one result", iter.hasNext());
+
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/AbstractGraphTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/AbstractGraphTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/AbstractGraphTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,778 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jrdf.util.ClosableIterator;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Abstract test case for graph implementations.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public abstract class AbstractGraphTest extends TestCase {
+
+  /**
+   * Instance of a graph object.
+   */
+  protected Graph graph;
+
+  /**
+   * Instance of a factory for the graph.
+   */
+  private GraphElementFactory elementFactory;
+
+  /**
+   * Blank node 1.
+   */
+  protected BlankNode blank1;
+
+  /**
+   * Blank node 2.
+   */
+  protected BlankNode blank2;
+
+  private URI uri1;
+  private URI uri2;
+  private URI uri3;
+  protected URIReference ref1;
+  protected URIReference ref2;
+  protected URIReference ref3;
+
+  /**
+   * Used to create literal.
+   */
+  private static final String TEST_STR1 = "A test string";
+
+  /**
+   * Used to create literal.
+   */
+  private static final String TEST_STR2 = "Another test string";
+
+  /**
+   * Literal 1.
+   */
+  protected static Literal l1;
+
+  /**
+   * Literal 2.
+   */
+  protected static Literal l2;
+
+  /**
+   * Hook for test runner to obtain an empty test suite from, because this test
+   * can't be run (it's abstract). This must be overridden in subclasses.
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    return suite;
+  }
+
+
+  /**
+   * Constructs a new test with the given name.
+   *
+   * @param name the name of the test
+   */
+  protected AbstractGraphTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Create test instance.
+   *
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   */
+  public void setUp() throws Exception {
+    graph = newGraph();
+    elementFactory = graph.getElementFactory();
+
+    blank1 = elementFactory.createResource();
+    blank2 = elementFactory.createResource();
+
+    uri1 = new URI("http://namespace#somevalue");
+    uri2 = new URI("http://namespace#someothervalue");
+    uri3 = new URI("http://namespace#yetanothervalue");
+    ref1 = elementFactory.createResource(uri1);
+    ref2 = elementFactory.createResource(uri2);
+    ref3 = elementFactory.createResource(uri3);
+
+    l1 = elementFactory.createLiteral(TEST_STR1);
+    l2 = elementFactory.createLiteral(TEST_STR2);
+  }
+
+  //
+  // implementation interfaces
+  //
+
+  /**
+   * Create a graph implementation.
+   *
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   * @return A new Graph.
+   */
+  protected abstract Graph newGraph() throws Exception;
+
+  //
+  // Test cases
+  //
+
+  /**
+   * Tests that a new graph is empty.
+   *
+   * @throws Exception if query fails when it should have succeeded
+   */
+  public void testEmpty() throws Exception {
+    assertTrue(graph.isEmpty());
+    assertEquals(0, graph.getNumberOfTriples());
+  }
+
+  /**
+   * Tests that it is possible to get a NodeFactory from a graph.
+   */
+  public void testFactory() {
+    GraphElementFactory f = graph.getElementFactory();
+    assertTrue(null != f);
+  }
+
+  /**
+   * Tests addition.
+   *
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   */
+  public void testAddition() throws Exception {
+
+    // add in a triple by nodes
+    graph.add(blank1, ref1, blank2);
+
+    assertFalse(graph.isEmpty());
+    assertEquals(1, graph.getNumberOfTriples());
+
+    // add in a whole triple
+    Triple triple2 = elementFactory.createTriple(blank2, ref1, blank2);
+    graph.add(triple2);
+
+    assertFalse(graph.isEmpty());
+    assertEquals(2, graph.getNumberOfTriples());
+
+    // add in the first triple again
+    graph.add(blank1, ref1, blank2);
+
+    assertFalse(graph.isEmpty());
+    assertEquals(2, graph.getNumberOfTriples());
+
+    // add in the second whole triple again
+    Triple triple2b = elementFactory.createTriple(blank2, ref1, blank2);
+    graph.add(triple2b);
+    assertFalse(graph.isEmpty());
+    assertEquals(2, graph.getNumberOfTriples());
+
+    // and again
+    graph.add(triple2);
+    assertFalse(graph.isEmpty());
+    assertEquals(2, graph.getNumberOfTriples());
+
+    // Add using iterator
+    List<Triple> list = new ArrayList<Triple>();
+    list.add(elementFactory.createTriple(ref1, ref1, ref1));
+    list.add(elementFactory.createTriple(ref2, ref2, ref2));
+
+    graph.add(list.iterator());
+    assertFalse(graph.isEmpty());
+    assertEquals(4, graph.getNumberOfTriples());
+  }
+
+  /**
+   * Tests removal.
+   *
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   */
+  public void testRemoval() throws Exception {
+    // add some test data
+    graph.add(blank1, ref1, blank2);
+    graph.add(blank1, ref2, blank2);
+    graph.add(ref1, ref2, l2);
+    Triple t1 = elementFactory.createTriple(blank2, ref1, blank1);
+    graph.add(t1);
+    Triple t2 = elementFactory.createTriple(blank2, ref2, blank1);
+    graph.add(t2);
+    Triple t3 = elementFactory.createTriple(blank2, ref1, l1);
+    graph.add(t3);
+
+    // check that all is well
+    assertFalse(graph.isEmpty());
+    assertEquals(6, graph.getNumberOfTriples());
+
+    // delete the first statement
+    graph.remove(blank1, ref1, blank2);
+    assertEquals(5, graph.getNumberOfTriples());
+
+    // delete the last statement
+    graph.remove(t3);
+    assertEquals(4, graph.getNumberOfTriples());
+
+    // delete the next last statement with a new "triple object"
+    t2 = elementFactory.createTriple(blank2, ref2, blank1);
+    graph.remove(t2);
+    assertEquals(3, graph.getNumberOfTriples());
+
+    // delete the next last statement with a triple different to what it was built with
+    graph.remove(blank2, ref1, blank1);
+    assertEquals(2, graph.getNumberOfTriples());
+
+    // delete the next last statement with a triple different to what it was built with
+    graph.remove(ref1, ref2, l2);
+    assertEquals(1, graph.getNumberOfTriples());
+
+    // delete the wrong triple
+    try {
+      graph.remove(blank2, ref1, blank1);
+      assertTrue(false);
+    }
+    catch (GraphException e) { /* no-op */}
+    assertEquals(1, graph.getNumberOfTriples());
+
+    // delete a triple that never existed
+    try {
+      graph.remove(blank2, ref2, l2);
+      assertTrue(false);
+    }
+    catch (GraphException e) { /* no-op */}
+    assertEquals(1, graph.getNumberOfTriples());
+
+    // and delete with a triple object
+    t1 = elementFactory.createTriple(blank2, ref1, blank1);
+    try {
+      graph.remove(t1);
+      assertTrue(false);
+    }
+    catch (GraphException e) { /* no-op */}
+    assertEquals(1, graph.getNumberOfTriples());
+
+    // now clear out the graph
+    assertFalse(graph.isEmpty());
+    graph.remove(blank1, ref2, blank2);
+    assertTrue(graph.isEmpty());
+    assertEquals(0, graph.getNumberOfTriples());
+
+    // check that we can't still remove things
+    try {
+      graph.remove(blank1, ref2, blank2);
+      assertTrue(false);
+    }
+    catch (GraphException e) { /* no-op */}
+    assertTrue(graph.isEmpty());
+    assertEquals(0, graph.getNumberOfTriples());
+
+    // Check removal using iterator
+    graph.add(elementFactory.createTriple(ref1, ref1, ref1));
+    graph.add(elementFactory.createTriple(ref2, ref2, ref2));
+
+    List<Triple> list = new ArrayList<Triple>();
+    list.add(elementFactory.createTriple(ref1, ref1, ref1));
+    list.add(elementFactory.createTriple(ref2, ref2, ref2));
+    graph.remove(list.iterator());
+
+    // check that we can't still remove things
+    try {
+      graph.remove(ref2, ref2, ref2);
+      assertTrue(false);
+    }
+    catch (GraphException e) { /* no-op */}
+
+    assertTrue(graph.isEmpty());
+    assertEquals(0, graph.getNumberOfTriples());
+  }
+
+  /**
+   * Tests containership.
+   *
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   */
+  public void testContains() throws Exception {
+    // add some test data
+    graph.add(blank1, ref1, blank2);
+    graph.add(blank1, ref2, blank2);
+    graph.add(ref1, ref2, l2);
+    Triple t1 = elementFactory.createTriple(blank2, ref1, blank1);
+    graph.add(t1);
+    Triple t2 = elementFactory.createTriple(blank2, ref2, blank1);
+    graph.add(t2);
+    Triple t3 = elementFactory.createTriple(blank2, ref1, l1);
+    graph.add(t3);
+
+    // test containership
+    assertTrue(graph.contains(blank1, ref1, blank2));
+    // test with existing and built triples
+    assertTrue(graph.contains(t1));
+    t1 = elementFactory.createTriple(blank2, ref2, blank1);
+    assertTrue(graph.contains(t1));
+
+    // test non containership
+    assertFalse(graph.contains(blank1, ref1, blank1));
+    t1 = elementFactory.createTriple(blank2, ref2, ref1);
+    assertFalse(graph.contains(t1));
+
+    // test containership after removal
+    graph.remove(blank1, ref1, blank2);
+    assertFalse(graph.contains(blank1, ref1, blank2));
+    t1 = elementFactory.createTriple(blank1, ref1, blank2);
+    assertFalse(graph.contains(t1));
+
+    // put it back in and test again
+    graph.add(blank1, ref1, blank2);
+    assertTrue(graph.contains(blank1, ref1, blank2));
+    assertTrue(graph.contains(t1));
+
+    // Null in contains.
+    Graph newGraph = newGraph();
+    assertFalse(newGraph.contains(null, null, null));
+
+    // Add a statement
+    GraphElementFactory newElementFactory = newGraph.getElementFactory();
+    blank1 = newElementFactory.createResource();
+    blank2 = newElementFactory.createResource();
+    ref1 = newElementFactory.createResource(uri1);
+    t1 = newElementFactory.createTriple(blank1, ref1, blank2);
+    newGraph.add(t1);
+
+    // Check for existance
+    assertTrue(newGraph.contains(null, ref1, blank2));
+    assertTrue(newGraph.contains(null, null, blank2));
+    assertTrue(newGraph.contains(null, null, null));
+    assertTrue(newGraph.contains(blank1, null, blank2));
+    assertTrue(newGraph.contains(blank1, null, null));
+    assertTrue(newGraph.contains(blank1, ref1, null));
+
+    // Check non-existance
+    assertFalse(newGraph.contains(null, ref2, blank1));
+    assertFalse(newGraph.contains(null, null, blank1));
+    assertFalse(newGraph.contains(blank2, null, blank1));
+    assertFalse(newGraph.contains(blank2, null, null));
+    assertFalse(newGraph.contains(blank2, ref2, null));
+  }
+
+  /**
+   * Tests finding.
+   *
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   */
+  public void testFinding() throws Exception {
+    graph.add(blank1, ref1, blank2);
+    graph.add(blank1, ref1, l1);
+    graph.add(blank1, ref2, blank2);
+    graph.add(blank1, ref1, l2);
+    graph.add(blank2, ref1, blank2);
+    graph.add(blank2, ref2, blank2);
+    graph.add(blank2, ref1, l1);
+    graph.add(blank2, ref1, l2);
+
+    // look for the first triple and check that one is returned
+    ClosableIterator<Triple> it = graph.find(blank1, ref1, blank2);
+    assertTrue(it.hasNext());
+    it.close();
+
+    // look for a non-existent triple
+    it = graph.find(ref1, ref1, blank1);
+    assertFalse(it.hasNext());
+    it.close();
+
+    // look for doubles and check that there is data there
+    it = graph.find(blank1, ref1, null);
+    assertTrue(it.hasNext());
+    it.close();
+    it = graph.find(blank1, null, blank2);
+    assertTrue(it.hasNext());
+    it.close();
+    it = graph.find(null, ref1, blank2);
+    assertTrue(it.hasNext());
+    it.close();
+
+    // look for a non-existent double
+    it = graph.find(ref1, ref1, null);
+    assertFalse(it.hasNext());
+    it.close();
+    it = graph.find(ref1, null, blank2);
+    assertFalse(it.hasNext());
+    it.close();
+    it = graph.find(null, ref3, blank2);
+    assertFalse(it.hasNext());
+    it.close();
+
+    // look for singles
+    it = graph.find(blank1, null, null);
+    assertTrue(it.hasNext());
+    it.close();
+    it = graph.find(null, ref1, null);
+    assertTrue(it.hasNext());
+    it.close();
+    it = graph.find(null, null, l1);
+    assertTrue(it.hasNext());
+    it.close();
+
+    // look for non-existent singles
+    it = graph.find(ref1, null, null);
+    assertFalse(it.hasNext());
+    it.close();
+    it = graph.find(null, ref3, null);
+    assertFalse(it.hasNext());
+    it.close();
+    it = graph.find(null, null, ref1);
+    assertFalse(it.hasNext());
+    it.close();
+
+    // do it all again with triples
+
+    // look for the first triple and check that one is returned
+    Triple t = elementFactory.createTriple(blank1, ref1, blank2);
+    it = graph.find(t);
+    assertTrue(it.hasNext());
+    it.close();
+
+    // look for a non-existent triple
+    t = elementFactory.createTriple(ref1, ref1, blank1);
+    it = graph.find(t);
+    assertFalse(it.hasNext());
+    it.close();
+
+    // look for doubles and check that there is data there
+    t = elementFactory.createTriple(blank1, ref1, null);
+    it = graph.find(t);
+    assertTrue(it.hasNext());
+    it.close();
+    t = elementFactory.createTriple(blank1, null, blank2);
+    it = graph.find(t);
+    assertTrue(it.hasNext());
+    it.close();
+    t = elementFactory.createTriple(null, ref1, blank2);
+    it = graph.find(t);
+    assertTrue(it.hasNext());
+    it.close();
+
+    // look for a non-existent double
+    t = elementFactory.createTriple(ref1, ref1, null);
+    it = graph.find(t);
+    assertFalse(it.hasNext());
+    it.close();
+    t = elementFactory.createTriple(ref1, null, blank2);
+    it = graph.find(t);
+    assertFalse(it.hasNext());
+    it.close();
+    t = elementFactory.createTriple(null, ref3, blank2);
+    it = graph.find(t);
+    assertFalse(it.hasNext());
+    it.close();
+
+    // look for singles
+    t = elementFactory.createTriple(blank1, null, null);
+    it = graph.find(t);
+    assertTrue(it.hasNext());
+    it.close();
+    t = elementFactory.createTriple(null, ref1, null);
+    it = graph.find(t);
+    assertTrue(it.hasNext());
+    it.close();
+    t = elementFactory.createTriple(null, null, l1);
+    it = graph.find(t);
+    assertTrue(it.hasNext());
+    it.close();
+
+    // look for non-existent singles
+    t = elementFactory.createTriple(ref1, null, null);
+    it = graph.find(t);
+    assertFalse(it.hasNext());
+    it.close();
+    t = elementFactory.createTriple(null, ref3, null);
+    it = graph.find(t);
+    assertFalse(it.hasNext());
+    it.close();
+    t = elementFactory.createTriple(null, null, ref1);
+    it = graph.find(t);
+    assertFalse(it.hasNext());
+    it.close();
+  }
+
+  /**
+   * Tests iteration over a found set.
+   *
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   */
+  public void testIteration() throws Exception {
+
+    GraphElementFactory factory = graph.getElementFactory();
+
+    //create nodes
+    BlankNode bNode1 = factory.createResource();
+    BlankNode bNode2 = factory.createResource();
+    URIReference testUri1 = factory.createResource(new URI(
+        "http://tucana.org/tucana#testUri1"));
+    URIReference testUri2 = factory.createResource(new URI(
+        "http://tucana.org/tucana#testUri2"));
+    Literal literal1 = factory.createLiteral("literal1");
+    Literal literal2 = factory.createLiteral("literal2");
+
+    //create some statements
+    Triple[] triples = new Triple[16];
+    triples[0] = factory.createTriple(bNode1, testUri1, literal1);
+    triples[1] = factory.createTriple(bNode1, testUri1, literal2);
+    triples[2] = factory.createTriple(bNode1, testUri2, literal1);
+    triples[3] = factory.createTriple(bNode1, testUri2, literal2);
+    triples[4] = factory.createTriple(bNode2, testUri1, literal1);
+    triples[5] = factory.createTriple(bNode2, testUri1, literal2);
+    triples[6] = factory.createTriple(bNode2, testUri2, literal1);
+    triples[7] = factory.createTriple(bNode2, testUri2, literal2);
+    triples[8] = factory.createTriple(bNode1, testUri1, bNode2);
+    triples[9] = factory.createTriple(bNode1, testUri2, bNode2);
+    triples[10] = factory.createTriple(bNode1, testUri1, testUri2);
+    triples[11] = factory.createTriple(bNode1, testUri2, testUri1);
+    triples[12] = factory.createTriple(testUri1, testUri2, bNode1);
+    triples[13] = factory.createTriple(testUri2, testUri1, bNode1);
+    triples[14] = factory.createTriple(testUri1, testUri2, bNode2);
+    triples[15] = factory.createTriple(testUri2, testUri1, bNode2);
+
+    //add them
+    for (int i = 0; i < triples.length; i++) {
+
+      graph.add(triples[i]);
+    }
+
+    //query them and put contents of iterator in a set for checking
+    //(iterator may return results in a different order)
+    Set<Triple> statements = new HashSet<Triple>();
+    ClosableIterator<Triple> iter = graph.find(null, null, null);
+    assertTrue("ClosableIterator is returning false for hasNext().", iter.hasNext());
+    while (iter.hasNext()) {
+
+      statements.add(iter.next());
+    }
+    iter.close();
+
+    //check that the iterator contained the correct number of statements
+    assertEquals("ClosableIterator is incomplete.", graph.getNumberOfTriples(),
+                 statements.size());
+
+    //check the the set contains all the original triples
+    for (int i = 0; i < triples.length; i++) {
+
+      if (!statements.contains(triples[i])) {
+
+        fail("Iterator did not contain triple: " + triples[i] + ".");
+      }
+    }
+  }
+
+  /**
+   * Tests iterative removal.
+   *
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   */
+  public void testIterativeRemoval() throws Exception {
+    // add some test data
+    graph.add(blank1, ref1, blank2);
+    graph.add(blank1, ref2, blank2);
+    graph.add(ref1, ref2, l2);
+    Triple t1 = elementFactory.createTriple(blank2, ref1, blank1);
+    graph.add(t1);
+    Triple t2 = elementFactory.createTriple(blank2, ref2, blank1);
+    graph.add(t2);
+    Triple t3 = elementFactory.createTriple(blank2, ref1, l1);
+    graph.add(t3);
+
+    // check that all is well
+    assertFalse(graph.isEmpty());
+    assertEquals(6, graph.getNumberOfTriples());
+
+    // get an iterator for the blank2,ref1 elements
+    ClosableIterator<Triple> ci = graph.find(blank2, ref1, null);
+    checkInvalidRemove(ci);
+
+    // remove the first element
+    assertTrue(ci.hasNext());
+    ci.next();
+    ci.remove();
+    assertEquals(5, graph.getNumberOfTriples());
+
+    // remove the second element
+    assertTrue(ci.hasNext());
+    ci.next();
+    ci.remove();
+    assertEquals(4, graph.getNumberOfTriples());
+
+    assertFalse(ci.hasNext());
+
+    // get an iterator for the blank1 elements
+    ci = graph.find(blank1, null, null);
+    checkInvalidRemove(ci);
+
+    // remove the first element
+    assertTrue(ci.hasNext());
+    ci.next();
+    ci.remove();
+    assertEquals(3, graph.getNumberOfTriples());
+
+    // remove the second element
+    assertTrue(ci.hasNext());
+    ci.next();
+    ci.remove();
+    assertEquals(2, graph.getNumberOfTriples());
+
+    assertFalse(ci.hasNext());
+
+    // get an iterator for the ref1, ref2, l2 element
+    ci = graph.find(ref1, ref2, l2);
+    checkInvalidRemove(ci);
+
+    // remove the element
+    assertTrue(ci.hasNext());
+    ci.next();
+    ci.remove();
+    assertEquals(1, graph.getNumberOfTriples());
+
+    assertFalse(ci.hasNext());
+
+    // get an iterator for the final element
+    ci = graph.find(null, null, null);
+    checkInvalidRemove(ci);
+
+    // remove the element
+    assertTrue(ci.hasNext());
+    ci.next();
+    ci.remove();
+    assertEquals(0, graph.getNumberOfTriples());
+    assertTrue(graph.isEmpty());
+
+    assertFalse(ci.hasNext());
+    ci.close();
+
+    // check that we can't still remove things
+    try {
+      graph.remove(ref2, ref2, ref2);
+      assertTrue(false);
+    }
+    catch (GraphException e) { /* no-op */}
+
+  }
+
+  private void checkInvalidRemove(ClosableIterator<Triple> ci) {
+    try {
+      ci.remove();
+      fail("Must throw an exception.");
+    }
+    catch (IllegalStateException ise) {
+      assertTrue(ise.getMessage().indexOf("Next not called or beyond end of data") != -1);
+    }
+  }
+
+  /**
+   * Tests full iterative removal.
+   *
+   * @throws Exception A generic exception - this should cause the tests to
+   *   fail.
+   */
+  public void testFullIterativeRemoval() throws Exception {
+    // add some test data
+    graph.add(blank1, ref1, blank2);
+    graph.add(blank1, ref2, blank2);
+    graph.add(ref1, ref2, l2);
+    Triple t1 = elementFactory.createTriple(blank2, ref1, blank1);
+    graph.add(t1);
+    Triple t2 = elementFactory.createTriple(blank2, ref2, blank1);
+    graph.add(t2);
+    Triple t3 = elementFactory.createTriple(blank2, ref1, l1);
+    graph.add(t3);
+
+    // check that all is well
+    assertFalse(graph.isEmpty());
+    assertEquals(6, graph.getNumberOfTriples());
+
+    // get an iterator for all the elements
+    ClosableIterator<Triple> ci = graph.find(null, null, null);
+    for (int i = 5; 0 <= i; i--) {
+      // remove the element
+      assertTrue(ci.hasNext());
+      ci.next();
+      ci.remove();
+      assertEquals(i, graph.getNumberOfTriples());
+    }
+
+    assertTrue(graph.isEmpty());
+
+    assertFalse(ci.hasNext());
+
+    ci.close();
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/AbstractLiteral.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/AbstractLiteral.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/AbstractLiteral.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,256 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java 2 standard
+import org.jrdf.util.EscapeUtil;
+import org.openrdf.model.impl.LiteralImpl;
+import org.openrdf.model.impl.URIImpl;
+
+import java.io.Serializable;
+import java.net.URI;
+
+/**
+ * A base implementation of an RDF {@link Literal}.
+ *
+ * @author Andrew Newman
+ * @author Simon Raboczi
+ *
+ * @version $Revision: 624 $
+ */
+public abstract class AbstractLiteral extends LiteralImpl implements Literal, Serializable {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 2589574733270452078L;
+
+  /**
+   * Whether the literal is well formed XML.
+   */
+  private boolean wellFormedXML;
+
+  /**
+   * RDF datatype URI, <code>null</code> for untyped literal.
+   */
+  private URI datatypeURI;
+
+  /**
+   * Construct a plain literal.
+   *
+   * @param newLexicalForm  the text part of the literal
+   * @throws IllegalArgumentException if <var>newLexicalForm</var> is <code>null</code>
+   */
+  protected AbstractLiteral(String newLexicalForm) {
+    super(newLexicalForm);
+
+    // Validate "newLexicalForm" parameter
+    if (null == newLexicalForm) {
+      throw new IllegalArgumentException("Null \"newLexicalForm\" parameter");
+    }
+
+    // Initialize fields
+    datatypeURI = null;
+  }
+
+  /**
+   * Construct a literal with language.
+   *
+   * @param newLexicalForm  the text part of the literal
+   * @param newLanguage  the language code, possibly the empty string but not
+   *    <code>null</code>
+   * @throws IllegalArgumentException if <var>lexicalForm</var> or
+   *    <var>lang</var> are <code>null</code>
+   */
+  protected AbstractLiteral(String newLexicalForm, String newLanguage) {
+    super(newLexicalForm, "".equals(newLanguage) ? null : newLanguage);
+
+    // Validate "lexicalForm" parameter
+    if (null == newLexicalForm) {
+      throw new IllegalArgumentException("Null \"lexicalForm\" parameter");
+    }
+
+    // Validate "language" parameter
+    if (null == newLanguage) {
+      throw new IllegalArgumentException("Null \"language\" parameter");
+    }
+
+    // Initialize fields
+    datatypeURI = null;
+  }
+
+  /**
+   * Construct a datatyped literal.
+   *
+   * @param newLexicalForm  the text part of the literal
+   * @param newDatatypeURI  the URI for a datatyped literal
+   * @throws IllegalArgumentException if <var>lexicalForm</var> or
+   *     <var>datatype</var> are <code>null</code>
+   */
+  protected AbstractLiteral(String newLexicalForm, URI newDatatypeURI) {
+    super(newLexicalForm, new URIImpl(newDatatypeURI.toString()));
+
+    // Validate "lexicalForm" parameter
+    if (null == newLexicalForm) {
+      throw new IllegalArgumentException("Null \"lexicalForm\" parameter");
+    }
+
+    // Validate "datatype" parameter
+    if (null == newDatatypeURI) {
+      throw new IllegalArgumentException("Null \"datatype\" parameter");
+    }
+
+    // Initialize fields
+    datatypeURI = newDatatypeURI;
+  }
+
+  /**
+   * Obtain the text of this literal.
+   *
+   * @return the text of the literal, never <code>null</code>
+   */
+  public String getLexicalForm() {
+    return getLabel();
+  }
+
+  /**
+   * Whether the literal is well formed XML.
+   *
+   * @return whether the literal is wll formed XML.
+   */
+  public boolean isWellFormedXML() {
+    return wellFormedXML;
+  }
+
+  /**
+   * Returns the URI of the RDF datatype of this resource, or <code>null</code>
+   *     for a plain literal.
+   *
+   * @return the URI of the RDF datatype of this resource, or <code>null</code>
+   *     for a plain literal.
+   */
+  public URI getDatatypeURI() {
+    return datatypeURI;
+  }
+
+  /**
+   * Accept a call from a TypedNodeVisitor.
+   *
+   * @param visitor the object doing the visiting.
+   */
+  public void accept(TypedNodeVisitor visitor) {
+    visitor.visitLiteral(this);
+  }
+
+  /**
+   * Provide a legible representation of a literal, following the N-Triples
+   * format defined in
+   * <a href="http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/#ntrip_strings">&sect;3.2</a>
+   * of the <a href="http://www.w3.org/">
+   * <acronym title="World Wide Web Consortium">W3C</acronym></a>'s
+   * <a href="http://www.w3.org/TR/2004/REC-rdf-testcases-20040210">RDF Test
+   * Cases</a> Recommendation.
+   *
+   * Well-formed Unicode surrogate pairs in the lexical form are escaped as a
+   * single 8-digit hexadecimal <code>\U</code> escape sequence rather than a
+   * pair of 4-digit <code>&x5C;u</code> sequences representing the surrogates.
+   *
+   * @return this instance in N-Triples format
+   */
+  public String getEscapedForm() {
+    String escaped = EscapeUtil.escape(getLexicalForm());
+    return '\"' + escaped + '\"' + appendType();
+  }
+
+  /**
+   * Returns the lexical form.
+   *
+   * @return the lexical form.
+   */
+  public String toString() {
+    return '\"' + getEscapedLexicalForm() + '\"' + appendType();
+  }
+
+  public String getEscapedLexicalForm() {
+    return getLexicalForm().replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"",
+        "\\\\\\\"");
+  }
+
+  /**
+   * Appends the datatype URI or language code of a literal.
+   *
+   * @return String the datatype URI in the form ^^<->, or language code @- or
+   *   an empty string.
+   */
+  private String appendType() {
+    String appendString = "";
+
+    if (null != getDatatypeURI()) {
+      appendString = "^^<" + getDatatypeURI() + '>';
+    }
+    else if (getLanguage() != null) {
+      appendString = '@' + getLanguage();
+    }
+
+    return appendString;
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/AbstractTriple.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/AbstractTriple.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/AbstractTriple.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,166 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import java.io.Serializable;
+
+/**
+ * A base implementation of an RDF {@link Triple}.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public abstract class AbstractTriple implements Triple, Serializable {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 8737092494833012690L;
+
+  /**
+   * Subject of this statement.
+   */
+  protected SubjectNode subjectNode;
+
+  /**
+   * Predicate of this statement.
+   */
+  protected PredicateNode predicateNode;
+
+  /**
+   * Object of this statement.
+   */
+  protected ObjectNode objectNode;
+
+  /**
+   * Obtains the subject of this statement.
+   *
+   * @return an {@link SubjectNode} which is either a {@link BlankNode} or
+   *     {@link URIReference}
+   */
+  public SubjectNode getSubject() {
+    return subjectNode;
+  }
+
+  /**
+   * Obtains the predicate of this statement.
+   *
+   * @return a {@link PredicateNode} which is a {@link URIReference}
+   */
+  public PredicateNode getPredicate() {
+    return predicateNode;
+  }
+
+  /**
+   * Obtains the object of this statement.
+   *
+   * @return a {@link ObjectNode} which is either a {@link BlankNode},
+   *     {@link URIReference} or {@link Literal}
+   */
+  public ObjectNode getObject() {
+    return objectNode;
+  }
+
+  public boolean equals(Object obj) {
+
+    // Check equal by reference
+    if (this == obj) {
+      return true;
+    }
+
+    boolean returnValue = false;
+
+    // Check for null and ensure exactly the same class - not subclass.
+    if (null != obj) {
+
+      try {
+
+        Triple tmpTriple = (Triple) obj;
+        returnValue = getSubject().equals(tmpTriple.getSubject()) &&
+            getPredicate().equals(tmpTriple.getPredicate()) &&
+            getObject().equals(tmpTriple.getObject());
+      }
+      catch (ClassCastException cce) {
+        // Leave return value to be false.
+      }
+    }
+    return returnValue;
+  }
+
+  public int hashCode() {
+    return getSubject().hashCode() ^ getPredicate().hashCode() ^
+        getObject().hashCode();
+  }
+
+  /**
+   * Provide a legible representation of a triple. Currently, square brackets
+   * with toString values of the parts of the triple.
+   *
+   * @return the string value of the subject, predicate and object in square
+   *   brackets.
+   */
+  public String toString() {
+    return "[" + getSubject() + ", " + getPredicate() + ", " + getObject() +
+        "]";
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/AbstractTripleFactory.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/AbstractTripleFactory.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/AbstractTripleFactory.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,324 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import org.jrdf.vocabulary.RDF;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+
+/**
+ * The base implementation of the Triple Factory which adds to a given graph
+ * reified statements, containers and collections.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public abstract class AbstractTripleFactory implements TripleFactory {
+
+  /**
+   * The graph that this factory constructs nodes for.
+   */
+  protected Graph graph;
+
+  /**
+   * The graph element factory.
+   */
+  protected GraphElementFactory elementFactory;
+
+  /**
+   * Reifies a triple.  A triple made up of the first three nodes is added to
+   * graph and the reificationNode is used to reify the triple.
+   *
+   * @param subjectNode the subject of the triple.
+   * @param predicateNode the predicate of the triple.
+   * @param objectNode the object of the triple.
+   * @param reificationNode a node denoting the reified triple.
+   * @throws TripleFactoryException If the resource failed to be created.
+   * @throws AlreadyReifiedException If there was already a triple URI for
+   *     the given triple.
+   */
+  public void reifyTriple(SubjectNode subjectNode,
+      PredicateNode predicateNode, ObjectNode objectNode,
+      SubjectNode reificationNode) throws TripleFactoryException,
+      AlreadyReifiedException {
+
+    // create the reification node
+    try {
+      reallyReifyTriple(subjectNode, predicateNode, objectNode, reificationNode);
+    }
+    catch (GraphElementFactoryException gefe) {
+      throw new TripleFactoryException(gefe);
+    }
+  }
+
+  /**
+   * Creates a reification of a triple.  The triple added to the graph and the
+   * reificationNode is used to reify the triple.
+   *
+   * @param triple the triple to be reified.
+   * @param reificationNode a node denoting the reified triple.
+   * @throws TripleFactoryException If the resource failed to be created.
+   * @throws AlreadyReifiedException If there was already a triple URI for
+   *     the given triple.
+   */
+  public void reifyTriple(Triple triple, SubjectNode reificationNode)
+      throws TripleFactoryException, AlreadyReifiedException {
+
+    try {
+      reallyReifyTriple(triple.getSubject(), triple.getPredicate(),
+          triple.getObject(), reificationNode);
+    }
+    catch (GraphElementFactoryException gefe) {
+      throw new TripleFactoryException(gefe);
+    }
+  }
+
+  /**
+   * Creates a reification of a triple.
+   *
+   * @param subjectNode the subject of the triple.
+   * @param predicateNode the predicate of the triple.
+   * @param objectNode the object of the triple.
+   * @return a node denoting the reified triple.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   * @throws AlreadyReifiedException If there was already a triple URI for
+   *     the given triple.
+   */
+  private Node reallyReifyTriple(SubjectNode subjectNode,
+      PredicateNode predicateNode, ObjectNode objectNode, Node ru)
+      throws GraphElementFactoryException, AlreadyReifiedException {
+
+    // get the nodes used for reification
+    PredicateNode hasSubject = elementFactory.createResource(RDF.SUBJECT);
+    PredicateNode hasPredicate = elementFactory.createResource(RDF.PREDICATE);
+    PredicateNode hasObject = elementFactory.createResource(RDF.OBJECT);
+    URIReference rdfType = elementFactory.createResource(RDF.TYPE);
+    URIReference rdfStatement = elementFactory.createResource(RDF.STATEMENT);
+
+    // assert that the statement is not already reified
+    try {
+
+      // An error if ru already reifies anything but the given s, p, o.
+      if (graph.contains((SubjectNode) ru, rdfType, rdfStatement) &&
+          !(graph.contains((SubjectNode) ru, hasSubject, (ObjectNode) subjectNode) &&
+            graph.contains((SubjectNode) ru, hasPredicate, (ObjectNode) predicateNode) &&
+            graph.contains((SubjectNode) ru, hasObject, objectNode))) {
+
+        throw new AlreadyReifiedException("SkipListNode: " + ru + " already used in " +
+          "reification");
+      }
+
+      // insert the reification statements
+      graph.add((SubjectNode) ru, rdfType, rdfStatement);
+      graph.add((SubjectNode) ru, hasSubject, (ObjectNode) subjectNode);
+      graph.add((SubjectNode) ru, hasPredicate, (ObjectNode) predicateNode);
+      graph.add((SubjectNode) ru, hasObject, (ObjectNode) objectNode);
+    }
+    catch (GraphException e) {
+      throw new GraphElementFactoryException(e);
+    }
+
+    // return the ru to make it easier for returning the value from this method
+    return ru;
+  }
+
+  public void addAlternative(SubjectNode subjectNode, Alternative alternative)
+      throws TripleFactoryException {
+    try {
+
+      graph.add(subjectNode,
+          (PredicateNode) elementFactory.createResource(RDF.TYPE),
+          (ObjectNode) elementFactory.createResource(RDF.ALT));
+
+      addContainer(subjectNode, alternative);
+    }
+    catch (GraphException e) {
+      throw new TripleFactoryException(e);
+    }
+    catch (GraphElementFactoryException e) {
+      throw new TripleFactoryException(e);
+    }
+  }
+
+  public void addBag(SubjectNode subjectNode, Bag bag)
+      throws TripleFactoryException {
+    try {
+
+      graph.add(subjectNode,
+          (PredicateNode) elementFactory.createResource(RDF.TYPE),
+          (ObjectNode) elementFactory.createResource(RDF.BAG));
+
+      addContainer(subjectNode, bag);
+    }
+    catch (GraphException e) {
+      throw new TripleFactoryException(e);
+    }
+    catch (GraphElementFactoryException e) {
+      throw new TripleFactoryException(e);
+    }
+  }
+
+  public void addSequence(SubjectNode subjectNode, Sequence sequence)
+      throws TripleFactoryException {
+    try {
+
+      graph.add(subjectNode,
+          (PredicateNode) elementFactory.createResource(RDF.TYPE),
+          (ObjectNode) elementFactory.createResource(RDF.SEQ));
+
+      addContainer(subjectNode, sequence);
+    }
+    catch (GraphException e) {
+      throw new TripleFactoryException(e);
+    }
+    catch (GraphElementFactoryException e) {
+      throw new TripleFactoryException(e);
+    }
+  }
+
+  /**
+   * Creates a container.
+   *
+   * @param subjectNode the subject of the triple.
+   * @param container the container to add.
+   * @throws TripleFactoryException If the resource failed to be created.
+   * @throws AlreadyReifiedException If there was already a triple URI for
+   *     the given triple.
+   */
+  private void addContainer(SubjectNode subjectNode, Container container)
+      throws TripleFactoryException {
+
+    // assert that the statement is not already reified
+    try {
+
+      // Insert statements from colletion.
+      long counter = 1;
+      Iterator<ObjectNode> iter = container.iterator();
+
+      while (iter.hasNext()) {
+        ObjectNode object = iter.next();
+        graph.add(subjectNode,
+            (PredicateNode) elementFactory.createResource(new URI(
+            RDF.BASE_URI + "_" + counter++)),
+            object);
+      }
+    }
+    catch (URISyntaxException e) {
+      throw new TripleFactoryException(e);
+    }
+    catch (GraphElementFactoryException e) {
+      throw new TripleFactoryException(e);
+    }
+    catch (GraphException e) {
+      throw new TripleFactoryException(e);
+    }
+  }
+
+  public void addCollection(SubjectNode firstNode, Collection collection)
+      throws TripleFactoryException {
+
+    try {
+
+      // Constants.
+      PredicateNode rdfFirst = (PredicateNode) elementFactory.createResource(
+          RDF.FIRST);
+      PredicateNode rdfRest = (PredicateNode) elementFactory.createResource(
+          RDF.REST);
+      ObjectNode rdfNil = (ObjectNode) elementFactory.createResource(RDF.NIL);
+
+      // Insert statements from the Colletion using the first given node.
+      SubjectNode subject = firstNode;
+
+      // Iterate through all elements in the Collection.
+      Iterator<ObjectNode> iter = collection.iterator();
+      while (iter.hasNext()) {
+
+        // Get the next object and create the new FIRST statement.
+        ObjectNode object = iter.next();
+        graph.add(subject, rdfFirst, object);
+
+        // Check if there are any more elements in the Collection.
+        if (iter.hasNext()) {
+
+          // Create a new blank node, link the existing subject to it using
+          // the REST predicate.
+          ObjectNode newSubject = (ObjectNode) elementFactory.createResource();
+          graph.add(subject, rdfRest, newSubject);
+          subject = (SubjectNode) newSubject;
+        }
+        else {
+
+          // If we are at the end of the list link the existing subject to NIL
+          // using the REST predicate.
+          graph.add(subject, rdfRest, rdfNil);
+        }
+      }
+    }
+    catch (GraphElementFactoryException e) {
+      throw new TripleFactoryException(e);
+    }
+    catch (GraphException e) {
+      throw new TripleFactoryException(e);
+    }
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/AbstractTripleFactoryTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/AbstractTripleFactoryTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/AbstractTripleFactoryTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,650 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java packages
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jrdf.util.ClosableIterator;
+import org.jrdf.vocabulary.RDF;
+
+import java.net.URI;
+
+/**
+ * Abstract test case for graph implementations.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public abstract class AbstractTripleFactoryTest extends TestCase {
+
+  /**
+   * Instance of a graph object.
+   */
+  private Graph graph;
+
+  /**
+   * Instance of a factory for the graph
+   */
+  protected GraphElementFactory elementFactory;
+
+  /**
+   * Instance of the triple factory for the graph.
+   */
+  private TripleFactory tripleFactory;
+
+  // The following are interally used "constants"
+  private BlankNode blank1;
+  private BlankNode blank2;
+
+  private URI uri1;
+  private URI uri2;
+  private URI uri3;
+  private URIReference ref1;
+  private URIReference ref2;
+  private URIReference ref3;
+
+  private final String TEST_STR1 = "A test string";
+  private final String TEST_STR2 = "Another test string";
+  private Literal l1;
+  private Literal l2;
+
+  /**
+   * Hook for test runner to obtain an empty test suite from, because this test
+   * can't be run (it's abstract). This must be overridden in subclasses.
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    return suite;
+  }
+
+
+  /**
+   * Constructs a new test with the given name.
+   *
+   * @param name the name of the test
+   */
+  public AbstractTripleFactoryTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Create test instance.
+   */
+  public void setUp() throws Exception {
+    graph = newGraph();
+    elementFactory = graph.getElementFactory();
+    tripleFactory = graph.getTripleFactory();
+
+    blank1 = elementFactory.createResource();
+    blank2 = elementFactory.createResource();
+
+    uri1 = new URI("http://namespace#somevalue");
+    uri2 = new URI("http://namespace#someothervalue");
+    uri3 = new URI("http://namespace#yetanothervalue");
+    ref1 = elementFactory.createResource(uri1);
+    ref2 = elementFactory.createResource(uri2);
+    ref3 = elementFactory.createResource(uri3);
+
+    l1 = elementFactory.createLiteral(TEST_STR1);
+    l2 = elementFactory.createLiteral(TEST_STR2);
+  }
+
+  //
+  // implementation interfaces
+  //
+
+  /**
+   * Create a graph implementation.
+   *
+   * @return A new GraphImpl.
+   */
+  protected abstract Graph newGraph() throws Exception;
+
+  /**
+   * Get the node used for subject reification.
+   *
+   * @return The subject reification node.
+   */
+  protected abstract PredicateNode getReifySubject() throws TripleFactoryException;
+
+  /**
+   * Get the node used for predicate reification.
+   *
+   * @return The predicate reification node.
+   */
+  protected abstract PredicateNode getReifyPredicate() throws TripleFactoryException;
+
+  /**
+   * Get the node used for object reification.
+   *
+   * @return The object reification node.
+   */
+  protected abstract PredicateNode getReifyObject() throws TripleFactoryException;
+
+  /**
+   * Get the node used for rdf:type.
+   *
+   * @return The object rdf:type node.
+   */
+  protected abstract PredicateNode getRdfType() throws TripleFactoryException;
+
+  /**
+   * Get the node used for rdf:Statement.
+   *
+   * @return The object rdf:statement node.
+   */
+  protected abstract ObjectNode getRdfStatement() throws TripleFactoryException;
+
+  /**
+   * Create a concrete Collection.
+   *
+   * @return the new collection.
+   */
+  protected abstract Collection createCollection(ObjectNode[] objects);
+
+  /**
+   * Create a concrete alternative
+   *
+   * @return the new alternative.
+   */
+  protected abstract Alternative createAlternative(ObjectNode[] objects);
+
+  /**
+   * Create a concrete bag
+   *
+   * @return the new bag.
+   */
+  protected abstract Bag createBag(ObjectNode[] objects);
+
+  /**
+   * Create a concrete sequence
+   *
+   * @return the new sequence.
+   */
+  protected abstract Sequence createSequence(ObjectNode[] objects);
+
+  //
+  // Test cases
+  //
+
+  /**
+   * Tests reification.
+   */
+  public void testReification() throws Exception {
+    PredicateNode reifySubject = getReifySubject();
+    PredicateNode reifyPredicate = getReifyPredicate();
+    PredicateNode reifyObject = getReifyObject();
+    PredicateNode rdfType = getRdfType();
+    ObjectNode rdfStatement = getRdfStatement();
+    assertTrue(graph.isEmpty());
+
+    // Make a reification about a triple that does not exist in the graph.
+    URIReference u = elementFactory.createResource(uri1);
+    tripleFactory.reifyTriple(blank1, ref1, blank2, u);
+    assertEquals(uri1, u.getURI());
+    assertEquals(4, graph.getNumberOfTriples());
+    assertTrue(graph.contains(u, rdfType, rdfStatement));
+    assertTrue(graph.contains(u, reifySubject, blank1));
+    assertTrue(graph.contains(u, reifyPredicate, ref1));
+    assertTrue(graph.contains(u, reifyObject, blank2));
+
+    // Make a reification about a triple that does exist in the graph.
+    Triple t = elementFactory.createTriple(blank1, ref2, blank2);
+    u = elementFactory.createResource(uri2);
+    graph.add(t);
+    tripleFactory.reifyTriple(t, u);
+    assertEquals(uri2, u.getURI());
+    assertEquals(9, graph.getNumberOfTriples());
+    assertTrue(graph.contains(u, rdfType, rdfStatement));
+    assertTrue(graph.contains(u, reifySubject, blank1));
+    assertTrue(graph.contains(u, reifyPredicate, ref2));
+    assertTrue(graph.contains(u, reifyObject, blank2));
+    assertTrue(graph.contains(blank1, ref2, blank2));
+
+    // test for double insertion (allowed)
+    tripleFactory.reifyTriple(blank1, ref1, blank2, elementFactory.createResource(uri1));
+    assertEquals(9, graph.getNumberOfTriples());
+
+    // test for double insertion (allowed)
+    tripleFactory.reifyTriple(t, elementFactory.createResource(uri2));
+    assertEquals(9, graph.getNumberOfTriples());
+
+    // test for insertion with a different reference (allowed)
+    tripleFactory.reifyTriple(blank1, ref1, blank2, elementFactory.createResource(uri3));
+    assertEquals(13, graph.getNumberOfTriples());
+
+    // test for insertion of a new triple with an existing reference (disallowed)
+    testCantInsert(blank2, ref1, blank1, elementFactory.createResource(uri1));
+    assertEquals(13, graph.getNumberOfTriples());
+
+    // test for insertion with a different reference (disallowed)
+    testCantInsert(t, uri3);
+    assertEquals(13, graph.getNumberOfTriples());
+
+    // test for insertion of a new triple with an existing reference
+    testCantInsert(elementFactory.createTriple(blank2, ref2, blank2), uri2);
+    assertEquals(13, graph.getNumberOfTriples());
+
+    // do it all again for blank nodes
+    // Make reification that does not exist in graph
+    BlankNode b = elementFactory.createResource();
+    tripleFactory.reifyTriple(blank1, ref1, l1, b);
+    assertEquals(17, graph.getNumberOfTriples());
+    assertTrue(graph.contains(b, rdfType, rdfStatement));
+    assertTrue(graph.contains(b, reifySubject, blank1));
+    assertTrue(graph.contains(b, reifyPredicate, ref1));
+    assertTrue(graph.contains(b, reifyObject, l1));
+
+    // Make a reification using a blank node for a statement that does exist
+    // in the graph.
+    t = elementFactory.createTriple(blank1, ref2, l2);
+    graph.add(t);
+    b = elementFactory.createResource();
+    tripleFactory.reifyTriple(t, b);
+    assertEquals(22, graph.getNumberOfTriples());
+    assertTrue(graph.contains(b, rdfType, rdfStatement));
+    assertTrue(graph.contains(b, reifySubject, blank1));
+    assertTrue(graph.contains(b, reifyPredicate, ref2));
+    assertTrue(graph.contains(b, reifyObject, l2));
+    assertTrue(graph.contains(blank1, ref2, l2));
+
+    // test for double insertion
+    testCanInsert(blank1, ref1, blank2);
+    // test for insertion with a a used blank reference
+    testCantInsert(blank1, ref3, blank2, u);
+    // test that the graph did not change with the invalid insertions
+    assertEquals(26, graph.getNumberOfTriples());
+
+    // test for double insertion
+    testCanInsert(t);
+    // test for insertion with a a used blank reference
+    testCantInsert(elementFactory.createTriple(blank1, ref3, blank2), u.getURI());
+    // test that the graph did not change with the invalid insertions
+    assertEquals(30, graph.getNumberOfTriples());
+
+    // Test reifying an existing statement
+    b = elementFactory.createResource();
+    graph.add(ref3, ref3, ref3);
+
+    try {
+      tripleFactory.reifyTriple(ref3, ref3, ref3, b);
+    }
+    catch (AlreadyReifiedException e) {
+      fail("Should allow reification of an existing");
+    }
+  }
+
+  /**
+   * Test collections implmentations.
+   */
+  public void testCollections() throws Exception {
+
+    // Ensure graph is empty before starting.
+    assertTrue(graph.isEmpty());
+
+    // Create initial statement
+    SubjectNode s = (SubjectNode) elementFactory.createResource(
+        new URI("http://example.org/basket"));
+    PredicateNode p = (PredicateNode) elementFactory.createResource(
+        new URI("http://example.org/stuff/1.0/hasFruit"));
+    ObjectNode o = (ObjectNode)
+        elementFactory.createResource();
+
+    // Add to graph
+    graph.add(s, p, o);
+
+    // Create collection object.
+    ObjectNode[] fruit = new ObjectNode[3];
+    fruit[0] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/banana"));
+    fruit[1] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/kiwi"));
+    fruit[2] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/pineapple"));
+
+    PredicateNode rdfFirst = (PredicateNode) elementFactory.createResource(
+        RDF.FIRST);
+    PredicateNode rdfRest = (PredicateNode) elementFactory.createResource(
+        RDF.REST);
+    ObjectNode rdfNil = (ObjectNode) elementFactory.createResource(
+        RDF.NIL);
+
+    // Create collection and add
+    Collection collection = createCollection(fruit);
+
+    // Add the collection to the graph.
+    tripleFactory.addCollection((SubjectNode) o, collection);
+
+    // Check we've inserted it correctly.
+    assertEquals("Should have seven statements", 7, graph.getNumberOfTriples());
+    assertTrue("Should have first statement", graph.contains(s, p, o));
+    assertTrue("Should have first object and first collection object",
+      graph.contains((SubjectNode) o, rdfFirst, fruit[0]));
+
+    // Get all rdf:first statements
+    ClosableIterator<Triple> iter = graph.find(null, rdfFirst, null);
+    int counter = 0;
+    while (iter.hasNext()) {
+//      System.err.println(iter.next());
+      iter.next();
+      counter++;
+    }
+    assertTrue("Should have three rdf:first statements, not " + counter, 3 ==
+        counter);
+
+    // Find all three parts of the collection.
+    for (int index = 0; index < fruit.length; index++) {
+      assertTrue("Should contain: " + fruit[index], graph.contains(
+          null, rdfFirst, fruit[index]));
+    }
+
+    // Get all rdf:rest statements
+    iter = graph.find(null, rdfRest, null);
+    counter = 0;
+    while (iter.hasNext()) {
+//      System.err.println(iter.next());
+      iter.next();
+      counter++;
+    }
+    assertTrue("Should have three rdf:rest statements", 3 == counter);
+
+    // Get all rdf:rest with rdf:nil statements
+    iter = graph.find(null, rdfRest, rdfNil);
+    counter = 0;
+    while (iter.hasNext()) {
+//      System.err.println(iter.next());
+      iter.next();
+      counter++;
+    }
+
+    assertTrue("Should have one rdf:rest with rdf:nil statements", 1 ==
+        counter);
+  }
+
+  /**
+   * Test altnerative implementation.
+   */
+  public void testAlternative() throws Exception {
+
+    // Ensure graph is empty before starting.
+    assertTrue(graph.isEmpty());
+
+    // Create initial statement
+    SubjectNode s = (SubjectNode) elementFactory.createResource(
+        new URI("http://example.org/favourite-bananas"));
+
+    // Create collection object.
+    ObjectNode[] fruit = new ObjectNode[4];
+    fruit[0] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/banana"));
+    fruit[1] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/cavendish"));
+    fruit[2] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/ladyfinger"));
+    fruit[3] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/banana"));
+
+    PredicateNode rdfType = (PredicateNode) elementFactory.createResource(
+        RDF.TYPE);
+    ObjectNode rdfAlternative = (ObjectNode) elementFactory.createResource(
+        RDF.ALT);
+
+    // Create collection and add
+    Alternative alt = createAlternative(fruit);
+
+    // Add the collection to the graph.
+    tripleFactory.addAlternative(s, alt);
+
+    // Check we've inserted it correctly (banana is in twice should be removed)
+    assertEquals("Should have five statements", 4, graph.getNumberOfTriples());
+    assertTrue("Should have statement", graph.contains(s, rdfType, rdfAlternative));
+    assertTrue("Should have statement", graph.contains(s, null, fruit[0]));
+    assertTrue("Should have statement", graph.contains(s, null, fruit[1]));
+    assertTrue("Should have statement", graph.contains(s, null, fruit[2]));
+    assertTrue("Should have statement", graph.contains(s, null, fruit[3]));
+
+    // Check that it doesn't allow duplicates.
+    ClosableIterator<Triple> iter = graph.find(null, null, fruit[0]);
+    int count = 0;
+    while (iter.hasNext()) {
+      iter.next();
+      count++;
+    }
+    assertTrue("Should have only the same statements: " + fruit[0], 1 == count);
+  }
+
+  /**
+   * Test bag implementation.
+   */
+  public void testBag() throws Exception {
+
+    // Ensure graph is empty before starting.
+    assertTrue(graph.isEmpty());
+
+    // Create initial statement
+    SubjectNode s = (SubjectNode) elementFactory.createResource(
+        new URI("http://example.org/favourite-fruit"));
+
+    // Create collection object.
+    ObjectNode[] fruit = new ObjectNode[5];
+    fruit[0] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/banana"));
+    fruit[1] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/kiwi"));
+    fruit[2] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/pineapple"));
+    fruit[3] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/pineapple"));
+    fruit[4] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/banana"));
+
+    PredicateNode rdfType = (PredicateNode) elementFactory.createResource(
+        RDF.TYPE);
+    ObjectNode rdfBag = (ObjectNode) elementFactory.createResource(
+        RDF.BAG);
+
+    // Create collection and add
+    Bag bag = createBag(fruit);
+
+    // Add the collection to the graph.
+    tripleFactory.addBag(s, bag);
+
+    // Check we've inserted it correctly
+    assertEquals("Should have six statements", 6, graph.getNumberOfTriples());
+    assertTrue("Should have statement", graph.contains(s, rdfType, rdfBag));
+    assertTrue("Should have statement", graph.contains(s, null, fruit[0]));
+    assertTrue("Should have statement", graph.contains(s, null, fruit[1]));
+    assertTrue("Should have statement", graph.contains(s, null, fruit[2]));
+
+    // Check that it allows duplicates.
+    ClosableIterator<Triple> iter = graph.find(s, null, fruit[2]);
+    int count = 0;
+    while (iter.hasNext()) {
+      iter.next();
+      count++;
+    }
+    assertTrue("Should have two of the same statements: " + fruit[2], 2 ==
+        count);
+  }
+
+  /**
+   * Test sequence implmentation.
+   */
+  public void testSequence() throws Exception {
+
+    // Ensure graph is empty before starting.
+    assertTrue(graph.isEmpty());
+
+    // Create initial statement
+    SubjectNode s = (SubjectNode) elementFactory.createResource(
+        new URI("http://example.org/favourite-fruit"));
+
+    // Create collection object.
+    ObjectNode[] fruit = new ObjectNode[4];
+    fruit[0] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/banana"));
+    fruit[1] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/kiwi"));
+    fruit[2] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/pineapple"));
+    fruit[3] = (ObjectNode) elementFactory.createResource(new URI(
+        "http://example.org/kiwi"));
+
+    PredicateNode rdfType = (PredicateNode) elementFactory.createResource(
+        RDF.TYPE);
+    PredicateNode rdfOne = (PredicateNode) elementFactory.createResource(
+        new URI(RDF.BASE_URI + "_1"));
+    PredicateNode rdfTwo = (PredicateNode) elementFactory.createResource(
+        new URI(RDF.BASE_URI + "_2"));
+    PredicateNode rdfThree = (PredicateNode) elementFactory.createResource(
+        new URI(RDF.BASE_URI + "_3"));
+    PredicateNode rdfFour = (PredicateNode) elementFactory.createResource(
+        new URI(RDF.BASE_URI + "_4"));
+    ObjectNode rdfSequence = (ObjectNode) elementFactory.createResource(
+        RDF.SEQ);
+
+    // Create collection and add
+    Sequence sequence = createSequence(fruit);
+
+    // Add the collection to the graph.
+    tripleFactory.addSequence(s, sequence);
+
+    // Check we've inserted it correctly.
+    assertEquals("Should have five statements", 5, graph.getNumberOfTriples());
+    assertTrue("Should have statement", graph.contains(s, rdfType, rdfSequence));
+    assertTrue("Should have statement", graph.contains(s, rdfOne, fruit[0]));
+    assertTrue("Should have statement", graph.contains(s, rdfTwo, fruit[1]));
+    assertTrue("Should have statement", graph.contains(s, rdfThree, fruit[2]));
+    assertTrue("Should have statement", graph.contains(s, rdfFour, fruit[3]));
+  }
+
+  /**
+   * Utility method to check that a triple cannot be reified.
+   *
+   * @param subject The subject for the triple.
+   * @param predicate The predicate for the triple.
+   * @param object The object for the triple.
+   * @param r The reification node for the triple.
+   * @throws Exception The triple could be reified.
+   */
+  private void testCantInsert(SubjectNode subject, PredicateNode predicate,
+      ObjectNode object, SubjectNode r) throws Exception {
+    try {
+      tripleFactory.reifyTriple(subject, predicate, object, r);
+      assertTrue(false);
+    } catch (AlreadyReifiedException e) {
+    }
+  }
+
+
+  /**
+   * Utility method to check that a triple cannot be reified.
+   *
+   * @param triple The triple to reify.
+   * @param r The reification node for the triple.
+   * @throws Exception The triple could be reified.
+   */
+  private void testCantInsert(Triple triple, URI r) throws Exception {
+    try {
+      tripleFactory.reifyTriple(triple, elementFactory.createResource(r));
+      assertTrue(false);
+    } catch (AlreadyReifiedException e) {
+    }
+  }
+
+
+  /**
+   * Utility method to check that a triple cannot be reified with a blank node.
+   *
+   * @param subject The subject for the triple.
+   * @param predicate The predicate for the triple.
+   * @param object The object for the triple.
+   * @throws Exception The triple could be reified.
+   */
+  private void testCanInsert(SubjectNode subject, PredicateNode predicate,
+      ObjectNode object) throws Exception {
+    try {
+      tripleFactory.reifyTriple(subject, predicate, object,
+          elementFactory.createResource());
+      assertTrue(true);
+    } catch (AlreadyReifiedException e) {
+    }
+  }
+
+
+  /**
+   * Utility method to check that a triple cannot be reified with a blank node.
+   *
+   * @param triple The triple to reify.
+   * @throws Exception The triple could be reified.
+   */
+  private void testCanInsert(Triple triple) throws Exception {
+    try {
+      tripleFactory.reifyTriple(triple, elementFactory.createResource());
+      assertTrue(true);
+    } catch (AlreadyReifiedException e) {
+    }
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/AbstractURIReference.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/AbstractURIReference.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/AbstractURIReference.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,161 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java 2 standard packages
+
+import java.io.Serializable;
+import java.net.URI;
+
+import org.openrdf.model.impl.URIImpl;
+
+/**
+ * A base implementation of an RDF {@link URIReference}.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public abstract class AbstractURIReference extends URIImpl implements URIReference,
+    Serializable {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 8034954863132812197L;
+
+  /**
+   * The URI of the node.
+   */
+  private URI uri;
+
+  /**
+   * Constructor.
+   *
+   * Enforces a non-<code>null</code> and absolute <var>newUri</var> parameter.
+   *
+   * @param newUri the URI to use in creation.
+   * @throws IllegalArgumentException if <var>newUri</var> is <code>null</code> or
+   *     not absolute
+   */
+  protected AbstractURIReference(URI newUri) {
+    super(newUri.toString());
+
+    // Validate "newUri" parameter
+    if (null == newUri) {
+      throw new IllegalArgumentException("Null \"newUri\" parameter");
+    }
+
+    if (!newUri.isAbsolute()) {
+      throw new IllegalArgumentException("\"" + newUri + "\" is not absolute");
+    }
+
+    // Initialize the field
+    uri = newUri;
+  }
+
+  /**
+   * Constructor.
+   *
+   * Enforces a non-<code>null</code> parameter.  Use only for applications
+   * where enforcement of valid URIs is too expensive or not necessary.
+   *
+   * @param newUri the URI to use in creation.
+   * @param validate whether to enforce valid RDF URIs.
+   * @throws IllegalArgumentException if <var>newUri</var> is not absolute and
+   *   validate is true.
+   */
+  protected AbstractURIReference(URI newUri, boolean validate) {
+    super(newUri.toString());
+
+    // Validate "newUri" parameter
+    if (null == newUri) {
+      throw new IllegalArgumentException("Null \"newUri\" parameter");
+    }
+
+    if (validate && !newUri.isAbsolute()) {
+      throw new IllegalArgumentException("\"" + newUri + "\" is not absolute");
+    }
+
+    // Initialize the field
+    uri = newUri;
+  }
+
+  /**
+   * The {@link URI} identifiying this resource.
+   *
+   * @return the {@link URI} identifying this resource.
+   */
+  public URI getURI() {
+    return uri;
+  }
+
+  /**
+   * Accept a call from a TypedNodeVisitor.
+   *
+   * @param visitor the object doing the visiting.
+   */
+  public void accept(TypedNodeVisitor visitor) {
+    visitor.visitURIReference(this);
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/AlreadyReifiedException.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/AlreadyReifiedException.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/AlreadyReifiedException.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,106 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+/**
+ * Exception from a {@link TripleFactory} operation involving the reificiation
+ * of a statement - if the statement already has a reified triple.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public class AlreadyReifiedException extends TripleFactoryException {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 1411562510088882899L;
+
+  /**
+   * Create an exception.
+   *
+   * @param message the message to wrap inside this exception.
+   */
+  public AlreadyReifiedException(String message) {
+    super(message);
+  }
+
+  /**
+   * Create a wrapper exception.
+   *
+   * @param message the message to wrap inside this exception.
+   * @param newCause the original exception to wrap.
+   */
+  public AlreadyReifiedException(String message, Throwable newCause) {
+    super(message, newCause);
+  }
+
+  /**
+   * Create a wrapper exception.
+   *
+   * @param newCause the original exception to wrap.
+   */
+  public AlreadyReifiedException(Throwable newCause) {
+    super(newCause);
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/Alternative.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/Alternative.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/Alternative.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,110 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java 2 standard packages
+import java.util.Collection;
+
+/**
+ * An Alt is a list of unordered statements which prevents duplicates.  It
+ * represents objects which are semantically the same.  The order in which the
+ * objects go in may not be the order in which they are returned.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface Alternative extends Container {
+
+   /**
+    * {@inheritDoc}
+    * @param c {@inheritDoc}
+    * @throws IllegalArgumentException if the given object is not the correct
+    *   type, Alternative.
+    */
+   boolean containsAll(Collection<ObjectNode> c)
+       throws IllegalArgumentException;
+
+   /**
+    * {@inheritDoc}
+    * @param c {@inheritDoc}
+    * @throws IllegalArgumentException if the given object is not the correct
+    *   type, Alternative.
+    */
+   boolean addAll(Collection<ObjectNode> c)
+       throws IllegalArgumentException;
+
+   /**
+    * {@inheritDoc}
+    * @param c {@inheritDoc}
+    * @throws IllegalArgumentException if the given object is not the correct
+    *   type, Alternative.
+    */
+   boolean removeAll(Collection<ObjectNode> c)
+       throws IllegalArgumentException;
+
+   /**
+    * {@inheritDoc}
+    * @param c {@inheritDoc}
+    * @throws IllegalArgumentException if the given object is not the correct
+    *   type, Alternative.
+    */
+   boolean retainAll(Collection<ObjectNode> c)
+       throws IllegalArgumentException;
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/Bag.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/Bag.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/Bag.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,111 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java 2 standard packages
+import java.util.Collection;
+
+/**
+ * A Bag is a group of statements that are an unorderd list which allow
+ * duplicates.  The order in which the objects go in may not be the order
+ * in which they are returned.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface Bag extends Container {
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @param c ${@inheritDoc}
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Bag.
+   */
+  boolean containsAll(Collection<ObjectNode> c)
+      throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @param c ${@inheritDoc}
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Bag.
+   */
+  boolean addAll(Collection<ObjectNode> c) throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @param c ${@inheritDoc}
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Bag.
+   */
+  boolean removeAll(Collection<ObjectNode> c) throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @param c ${@inheritDoc}
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Bag.
+   */
+  boolean retainAll(Collection<ObjectNode> c) throws IllegalArgumentException;
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/BlankNode.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/BlankNode.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/BlankNode.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,95 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import org.openrdf.model.BNode;
+
+/**
+ * RDF blank node. Note that blank nodes are deliberately devoid of indentifying
+ * attributes.
+ *
+ * Blank nodes, can either be subjects or objects.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface BlankNode extends SubjectNode, ObjectNode, TypedNodeVisitable, BNode {
+
+  /**
+   * Returns a hash-code value for this BlankNode.  While the implementation
+   * is not defined, if there is a blank node identifier then it should be
+   * the hash code generated from this.  Hash code generation should follow
+   * the normal contract.
+   *
+   * @return a hash-code value for this blank node.
+   */
+  int hashCode();
+
+  /**
+   * While the internal structure of a BlankNode is not defined equality between
+   * two nodes should be able to be determined.  In some representations this
+   * equality would be defined by a blank node identifier.
+   *
+   * @param obj the reference object with which to compare.
+   * @return true if this object is the same as the obj argument; false otherwise.
+   */
+  boolean equals(Object obj);
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/Collection.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/Collection.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/Collection.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,191 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import java.util.Iterator;
+
+/**
+ * A Collection holds all the statements of a particular group.  A linked list
+ * is created by using pointer statements (REST) to the next item in the
+ * collection.  The group is closed, where the last statement in the group
+ * points to a NIL entry.
+ *
+ * See <A HREF="http://www.w3.org/TR/rdf-primer/#collections">4.1 RDF Collections</A>.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface Collection {
+
+  /**
+   * Add an ${@link ObjectNode} to the collection.
+   *
+   * @param element object to add.
+   * @return true if the object was added successfully.
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  boolean add(ObjectNode element) throws IllegalArgumentException;
+
+  /**
+   * Add an ${@link ObjectNode} to the collection at the given position.
+   *
+   * @param index the index into the collection to add.
+   * @param element the object to add.
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  void add(int index, ObjectNode element) throws IllegalArgumentException;
+
+  /**
+   * Add a collection of ${@link ObjectNode}s to this one.
+   *
+   * @param c the collection to add.
+   * @return true if the object was added successfully.
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Collection.
+   */
+  boolean addAll(java.util.Collection<ObjectNode> c) throws IllegalArgumentException;
+
+  /**
+   * Add a collection of ${@link ObjectNode}s to this one starting at the given
+   * index.
+   *
+   * @param index the index into the collection to start adding.
+   * @param c the collection to add.
+   * @return true if the object was added successfully.
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Collection.
+   */
+  boolean addAll(int index, java.util.Collection<ObjectNode> c) throws
+      IllegalArgumentException;
+
+  /**
+   * Add an ${@link ObjectNode} to the start of the collection.
+   *
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  void addFirst(ObjectNode element);
+
+  /**
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  void addLast(ObjectNode element);
+
+  /**
+   * Search the collection and return if the object was found or not.
+   *
+   * @return true of the object was found.
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  boolean contains(ObjectNode element);
+
+  /**
+   * Search the collection and return if all of the given objects were found.
+   *
+   * @param c the collection containing the elements to search.
+   * @return true if all of the given objects were found. 
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Collection.
+   */
+  boolean containsAll(java.util.Collection<ObjectNode> c);
+
+  /**
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  int indexOf(ObjectNode element) throws IllegalArgumentException;
+
+  Iterator<ObjectNode> iterator();
+
+  /**
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  int lastIndexOf(ObjectNode element) throws IllegalArgumentException;
+
+  /**
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  boolean remove(ObjectNode element) throws IllegalArgumentException;
+
+  /**
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Collection.
+   */
+  boolean removeAll(java.util.Collection<ObjectNode> c) throws IllegalArgumentException;
+
+  /**
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Collection.
+   */
+  boolean retainAll(java.util.Collection<ObjectNode> c) throws IllegalArgumentException;
+
+  /**
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  Object set(int index, ObjectNode element) throws IllegalArgumentException;
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/Container.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/Container.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/Container.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,101 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java 2 standard packages
+import java.util.Collection;
+
+/**
+ * A Container is a grouping of statements.  A container can either be a
+ * {@link Alternative}, {@link Bag}, or {@link Sequence}.
+ *
+ * See <A HREF="http://www.w3.org/TR/rdf-primer/#containers">4.1 RDF Containers</A>.
+ *
+ * Alternatives are unordered lists that do not allow duplicates.  Bags are
+ * unordered lists that allow duplicates.  Sequences are ordered lists that
+ * allows duplicates.
+ *
+ * Currently, this is just an extension of java.util.Collection that throws
+ * exceptions when inappropriate objects are used, for example non-ObjectNodes
+ * are added.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface Container extends Collection<ObjectNode> {
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @param o ${@inheritDoc}
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  boolean add(ObjectNode o) throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @param o ${@inheritDoc}
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  boolean remove(ObjectNode o) throws IllegalArgumentException;
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/Graph.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/Graph.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/Graph.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,224 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import org.jrdf.util.ClosableIterator;
+
+import java.io.Serializable;
+import java.util.Iterator;
+
+/**
+ * An RDF Graph. As defined by the
+ * <a href="http://www.w3.org/TR/2003/WD-rdf-concepts-20031010"><cite>Resource
+ * Description Framework (RDF): Concepts and Abstract Syntax</cite> </a>
+ * specification.  An RDF graph is a set of RDF triples.  The set of nodes of
+ * an RDF graph is the set of subjects and objects of triples in the graph.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ */
+public interface Graph extends Serializable {
+
+  /**
+   * Test the graph for the occurrence of a statement.  A null value for any
+   * of the parts of a triple are treated as unconstrained, any values will be
+   * returned.
+   *
+   * @param subject The subject to find or null to indicate any subject.
+   * @param predicate The predicate to find or null to indicate any predicate.
+   * @param object The object to find or null to indicate any object.
+   * @return True if the statement is found in the model, otherwise false.
+   * @throws GraphException If there was an error accessing the graph.
+   */
+  boolean contains(SubjectNode subject, PredicateNode predicate, ObjectNode object)
+      throws GraphException;
+
+  /**
+   * Test the graph for the occurrence of the triple.  A null value for any
+   * of the parts of a triple are treated as unconstrained, any values will be
+   * returned.
+   *
+   * @param triple The triple to find.
+   * @return True if the triple is found in the graph, otherwise false.
+   * @throws GraphException If there was an error accessing the graph.
+   */
+  boolean contains(Triple triple) throws GraphException;
+
+  /**
+   * Returns an iterator of {@link Triple}s to a set of statements that
+   * match a given subject, predicate and object.  A null value for any of
+   * the parts of a triple are treated as unconstrained, any values will be
+   * returned.
+   *
+   * @param subject The subject to find or null to indicate any subject.
+   * @param predicate The predicate to find or null to indicate any predicate.
+   * @param object ObjectNode The object to find or null to indicate any object.
+   * @return an iterator containing the matching statements.
+   * @throws GraphException If there was an error accessing the graph.
+   */
+  ClosableIterator<Triple> find(SubjectNode subject, PredicateNode predicate, ObjectNode object)
+      throws GraphException;
+
+  /**
+   * Returns an iterator of {@link Triple}s to a set of statements that
+   * match a given subject, predicate and object.  A null value for any of
+   * the parts of a triple are treated as unconstrained, any values will be
+   * returned.
+   *
+   * @param triple The triple to find.
+   * @return an iterator containing the matching statements.
+   * @throws GraphException If there was an error accessing the graph.
+   */
+  ClosableIterator<Triple> find(Triple triple) throws GraphException;
+
+  /**
+   * Adds a triple to the graph.  The nodes must have already been created
+   * using {@link GraphElementFactory}.
+   *
+   * @param subject The subject.
+   * @param predicate The predicate.
+   * @param object The object.
+   * @throws GraphException If the statement can't be made.
+   */
+  void add(SubjectNode subject, PredicateNode predicate, ObjectNode object)
+      throws GraphException;
+
+  /**
+   * Adds a triple to the graph.  The nodes must have already been created
+   * using {@link GraphElementFactory}.
+   *
+   * @param triple The triple.
+   * @throws GraphException If the statement can't be made.
+   */
+  void add(Triple triple) throws GraphException;
+
+  /**
+   * Adds all the triples contained in an iterator into the graph.  The nodes
+   * must have already been created using {@link GraphElementFactory}.
+   *
+   * @param triples The triple iterator.
+   * @throws GraphException If the statements can't be made.
+   */
+  void add(Iterator<Triple> triples) throws GraphException;
+
+  /**
+   * Closes any resources associated with this graph.
+   */
+  void close();
+
+  /**
+   * Removes a triple from the graph.  The nodes must have already been
+   * created using {@link GraphElementFactory}.
+   *
+   * @param subject The subject.
+   * @param predicate The predicate.
+   * @param object The object.
+   * @throws GraphException If there was an error revoking the statement, For
+   *     example if it didn't exist.
+   */
+  void remove(SubjectNode subject, PredicateNode predicate, ObjectNode object)
+      throws GraphException;
+
+  /**
+   * Removes a triple from the graph.  The nodes must have already been
+   * created using {@link GraphElementFactory}.
+   *
+   * @param triple The triple.
+   * @throws GraphException If there was an error revoking the statement, For
+   *     example if it didn't exist.
+   */
+  void remove(Triple triple) throws GraphException;
+
+  /**
+   * Removes all the triples contained in an iterator from the graph.  The
+   * nodes must have already been created using {@link GraphElementFactory}.
+   *
+   * @param triples The triple iterator.
+   * @throws GraphException If the statements can't be revoked.
+   */
+  void remove(Iterator<Triple> triples) throws GraphException;
+
+  /**
+   * Returns the node factory for the graph, or creates one.
+   *
+   * @return the node factory for the graph, or creates one.
+   */
+  GraphElementFactory getElementFactory();
+
+  /**
+   * Returns the triple factory for the graph, or creates one.
+   *
+   * @return the triple factory for the graph, or creates one.
+   */
+  TripleFactory getTripleFactory();
+
+  /**
+   * Returns the number of triples in the graph.
+   *
+   * @return the number of triples in the graph.
+   * @throws GraphException If the statements number of statements in the graph
+   *   fails to be found.
+   */
+  long getNumberOfTriples() throws GraphException;
+
+  /**
+   * Returns true if the graph is empty i.e. the number of triples is 0.
+   *
+   * @return true if the graph is empty i.e. the number of triples is 0.
+   * @throws GraphException If the statements number of statements in the graph
+   *   fails to be found.
+   */
+  boolean isEmpty() throws GraphException;
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/GraphElementFactory.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/GraphElementFactory.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/GraphElementFactory.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,139 @@
+/*
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java 2 standard packages
+import java.net.URI;
+
+/**
+ * A Graph Element Factory is a class which creates the various components of a
+ * graph including: resources, literals and triples.  It is generally tied to a
+ * specific graph.
+ *
+ * @author Andrew Newman
+ */
+public interface GraphElementFactory {
+
+  /**
+   * Create a blank nodes that is associated with a specific graph.
+   *
+   * @return the newly created blank node value.
+   * @throws GraphElementFactoryException if adding a blank node fails.
+   */
+  BlankNode createResource() throws GraphElementFactoryException;
+
+  /**
+   * Create a URI reference.
+   *
+   * @param uri The URI of the resource.
+   * @return the newly created URI reference value.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  URIReference createResource(URI uri) throws GraphElementFactoryException;
+
+  /**
+   * Create a URI reference without checking if the URI given is a valid RDF
+   * URI, currently if the URI is absolute.
+   *
+   * @param uri The URI of the resource.
+   * @param validate true if we disbale checking to see if the URI is valid.
+   * @return The newly created URI reference value.
+   * @throws GraphElementFactoryException
+   */
+  URIReference createResource(URI uri, boolean validate) throws GraphElementFactoryException;
+
+  /**
+   * Creates a new literal with the given lexical value, with no language or
+   * datatype.
+   *
+   * @param lexicalValue The lexical value for the literal.
+   * @return the newly created literal value.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  Literal createLiteral(String lexicalValue) throws GraphElementFactoryException;
+
+  /**
+   * Creates a new literal with the given lexical value, with a given language
+   * but no datatype.
+   *
+   * @param lexicalValue The lexical value for the literal.  Cannot be null.
+   * @param languageType The language of the literal or null if not required.
+   * @return the newly created literal value.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  Literal createLiteral(String lexicalValue, String languageType)
+      throws GraphElementFactoryException;
+
+  /**
+   * Creates a new literal with the given lexical value and given datatype.
+   *
+   * @param lexicalValue The lexical value for the literal.  Cannot be null.
+   * @param datatypeURI The URI of the datatype of the literal or null if not required.
+   * @return the newly created literal value.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  Literal createLiteral(String lexicalValue, URI datatypeURI) throws GraphElementFactoryException;
+
+  /**
+   * Creates a new triple to be used in the graph.  Does not add it to an
+   * associated graph.  Use @see Graph#add.
+   *
+   * @param subject The subject of the statement.
+   * @param predicate The predicate of the statement.
+   * @param object The object of the statement.
+   * @return the newly created triple object.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  Triple createTriple(SubjectNode subject, PredicateNode predicate, ObjectNode object) throws GraphElementFactoryException;
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/GraphElementFactoryException.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/GraphElementFactoryException.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/GraphElementFactoryException.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,105 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+/**
+ * Exception from a {@link GraphElementFactory} operation.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public class GraphElementFactoryException extends Exception {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = -8660240321973373993L;
+
+  /**
+   * Create an exception.
+   *
+   * @param message the message to wrap inside this exception.
+   */
+  public GraphElementFactoryException(String message) {
+    super(message);
+  }
+
+  /**
+   * Create a wrapper exception.
+   *
+   * @param message the message to wrap inside this exception.
+   * @param newCause the original exception to wrap.
+   */
+  public GraphElementFactoryException(String message, Throwable newCause) {
+    super(message, newCause);
+  }
+
+  /**
+   * Create a wrapper exception.
+   *
+   * @param newCause the original exception to wrap.
+   */
+  public GraphElementFactoryException(Throwable newCause) {
+    super(newCause);
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/GraphException.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/GraphException.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/GraphException.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,105 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+/**
+ * Exception from an {@link Graph} operation.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ *
+ * @version $Revision: 624 $
+ */
+public class GraphException extends Exception {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = -5259349384211599957L;
+
+  /**
+   * Create an exception.
+   *
+   * @param message the message to wrap inside this exception.
+   */
+  public GraphException(String message) {
+    super(message);
+  }
+
+  /**
+   * Create a wrapper exception.
+   *
+   * @param message the message to wrap inside this exception.
+   * @param newCause the original exception to wrap.
+   */
+  public GraphException(String message, Throwable newCause) {
+    super(message, newCause);
+  }
+
+  /**
+   * Create a wrapper exception.
+   *
+   * @param newCause the original exception to wrap.
+   */
+  public GraphException(Throwable newCause) {
+    super(newCause);
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/Literal.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/Literal.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/Literal.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,164 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java 2 standard
+import java.net.URI;
+
+/**
+ * RDF literal node.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface Literal extends ObjectNode, TypedNodeVisitable, org.openrdf.model.Literal {
+
+  /**
+   * Obtain the text of this literal.
+   *
+   * @return the text of the literal, never <code>null</code>
+   */
+  String getLexicalForm();
+
+  /**
+   * Returns the language code of the literal, or <code>null</code> if no
+   *     language specified.
+   *
+   * @return the language code of the literal, or <code>null</code> if no
+   *     language specified.
+   */
+  String getLanguage();
+
+  /**
+   * Whether the literal is well formed XML.
+   *
+   * @return whether the literal is wll formed XML.
+   */
+  boolean isWellFormedXML();
+
+  /**
+   * Returns the URI of the RDF datatype of this resource, or <code>null</code>
+   *     for an untyped node.
+   *
+   * @return the URI of the RDF datatype of this resource, or <code>null</code>
+   *     for an untyped node.
+   */
+  URI getDatatypeURI();
+
+  /**
+   * Indicates whether some other object is "equal to" this one.
+   *
+   * A literal is equal to another literal if:
+   * <ul>
+   * <li> The strings of the two lexical forms compare equal, character by
+   * character.
+   * <li> Either both or neither have language tags.
+   * <li> The language tags, if any, compare equal.
+   * <li> Either both or neither have datatype URIs.
+   * <li> The two datatype URIs, if any, compare equal, character by character.
+   * </ul>
+   *
+   * @param obj the reference object with which to compare.
+   * @return true if this object is the same as the obj argument; false otherwise.
+   */
+  boolean equals(Object obj);
+
+  /**
+   * Returns a hash-code value for this literal. The hash code is based upon
+   * XORing all of the literal's components hash codes including the
+   * lexical form, datatype, and language.
+   *
+   * @return a hash-code value for this literal.
+   */
+  int hashCode();
+
+  /**
+   * Provide a legible representation of a literal, following the N-Triples
+   * format defined in
+   * <a href="http://www.w3.org/TR/2004/REC-rdf-testcases-20040210/#ntrip_strings">&sect;3.2</a>
+   * of the <a href="http://www.w3.org/">
+   * <acronym title="World Wide Web Consortium">W3C</acronym></a>'s
+   * <a href="http://www.w3.org/TR/2004/REC-rdf-testcases-20040210">RDF Test
+   * Cases</a> Recommendation.
+   *
+   * Well-formed Unicode surrogate pairs in the lexical form are escaped as a
+   * single 8-digit hexadecimal <code>\U</code> escape sequence rather than a
+   * pair of 4-digit <code>&x5C;u</code> sequences representing the surrogates.
+   *
+   * @return this instance in N-Triples format
+   */
+  String getEscapedForm();
+
+  /**
+   * Returns an escaped lexical form where double quotes and backslashes are
+   * escaped.
+   *
+   * @return String the lexical form.
+   */
+  String getEscapedLexicalForm();
+
+  /**
+   * Returns the lexical form.
+   *
+   * @return the lexical form.
+   */
+  String toString();
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/Node.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/Node.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/Node.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,74 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import java.io.Serializable;
+
+import org.openrdf.model.Value;
+
+/**
+ * RDF node.  This includes all things in the graph.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface Node extends Serializable, Value {
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/ObjectNode.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/ObjectNode.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/ObjectNode.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,71 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+/**
+ * Indicates if a Java object can be the object part of an RDF Triple.
+ * Currently, this is either a URI Reference, Literal or a Blank node.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface ObjectNode extends Node {
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/PredicateNode.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/PredicateNode.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/PredicateNode.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,73 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import org.openrdf.model.URI;
+
+/**
+ * Indicates if a Java object can be the predicate part of an RDF Triple.
+ * Currently, this is a URI Reference.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface PredicateNode extends Node, URI {
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/Sequence.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/Sequence.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/Sequence.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,156 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java 2 standard packages
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * A Sequence is a group of statements that are kept in an orderd list.  The
+ * order in which the objects go in dictates how they are returned in a First
+ * In, First Out manner.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface Sequence extends Container, List<ObjectNode> {
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  void add(int index, ObjectNode o) throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Sequence.
+   */
+  boolean addAll(Collection<? extends ObjectNode> c) throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Sequence.
+   */
+  boolean addAll(int index, Collection<? extends ObjectNode> c)
+      throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  boolean contains(ObjectNode o);
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Sequence.
+   */
+  boolean containsAll(Collection<?> c);
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  int indexOf(ObjectNode o) throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  int lastIndexOf(ObjectNode o) throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Sequence.
+   */
+  boolean removeAll(Collection<?> c) throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Sequence.
+   */
+  boolean retainAll(Collection<?> c) throws IllegalArgumentException;
+
+  /**
+   * ${@inheritDoc}
+   *
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, ObjectNode.
+   */
+  ObjectNode set(int index, ObjectNode element) throws IllegalArgumentException;
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/SubjectNode.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/SubjectNode.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/SubjectNode.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,73 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import org.openrdf.model.Resource;
+
+/**
+ * Indicates if a Java object can be the subject part of an RDF Triple.
+ * Currently, this is either a URI Reference or a Blank node.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface SubjectNode extends Node, Resource {
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/Triple.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/Triple.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/Triple.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,117 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+import java.io.Serializable;
+
+/**
+ * RDF Triple. An RDF triple as defined in "Resource Description Framework (RDF):
+ * Concepts and Abstract Syntax"
+ * <a href="http://www.w3c.org/TR/rdf-concepts/#section-triples"/>6.1 RDF Triples</a>.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface Triple extends Serializable {
+
+  /**
+   * Obtains the subject of this statement.
+   *
+   * @return an {@link SubjectNode} which is either a {@link BlankNode} or
+   *     {@link URIReference}
+   */
+  SubjectNode getSubject();
+
+  /**
+   * Obtains the predicate of this statement.
+   *
+   * @return a {@link PredicateNode} which is a {@link URIReference}
+   */
+  PredicateNode getPredicate();
+
+  /**
+   * Obtains the object of this statement.
+   *
+   * @return a {@link ObjectNode} which is either a {@link BlankNode},
+   *     {@link URIReference} or {@link Literal}
+   */
+  ObjectNode getObject();
+
+  /**
+   * Indicates whether some other object is "equal to" this one.
+   *
+   * A triple is equal to another triple if the subject, predicate and object
+   * are all equal.
+   *
+   * @param obj the reference object with which to compare.
+   * @return true if this object is the same as the obj argument; false otherwise.
+   */
+  boolean equals(Object obj);
+
+  /**
+   * Returns a hash-code value for this triple. The hash code is based upon
+   * XORing all of the components of a triple i.e. the subject, predicate and
+   * object.
+   *
+   * @return a hash-code value for this triple.
+   */
+  int hashCode();
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/TripleFactory.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/TripleFactory.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/TripleFactory.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,144 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+/**
+ * A Triple Factory is a class which defines the creation of certain sets of
+ * triples.  This includes reification, containers and collections.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface TripleFactory {
+
+  /**
+   * Reifies a triple.  A triple made up of the first three nodes is added to
+   * graph and the reificationNode is used to reify the triple.
+   *
+   * @param subjectNode the subject of the triple.
+   * @param predicateNode the predicate of the triple.
+   * @param objectNode the object of the triple.
+   * @param reificationNode a node denoting the reified triple.
+   * @throws TripleFactoryException If the resource failed to be added.
+   * @throws AlreadyReifiedException If there was already a triple URI for
+   *     the given triple.
+   */
+  void reifyTriple(SubjectNode subjectNode,
+      PredicateNode predicateNode, ObjectNode objectNode,
+      SubjectNode reificationNode) throws TripleFactoryException,
+      AlreadyReifiedException;
+
+  /**
+   * Reifies a triple.  The triple added to the graph and the
+   * reificationNode is used to reify the triple.
+   *
+   * @param triple the triple to be reified.
+   * @param reificationNode a node denoting the reified triple.
+   * @throws TripleFactoryException If the resource failed to be added.
+   * @throws AlreadyReifiedException If there was already a triple URI for
+   *     the given triple.
+   */
+  void reifyTriple(Triple triple, SubjectNode reificationNode)
+      throws TripleFactoryException, AlreadyReifiedException;
+
+  /**
+   * Inserts a alternative using the given subject.  The subject is also
+   * the object of a proceeding statement that identifies the container.
+   *
+   * @param subjectNode the subject node of the triple.
+   * @param alternative the alternative to add.
+   * @throws TripleFactoryException If the resources were failed to be added.
+   */
+  void addAlternative(SubjectNode subjectNode, Alternative alternative)
+      throws TripleFactoryException;
+
+  /**
+   * Inserts a bag using the given subject.  The subject is also
+   * the object of a proceeding statement that identifies the container.
+   *
+   * @param subjectNode the subject node of the triple.
+   * @param bag the bag to add.
+   * @throws TripleFactoryException If the resources were failed to be added.
+   */
+  void addBag(SubjectNode subjectNode, Bag bag)
+      throws TripleFactoryException;
+
+  /**
+   * Inserts a sequence using the given subject.  The subject is also
+   * the object of a proceeding statement that identifies the container.
+   *
+   * @param subjectNode the subject node of the triple.
+   * @param sequence the sequence to add.
+   * @throws TripleFactoryException If the resources were failed to be added.
+   */
+  void addSequence(SubjectNode subjectNode, Sequence sequence)
+      throws TripleFactoryException;
+
+  /**
+   * Inserts a collection using the given subject.  The subject is also
+   * the object of a proceeding statement that identifies the collection.
+   *
+   * @param firstNode the subject node of the triple.
+   * @param collection the collection to add.
+   * @throws TripleFactoryException If the resources were failed to be added.
+   */
+  void addCollection(SubjectNode firstNode, Collection collection)
+      throws TripleFactoryException;
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/TripleFactoryException.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/TripleFactoryException.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/TripleFactoryException.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,105 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+/**
+ * Exception from a {@link TripleFactory} operation.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public class TripleFactoryException extends Exception {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 285284678430193536L;
+
+  /**
+   * Create an exception.
+   *
+   * @param message the message to wrap inside this exception.
+   */
+  public TripleFactoryException(String message) {
+    super(message);
+  }
+
+  /**
+   * Create a wrapper exception.
+   *
+   * @param message the message to wrap inside this exception.
+   * @param newCause the original exception to wrap.
+   */
+  public TripleFactoryException(String message, Throwable newCause) {
+    super(message, newCause);
+  }
+
+  /**
+   * Create a wrapper exception.
+   *
+   * @param newCause the original exception to wrap.
+   */
+  public TripleFactoryException(Throwable newCause) {
+    super(newCause);
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitable.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitable.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitable.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,77 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+/**
+ * Indicates that a {@link BlankNode}, {@link URIReference} or
+ * {@link Literal} are able to be visited.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface TypedNodeVisitable {
+
+  /**
+   * Accept a call from a TypedNodeVisitor.
+   *
+   * @param visitor the object doing the visiting.
+   */
+  void accept(TypedNodeVisitor visitor);
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitor.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitor.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitor.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,91 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+/**
+ * An object which can visit a {@link BlankNode}, {@link URIReference} and
+ * {@link Literal}.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface TypedNodeVisitor {
+
+  /**
+   * Visit blank node.
+   *
+   * @param blankNode the blank node to visit.
+   */
+  void visitBlankNode(BlankNode blankNode);
+
+  /**
+   * Visit URI Reference.
+   *
+   * @param uriReference the URI Reference to visit.
+   */
+  void visitURIReference(URIReference uriReference);
+
+  /**
+   * Visit Literal.
+   *
+   * @param literal the Literal to visit.
+   */
+  void visitLiteral(Literal literal);
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitorAdapter.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitorAdapter.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/TypedNodeVisitorAdapter.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,101 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+/**
+ * An adapter from {@link TypedNodeVisitor}.  Implements empty implementations
+ * to reduce the burden of creating a concrete implementation that doesn't
+ * need to implement all methods.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+
+class TypedNodeVisitorAdapter implements TypedNodeVisitor {
+  public TypedNodeVisitorAdapter() {
+  }
+
+  /**
+   * Visit blank node.
+   *
+   * @param blankNode the blank node to visit.
+   */
+  public void visitBlankNode(BlankNode blankNode) {
+    // this method is left intentionally blank.
+  }
+
+  /**
+   * Visit URI Reference.
+   *
+   * @param uriReference the URI Reference to visit.
+   */
+  public void visitURIReference(URIReference uriReference) {
+    // this method is left intentionally blank.
+  }
+
+  /**
+   * Visit Literal.
+   *
+   * @param literal the Literal to visit.
+   */
+  public void visitLiteral(Literal literal) {
+    // this method is left intentionally blank.
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/URIReference.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/URIReference.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/URIReference.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,106 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph;
+
+// Java 2 standard packages
+import java.net.URI;
+
+/**
+ * RDF URI reference - resource node. Some RDF resources are properties. It's
+ * not always possible to say whether a resource is a property or not until
+ * it's used as a predicate, because we don't always have access to an RDF
+ * Schema that defines the property.
+ *
+ * A URI Reference can be any part of an RDF Triple: subject, predicate or
+ * object.
+ *
+ * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface URIReference extends SubjectNode, PredicateNode, ObjectNode,
+    TypedNodeVisitable, org.openrdf.model.URI {
+
+  /**
+   * The {@link URI} identifiying this resource.
+   *
+   * @return the {@link URI} identifying this resource.
+   */
+  URI getURI();
+
+  /**
+   * Returns a hash-code value for this URI Reference. This is the hash code
+   * of the URI.
+   *
+   * @return a hash-code value for this literal.
+   */
+  int hashCode();
+
+  /**
+   * Indicates whether some other object is "equal to" this one.
+   *
+   * A URI Reference is equal to another URI Reference if their URIs are equal
+   * to one another, character by character.
+   *
+   * @param obj the reference object with which to compare.
+   * @return true if this object is the same as the obj argument; false otherwise.
+   */
+  boolean equals(Object obj);
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/AbstractUnorderedContainer.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/AbstractUnorderedContainer.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/AbstractUnorderedContainer.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,151 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+// Java 2 standard packages
+import org.jrdf.graph.Container;
+import org.jrdf.graph.ObjectNode;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * The base class for the implementation of Bag and Alternative.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public abstract class AbstractUnorderedContainer implements Container {
+
+  /**
+   * The hashmap containing the elements.
+   */
+  Map<Long,ObjectNode> elements = new HashMap<Long,ObjectNode>();
+
+  /**
+   * Counter used to generate keys to add to the hashmap.
+   */
+  long key;
+
+  public int size() {
+    return elements.values().size();
+  }
+
+  public boolean isEmpty() {
+    return elements.values().isEmpty();
+  }
+
+  public boolean contains(Object o) {
+    return elements.values().contains(o);
+  }
+
+  public Iterator<ObjectNode> iterator() {
+    return elements.values().iterator();
+  }
+
+  public ObjectNode[] toArray() {
+    return (ObjectNode[])elements.values().toArray();
+  }
+
+  public ObjectNode[] toArray(ObjectNode[] a) {
+    return (ObjectNode[])elements.values().toArray(a);
+  }
+
+  public boolean add(ObjectNode o) throws IllegalArgumentException {
+    if (!(o instanceof ObjectNode)) {
+      throw new IllegalArgumentException("Can only add Object nodes");
+    }
+
+    elements.put(new Long(key++), o);
+    return true;
+  }
+
+  public boolean remove(Object o) throws IllegalArgumentException {
+    if (!(o instanceof ObjectNode)) {
+      throw new IllegalArgumentException("Can only add Object nodes");
+    }
+
+    Iterator<Map.Entry<Long,ObjectNode>> iter = elements.entrySet().iterator();
+    boolean found = false;
+
+    // Removes the first entry in the map that matches the given object.
+    while (!found && iter.hasNext()) {
+      Map.Entry<Long,ObjectNode> entry = iter.next();
+      if (o.equals(entry.getValue())) {
+        elements.remove(o);
+        found = true;
+      }
+    }
+
+    return found;
+  }
+
+  public void clear() {
+    key = 0;
+    elements.clear();
+  }
+
+  public int hashCode() {
+    return elements.hashCode();
+  }
+
+  public abstract boolean equals(Object o);
+}
\ No newline at end of file

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/BlankNodeImpl.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/BlankNodeImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/BlankNodeImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,195 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+// JRDF objects
+
+import org.jrdf.graph.AbstractBlankNode;
+import org.jrdf.graph.BlankNode;
+
+/**
+ * RDF blank node. Note that blank nodes are deliberately devoid of external indentifying
+ * attributes.
+ *
+ * Blank nodes, can either be subjects or objects.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ *
+ * @version $Revision: 624 $
+ */
+public class BlankNodeImpl extends AbstractBlankNode implements MemNode {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 1573129076314000518L;
+
+  /** The internal identifier for this node. */
+  private Long id;
+
+  /** Globally Unique Identifier. */
+  private String uid;
+
+  private String stringValue;
+
+  /**
+   * The constructor for this node.  Package scope so that only NodeFactory and
+   * static methods can call it.
+   *
+   * @param newId The id to be used for this node.
+   * @param newUid String Globally Unique Identifier for external communication.
+   */
+  BlankNodeImpl(Long newId, String newUid) {
+    id = newId;
+    uid = newUid;
+    stringValue = uid + "#" + id;
+  }
+
+  /**
+   * Retrieves an internal identifier for this node.
+   *
+   * @return A numeric identifier for thisa node.
+   */
+  public Long getId() {
+    return id;
+  }
+
+  /**
+   * Retrieves a Globally Unique Identifier for this node.
+   *
+   * @return A global String identifier for this node.
+   */
+  private String getUID() {
+    return uid;
+  }
+
+  /**
+   * While the internal structure of a BlankNode is not defined equality between
+   * two nodes should be able to be determined.
+   *
+   * @param obj the reference object with which to compare.
+   * @return true if this object is the same as the obj argument; false otherwise.
+   */
+  public boolean equals(Object obj) {
+
+    // Check equal by reference
+    if (this == obj) {
+      return true;
+    }
+
+    // Check for null and ensure exactly the same class - not subclass.
+    if (obj == null || getClass() != obj.getClass()) {
+      return super.equals(obj);
+    }
+
+    // Cast and check for equality by value. (same class)
+    try {
+      BlankNodeImpl tmpNode = (BlankNodeImpl) obj;
+      return tmpNode.getId().equals(id) && tmpNode.getUID().equals(uid);
+    }
+    catch (ClassCastException cce) {
+      return false;
+    }
+  }
+
+  /**
+   * Returns the String value of this BlankNode as:
+   * uid#id (eg. 29fbf7ba364f1425dda058737d764603#69)
+   *
+   * @return String
+   */
+  public String toString() {
+
+    return uid + "#" + id;
+  }
+
+  public String getID() {
+
+    return stringValue;
+  }
+
+  /**
+   * Parses a String in the format of:
+   * uid#id (eg. 29fbf7ba364f1425dda058737d764603#69) and creates a new
+   * BlankNodeImpl from it.
+   *
+   * Should only be applied to a value previously returned by toString()
+   *
+   * @param nodeString String previously returned by toString()
+   * @return BlankNodeImpl
+   * @throws IllegalArgumentException
+   */
+  public static BlankNode valueOf(String nodeString) throws
+      IllegalArgumentException {
+
+    String[] split = nodeString.split("#");
+
+    //validate
+    if (null == split || 2 > split.length) {
+      throw new IllegalArgumentException("String: " + nodeString + " is not " +
+          "of the format: uid#id");
+    }
+
+    return new BlankNodeImpl(Long.valueOf(split[1]), split[0]);
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/EmptyClosableIterator.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/EmptyClosableIterator.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/EmptyClosableIterator.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,106 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.util.ClosableIterator;
+
+import java.util.NoSuchElementException;
+
+/**
+ * An iterator that returns no triples.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public class EmptyClosableIterator<T> implements ClosableIterator<T> {
+
+  EmptyClosableIterator() {
+  }
+
+  /**
+   * Returns false.
+   *
+   * @return <code>false</code>.
+   */
+  public boolean hasNext() {
+    return false;
+  }
+
+  /**
+   * Never returns anything.  A call to this will throw NoSuchElementException.
+   *
+   * @return will not return.
+   * @throws NoSuchElementException iteration has no more elements.
+   */
+  public T next() throws NoSuchElementException {
+    throw new NoSuchElementException();
+  }
+
+  /**
+   * Implemented for java.util.Iterator.  Not supported by this implementation.
+   */
+  public void remove() {
+    throw new UnsupportedOperationException();
+  }
+
+  public boolean close() {
+    return true;
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/GraphElementFactoryImpl.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/GraphElementFactoryImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/GraphElementFactoryImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,361 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.*;
+import org.jrdf.util.UIDGenerator;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A SkipListNode Factory is a class which create the various components of a graph.
+ * It is tied to a specific instance of GraphImpl.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ */
+public class GraphElementFactoryImpl implements GraphElementFactory {
+
+  /** The pool of all nodes, mapped from their ids. */
+  private Map<Long,MemNode> nodePool;
+
+  /** A reverse mapping of all ids, mapped from their string. */
+  private Map<String,Long> stringPool;
+
+  /** The graph that this factory constructs nodes for. */
+  @SuppressWarnings("unused")
+  private Graph graph;
+
+  /** The next available node id. */
+  private long nextNode;
+
+  /**
+   * Package scope constructor.
+   *
+   * @param newGraph The GraphImpl that this class is attached to.
+   */
+  GraphElementFactoryImpl(Graph newGraph) throws TripleFactoryException {
+    graph = newGraph;
+    nodePool = new HashMap<Long,MemNode>();
+    stringPool = new HashMap<String,Long>();
+    nextNode = 1;
+  }
+
+
+  /**
+   * Create a blank nodes that is associated with a specific graph.
+   * @return A new blank node within the graph.
+   * @return the newly created blank node value.
+   * @throws GraphElementFactoryException If anonymous resources can't be generated.
+   */
+  public BlankNode createResource() throws GraphElementFactoryException {
+    Long id = new Long(nextNode);
+
+    //get an Unique Identifier
+    String uid = "";
+    try {
+      uid = UIDGenerator.generateUID();
+    } catch (Exception exception) {
+      throw new GraphElementFactoryException(
+          "Could not generate Unique Identifier for BlankNode.", exception);
+    }
+
+    // create the new node
+    BlankNodeImpl node = new BlankNodeImpl(id, uid);
+
+    // put the node in the pool
+    nodePool.put(id, node);
+
+    // go on to the next node id
+    nextNode++;
+    return node;
+  }
+
+
+  /**
+   * Create a URI reference.
+   * @param uri The URI of the resource.
+   * @return the newly created URI reference value.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  public URIReference createResource(URI uri)
+      throws GraphElementFactoryException {
+    if (null == uri) {
+      throw new GraphElementFactoryException("URI may not be null for a URIReference");
+    }
+
+    // check if the node already exists in the string pool
+    Long nodeid = getNodeIdByString(uri.toString());
+
+    if (null != nodeid) {
+      return (URIReference)getNodeById(nodeid);
+    }
+
+    // create the node identifier and increment the node
+    nodeid = new Long(nextNode++);
+
+    // create the new node
+    URIReferenceImpl node = new URIReferenceImpl(uri, nodeid);
+
+    // put the node in the pool
+    nodePool.put(nodeid, node);
+
+    // put the URI string into the pool
+    // TODO: This could conflict with a literal
+    stringPool.put(uri.toString(), nodeid);
+    return node;
+  }
+
+
+  /**
+   * Create a URI reference without checking if the URI given is a valid RDF
+   * URI, currently if the URI is absolute.
+   * @param uri The URI of the resource.
+   * @param validate true if we disbale checking to see if the URI is valid.
+   * @return The newly created URI reference value.
+   * @throws GraphElementFactoryException
+   */
+  public URIReference createResource(URI uri, boolean validate) throws GraphElementFactoryException {
+
+    if (null == uri) {
+      throw new GraphElementFactoryException("URI may not be null for a URIReference");
+    }
+
+    // check if the node already exists in the string pool
+    Long nodeid = getNodeIdByString(uri.toString());
+    if (null != nodeid) {
+      return (URIReference)getNodeById(nodeid);
+    }
+
+    // create the node identifier and increment the node
+    nodeid = new Long(nextNode++);
+
+    // create the new node
+    URIReferenceImpl node = new URIReferenceImpl(uri, validate, nodeid);
+
+    // put the node in the pool
+    nodePool.put(nodeid, node);
+
+    // put the URI string into the pool
+    // TODO: This could conflict with a literal
+    stringPool.put(uri.toString(), nodeid);
+    return node;
+  }
+
+
+  /**
+   * Creates a new literal with the given lexical value, with no language or datatype.
+   * @param lexicalValue The lexical value for the literal.
+   * @return the newly created literal value.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  public Literal createLiteral(String lexicalValue) throws GraphElementFactoryException {
+    LiteralImpl literal = new LiteralImpl(lexicalValue);
+    addNodeId(literal);
+    return literal;
+  }
+
+
+  /**
+   * Creates a new literal with the given lexical value, with a given language
+   * but no datatype.
+   * @param lexicalValue The lexical value for the literal.  Cannot be null.
+   * @param languageType The language of the literal or null if not required.
+   * @return the newly created literal value.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  public Literal createLiteral(String lexicalValue, String languageType) throws GraphElementFactoryException {
+    LiteralImpl newLiteral = new LiteralImpl(lexicalValue, languageType);
+    addNodeId(newLiteral);
+    return newLiteral;
+  }
+
+
+  /**
+   * Creates a new literal with the given lexical value and given datatype.
+   * @param lexicalValue The lexical value for the literal.  Cannot be null.
+   * @param datatypeURI The URI of the datatype of the literal or null if not required.
+   * @return the newly created literal value.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  public Literal createLiteral(String lexicalValue, URI datatypeURI) throws GraphElementFactoryException {
+    // create the node identifier
+    LiteralImpl newLiteral = new LiteralImpl(lexicalValue, datatypeURI);
+    addNodeId(newLiteral);
+    return newLiteral;
+  }
+
+
+  /**
+   * Creates a new node id for the given Literal.  Sets the node id of the given newLiteral.
+   * @param newLiteral A newly created newLiteral.
+   */
+  private void addNodeId(LiteralImpl newLiteral) {
+
+    // find the string identifier for this node
+    String strId = newLiteral.getEscapedForm();
+
+    // check if the node already exists in the string pool
+    Long tmpNodeId = stringPool.get(strId);
+
+    if (null != tmpNodeId) {
+      // return the existing node instead
+      newLiteral.setId(tmpNodeId);
+      return;
+    } else {
+
+      // create the node identifier
+      Long nodeId = new Long(nextNode);
+      newLiteral.setId(nodeId);
+
+      // put the node in the pool
+      nodePool.put(nodeId, newLiteral);
+
+      // put the URI string into the pool
+      stringPool.put(strId, nodeId);
+
+      // increment the node, since we used it
+      nextNode++;
+    }
+  }
+
+
+  /**
+   * Creates a new triple to be used in the graph.  Does not add it to the
+   * graph.  Use @see Graph#add.
+   * @param subject The subject of the statement.
+   * @param predicate The predicate of the statement.
+   * @param object The object of the statement.
+   * @return the newly created triple object.
+   * @throws GraphElementFactoryException If the resource failed to be created.
+   */
+  public Triple createTriple(SubjectNode subject, PredicateNode predicate,
+      ObjectNode object) throws GraphElementFactoryException {
+    return new TripleImpl(subject, predicate, object);
+  }
+
+
+  /**
+   * Package method for adding in a node that was not created by this factory.
+   * Used by GraphImpl for deserializing.
+   * @param node The node to add.
+   * @throws IllegalArgumentException The node conflicts with one already in use.
+   */
+  void registerNode(MemNode node) {
+    // get the id for this node
+    Long id = node.getId();
+
+    // look the node up to see if it already exists in the graph
+    MemNode existingNode = nodePool.get(id);
+    if (null != existingNode) {
+      // check that the node is equal to the one that is already in the graph
+      if (existingNode.equals(node)) return;
+      // node does not match
+      throw new IllegalArgumentException("SkipListNode conflicts with one already in the graph");
+    }
+    // add the node
+    nodePool.put(id, node);
+
+    // check if the node has a string representation
+    if (!(node instanceof BlankNode)) {
+
+      if (node instanceof Literal) {
+        stringPool.put(((Literal) node).getEscapedForm(), node.getId());
+      } else {
+        stringPool.put(node.toString(), node.getId());
+      }
+    }
+
+    // update the nextNode counter to a unique number
+    if (id.longValue() >= nextNode) nextNode = id.longValue() + 1;
+  }
+
+
+  /**
+   * Package scope method to get all the nodes in the node pool.  Used by GraphImpl for serializing.
+   * @return The node pool.
+   */
+  java.util.Collection<MemNode> getNodePool() {
+    return nodePool.values();
+  }
+
+
+  /**
+   * Package method to find a node in the node pool by its id.
+   *
+   * @param id The id of the node to search for.
+   * @return The node referred to by the id, null if not found.
+   */
+  Node getNodeById(Long id) {
+    return nodePool.get(id);
+  }
+
+
+  /**
+   * Package method to find a node id based on its string representation.
+   *
+   * @param str The string representation of a node.
+   * @return The id of the node with the given string.
+   */
+  Long getNodeIdByString(String str) {
+    return stringPool.get(str);
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/GraphElementFactoryImplUnitTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/GraphElementFactoryImplUnitTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/GraphElementFactoryImplUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,142 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.jrdf.graph.AbstractGraphElementFactoryTest;
+import org.jrdf.graph.Graph;
+import org.jrdf.graph.GraphException;
+
+import java.net.URI;
+
+
+/**
+ * Implementation of {@link AbstractGraphElementFactoryTest}
+ * test case.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ *
+ * @version $Revision: 624 $
+ */
+public class GraphElementFactoryImplUnitTest
+    extends AbstractGraphElementFactoryTest {
+
+  /**
+   * Constructs a new test with the given name.
+   *
+   * @param name the name of the test
+   */
+  private GraphElementFactoryImplUnitTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Create a new graph of the appropriate type.
+   *
+   * @return A new graph implementation object.
+   */
+  public Graph newGraph() throws GraphException {
+    return new GraphImpl();
+  }
+
+  /**
+   * Hook for test runner to obtain a test suite from.
+   *
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new GraphElementFactoryImplUnitTest("testCreateLiterals"));
+    suite.addTest(new GraphElementFactoryImplUnitTest("testCreateResources"));
+    suite.addTest(new GraphElementFactoryImplUnitTest("testCreateTriples"));
+    suite.addTest(new GraphElementFactoryImplUnitTest("testTwoGraphs"));
+    return suite;
+  }
+
+  /**
+   * Default test runner.
+   *
+   * @param args The command line arguments
+   */
+  public static void main(String[] args) throws Exception {
+
+    TestRunner.run(suite());
+  }
+
+  /**
+   * Return the default literal type from the implementation.
+   *
+   * @return The default Literal type.
+   */
+  public URI getDefaultLiteralType() {
+    return null;
+  }
+
+  /**
+   * Get the default literal language from the implementation.
+   *
+   * @return The default Literal language.
+   */
+  public String getDefaultLiteralLanguage() {
+    return null;
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,72 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.GraphException;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Handles the modification of an index as we iterate through.
+ *
+ * @author Andrew Newman
+ */
+public interface GraphHandler {
+  void remove(Long[] currentNodes) throws GraphException ;
+
+  void clean(Set<Long> subGroup, Map<Long,Set<Long>> subIndex,
+      Map<Long,Map<Long,Set<Long>>> index, Long first, Long second);
+}
\ No newline at end of file

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler012.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler012.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler012.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,96 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.GraphException;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Handles the modification of an index as we iterate through for the 012 index.
+ *
+ * @author Andrew Newman
+ */
+public class GraphHandler012 implements GraphHandler {
+
+  protected GraphImpl graph;
+
+  public GraphHandler012(GraphImpl graph) {
+    this.graph = graph;
+  }
+
+  public void remove(Long[] currentNodes) throws GraphException {
+//    graph.removeFrom012(currentNodes[0], currentNodes[1], currentNodes[2]);
+    graph.removeFrom120(currentNodes[1], currentNodes[2], currentNodes[0]);
+    graph.removeFrom201(currentNodes[2], currentNodes[0], currentNodes[1]);
+  }
+
+  public void clean(Set<Long> subGroup, Map<Long,Set<Long>> subIndex,
+      Map<Long,Map<Long,Set<Long>>> index, Long first, Long second) {
+
+//    // check if a set was cleaned out
+//    if (subGroup.isEmpty()) {
+//      // remove the entry for the set
+//      subIndex.remove(second);
+//      // check if a subindex was cleaned out
+//      if (subIndex.isEmpty()) {
+//        // remove the subindex
+//        index.remove(first);
+//        subIndex = null;
+//      }
+//    }
+  }
+}
\ No newline at end of file

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler120.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler120.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler120.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,97 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.GraphException;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Handles the modification of an index as we iterate through for the 120 index.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public class GraphHandler120 implements GraphHandler {
+  protected GraphImpl graph;
+
+  public GraphHandler120(GraphImpl graph) {
+    this.graph = graph;
+  }
+
+  public void remove(Long[] currentNodes) throws GraphException {
+//    graph.removeFrom012(currentNodes[2], currentNodes[0], currentNodes[1]);
+    graph.removeFrom120(currentNodes[0], currentNodes[1], currentNodes[2]);
+    graph.removeFrom201(currentNodes[1], currentNodes[2], currentNodes[0]);
+  }
+
+  public void clean(Set<Long> subGroup, Map<Long,Set<Long>> subIndex,
+      Map<Long,Map<Long,Set<Long>>> index, Long first, Long second) {
+
+//    // check if a set was cleaned out
+//    if (subGroup.isEmpty()) {
+//      // remove the entry for the set
+//      subIndex.remove(second);
+//      // check if a subindex was cleaned out
+//      if (subIndex.isEmpty()) {
+//        // remove the subindex
+//        index.remove(first);
+//        subIndex = null;
+//      }
+//    }
+  }
+}
\ No newline at end of file

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler201.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler201.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/GraphHandler201.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,83 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.GraphException;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Handles the modification of an index as we iterate through for the 201 index.
+ *
+ * @author Andrew Newman
+ */
+public class GraphHandler201 implements GraphHandler {
+  protected GraphImpl graph;
+
+  public GraphHandler201(GraphImpl graph) {
+    this.graph = graph;
+  }
+
+  public void remove(Long[] currentNodes) throws GraphException {
+    graph.removeFrom012(currentNodes[1], currentNodes[2], currentNodes[0]);
+    graph.removeFrom120(currentNodes[2], currentNodes[0], currentNodes[1]);
+  }
+
+  public void clean(Set<Long> subGroup, Map<Long,Set<Long>> subIndex,
+      Map<Long,Map<Long,Set<Long>>> index, Long first, Long second) {
+    throw new UnsupportedOperationException();
+  }
+}
\ No newline at end of file

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/GraphImpl.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/GraphImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/GraphImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,769 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.*;
+import org.jrdf.util.ClosableIterator;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.*;
+
+/**
+ * A memory based RDF Graph.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public class GraphImpl implements Graph, Serializable {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = -3066836734480153804L;
+
+  // indexes are mapped as:
+  // s -> {p -> {set of o}}
+  // This is defined in the private add() method
+
+  /**
+   * First index.
+   */
+  private Map<Long,Map<Long,Set<Long>>> index012;
+
+  /**
+   * Second index.
+   */
+  private transient Map<Long,Map<Long,Set<Long>>> index120;
+
+  /**
+   * Third index.
+   */
+  private transient Map<Long,Map<Long,Set<Long>>> index201;
+
+  /**
+   * Graph Element Factory.  This caches the node factory.
+   */
+  private transient GraphElementFactoryImpl elementFactory;
+
+  /**
+   * Triple Element Factory.  This caches the element factory.
+   */
+  private transient TripleFactoryImpl tripleFactory;
+
+  /**
+   * Default constructor.
+   *
+   * @throws GraphException There was an error creating the factory.
+   */
+  public GraphImpl() throws GraphException {
+    init();
+  }
+
+  /**
+   * Initialization method used by the constructor and the deserializer.
+   *
+   * @throws GraphException There was an error creating the factory.
+   */
+  private void init() throws GraphException {
+
+    // protect each field allocation with a test for null
+    if (null == index012) {
+      index012 = new HashMap<Long, Map<Long, Set<Long>>>();
+    }
+    if (null == index120) {
+      index120 = new HashMap<Long, Map<Long, Set<Long>>>();
+    }
+    if (null == index201) {
+      index201 = new HashMap<Long, Map<Long, Set<Long>>>();
+    }
+
+    if (null == elementFactory) {
+      try {
+        elementFactory = new GraphElementFactoryImpl(this);
+      } catch (TripleFactoryException e) {
+        throw new GraphException(e);
+      }
+    }
+
+    if (null == tripleFactory) {
+      tripleFactory = new TripleFactoryImpl(this, elementFactory);
+    }
+  }
+
+
+  /**
+   * Test the graph for the occurrence of a statement.  A null value for any
+   * of the parts of a triple are treated as unconstrained, any values will be
+   * returned.
+   * @param subject The subject to find or null to indicate any subject.
+   * @param predicate The predicate to find or null to indicate any predicate.
+   * @param object The object to find or null to indicate any object.
+   * @return True if the statement is found in the model, otherwise false.
+   * @throws GraphException If there was an error accessing the graph.
+   */
+  public boolean contains(SubjectNode subject, PredicateNode predicate, ObjectNode object) throws GraphException {
+
+    // Get local node values
+    Long[] values;
+    try {
+      values = localize(subject, predicate, object);
+    } catch (GraphException ge) {
+
+      // Graph exception on localize implies that the subject, predicate or
+      // object did not exist in the graph.
+      return false;
+    }
+
+    // Return true if all are null and size is greater than zero.
+    if (null == subject && null == predicate && null == object) {
+      return 0 < index012.size();
+    }
+
+    // Subject null.
+    if (null == subject) {
+
+      // Predicate null - was null, null obj.
+      if (null == predicate) {
+        Map<Long,Set<Long>> objIndex = index201.get(values[2]);
+        return null != objIndex;
+      } else {
+        // Predicate is not null.  Could be null, pred, null or null, pred, obj.
+        Map<Long,Set<Long>> predIndex = index120.get(values[1]);
+
+        // If predicate not found return false.
+        if (null == predIndex) return false;
+
+        // If the object is null and we found the predicate return true.
+        if (null == object) {
+          return true;
+        } else {
+          // Was null, pred, obj
+          Set<Long> group = predIndex.get(values[2]);
+          return null != group;
+        }
+      }
+    } else {
+      // Subject is not null.
+      Map<Long,Set<Long>> subIndex = index012.get(values[0]);
+
+      // If subject not found return false.
+      if (null == subIndex) return false;
+
+      // Predicate null.  Could be subj, null, null or subj, null, obj.
+      if (null == predicate) {
+
+        // If object null then we've found all we need to find.
+        if (null == object) {
+          return true;
+        } else {
+          // If the object is not null we need to find subj, null, obj
+          Map<Long,Set<Long>> objIndex = index201.get(values[2]);
+
+          if (null == objIndex) return false;
+
+          Set<Long> group = objIndex.get(values[0]);
+          return null != group;
+        }
+      } else {
+        // Predicate not null.  Could be subj, pred, obj or subj, pred, null.
+
+        // look up the predicate
+        Set<Long> group = subIndex.get(values[1]);
+        if (null == group) return false;
+
+        // Object not null.  Must be subj, pred, obj.
+        if (null != object) {
+          return group.contains(values[2]);
+        } else {
+          // Was subj, pred, null - must be true if we get this far.
+          return true;
+        }
+      }
+    }
+  }
+
+
+  /**
+   * Test the graph for the occurrence of the triple.  A null value for any
+   * of the parts of a triple are treated as unconstrained, any values will be
+   * returned.
+   *
+   * @param triple The triple to find.
+   * @return True if the triple is found in the graph, otherwise false.
+   * @throws GraphException If there was an error accessing the graph.
+   */
+  public boolean contains(Triple triple) throws GraphException {
+    return contains(triple.getSubject(), triple.getPredicate(),
+        triple.getObject());
+  }
+
+
+  /**
+   * Returns an iterator to a set of statements that match a given subject,
+   * predicate and object.  A null value for any of the parts of a triple are
+   * treated as unconstrained, any values will be returned.
+   * @param subject The subject to find or null to indicate any subject.
+   * @param predicate The predicate to find or null to indicate any predicate.
+   * @param object ObjectNode The object to find or null to indicate any object.
+   * @throws GraphException If there was an error accessing the graph.
+   */
+  public ClosableIterator<Triple> find(SubjectNode subject, PredicateNode predicate,
+      ObjectNode object) throws GraphException {
+
+    // Get local node values
+    Long[] values;
+    try {
+      values = localize(subject, predicate, object);
+    } catch (GraphException ge) {
+
+      // A graph exception implies that the subject, predicate or object does
+      // not exist in the graph.
+      return new EmptyClosableIterator<Triple>();
+    }
+
+    // test which index to use
+    if (null != subject) {
+      // test for {sp*}
+      if (null != predicate) {
+        // test for {spo}
+        if (null != object) {
+          // got {spo}
+          return new ThreeFixedIterator(this, subject, predicate, object);
+        } else {
+          // got {sp*}
+          return new TwoFixedIterator(index012, 0, values[0], values[1],
+              elementFactory, new GraphHandler012(this), index012.get(values[0]));
+        }
+      } else {
+        // test for {s**}
+        if (null == object) {
+          return new OneFixedIterator(index012, 0, values[0], elementFactory,
+              new GraphHandler012(this), index012.get(values[0]));
+        }
+        // {s*o} so fall through
+      }
+    }
+
+    if (null != predicate) {
+      // test for {*po}
+      if (null != object) {
+        return new TwoFixedIterator(index120, 2, values[1], values[2],
+            elementFactory, new GraphHandler120(this), index120.get(values[1]));
+      } else {
+        // test for {*p*}.  {sp*} should have been picked up above
+        assert null == subject;
+        return new OneFixedIterator(index120, 2, values[1], elementFactory,
+            new GraphHandler120(this), index120.get(values[1]));
+      }
+    }
+
+    if (null != object) {
+      // test for {s*o}
+      if (null != subject) {
+        return new TwoFixedIterator(index201, 1, values[2], values[0],
+            elementFactory, new GraphHandler201(this), index201.get(values[2]));
+      } else {
+        // test for {**o}.  {*po} should have been picked up above
+        assert null == predicate;
+        return new OneFixedIterator(index201, 1, values[2], elementFactory,
+            new GraphHandler201(this), index201.get(values[2]));
+      }
+    }
+
+    // {***} so return entire graph
+    return new GraphIterator(index012.entrySet().iterator(), elementFactory,
+        new GraphHandler012(this));
+  }
+
+
+  /**
+   * Returns an iterator to a set of statements that match a given subject,
+   * predicate and object.  A null value for any of the parts of a triple are
+   * treated as unconstrained, any values will be returned.
+   * @param triple The triple to find.
+   * @throws GraphException If there was an error accessing the graph.
+   */
+  public ClosableIterator<Triple> find(Triple triple) throws GraphException {
+    return find(triple.getSubject(), triple.getPredicate(), triple.getObject());
+  }
+
+  /**
+   * Adds a triple to the graph.
+   *
+   * @param subject The subject.
+   * @param predicate The predicate.
+   * @param object The object.
+   * @throws GraphException If the statement can't be made.
+   */
+  public void add(SubjectNode subject, PredicateNode predicate, ObjectNode object) throws GraphException {
+
+    // Get local node values also tests that it's a valid subject, predicate and object.
+    Long[] values = localize(subject, predicate, object);
+
+    // add to the first index
+    add(index012, values[0], values[1], values[2]);
+
+    // try and back out changes if an insertion fails
+    try {
+      // add to the second index
+      add(index120, values[1], values[2], values[0]);
+      try {
+        // add to the third index
+        add(index201, values[2], values[0], values[1]);
+      } catch (GraphException e) {
+        removeFrom120(values[1], values[2], values[0]);
+        throw e;
+      }
+    } catch (GraphException e) {
+      removeFrom012(values[0], values[1], values[2]);
+      throw e;
+    }
+  }
+
+
+  /**
+   * Adds a triple to the graph.
+   * @param triple The triple.
+   * @throws GraphException If the statement can't be made.
+   */
+  public void add(Triple triple) throws GraphException {
+    add(triple.getSubject(), triple.getPredicate(), triple.getObject());
+  }
+
+
+  /**
+   * Adds an iterator containing triples into the graph.
+   * @param triples The triple iterator.
+   * @throws GraphException If the statements can't be made.
+   */
+  public void add(Iterator<Triple> triples) throws GraphException {
+    while (triples.hasNext()) add(triples.next());
+  }
+
+
+  /**
+   * Removes a triple from the graph.
+   * @param subject The subject.
+   * @param predicate The predicate.
+   * @param object The object.
+   * @throws GraphException If there was an error revoking the statement, for
+   *         example if it didn't exist.
+   */
+  public void remove(SubjectNode subject, PredicateNode predicate, ObjectNode object) throws GraphException {
+
+    // Get local node values also tests that it's a valid subject, predicate
+    // and object.
+    Long[] values = localize(subject, predicate, object);
+
+    removeFrom012(values[0], values[1], values[2]);
+    // if the first one succeeded then try and attempt removal on both of the others
+    try {
+      removeFrom120(values[1], values[2], values[0]);
+    } finally {
+      removeFrom201(values[2], values[0], values[1]);
+    }
+  }
+
+
+  /**
+   * Removes a triple from the graph.
+   * @param triple The triple.
+   * @throws GraphException If there was an error revoking the statement, for
+   *         example if it didn't exist.
+   */
+  public void remove(Triple triple) throws GraphException {
+    remove(triple.getSubject(), triple.getPredicate(), triple.getObject());
+  }
+
+
+  /**
+   * Removes an iterator containing triples from the graph.
+   * @param triples The triple iterator.
+   * @throws GraphException If the statements can't be revoked.
+   */
+  public void remove(Iterator<Triple> triples) throws GraphException {
+    while (triples.hasNext()) remove(triples.next());
+  }
+
+
+  /**
+   * Returns the node factory for the graph, or creates one.
+   * @return the node factory for the graph, or creates one.
+   */
+  public GraphElementFactory getElementFactory() {
+    return elementFactory;
+  }
+
+
+  /**
+   * Returns the triple factory for the graph, or creates one.
+   * @return the triple factory for the graph, or creates one.
+   */
+  public TripleFactory getTripleFactory() {
+    return tripleFactory;
+  }
+
+
+  /**
+   * Returns the number of triples in the graph.
+   * @return the number of triples in the graph.
+   */
+  public long getNumberOfTriples() throws GraphException {
+    long size = 0;
+    // go over the index map
+    Iterator<Map<Long,Set<Long>>> first = index012.values().iterator();
+    while (first.hasNext()) {
+      // go over the sub indexes
+      Iterator<Set<Long>> second = first.next().values().iterator();
+      while (second.hasNext()) {
+        // accumulate the sizes of the groups
+        size += second.next().size();
+      }
+    }
+    return size;
+  }
+
+
+  /**
+   * Returns true if the graph is empty i.e. the number of triples is 0.
+   * @return true if the graph is empty i.e. the number of triples is 0.
+   */
+  public boolean isEmpty() throws GraphException {
+    return index012.isEmpty();
+  }
+
+
+  /**
+   * Closes any underlying resources used by this graph.
+   */
+  public void close() {
+    // no op
+  }
+
+
+  /**
+   * Adds a triple to a single index.
+   * @param first The first node.
+   * @param second The second node.
+   * @param third The last node.
+   * @throws GraphException If there was an error adding the statement.
+   */
+  private Long[] localize(Node first, Node second, Node third) throws GraphException {
+
+    Long[] localValues = new Long[3];
+
+    // convert the nodes to local memory nodes for convenience
+    if (null != first) {
+      if (first instanceof BlankNodeImpl) {
+        localValues[0] = ((BlankNodeImpl) first).getId();
+      } else {
+        localValues[0] = elementFactory.getNodeIdByString(String.valueOf(first));
+      }
+
+      if (null == localValues[0]) {
+        throw new GraphException("Subject does not exist in graph");
+      }
+    }
+
+    if (null != second) {
+      localValues[1] = elementFactory.getNodeIdByString(String.valueOf(second));
+
+      if (null == localValues[1]) {
+        throw new GraphException("Predicate does not exist in graph");
+      }
+    }
+
+    if (null != third) {
+      if (third instanceof BlankNodeImpl) {
+        localValues[2] = ((BlankNodeImpl)third).getId();
+      } else if (third instanceof LiteralImpl) {
+        localValues[2] = elementFactory.getNodeIdByString(((LiteralImpl)third).getEscapedForm());
+      } else {
+        localValues[2] = elementFactory.getNodeIdByString(String.valueOf(third));
+      }
+
+      if (null == localValues[2]) {
+        throw new GraphException("Object does not exist in graph");
+      }
+    }
+
+    return localValues;
+  }
+
+
+  /**
+   * Adds a triple to a single index.  This method defines the internal structure.
+   * @param index The index to add the statement to.
+   * @param first The first node id.
+   * @param second The second node id.
+   * @param third The last node id.
+   * @throws GraphException If there was an error adding the statement.
+   */
+  private void add(Map<Long,Map<Long,Set<Long>>> index, Long first, Long second, Long third) throws GraphException {
+    // find the sub index
+    Map<Long,Set<Long>> subIndex = index.get(first);
+    // check that the subindex exists
+    if (null == subIndex) {
+      // no, so create it and add it to the index
+      subIndex = new HashMap<Long,Set<Long>>();
+      index.put(first, subIndex);
+    }
+
+    // find the final group
+    Set<Long> group = subIndex.get(second);
+    // check that the group exists
+    if (null == group) {
+      // no, so create it and add it to the subindex
+      group = new HashSet<Long>();
+      subIndex.put(second, group);
+    }
+
+    // Add the final node to the group
+    group.add(third);
+  }
+
+
+  void removeFrom012(Long first, Long second, Long third) throws GraphException {
+    remove(index012, first, second, third);
+  }
+
+
+  void removeFrom120(Long first, Long second, Long third) throws GraphException {
+    remove(index120, first, second, third);
+  }
+
+
+  void removeFrom201(Long first, Long second, Long third) throws GraphException {
+    remove(index201, first, second, third);
+  }
+
+
+  /**
+   * Removes a triple from a single index.
+   * @param index The index to remove the statement from.
+   * @param first The first node.
+   * @param second The second node.
+   * @param third The last node.
+   * @throws GraphException If there was an error revoking the statement, for
+   *     example if it didn't exist.
+   */
+  private void remove(Map<Long,Map<Long,Set<Long>>> index, Long first, Long second, Long third) throws GraphException {
+
+    // find the sub index
+    Map<Long,Set<Long>> subIndex = index.get(first);
+    // check that the subindex exists
+    if (null == subIndex) {
+      throw new GraphException("Unable to remove nonexistent statement");
+    }
+    // find the final group
+    Set<Long> group = subIndex.get(second);
+    // check that the group exists
+    if (null == group) {
+      throw new GraphException("Unable to remove nonexistent statement");
+    }
+    // remove from the group, report error if it didn't exist
+    if (!group.remove(third)) {
+      throw new GraphException("Unable to remove nonexistent statement");
+    }
+    // clean up the graph
+    if (group.isEmpty()) {
+      subIndex.remove(second);
+      if (subIndex.isEmpty()) index.remove(first);
+    }
+  }
+
+
+  /**
+   * Serializes the current object to a stream.
+   * @param out The stream to write to.
+   * @throws IOException If an I/O error occurs while writing.
+   */
+  private void writeObject(ObjectOutputStream out) throws IOException {
+    // write out the first index with the default writer
+    out.defaultWriteObject();
+    // write all the nodes as well
+    out.writeObject(elementFactory.getNodePool().toArray());
+    // TODO: Consider writing these nodes individually.  Converting to an array
+    // may take up unnecessary memory
+  }
+
+
+  /**
+   * Deserializes an object from a stream.
+   * @param in The stream to read from.
+   * @throws IOException If an I/O error occurs while reading.
+   */
+  private void readObject(ObjectInputStream in) throws IOException,
+      ClassNotFoundException {
+    // read in the first index with the default reader
+    in.defaultReadObject();
+    // initialize the fields not yet done by the constructor
+    try {
+      init();
+    } catch (GraphException e) {
+      throw new ClassNotFoundException("Unable to initialize a new graph", e);
+    }
+
+    // read all the nodes as well
+    Object[] nodes = (Object[])in.readObject();
+
+    try {
+      // test node factory creation in case the constructor did it
+      if (null == elementFactory) elementFactory = new GraphElementFactoryImpl(this);
+    } catch (TripleFactoryException e) {
+      throw new ClassNotFoundException("Unable to build NodeFactory", e);
+    }
+    // populate the node factory with these nodes
+    for (int n = 0; n < nodes.length; n++) elementFactory.registerNode((MemNode)nodes[n]);
+
+    // fill in the other indexes
+    try {
+      // iterate over the first column
+      Iterator<Map.Entry<Long,Map<Long,Set<Long>>>> firstEntries = index012.entrySet().iterator();
+      while (firstEntries.hasNext()) {
+        Map.Entry<Long,Map<Long,Set<Long>>> firstEntry = firstEntries.next();
+        Long first = firstEntry.getKey();
+        // now iterate over the second column
+        Iterator<Map.Entry<Long,Set<Long>>> secondEntries = firstEntry.getValue().entrySet().iterator();
+        while (secondEntries.hasNext()) {
+          Map.Entry<Long,Set<Long>> secondEntry = secondEntries.next();
+          Long second = secondEntry.getKey();
+          // now iterate over the third column
+          Iterator<Long> thirdValues = secondEntry.getValue().iterator();
+          while (thirdValues.hasNext()) {
+            Long third = thirdValues.next();
+            // now add the row to the other two indexes
+            add(index120, second, third, first);
+            add(index201, third, first, second);
+          }
+        }
+      }
+    } catch (GraphException e) {
+      throw new ClassNotFoundException("Unable to add to a graph index", e);
+    }
+  }
+
+
+  /**
+   * Debug method to see the current state of the first index.
+   * @param index The index to display
+   */
+  static void dumpIndex(Map<Long,Map<Long,Set<Long>>> index) {
+    Iterator<Map.Entry<Long,Map<Long,Set<Long>>>> iterator = index.entrySet().iterator();
+    while (iterator.hasNext()) {
+      Map.Entry<Long,Map<Long,Set<Long>>> subjectEntry = iterator.next();
+      Long subject = (Long) subjectEntry.getKey();
+      int sWidth = subject.toString().length() + 5;
+      System.out.print(subject.toString() + " --> ");
+
+      Map<Long,Set<Long>> secondIndex = subjectEntry.getValue();
+      if (secondIndex.isEmpty()) {
+        System.out.println("X");
+        continue;
+      }
+      boolean firstPredicate = true;
+
+      Iterator<Map.Entry<Long,Set<Long>>> predIterator = secondIndex.entrySet().iterator();
+      while (predIterator.hasNext()) {
+        Map.Entry<Long,Set<Long>> predicateEntry = predIterator.next();
+        Long predicate = predicateEntry.getKey();
+        int pWidth = predicate.toString().length() + 5;
+        if (!firstPredicate) {
+          StringBuilder space = new StringBuilder(sWidth);
+          space.setLength(sWidth);
+          for (int c = 0; c < sWidth; c++) space.setCharAt(c, ' ');
+          System.out.print(space.toString());
+        } else {
+          firstPredicate = false;
+        }
+        System.out.print(predicate.toString() + " --> ");
+
+        Set<Long> thirdIndex = predicateEntry.getValue();
+        if (thirdIndex.isEmpty()) {
+          System.out.println("X");
+          continue;
+        }
+        boolean firstObject = true;
+
+        Iterator<Long> objIterator = thirdIndex.iterator();
+        while (objIterator.hasNext()) {
+          Long object = objIterator.next();
+          if (!firstObject) {
+            StringBuilder sp2 = new StringBuilder(sWidth + pWidth);
+            sp2.setLength(sWidth + pWidth);
+            for (int d = 0; d < sWidth + pWidth; d++) sp2.setCharAt(d, ' ');
+            System.out.print(sp2.toString());
+          } else {
+            firstObject = false;
+          }
+          System.out.println(object);
+        }
+      }
+    }
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/GraphImplUnitTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/GraphImplUnitTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/GraphImplUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,187 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.jrdf.graph.AbstractGraphTest;
+import org.jrdf.graph.Graph;
+import org.jrdf.graph.Literal;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * Implementation of {@link AbstractGraphTest} test case.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public class GraphImplUnitTest extends AbstractGraphTest {
+
+  /**
+   * Constructs a new test with the given name.
+   *
+   * @param name the name of the test
+   */
+  private GraphImplUnitTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Create a graph implementation.
+   *
+   * @return A new GraphImplUnitTest.
+   */
+  public Graph newGraph() throws Exception {
+    return new GraphImpl();
+  }
+
+  /**
+   * Hook for test runner to obtain a test suite from.
+   *
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new GraphImplUnitTest("testEmpty"));
+    suite.addTest(new GraphImplUnitTest("testFactory"));
+    suite.addTest(new GraphImplUnitTest("testAddition"));
+    suite.addTest(new GraphImplUnitTest("testRemoval"));
+    suite.addTest(new GraphImplUnitTest("testContains"));
+    suite.addTest(new GraphImplUnitTest("testFinding"));
+    suite.addTest(new GraphImplUnitTest("testIteration"));
+    suite.addTest(new GraphImplUnitTest("testIterativeRemoval"));
+    suite.addTest(new GraphImplUnitTest("testFullIterativeRemoval"));
+    suite.addTest(new GraphImplUnitTest("testSerializing"));
+    return suite;
+  }
+
+  /**
+   * Default test runner.
+   *
+   * @param args The command line arguments
+   */
+  public static void main(String[] args) throws Exception {
+
+    TestRunner.run(suite());
+  }
+
+  /**
+   * Implementation method for testing serialization of the graph.
+   *
+   * @throws Exception When a problem is found.
+   */
+  public void testSerializing() throws Exception {
+    // populate the graph
+    graph.add(blank1, ref1, blank2);
+    graph.add(blank1, ref2, blank2);
+    graph.add(blank1, ref1, l1);
+    graph.add(blank1, ref1, l2);
+    graph.add(blank2, ref1, blank2);
+    graph.add(blank2, ref2, blank2);
+    graph.add(blank2, ref1, l1);
+    graph.add(blank2, ref1, l2);
+    graph.add(blank2, ref1, l2);
+    graph.add(ref1, ref1, ref1);
+
+    // check that the graph is as expected
+    assertEquals(9, graph.getNumberOfTriples());
+
+    // create an in-memory output stream
+    ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
+    ObjectOutputStream os = new ObjectOutputStream(outputBytes);
+
+    // write the graph
+    os.writeObject(graph);
+
+    // read a new graph back in
+    ByteArrayInputStream inputBytes = new ByteArrayInputStream(outputBytes.toByteArray());
+    ObjectInputStream is = new ObjectInputStream(inputBytes);
+
+    // read the graph
+    Graph graph2 = (Graph) is.readObject();
+
+    ref3 = graph2.getElementFactory().createResource(ref1.getURI());
+    Literal l3 = graph2.getElementFactory().createLiteral(l1.getLexicalForm());
+
+    // test that the graphs are equivalent
+    assertEquals(graph.getNumberOfTriples(), graph2.getNumberOfTriples());
+    assertTrue(graph2.contains(blank1, ref1, blank2));
+    assertTrue(graph2.contains(blank1, ref2, blank2));
+    assertTrue(graph2.contains(blank1, ref1, l1));
+    assertTrue(graph2.contains(blank1, ref1, l2));
+    assertTrue(graph2.contains(blank2, ref1, blank2));
+    assertTrue(graph2.contains(blank2, ref2, blank2));
+    assertTrue(graph2.contains(blank2, ref1, l1));
+    assertTrue(graph2.contains(blank2, ref3, l2));
+    assertTrue(graph2.contains(blank1, ref3, l3));
+    assertTrue(graph2.contains(ref1, ref1, ref1));
+    assertTrue(graph2.contains(null, ref1, null));
+    assertTrue(graph2.contains(ref3, ref3, ref3));
+    assertTrue(graph2.contains(null, ref3, null));
+    assertTrue(graph2.contains(null, ref3, l3));
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/GraphIterator.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/GraphIterator.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/GraphIterator.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,261 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.GraphElementFactory;
+import org.jrdf.graph.GraphException;
+import org.jrdf.graph.Triple;
+import org.jrdf.util.ClosableIterator;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * An iterator that iterates over an entire graph.
+ * Relies on internal iterators which iterate over all entries in
+ * the first map, the maps it points to, and the sets they point to.
+ * The itemIterator  is used to indicate the current position.
+ * It will always be set to return the next value until it reaches
+ * the end of the graph.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @author Andrew Newman
+ */
+public class GraphIterator implements ClosableIterator<Triple> {
+
+  /** The iterator for the first index. */
+  private Iterator<Map.Entry<Long,Map<Long,Set<Long>>>> iterator;
+
+  /** The iterator for the second index. */
+  private Iterator<Map.Entry<Long,Set<Long>>> subIterator;
+
+  /** The iterator for the third index. */
+  private Iterator<Long> itemIterator;
+
+  /** The current element for the iterator on the first index. */
+  private Map.Entry<Long,Map<Long,Set<Long>>> firstEntry;
+
+  /** The current element for the iterator on the second index. */
+  private Map.Entry<Long,Set<Long>> secondEntry;
+
+  /** The current subject predicate and object, last returned from next().  Only needed by the remove method. */
+  private Long[] currentNodes;
+
+  /** The nodeFactory used to create the nodes to be returned in the triples. */
+  private GraphElementFactoryImpl nodeFactory;
+
+  /** Handles the removal of nodes */
+  private GraphHandler handler;
+  private boolean nextCalled = false;
+
+  /**
+   * Constructor.  Sets up the internal iterators.
+   * @throws IllegalArgumentException Must be created with implementations from
+   *   the memory package.
+   */
+  GraphIterator(Iterator<Map.Entry<Long,Map<Long,Set<Long>>>> newIterator, GraphElementFactory newNodeFactory, GraphHandler newHandler) {
+    if (!(newNodeFactory instanceof GraphElementFactoryImpl)) {
+      throw new IllegalArgumentException("Node factory must be a memory implementation");
+    }
+
+    // store the node factory
+    nodeFactory = (GraphElementFactoryImpl) newNodeFactory;
+    handler = newHandler;
+    iterator = newIterator;
+  }
+
+
+  /**
+   * Returns true if the iteration has more elements.
+   * @return <code>true</code> If there is an element to be read.
+   */
+  public boolean hasNext() {
+    // confirm we still have an item iterator, and that it has data available
+    return null != itemIterator && itemIterator.hasNext() ||
+        null != subIterator && subIterator.hasNext() ||
+        null != iterator && iterator.hasNext();
+  }
+
+
+  /**
+   * Returns the next element in the iteration.
+   *
+   * @return the next element in the iteration.
+   * @throws NoSuchElementException iteration has no more elements.
+   */
+  public Triple next() throws NoSuchElementException {
+    if (null == iterator) throw new NoSuchElementException();
+
+    // move to the next position
+    updatePosition();
+
+    if (null == iterator) throw new NoSuchElementException();
+
+    nextCalled = true;
+
+    // get the next item
+    Long third = itemIterator.next();
+
+    // construct the triple
+    Long second = secondEntry.getKey();
+    Long first = firstEntry.getKey();
+
+    // get back the nodes for these IDs and uild the triple
+    currentNodes = new Long[]{first, second, third};
+    return new TripleImpl((GraphElementFactoryImpl) nodeFactory, first, second, third);
+  }
+
+
+  /**
+   * Helper method to move the iterators on to the next position.
+   * If there is no next position then {@link #itemIterator itemIterator}
+   * will be set to null, telling {@link #hasNext() hasNext} to return
+   * <code>false</code>.
+   */
+  private void updatePosition() {
+    // progress to the next item if needed
+    if (null == itemIterator || !itemIterator.hasNext()) {
+      // the current iterator been exhausted
+      if (null == subIterator || !subIterator.hasNext()) {
+        // the subiterator has been exhausted
+        if (!iterator.hasNext()) {
+          // the main iterator has been exhausted
+          // tell the iterator to finish
+          iterator = null;
+          return;
+        }
+        // move on the main iterator
+        firstEntry = iterator.next();
+        // now get an iterator to the sub index map
+        subIterator = firstEntry.getValue().entrySet().iterator();
+        assert subIterator.hasNext();
+      }
+      // get the next entry of the sub index
+      secondEntry = subIterator.next();
+      // get an interator to the next set from the sub index
+      itemIterator = secondEntry.getValue().iterator();
+      assert itemIterator.hasNext();
+    }
+  }
+
+
+  /**
+   * Implemented for java.util.Iterator.
+   */
+  public void remove() {
+    if (nextCalled && null != itemIterator) {
+      itemIterator.remove();
+      // clean up the current index after the removal
+      cleanIndex();
+      // now remove from the other 2 indexes
+      removeFromNonCurrentIndex();
+    } else {
+      throw new IllegalStateException("Next not called or beyond end of data");
+    }
+  }
+
+
+  /**
+   * Checks if a removed item is the last of its type, and removes any associated subindexes if appropriate.
+   */
+  private void cleanIndex() {
+    // check if a set was cleaned out
+    Set<Long> subGroup = secondEntry.getValue();
+    Map<Long,Set<Long>> subIndex = firstEntry.getValue();
+    if (subGroup.isEmpty()) {
+      // remove the entry for the set
+      subIterator.remove();
+      // check if a subindex was cleaned out
+      if (subIndex.isEmpty()) {
+        // remove the subindex
+        iterator.remove();
+      }
+    }
+    //handler.clean(secondEntry, subIterator, subIndex, );
+  }
+
+
+  /**
+   * Helper function for removal.  This removes the current statement from the indexes which
+   * the current iterator is not associated with.
+   */
+  private void removeFromNonCurrentIndex() {
+    try {
+      // can instead use var here to determine how to delete, but this is more intuitive
+      handler.remove(currentNodes);
+    } catch (GraphException ge) {
+      IllegalStateException illegalStateException = new IllegalStateException();
+      illegalStateException.setStackTrace(ge.getStackTrace());
+      throw illegalStateException;
+    }
+  }
+
+
+  /**
+   * Closes the iterator by freeing any resources that it current holds.
+   * Nothing to be done for this class.
+   * @return <code>true</code> indicating success.
+   */
+  public boolean close() {
+    return true;
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/LiteralImpl.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/LiteralImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/LiteralImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,163 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+// Java 2 standard
+import org.jrdf.graph.AbstractLiteral;
+
+import java.net.URI;
+
+/**
+ * RDF literal node.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ *
+ * @version $Revision: 624 $
+ */
+public class LiteralImpl extends AbstractLiteral implements MemNode {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = -6515350357124372641L;
+
+  /**
+   * The internal identifier for this node.
+   */
+  private Long id;
+
+  /**
+   * A cache of the toString value for efficiency in mapping.
+   */
+  private String thisString;
+
+  /**
+   * Construct a literal.
+   *
+   * @param newLexicalForm  the text part of the literal
+   * @throws IllegalArgumentException if <var>newLexicalForm</var> is <code>null</code>
+   */
+  LiteralImpl(String newLexicalForm) {
+    super(newLexicalForm);
+    thisString = super.toString();
+  }
+
+  /**
+   * Construct a fully general literal.
+   *
+   * @param newLexicalForm  the text part of the literal
+   * @param newLanguage  the language code, possibly the empty string but not
+   *    <code>null</code>
+   * @throws IllegalArgumentException if <var>lexicalForm</var> or
+   *    <var>lang</var> are <code>null</code>
+   */
+  LiteralImpl(String newLexicalForm, String newLanguage) {
+    super(newLexicalForm, newLanguage);
+    thisString = super.toString();
+  }
+
+
+  /**
+   * Construct a fully general literal.
+   *
+   * @param newLexicalForm  the text part of the literal
+   * @param datatype  the URI for a datatyped literal, or <code>null</code> for
+   *     an untyped literal
+   * @throws IllegalArgumentException if <var>newLexicalForm</var> or
+   *     <var>lang</var> are <code>null</code>
+   */
+  LiteralImpl(String newLexicalForm, URI datatype) {
+    super(newLexicalForm, datatype);
+    thisString = super.toString();
+  }
+
+
+  /**
+   * Retrieves an internal identifier for this node.
+   *
+   * @return A numeric identifier for thisa node.
+   */
+  public Long getId() {
+    return id;
+  }
+
+  /**
+   * Sets the interanl identifier for this node.
+   *
+   * @param newId new id.
+   */
+  public void setId(Long newId) {
+    id = newId;
+  }
+
+  /**
+   * Provide a legible representation of a literal.  Caches the immutable value
+   * so it gets mapped efficiently.
+   *
+   * @return the <var>lexicalForm</var> property, enclosed in <code>"</code>
+   *     characters.
+   */
+  public String toString() {
+    return thisString;
+  }
+}
+

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/MemNode.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/MemNode.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/MemNode.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,82 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import java.io.Serializable;
+
+import org.jrdf.graph.Node;
+
+/**
+ * Memory node.  This is an additional interface for nodes so they can be accessed by id.
+ * Extends {@link Serializable} so all nodes will be serializable.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ *
+ * @version $Revision: 624 $
+ */
+public interface MemNode extends Node, Serializable {
+
+  /**
+   * Retrieves an internal identifier for a node.
+   *
+   * @return A numeric identifier for a node.
+   */
+  Long getId();
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/OneFixedIterator.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/OneFixedIterator.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/OneFixedIterator.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,248 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.GraphElementFactory;
+import org.jrdf.graph.GraphException;
+import org.jrdf.graph.Triple;
+import org.jrdf.util.ClosableIterator;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * An iterator that iterates over a group with a single fixed node.
+ * Relies on internal iterators which iterate over all entries in
+ * a submap, and the sets they point to.
+ * The thirdIndexIterator is used to indicate the current position.
+ * It will always be set to return the next value until it reaches
+ * the end of the group.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @author Andrew Newman
+ */
+public class OneFixedIterator implements ClosableIterator<Triple> {
+
+  /** The iterator for the second index. */
+  private Iterator<Map.Entry<Long,Set<Long>>> secondIndexIterator;
+
+  /** The iterator for the third index. */
+  private Iterator<Long> thirdIndexIterator;
+
+  /** The current element for the iterator on the second index. */
+  private Map.Entry<Long,Set<Long>> secondEntry;
+
+  /** The factory used to create the nodes to be returned in the triples. */
+  private GraphElementFactoryImpl factory;
+
+  /** The index of this iterator.  Only needed for initialization and the remove method. */
+  private Map<Long,Map<Long,Set<Long>>> index;
+
+  /** The subIndex of this iterator.  Only needed for initialization and the remove method. */
+  private Map<Long,Set<Long>> subIndex;
+
+  /** The fixed item. */
+  private Long first;
+
+  /** The offset for the index. */
+  private int var;
+
+  /** The current subject predicate and object, last returned from next().  Only needed by the remove method. */
+  private Long[] currentNodes;
+
+  /** Handles the removal of nodes */
+  private GraphHandler handler;
+
+
+  /**
+   * Constructor.  Sets up the internal iterators.
+   * @throws IllegalArgumentException Must pass in a GraphElementFactory memory implementation.
+   */
+  OneFixedIterator(Map<Long,Map<Long,Set<Long>>> newIndex, int newVar, Long newFirst,
+      GraphElementFactory newFactory, GraphHandler newHandler, Map<Long,Set<Long>> newSubIndex) {
+    if (!(newFactory instanceof GraphElementFactoryImpl)) {
+      throw new IllegalArgumentException("Must use the memory implementation of GraphElementFactory");
+    }
+
+    // store the node factory and other starting data
+    factory = (GraphElementFactoryImpl)newFactory;
+    handler = newHandler;
+
+    first = newFirst;
+    var = newVar;
+    index = newIndex;
+    currentNodes = null;
+    // initialise the iterators to empty
+    thirdIndexIterator = null;
+    secondIndexIterator = null;
+    // find the subIndex from the main index
+    subIndex = newSubIndex;
+    // check that data exists
+    if (null != subIndex) {
+      // now get an iterator to the sub index map
+      secondIndexIterator = subIndex.entrySet().iterator();
+      // check if there is data available - structural constraints say there should be
+      assert secondIndexIterator.hasNext();
+    }
+  }
+
+
+  /**
+   * Returns true if the iteration has more elements.
+   * @return <code>true</code> If there is an element to be read.
+   */
+  public boolean hasNext() {
+    // confirm we still have an item iterator, and that it has data available
+    return null != thirdIndexIterator && thirdIndexIterator.hasNext() ||
+        null != secondIndexIterator && secondIndexIterator.hasNext();
+  }
+
+
+  /**
+   * Returns the next element in the iteration.
+   * @return the next element in the iteration.
+   * @throws NoSuchElementException iteration has no more elements.
+   */
+  public Triple next() throws NoSuchElementException {
+    if (null == secondIndexIterator) {
+      throw new NoSuchElementException();
+    }
+    // move to the next position
+    updatePosition();
+    if (null == secondIndexIterator) {
+      throw new NoSuchElementException();
+    }
+    // get the next item
+    Long third = thirdIndexIterator.next();
+    // construct the triple
+    Long second = secondEntry.getKey();
+    // get back the nodes for these IDs and build the triple
+    currentNodes = new Long[]{first, second, third};
+    return new TripleImpl(factory, var, first, second, third);
+  }
+
+
+  /**
+   * Helper method to move the iterators on to the next position.
+   * If there is no next position then {@link #thirdIndexIterator thirdIndexIterator}
+   * will be set to null, telling {@link #hasNext() hasNext} to return
+   * <code>false</code>.
+   */
+  private void updatePosition() {
+    // progress to the next item if needed
+    if (null == thirdIndexIterator || !thirdIndexIterator.hasNext()) {
+      // the current iterator been exhausted
+      if (!secondIndexIterator.hasNext()) {
+        // the subiterator has been exhausted
+        // tell the secondIndexIterator to finish
+        secondIndexIterator = null;
+        return;
+      }
+      // get the next entry of the sub index
+      secondEntry = secondIndexIterator.next();
+      // get an iterator to the next set from the sub index
+      thirdIndexIterator = secondEntry.getValue().iterator();
+      assert thirdIndexIterator.hasNext();
+    }
+  }
+
+
+  /**
+   * Implemented for java.util.Iterator.
+   */
+  public void remove() {
+    if (null != thirdIndexIterator) {
+      // now remove from the other 2 indexes
+      try {
+        thirdIndexIterator.remove();
+        handler.remove(currentNodes);
+
+        // check if a set was cleaned out
+        Set<Long> subGroup = secondEntry.getValue();
+        if (subGroup.isEmpty()) {
+          // remove the entry for the set
+          secondIndexIterator.remove();
+          // check if a subindex was cleaned out
+          if (subIndex.isEmpty()) {
+            // remove the subindex
+            index.remove(first);
+            subIndex = null;
+          }
+        }
+      } catch (GraphException ge) {
+        throw new IllegalStateException(ge.getMessage());
+      }
+    } else {
+      throw new IllegalStateException("Next not called or beyond end of data");
+    }
+  }
+
+
+  /**
+   * Closes the iterator by freeing any resources that it current holds.
+   * Nothing to be done for this class.
+   * @return <code>true</code> indicating success.
+   */
+  public boolean close() {
+    return true;
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/SequenceImpl.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/SequenceImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/SequenceImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,173 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+// Java 2 standard packages
+
+import org.jrdf.graph.ObjectNode;
+import org.jrdf.graph.Sequence;
+
+import java.util.ArrayList;
+
+/**
+ * An implementation of {@link Sequence}.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public class SequenceImpl extends ArrayList<ObjectNode> implements Sequence {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = -8659292687902645229L;
+
+  public SequenceImpl() {
+  }
+
+
+  /**
+   * @throws IllegalArgumentException if the given object is not the correct
+   *   type, Sequence.
+   */
+  public boolean addAll(java.util.Collection<? extends ObjectNode> c)
+      throws IllegalArgumentException {
+    if (!(c instanceof Sequence)) {
+      throw new IllegalArgumentException("Can only add sequences to other " +
+          "sequences");
+    }
+
+    return super.addAll(c);
+  }
+
+  public boolean addAll(Sequence s) throws IllegalArgumentException {
+    return super.addAll(s);
+  }
+
+  public boolean addAll(int index, java.util.Collection<? extends ObjectNode> c) throws
+      IllegalArgumentException {
+    if (!(c instanceof Sequence)) {
+      throw new IllegalArgumentException("Can only add sequences to other sequences");
+    }
+
+    return super.addAll(index, c);
+  }
+
+  public boolean addAll(int index, Sequence s) {
+    return super.addAll(index, s);
+  }
+
+  public boolean containsAll(java.util.Collection<?> c) {
+    if (!(c instanceof Sequence)) {
+      throw new IllegalArgumentException("Can only add sequences to other sequences");
+    }
+    return super.containsAll(c);
+  }
+
+  public boolean containsAll(Sequence s) {
+    return super.containsAll(s);
+  }
+
+  public boolean removeAll(java.util.Collection<?> c) throws IllegalArgumentException {
+    if (!(c instanceof Sequence)) {
+      throw new IllegalArgumentException("Can only add bags to other bags");
+    }
+    return super.removeAll(c);
+  }
+
+  public boolean removeAll(Sequence s) throws IllegalArgumentException {
+    return super.removeAll(s);
+  }
+
+  public boolean retainAll(java.util.Collection<?> c) throws IllegalArgumentException {
+    if (!(c instanceof Sequence)) {
+      throw new IllegalArgumentException("Can only add bags to other bags");
+    }
+    return super.retainAll(c);
+  }
+
+  public boolean retainAll(Sequence s) throws IllegalArgumentException {
+    return super.retainAll(s);
+  }
+
+
+  public boolean contains(ObjectNode o) {
+    return super.contains(o);
+  }
+
+
+  public int indexOf(ObjectNode o) throws IllegalArgumentException {
+    return super.indexOf(o);
+  }
+
+
+  public int lastIndexOf(ObjectNode o) throws IllegalArgumentException {
+    return super.lastIndexOf(o);
+  }
+
+
+  public boolean remove(ObjectNode o) throws IllegalArgumentException {
+    return super.remove(o);
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/ThreeFixedIterator.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/ThreeFixedIterator.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/ThreeFixedIterator.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,146 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.*;
+import org.jrdf.util.ClosableIterator;
+
+import java.util.NoSuchElementException;
+
+/**
+ * An iterator that returns only a single triple, if any exists.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ *
+ * @version $Revision: 624 $
+ */
+public class ThreeFixedIterator implements ClosableIterator<Triple> {
+
+  /** The graph this iterator will operate on.  Only needed by the remove method. */
+  private Graph graph;
+
+  /** The triple to return on */
+  private TripleImpl triple;
+
+  /** The triple to remove */
+  private TripleImpl removeTriple;
+
+
+  /**
+   * Constructor.
+   */
+  ThreeFixedIterator(Graph newGraph, Node subject, Node predicate, Node object) throws GraphException {
+    graph = newGraph;
+    if (newGraph.contains((SubjectNode)subject, (PredicateNode)predicate, (ObjectNode)object)) {
+      triple = new TripleImpl((SubjectNode)subject, (PredicateNode)predicate, (ObjectNode)object);
+    }
+    removeTriple = null;
+  }
+
+
+  /**
+   * Returns true if the iteration has more elements.
+   * @return <code>true</code> If there is an element to be read.
+   */
+  public boolean hasNext() {
+    return null != triple;
+  }
+
+
+  /**
+   * Returns the next element in the iteration.
+   * @return the next element in the iteration.
+   * @throws NoSuchElementException iteration has no more elements.
+   */
+  public Triple next() throws NoSuchElementException {
+    if (null == triple) throw new NoSuchElementException();
+    // return the triple, clearing it first so next will fail on a subsequent call
+    removeTriple = triple;
+    triple = null;
+    return removeTriple;
+  }
+
+
+  /**
+   * @see java.util.Iterator#remove()
+   */
+  public void remove() {
+    if (null != removeTriple) {
+      try {
+        graph.remove(removeTriple);
+        removeTriple = null;
+      } catch (GraphException ge) {
+        throw new IllegalStateException(ge.getMessage());
+      }
+    } else {
+      throw new IllegalStateException("Next not called or beyond end of data");
+    }
+  }
+
+
+  /**
+   * Closes the iterator by freeing any resources that it current holds.
+   * Nothing to be done for this class.
+   * @return <code>true</code> indicating success.
+   */
+  public boolean close() {
+    return true;
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/TripleFactoryImpl.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/TripleFactoryImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/TripleFactoryImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,83 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.AbstractTripleFactory;
+import org.jrdf.graph.Graph;
+import org.jrdf.graph.GraphElementFactory;
+
+/**
+ * A Triple Factory which is tied to a specific instance of GraphImpl.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ *
+ * @version $Revision: 624 $
+ */
+class TripleFactoryImpl extends AbstractTripleFactory {
+
+  /**
+   * Package scope constructor.
+   *
+   * @param newGraph The GraphImpl that this class is attached to.
+   */
+  TripleFactoryImpl(Graph newGraph, GraphElementFactory newElementFactory) {
+    graph = newGraph;
+    elementFactory = newElementFactory;
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/TripleImpl.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/TripleImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/TripleImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,129 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.*;
+
+/**
+ * A trivial implementation of an RDF {@link Triple}.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ *
+ * @version $Revision: 624 $
+ */
+public class TripleImpl extends AbstractTriple {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 7468341140195609635L;
+
+  /**
+   * Constructor for this Triple, only to be used by the NodeFactory.
+   *
+   * @param subject The subject node of this triple.
+   * @param predicate The predicate node of this triple.
+   * @param object The object node of this triple.
+   */
+  TripleImpl(SubjectNode subject, PredicateNode predicate, ObjectNode object) {
+    subjectNode = subject;
+    predicateNode = predicate;
+    objectNode = object;
+  }
+
+
+  /**
+   * Constructor for this Triple, only to be used by the iterators.
+   *
+   * @param factory the factory to use to get the nodes that make up this
+   *   triple.
+   * @param subject The subject node id of this triple.
+   * @param predicate The predicate node id of this triple.
+   * @param object The object node id of this triple.
+   */
+  TripleImpl(GraphElementFactory factory, Long subject, Long predicate,
+      Long object) {
+    GraphElementFactoryImpl graphFactory = (GraphElementFactoryImpl) factory;
+    subjectNode = (SubjectNode) graphFactory.getNodeById(subject);
+    predicateNode = (PredicateNode) graphFactory.getNodeById(predicate);
+    objectNode = (ObjectNode) graphFactory.getNodeById(object);
+  }
+
+
+  /**
+   * Constructor for this Triple, only to be used by the variable iterators.
+   *
+   * @param factory the factory to use to get the nodes that make up this
+   *   triple.
+   * @param first The first node id of this triple.
+   * @param second The second node id of this triple.
+   * @param third The third node id of this triple.
+   */
+  TripleImpl(GraphElementFactoryImpl factory, int var, Long first,
+      Long second, Long third) {
+    Long[] nodes = new Long[]{first, second, third};
+    subjectNode = (SubjectNode) factory.getNodeById(nodes[var]);
+    predicateNode = (PredicateNode) factory.getNodeById(
+        nodes[(var + 1) % 3]);
+    objectNode = (ObjectNode) factory.getNodeById(nodes[(var + 2) % 3]);
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/TwoFixedIterator.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/TwoFixedIterator.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/TwoFixedIterator.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,221 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+import org.jrdf.graph.GraphElementFactory;
+import org.jrdf.graph.GraphException;
+import org.jrdf.graph.Triple;
+import org.jrdf.util.ClosableIterator;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * An iterator that iterates over a group with a two fixed nodes.
+ * Relies on an internal iterator which iterates over all entries in
+ * a set, found in a subIndex.
+ * 
+ * The thirdIndexIterator is used to indicate the current position.
+ * It will always be set to return the next value until it reaches
+ * the end of the group.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public class TwoFixedIterator implements ClosableIterator<Triple> {
+
+  /** The iterator for the third index. */
+  private Iterator<Long> thirdIndexIterator;
+
+  /** The nodeFactory used to create the nodes to be returned in the triples. */
+  private GraphElementFactoryImpl nodeFactory;
+
+  /** The index of this iterator.  Only needed for initialization and the remove method. */
+  private Map<Long,Map<Long,Set<Long>>> index;
+
+  /** The subIndex of this iterator.  Only needed for initialization and the remove method. */
+  private Map<Long,Set<Long>> subIndex;
+
+  /** The subSubIndex of this iterator.  Only needed for initialization and the remove method. */
+  private Set<Long> subGroup;
+
+  /** The current subject predicate and object, last returned from next().  Only needed by the remove method. */
+  private Long[] currentNodes;
+
+  /** The first fixed item. */
+  private Long first;
+
+  /** The second fixed item. */
+  private Long second;
+
+  /** The current third item */
+  private Long third;
+
+  /** If there are anymore items left */
+  private boolean hasNext;
+
+  /** The offset for the index. */
+  private int var;
+
+  /** Handles the removal of nodes */
+  private GraphHandler handler;
+
+  /**
+   * Constructor.  Sets up the internal iterators.
+   */
+  TwoFixedIterator(Map<Long,Map<Long,Set<Long>>> newIndex, int newVar, Long newFirst, Long newSecond,
+      GraphElementFactory newFactory, GraphHandler newHandler, Map<Long,Set<Long>> newSubIndex) {
+
+    if (!(newFactory instanceof GraphElementFactoryImpl)) {
+      throw new IllegalArgumentException("Must use the memory implementation of GraphElementFactory");
+    }
+
+    // store the node factory and other starting data
+    nodeFactory = (GraphElementFactoryImpl) newFactory;
+    handler = newHandler;
+    index = newIndex;
+    first = newFirst;
+    second = newSecond;
+    var = newVar;
+    currentNodes = null;
+
+    // find the subIndex from the main index
+    subIndex = newSubIndex;
+
+    // check that data exists
+    if (null != subIndex) {
+      // now find the set from the sub index map
+      subGroup = subIndex.get(second);
+      if (null != subGroup) {
+        // get an iterator for the set
+        thirdIndexIterator = subGroup.iterator();
+        hasNext = thirdIndexIterator.hasNext();
+      }
+    }
+  }
+
+
+  /**
+   * Returns true if the iteration has more elements.
+   *
+   * @return <code>true</code> If there is an element to be read.
+   */
+  public boolean hasNext() {
+    return hasNext;
+  }
+
+
+  /**
+   * Returns the next element in the iteration.
+   *
+   * @return the next element in the iteration.
+   * @throws NoSuchElementException iteration has no more elements.
+   */
+  public Triple next() throws NoSuchElementException {
+    if (!hasNext()) throw new NoSuchElementException();
+
+    // Get next node.
+    third = (Long) thirdIndexIterator.next();
+    hasNext = thirdIndexIterator.hasNext();
+    currentNodes = new Long[]{first, second, third};
+    return new TripleImpl(nodeFactory, var, first, second, third);
+  }
+
+
+  /**
+   * Implemented for java.util.Iterator.
+   */
+  public void remove() {
+    if (null != third) {
+      try {
+        thirdIndexIterator.remove();
+        handler.remove(currentNodes);
+
+        // check if a set was cleaned out
+        if (subGroup.isEmpty()) {
+          // remove the entry for the set
+          subIndex.remove(second);
+          // check if a subindex was cleaned out
+          if (subIndex.isEmpty()) {
+            // remove the subindex
+            index.remove(first);
+          }
+        }
+      } catch (GraphException ge) {
+        throw new IllegalStateException(ge.getMessage());
+      }
+    } else {
+      throw new IllegalStateException("Next not called or beyond end of data");
+    }
+  }
+
+
+  /**
+   * Closes the iterator by freeing any resources that it current holds.
+   * Nothing to be done for this class.
+   * @return <code>true</code> indicating success.
+   */
+  public boolean close() {
+    return true;
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/mem/URIReferenceImpl.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/mem/URIReferenceImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/mem/URIReferenceImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,125 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.graph.mem;
+
+// Java 2 standard packages
+import org.jrdf.graph.AbstractURIReference;
+
+import java.net.URI;
+
+/**
+ * RDF URI reference - resource node. Some RDF resources are properties. It's
+ * not always possible to say whether a resource is a property or not until
+ * it's used as a predicate, because we don't always have access to an RDF
+ * Schema that defines the property.
+ *
+ * A URI Reference can be any part of an RDF Triple: subject, predicate or
+ * object.
+ *
+ * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ *
+ * @version $Revision: 624 $
+ */
+public class URIReferenceImpl extends AbstractURIReference implements MemNode {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = -4120822410726711976L;
+
+  /** The internal identifier for this node. */
+  private Long id;
+
+
+  /**
+   * Constructor for use by GraphElementFactory only.
+   *
+   * @param newUri The newUri of this node.
+   * @param newId The internal identifier for this node.
+   */
+  URIReferenceImpl(URI newUri, Long newId) {
+    super(newUri);
+    id = newId;
+  }
+
+  /**
+   * Constructor for use by GraphElementFactory only.
+   *
+   * @param newUri The uri of this node.
+   * @param validate whether to enforce valid RDF URIs.
+   * @param newId The internal identifier for this node.
+   */
+  URIReferenceImpl(URI newUri, boolean validate, Long newId) {
+    super(newUri, validate);
+    id = newId;
+  }
+
+
+  /**
+   * Retrieves an internal identifier for this node.
+   *
+   * @return A numeric identifier for this node.
+   */
+  public Long getId() {
+    return id;
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/graph/package.html
===================================================================
--- trunk/src/jar/query/java/org/jrdf/graph/package.html	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/graph/package.html	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,28 @@
+<html>
+<head>
+<title>Java RDF (JRDF) Graph Package</title>
+</head>
+<body>
+<p>
+This package defines a set of APIs required to implement an RDF Graph and it's
+associated objects. The basis for this package structure comes
+from various sources including:
+<A HREF="http://www.w3.org/RDF/">the W3C RDF specifications</A>
+and existing Java mappings including:
+<A HREF="http://www.hpl.hp.com/semweb/jena.htm">Jena</A>,
+<A HREF="http://sesame.aidministrator.nl/">Sesame</A> and
+<A HREF="http://www-db.stanford.edu/~melnik/rdf/api.html">Sergey Melnik's RDF API</A>.
+</p>
+<p>
+An RDF Graph is made from RDF triples.  Triples consist of a subject,
+predicate and object.  Triples are made of nodes.  Nodes can either be resources
+or literals.  Resources can either be labelled with a URI, called URI
+references, or be blank.
+</p>
+<p>
+To construct nodes you use a GraphElementFactory which allows you to create any of the
+nodes individually.  This allows a separation between the implementation of the
+Graphs and of Node storage and handling.
+</p>
+</body>
+</html>

Added: trunk/src/jar/query/java/org/jrdf/parser/ParserBlankNodeFactory.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/parser/ParserBlankNodeFactory.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/parser/ParserBlankNodeFactory.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,111 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003-2005 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.parser;
+
+import org.jrdf.graph.BlankNode;
+import org.jrdf.graph.GraphElementFactoryException;
+
+/**
+ * A factory for creating BlankNodes.  One possible implementation might create
+ * BlankNodes that maintain their identity relative to the RDF file being
+ * parsed, possibly by wrapping the nodeID in the case of
+ * {@link #createBlankNode(String)} or by wrapping a sequence number in the
+ * case of {@link #createBlankNode()}.  In that case the resulting BlankNodes
+ * would only be useful as a temporary object that is used while an RDF file is
+ * being parsed. <br>
+ * Another implementation might keep a map from <code>nodeID</code> to
+ * <code>BlankNode</code> so that {@link #createBlankNode(String)} would always
+ * return the same BlankNode object when called with a particular
+ * <code>nodeID</code>.
+ *
+ * @author David Makepeace
+ *
+ * @version $Revision: 624 $
+ */
+public interface ParserBlankNodeFactory {
+
+  /**
+   * Creates a BlankNode that is unique relative to this instance of the
+   * ParserBlankNodeFactory.
+   *
+   * @return the BlankNode.
+   * @throws GraphElementFactoryException if there is a failure to create the
+   *   blank node.
+   */
+  BlankNode createBlankNode() throws GraphElementFactoryException;
+
+  /**
+   * Creates a BlankNode that is only distinguished by the nodeID value.
+   *
+   * @param nodeID the nodeID of the blank node - consistently returns the same
+   *   blank node if it exists. 
+   * @return the BlankNode.
+   * @throws GraphElementFactoryException if there is a failure to create the
+   *   blank node.
+   */
+  BlankNode createBlankNode(String nodeID) throws GraphElementFactoryException;
+
+  /**
+   * Resets this ParserBlankNodeFactory.  Subsequent calls to
+   * {@link #createBlankNode()} may return BlankNodes that compare equal to
+   * BlankNodes that were created before the call to <code>clear()</code>.
+   */
+  void clear();
+
+}

Added: trunk/src/jar/query/java/org/jrdf/parser/mem/ParserBlankNodeFactoryImpl.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/parser/mem/ParserBlankNodeFactoryImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/parser/mem/ParserBlankNodeFactoryImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,136 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.parser.mem;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.jrdf.graph.BlankNode;
+import org.jrdf.graph.GraphElementFactory;
+import org.jrdf.graph.GraphElementFactoryException;
+import org.jrdf.parser.ParserBlankNodeFactory;
+
+/**
+ * A factory for BlankNodes that uses a Map to keep track of the BlankNodes
+ * that have been allocated by {@link #createBlankNode(String)} so that the
+ * same BlankNode object can be returned for a given <code>nodeID</code>.
+ *
+ * @author David Makepeace
+ */
+public class ParserBlankNodeFactoryImpl implements ParserBlankNodeFactory {
+
+  /**
+   * A factory for creating BlankNodes (as well as resources and literals).
+   */
+  private GraphElementFactory valueFactory;
+
+  /**
+   * Mapping from bNode ID's as used in the RDF document to the
+   * object created for it by the GraphElementFactory.
+   */
+  private Map<String,BlankNode> bNodeIdMap = new HashMap<String,BlankNode>();
+
+
+  /**
+   * Create a new blank node factory with the given value factory.
+   *
+   * @param newValueFactory factory to create nodes with.
+   */
+  public ParserBlankNodeFactoryImpl(GraphElementFactory newValueFactory) {
+    valueFactory = newValueFactory;
+  }
+
+  /**
+   * Always creates a new BlankNode object from the GraphElementFactory.
+   *
+   * @return the new BlankNode object.
+   * @throws GraphElementFactoryException if it fails to create a new blank node.
+   */
+  public BlankNode createBlankNode() throws GraphElementFactoryException {
+    return valueFactory.createResource();
+  }
+
+  /**
+   * Returns the BlankNode for a <code>nodeID</code> that has not been seen
+   * before or calls the GraphElementFactory to create a new BlankNode
+   * otherwise.
+   *
+   * @param nodeID the node that labels the bNode in the file being parsed.
+   * @return the BlankNode object.
+   * @throws GraphElementFactoryException if it fails to create a new blank node.
+   */
+  public BlankNode createBlankNode(String nodeID) throws GraphElementFactoryException {
+    // Maybe the node ID has been used before:
+    BlankNode result = bNodeIdMap.get(nodeID);
+
+    if (null == result) {
+      // This is a new node ID, create a new BNode object for it
+      result = valueFactory.createResource();
+
+      // Remember it, the nodeID might occur again.
+      bNodeIdMap.put(nodeID, result);
+    }
+
+    return result;
+  }
+
+  /**
+   * Clears the internal Map.
+   */
+  public void clear() {
+    bNodeIdMap.clear();
+  }
+
+}

Added: trunk/src/jar/query/java/org/jrdf/util/ClosableIterator.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/ClosableIterator.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/ClosableIterator.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,78 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.util;
+
+import java.util.Iterator;
+
+/**
+ * An that intializes objects from a graph one at a time.  The close method
+ * indicates that the resources being held by the iterator should be freed.
+ * Based on Jena's CloseableIterator class.
+ *
+ * @author Andrew Newman
+ *
+ * @version $Revision: 624 $
+ */
+public interface ClosableIterator<T> extends Iterator<T> {
+
+  /**
+   * Closes the iterator by freeing any resources that it current holds.  This
+   * must be done as soon as possible.  Once an iterator is closed none of the
+   * operations on a iterator will operate i.e. they will throw an exception.
+   *
+   * @return true if it was successfully closed.
+   */
+  boolean close();
+}

Added: trunk/src/jar/query/java/org/jrdf/util/EscapeUtil.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/EscapeUtil.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/EscapeUtil.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,150 @@
+package org.jrdf.util;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A utility which applies N-Triples escaping.
+ *
+ * @author Andrew Newman
+ * @version $Revision: 624 $
+ */
+public class EscapeUtil {
+    /**
+     * A regular expression to pick out characters needing escape from Unicode to
+     * ASCII.  A different regular expression is used depending on which version of the JDK is detected - Java 1.4 has
+     * different character support compared with 1.5 and above.
+     * <p/>
+     * This is used by the {@link #escape} method.
+     */
+    private static Pattern pattern;
+
+    static {
+        try {
+            if (System.getProperty("java.version").indexOf("1.4") >= 0) {
+                pattern = Pattern.compile("[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]" +
+                        "|" +
+                        "[\\x00-\\x1F\\x22\\\\\\x7F-\\uFFFF]");
+            } else {
+                pattern = Pattern.compile("[\uD800\uDC00-\uDBFF\uDFFF]" +
+                        "|" +
+                        "[\\x00-\\x1F\\x22\\\\\\x7F-\\uFFFF]");
+            }
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Base UTF Code point.
+     */
+    private static final int UTF_BASE_CODEPOINT = 0x10000;
+
+    /**
+     * How shift to get UTF-16 to character codes.
+     */
+    private static final int CHARACTER_CODE_OFFSET = 0x3FF;
+
+    /**
+     * How many characters at a time to decode for 8 bit encoding.
+     */
+    private static final int CHARACTER_LENGTH_8_BIT = 11;
+
+    /**
+     * How many characters at a time to decode for 16 bit encoding.
+     */
+    private static final int CHARACTER_LENGTH_16_BIT = 7;
+
+    private EscapeUtil() {
+    }
+
+    /**
+     * Escapes a string literal to a string that is N-Triple escaped.
+     *
+     * @param string a string to escape, never <code>null</code>.
+     * @return a version of the <var>string</var> with N-Triples escapes applied.
+     */
+    public static String escape(String string) {
+        assert null != string;
+
+        // Obtain a fresh matcher
+        Matcher matcher = pattern.matcher(string);
+
+        // Try to short-circuit the whole process -- maybe nothing needs escaping?
+        if (!matcher.find()) {
+            return string;
+        }
+
+        // Perform escape character substitutions on each match found by the
+        // matcher, accumulating the escaped text into a stringBuffer
+        StringBuffer stringBuffer = new StringBuffer();
+        do {
+            // The escape text with which to replace the current match
+            String escapeString;
+
+            // Depending of the character sequence we're escaping, determine an
+            // appropriate replacement
+            String groupString = matcher.group();
+            switch (groupString.length()) {
+                case 1: // 16-bit characters requiring escaping
+                    switch (groupString.charAt(0)) {
+                        case '\t': // tab
+                            escapeString = "\\\\t";
+                            break;
+                        case '\n': // newline
+                            escapeString = "\\\\n";
+                            break;
+                        case '\r': // carriage return
+                            escapeString = "\\\\r";
+                            break;
+                        case '"':  // quote
+                            escapeString = "\\\\\\\"";
+                            break;
+                        case '\\': // backslash
+                            escapeString = "\\\\\\\\";
+                            break;
+                        default:   // other characters use 4-digit hex escapes
+                            String hexString = Integer.toHexString(groupString.charAt(0)).toUpperCase();
+
+                            escapeString = "\\\\u0000".substring(0, CHARACTER_LENGTH_16_BIT - hexString.length()) +
+                                    hexString;
+
+                            assert CHARACTER_LENGTH_16_BIT == escapeString.length();
+                            assert escapeString.startsWith("\\\\u");
+                            break;
+                    }
+                    break;
+
+                case 2: // surrogate pairs are represented as 8-digit hex escapes
+                    assert Character.SURROGATE == Character.getType(groupString.charAt(0));
+                    assert Character.SURROGATE == Character.getType(groupString.charAt(1));
+
+                    int highSurrogate = ((groupString.charAt(0) & CHARACTER_CODE_OFFSET) << 10);
+                    int lowSurrogate = (groupString.charAt(1) & CHARACTER_CODE_OFFSET);
+                    String hexString = Integer.toHexString(highSurrogate + lowSurrogate + UTF_BASE_CODEPOINT).
+                            toUpperCase();
+                    escapeString = "\\\\U00000000".substring(0, CHARACTER_LENGTH_8_BIT - hexString.length()) +
+                            hexString;
+
+                    assert CHARACTER_LENGTH_8_BIT == escapeString.length();
+                    assert escapeString.startsWith("\\\\U00") : "Expected a start of \\\\U00, but got " + escapeString;
+                    break;
+
+                default:
+                    throw new Error("Escape sequence " + groupString + " has no handler");
+            }
+            assert null != escapeString;
+
+            // Having determined an appropriate escapeString, add it to the
+            // stringBuffer
+            matcher.appendReplacement(stringBuffer, escapeString);
+        }
+        while (matcher.find());
+
+        // Finish off by appending any remaining text that didn't require escaping,
+        // and return the assembled buffer
+        matcher.appendTail(stringBuffer);
+        return stringBuffer.toString();
+    }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/EscapeUtilUnitTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/EscapeUtilUnitTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/EscapeUtilUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,53 @@
+package org.jrdf.util;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link EscapeUtil}.
+ *
+ * @author Andrew Newman
+ */
+public class EscapeUtilUnitTest extends TestCase {
+
+    public void testSurrgates() {
+        // ISO 10646 Amendment 1
+        // High surrogates from D800...DBFF, low surrogates from DC00...DFFF.
+        testEscapedValue("\\U00010000", "\uD800\uDC00");
+        testEscapedValue("\\U00010001", "\uD800\uDC01");
+        testEscapedValue("\\U00010401", "\uD801\uDC01");
+        testEscapedValue("\\U00020000", "\uD840\uDC00");
+        testEscapedValue("\\U00030000", "\uD880\uDC00");
+        testEscapedValue("\\U00100000", "\uDBC0\uDC00");
+        testEscapedValue("\\U0010FFFF", "\uDBFF\uDFFF");
+    }
+
+    public void testNearSurrogates() {
+        // ISO 10646 Amendment 1
+        // High surrogates from D800...DBFF, low surrogates from DC00...DFFF.
+        testEscapedValue("\\uD799\\uDC00", "\uD799\uDC00");
+        testEscapedValue("\\uD799\\uDC01", "\uD799\uDC01");
+        testEscapedValue("\\uD800\\uDBFF", "\uD800\uDBFF");
+        testEscapedValue("\\uD801\\uDBFF", "\uD801\uDBFF");
+        testEscapedValue("\\uDC00\\uDFFF", "\uDC00\uDFFF");
+        testEscapedValue("\\uDBFF\\uE000", "\uDBFF\uE000");
+    }
+
+    public void testExampleCodePoints() {
+        testEscapedValue("\\U000233B4", "\uD84C\uDFB4");
+        testEscapedValue("\\u2260", "\u2260");
+        testEscapedValue("q", "\u0071");
+        testEscapedValue("\\u030C", "\u030c");
+    }
+
+    public void testControlCharacters() {
+        testEscapedValue("\\\\", new String(new char[] {(char) 92}));
+        testEscapedValue("\\\"", new String(new char[] {(char) 34}));
+        testEscapedValue("\\r", new String(new char[] {(char) 13}));
+        testEscapedValue("\\n", new String(new char[] {(char) 10}));
+        testEscapedValue("\\t", new String(new char[] {(char) 9}));
+    }
+
+    private void testEscapedValue(String expectedValue, String testString) {
+        assertEquals(expectedValue, EscapeUtil.escape(testString));
+    }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/UIDGenerator.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/UIDGenerator.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/UIDGenerator.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,303 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.util;
+
+//Java 2 standard packages
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.rmi.dgc.VMID;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+
+/**
+ * Utility class that generates an Unique identifier.
+ *
+ * @author <a href="mailto:robert.turner at tucanatech.com">Robert Turner</a>
+ */
+public class UIDGenerator {
+
+  /** Computers IP address. */
+  private static String ipAddress;
+
+  /** Unique Java Virtual Machine Identifier. */
+  private static String vmID;
+
+  /** time the method was called (used to prevent duplicates). */
+  private static long callTime;
+
+  /** count of UIDs generated by this JVM (to avoid per millisecond duplicates). */
+  private static long uidCounter;
+  private static final int SINGLE_DIGIT = 0x10;
+  private static final int INT_OFFSET = 0xFF;
+
+  private UIDGenerator() {
+  }
+
+  /**
+   * Generates an Unique Identifier using the current time and the machines
+   * IP address.
+   *
+   * @throws Exception
+   * @return String
+   */
+  public static synchronized String generateUID() throws Exception {
+    String uniqueID = getUniqueID(getSeed());
+    return uniqueID;
+  }
+
+  /**
+   * Returns a MD5 sum of the seed.
+   *
+   * @param seed char[]
+   * @throws Exception
+   * @return String
+   */
+  private static synchronized String getUniqueID(char[] seed) throws
+      Exception {
+
+    String uid = null;
+
+    //digest the seed and convert to hex
+    byte[] digested = digest(seed);
+    StringBuffer buffer = new StringBuffer();
+    int currentInt = 0;
+
+    //convert each byte to an int (as hex)
+    for (int i = 0; i < digested.length; ++i) {
+
+      //conver to int
+      currentInt = digested[i] & INT_OFFSET;
+
+      //is the int smaller than 16? (single digit hex)
+      if (SINGLE_DIGIT > currentInt) {
+
+        buffer.append('0');
+      }
+
+      buffer.append(Integer.toHexString(currentInt));
+    }
+
+    uid = buffer.toString();
+
+    //validate
+    if (null == uid) {
+
+      throw new Exception("Failed to generate UID.");
+    }
+
+    return uid;
+  }
+
+  /**
+   * Returns an MD5 sum for the char []  .
+   *
+   * @param chars []
+   * @throws Exception
+   * @return byte[]
+   */
+  private static byte[] digest(char[] chars) throws Exception {
+
+    //validate
+    if (null == chars) {
+
+      throw new IllegalArgumentException("Cannot get MD5 sum for null char [].");
+    }
+
+    try {
+
+      MessageDigest digest = MessageDigest.getInstance("MD5");
+
+      //add the chars to the buffer
+      int bufferSize = chars.length * 2;
+      ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
+      for (int i = 0; i < chars.length; i++) {
+
+        buffer.putChar(chars[i]);
+      }
+
+      //digest
+      return digest.digest(buffer.array());
+    }
+    catch (NoSuchAlgorithmException algorithmException) {
+
+      throw new Exception("Could not get MD5 algorithm.", algorithmException);
+    }
+  }
+
+  /**
+   * Returns an unique seed.
+   *
+   * @throws Exception
+   * @return char []
+   */
+  private static synchronized char[] getSeed() throws Exception {
+
+    StringBuffer seed = new StringBuffer();
+
+    //location in universe (cyberspace). A JVM running on a particular machine.
+    seed.append(getIP());
+    seed.append(getJVMID());
+    //time (current millisecond)
+    seed.append(getTime());
+    //random, allows multiple new UIDS per millisecond. (validated by List)
+    seed.append(getRandom());
+    //another Class could be generating UIDS the same way within the same JVM
+    seed.append(UIDGenerator.class.getName());
+    //two random numbers could (possibly) be generated in the same millisecond
+    seed.append(getCount());
+    //more than one UIDGenerator class may be loaded by different ClassLoaders
+    seed.append(getClassLoaderId());
+
+    //conver to char []
+    char[] chars = new char[seed.length()];
+    seed.getChars(0, seed.length(), chars, 0);
+
+    return chars;
+  }
+
+  /**
+   * Returns a Random number/String.
+   *
+   * @return String
+   */
+  private static synchronized String getRandom() {
+
+    long random = new SecureRandom().nextLong();
+
+    return "" + random;
+  }
+
+  /**
+   * Returns the current time in milliseconds.
+   *
+   * @return String
+   */
+  private static synchronized String getTime() {
+
+    callTime = System.currentTimeMillis();
+
+    return "" + callTime;
+  }
+
+  /**
+   * Returns an incremented count of UIDs generated by this instance.
+   * @return long
+   */
+  private static synchronized long getCount() {
+    return++uidCounter;
+  }
+
+  /**
+   * Returns the IP address for this machine.
+   *
+   * @throws Exception
+   * @return String
+   */
+  private static synchronized String getIP() throws Exception {
+
+    try {
+
+      //lazily obtain IP address
+      if (null == ipAddress) {
+
+        ipAddress = InetAddress.getLocalHost().getHostAddress();
+      }
+
+      return ipAddress;
+    }
+    catch (UnknownHostException hostException) {
+
+      throw new Exception("Could not determine IP Address.", hostException);
+    }
+  }
+
+  /**
+   * Returns an Unique Identifier for this particular Java Virtual Machine.
+   *
+   * @return String
+   */
+  private static synchronized String getJVMID() {
+
+    //lazily obtain JVM ID
+    if (null == vmID) {
+
+      vmID = new VMID().toString();
+    }
+
+    return vmID;
+  }
+
+  /**
+   * If multiple UIDGenerators are loaded by different class loaders, they
+   * will be operating independantly of each other (ie. multiple web
+   * applications within an application server), It is (remotely) possible
+   * that multiple UIDGenerator may duplicate their count and random numbers
+   * within the same millisecond.
+   *
+   * @return int
+   */
+  private static synchronized int getClassLoaderId() {
+    //what ClassLoader within this JVM loaded this UIDGenerator class
+    int classLoaderId = System.identityHashCode(UIDGenerator.class.
+        getClassLoader());
+    return classLoaderId;
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/UIDGeneratorUnitTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/UIDGeneratorUnitTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/UIDGeneratorUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,292 @@
+/*
+ * $Header$
+ * $Revision: 624 $
+ * $Date: 2006-06-24 21:02:12 +1000 (Sat, 24 Jun 2006) $
+ *
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003, 2004 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.util;
+
+// Third party packages
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Unit test for testing the Unique Identifier Generator (UIDGenerator).
+ *
+ * @author <a href="mailto:robert.turner at tucanatech.com">Robert Turner </a>
+ */
+public class UIDGeneratorUnitTest extends TestCase {
+
+  /** Set of UIDs that have been generated. */
+  private Set<String> uids;
+
+  /** Number of UIDs generated. */
+  private static final int NUM_UIDS = 10000;
+
+  /** Number of Threads concurrently generating UIDs. */
+  private static final int NUM_THREADS = 10;
+
+  /** Number of ClassLoaders using UIDGenerator classes to genreateUIDs .*/
+  private static final int NUM_CLASSLOADERS = 10;
+
+  /** Short name of the UIDGenerator class. */
+  private static final String CLASS_NAME = "UIDGenerator";
+
+  /** Fully qualified name of the UIDGenerator class. */
+  private static final String FULL_CLASS_NAME = "org.jrdf.util." + CLASS_NAME;
+
+  /**
+   * Constructs a new test with the given name.
+   *
+   * @param name
+   *            the name of the test
+   */
+  public UIDGeneratorUnitTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Hook for test runner to obtain a test suite from.
+   *
+   * @return The test suite
+   */
+  public static Test suite() {
+
+    TestSuite suite = new TestSuite();
+    suite.addTest(new UIDGeneratorUnitTest("testUID"));
+    suite.addTest(new UIDGeneratorUnitTest("testConcurrency"));
+//    suite.addTest(new UIDGeneratorUnitTest("testMultiClassLoader"));
+    return suite;
+  }
+
+  /**
+   * Default test runner.
+   *
+   * @param args The command line arguments
+   */
+  public static void main(String[] args) {
+
+    TestRunner.run(suite());
+  }
+
+  /**
+   * Tests that UID are unique.
+   *
+   * @throws Exception
+   */
+  public void testUID() throws Exception {
+
+    String currentUID = "";
+
+    for (int i = 0; NUM_UIDS > i; i++) {
+
+      currentUID = UIDGenerator.generateUID();
+
+      //is it unique??
+      if (uids.contains(currentUID)) {
+
+        fail("UID set already contains UID [" + i + "]: " + currentUID);
+      }
+
+      uids.add(currentUID);
+    }
+  }
+
+  /**
+   * Tests that UID are unique when generated from differnet Threads.
+   *
+   * @throws Exception
+   */
+  public void testConcurrency() throws Exception {
+
+    //threads that have to complete before the test finished
+    List<Thread> threadList = new ArrayList<Thread>();
+    Thread currentThread = null;
+
+    //start threads that generate UIDs
+    for (int i = 0; NUM_THREADS > i; i++) {
+      //start a new thread that inserts and checks UIDS
+      currentThread = new Thread(new Runnable() {
+
+        /** run test */
+        public void run() {
+          try {
+            String currentUID = "";
+            int numUIDS = NUM_UIDS / NUM_THREADS;
+            for (int i = 0; i < numUIDS; i++) {
+              currentUID = UIDGenerator.generateUID();
+              synchronized (UIDGeneratorUnitTest.class) {
+                //is it unique??
+                if (uids.contains(currentUID)) {
+                  fail("UID set already contains UID [" + i
+                      + "]: " + currentUID);
+                }
+                uids.add(currentUID);
+              }
+            }
+          } catch (Exception exception) {
+            throw new RuntimeException(
+                "Error occurred while testing concurrency.",
+                exception);
+          }
+        }
+      });
+      //end thread
+
+      //keep reference
+      threadList.add(currentThread);
+
+      //start it
+      currentThread.start();
+    }
+
+    //must wait for all threads to finish
+    for (int i = 0; NUM_THREADS > i; i++) {
+      threadList.get(i).join();
+    }
+  }
+
+  /**
+   * Tests the corner case of having multiple applications loaded by different
+   * ClassLoaders.
+   *
+   * @throws Exception
+   */
+  @SuppressWarnings("unchecked")
+  public void testMultiClassLoader() throws Exception {
+
+    //load UIDGenerator from multiple classes
+    URLClassLoader currentLoader = null;
+    Class<UIDGenerator> currentUIDGeneratorClass = null;
+
+    //get an URL to the UIDGenerator class file
+    URL[] uidClass = new URL[] {
+        ClassLoader.getSystemClassLoader().getResource(CLASS_NAME)};
+
+    for (int i = 0; NUM_CLASSLOADERS > i; i++) {
+      currentLoader = new URLClassLoader(uidClass);
+      currentUIDGeneratorClass = (Class<UIDGenerator>)currentLoader.loadClass(FULL_CLASS_NAME);
+      testUIDGeneratorClass(currentUIDGeneratorClass);
+    }
+
+  }
+
+  /**
+   * Uses the supplied UIDGenerator class to generate UIDs.
+   *
+   * @param uidGenerator
+   * @throws Exception
+   */
+  private void testUIDGeneratorClass(Class<UIDGenerator> uidGenerator) throws Exception {
+    //get the UIDGenerator's generateUID method
+    Method generateUID = uidGenerator.getMethod("generateUID", (Class[])null);
+    String currentUID = "";
+    for (int i = 0; NUM_UIDS > i; i++) {
+      currentUID = (String) generateUID.invoke(null, (Object[])null);
+      //is it unique??
+      if (uids.contains(currentUID)) {
+        fail("UID set already contains UID [" + i + "]: " + currentUID);
+      }
+      uids.add(currentUID);
+    }
+  }
+
+  //set up and tear down
+
+  /**
+   * Initialise members.
+   *
+   * @throws Exception if something goes wrong
+   */
+  public void setUp() throws Exception {
+
+    try {
+
+      uids = new HashSet<String>();
+
+      super.setUp();
+    } catch (Exception exception) {
+
+      //try to tear down first
+      tearDown();
+
+      //then throw
+      throw exception;
+    }
+  }
+
+  /**
+   * The teardown method for JUnit.
+   *
+   * @throws Exception
+   */
+  public void tearDown() throws Exception {
+
+    uids.clear();
+
+    //allow super to close down
+    super.tearDown();
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/package.html
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/package.html	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/package.html	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,10 @@
+<html>
+<head>
+<title>Java RDF (JRDF) Utility Package</title>
+</head>
+<body>
+<p>
+Utility classes - ones that don't belong elsewhere.
+</p>
+</body>
+</html>

Added: trunk/src/jar/query/java/org/jrdf/util/param/EmtpyStringChecker.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/param/EmtpyStringChecker.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/param/EmtpyStringChecker.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,29 @@
+package org.jrdf.util.param;
+
+/**
+ * Checks that empty strings are not passed to methods.
+ *
+ * @author Tom Adams
+ * @version $Revision: 624 $
+ */
+final class EmtpyStringChecker implements ParameterChecker {
+
+  private static final String EMPTY_STRING = "";
+
+  /**
+   * Checks if this checker allows a parameter with the given value.
+   * <p>
+   * Note. This checker assumes that <var>param</var> is not <code>null</code>.
+   * </p>
+   *
+   * @param param The parameter to check the value of.
+   * @return <code>true</code> if the parameter is allowed by this checker.
+   */
+  public boolean paramAllowed(Object param) {
+    return (paramAllowed((String) param));
+  }
+
+  private boolean paramAllowed(String param) {
+    return !param.trim().equals(EMPTY_STRING);
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/param/EmtpyStringCheckerUnitTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/param/EmtpyStringCheckerUnitTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/param/EmtpyStringCheckerUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,22 @@
+package org.jrdf.util.param;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link EmtpyStringChecker}.
+ *
+ * @author Tom Adams
+ * @version $Revision: 624 $
+ */
+public final class EmtpyStringCheckerUnitTest extends TestCase {
+
+  public void testParamAllowed() {
+    //checkParam(ParameterTestUtil.NULL_STRING); // assume null's are not handled by this checker
+    checkParam(ParameterTestUtil.EMPTY_STRING);
+    checkParam(ParameterTestUtil.SINGLE_SPACE);
+  }
+
+  private void checkParam(String param) {
+    assertFalse(new EmtpyStringChecker().paramAllowed(param));
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/param/NullChecker.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/param/NullChecker.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/param/NullChecker.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,21 @@
+package org.jrdf.util.param;
+
+
+/**
+ * Checks that nulls are not passed to methods.
+ *
+ * @author Tom Adams
+ * @version $Revision: 624 $
+ */
+final class NullChecker implements ParameterChecker {
+
+  /**
+   * Checks if this checker allows a parameter with the given value.
+   *
+   * @param param The parameter to check the value of.
+   * @return <code>true</code> if the parameter is allowed by this checker.
+   */
+  public boolean paramAllowed(Object param) {
+    return param != null;
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/param/NullCheckerUnitTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/param/NullCheckerUnitTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/param/NullCheckerUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,17 @@
+package org.jrdf.util.param;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link NullChecker}.
+ *
+ * @author Tom Adams
+ * @version $Revision: 624 $
+ */
+public final class NullCheckerUnitTest extends TestCase {
+
+  public void testParamAllowed() {
+    assertFalse(new NullChecker().paramAllowed(ParameterTestUtil.NULL_STRING));
+    assertTrue(new NullChecker().paramAllowed(ParameterTestUtil.SINGLE_SPACE));
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/param/ParameterChecker.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/param/ParameterChecker.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/param/ParameterChecker.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,18 @@
+package org.jrdf.util.param;
+
+/**
+ * Checks parameters for conformance against some criteria.
+ *
+ * @author Tom Adams
+ * @version $Revision: 624 $
+ */
+interface ParameterChecker {
+
+  /**
+   * Checks if this checker allows a parameter with the given value.
+   *
+   * @param param The parameter to check the value of.
+   * @return <code>true</code> if the parameter is allowed by this checker.
+   */
+  boolean paramAllowed(Object param);
+}

Added: trunk/src/jar/query/java/org/jrdf/util/param/ParameterTestUtil.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/param/ParameterTestUtil.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/param/ParameterTestUtil.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,44 @@
+package org.jrdf.util.param;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.Assert;
+
+/**
+ * Test utility for checking parameters bad to methods.
+ *
+ * @author Tom Adams
+ * @version $Revision: 624 $
+ */
+public final class ParameterTestUtil {
+  public static final String NULL_STRING = null;
+  public static final String EMPTY_STRING = "";
+  public static final String SINGLE_SPACE = " ";
+  public static final String NON_EMPTY_STRING = "FOO";
+  public static final Object NON_NULL_OBJECT = new Object();
+
+  private ParameterTestUtil() {
+  }
+
+  public static void checkBadStringParam(Object ref, String methodName, String param) throws Exception {
+    try {
+      invokeMethod(ref, methodName, String.class, param);
+      Assert.fail("Bad argument should have throw IllegalArgumentException");
+    } catch (IllegalArgumentException expected) {
+    }
+  }
+
+  private static void invokeMethod(Object cls, String methodName, Class<?> paramClass, String paramValue) throws Exception {
+    try {
+      Method method = cls.getClass().getMethod(methodName, new Class[]{paramClass});
+      method.invoke(cls, new Object[]{paramValue});
+    } catch (InvocationTargetException e) {
+      Throwable cause = e.getCause();
+      if (cause instanceof RuntimeException) {
+        throw (RuntimeException) cause;
+      }
+      throw e;
+    }
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/param/ParameterUtil.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/param/ParameterUtil.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/param/ParameterUtil.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,42 @@
+package org.jrdf.util.param;
+
+/**
+ * Utility for checking parameters to methods.
+ *
+ * @author Tom Adams
+ * @version $Revision: 624 $
+ */
+public final class ParameterUtil {
+
+  private static final ParameterChecker NULL_CHECKER = new NullChecker();
+  private static final ParameterChecker EMPTY_STRING_CHECKER = new EmtpyStringChecker();
+
+  private ParameterUtil() { }
+
+  /**
+   * Checks if <var>param</var> is <code>null</code> and throws an exception if it is.
+   *
+   * @param name The name of the parameter to check.
+   * @param param The parameter to check.
+   * @throws IllegalArgumentException If <car>param</var> is <code>null</code>.
+   */
+  public static void checkNotNull(String name, Object param) throws IllegalArgumentException {
+    if (!NULL_CHECKER.paramAllowed(param)) {
+      throw new IllegalArgumentException(name + " parameter cannot be null");
+    }
+  }
+
+  /**
+   * Checks if <var>param</var> is <code>null</code> or the empty string and throws an exception if it is.
+   *
+   * @param name The name of the parameter to check.
+   * @param param The parameter to check.
+   * @throws IllegalArgumentException If <car>param</var> is <code>null</code> or the empty string.
+   */
+  public static void checkNotEmptyString(String name, String param) throws IllegalArgumentException {
+    checkNotNull(name, param);
+    if (!EMPTY_STRING_CHECKER.paramAllowed(param)) {
+      throw new IllegalArgumentException(name + " parameter cannot be the empty string");
+    }
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/param/ParameterUtilUnitTest.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/param/ParameterUtilUnitTest.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/param/ParameterUtilUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,46 @@
+package org.jrdf.util.param;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link ParameterUtil}.
+ *
+ * @author Tom Adams
+ * @version $Revision: 624 $
+ */
+public final class ParameterUtilUnitTest extends TestCase {
+    private static final String NULL = ParameterTestUtil.NULL_STRING;
+    private static final String EMPTY_STRING = ParameterTestUtil.EMPTY_STRING;
+    private static final String SINGLE_SPACE = ParameterTestUtil.SINGLE_SPACE;
+    private static final String NON_EMPTY_STRING = ParameterTestUtil.NON_EMPTY_STRING;
+    private static final Object NON_NULL_OBJECT = ParameterTestUtil.NON_NULL_OBJECT;
+    private static final String DUMMY_PARAM_NAME = "foo";
+
+    public void testNoNullsAllowed() {
+        try {
+            ParameterUtil.checkNotNull(DUMMY_PARAM_NAME, NULL);
+            fail("Nulls should not be allowed");
+        } catch (IllegalArgumentException expected) { }
+    }
+
+    public void testEmptyStringNotAllowed() {
+        checkStringNotAllowed(NULL);
+        checkStringNotAllowed(EMPTY_STRING);
+        checkStringNotAllowed(SINGLE_SPACE);
+    }
+
+    public void testNonEmptyStringAllowed() {
+        ParameterUtil.checkNotEmptyString(DUMMY_PARAM_NAME, NON_EMPTY_STRING);
+    }
+
+    public void testNonNullObjectAllowed() {
+        ParameterUtil.checkNotNull(DUMMY_PARAM_NAME, NON_NULL_OBJECT);
+    }
+
+    private void checkStringNotAllowed(String param) {
+        try {
+            ParameterUtil.checkNotEmptyString(DUMMY_PARAM_NAME, param);
+            fail("Empty strings should not be allowed");
+        } catch (IllegalArgumentException expected) { }
+    }
+}

Added: trunk/src/jar/query/java/org/jrdf/util/param/package.html
===================================================================
--- trunk/src/jar/query/java/org/jrdf/util/param/package.html	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/util/param/package.html	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,10 @@
+<html>
+<head>
+<title>Utilities for handling parameters</title>
+</head>
+<body>
+<p>
+Utilities for handling parameters to methods, for example null and emtpy string checks.
+</p>
+</body>
+</html>

Added: trunk/src/jar/query/java/org/jrdf/vocabulary/RDF.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/vocabulary/RDF.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/vocabulary/RDF.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,155 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.vocabulary;
+
+// Java 2 standard
+import java.net.URI;
+
+/**
+ * A set of constants for the standard RDF vocabulary.
+ *
+ * @author Andrew Newman
+ */
+public abstract class RDF extends Vocabulary {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 5974585938932893808L;
+
+  /** The URI of the RDF name space. */
+  public static final URI BASE_URI = URI.create("http://www.w3.org/1999/02/22-rdf-syntax-ns#");;
+
+  /** The class of unordered containers. */
+  public static final URI BAG = URI.create(BASE_URI + "Bag");
+
+  /** The class of ordered containers. */
+  public static final URI SEQ = URI.create(BASE_URI + "Seq");
+
+  /** The class of containers of alternatives. */
+  public static final URI ALT = URI.create(BASE_URI + "Alt");
+
+  /** The class of RDF statements. */
+  public static final URI STATEMENT = URI.create(BASE_URI + "Statement");
+
+  /** The class of RDF properties. */
+  public static final URI PROPERTY = URI.create(BASE_URI + "Property");
+
+  /** The class of XML literal values. */
+  public static final URI XML_LITERAL = URI.create(BASE_URI + "XMLLiteral");
+
+  /** The class of RDF Lists. */
+  public static final URI LIST = URI.create(BASE_URI + "List");
+
+  /**
+   * A special property element that is equivalent to rdf:_1, rdf:_2 in order.
+   * Only used in RDF/XML as inserting members of containers using LI normally
+   * will result in duplicate instances not being recorded.
+   */
+  public static final URI LI = URI.create(BASE_URI + "li");
+
+  /**
+   * The empty list, with no items in it. If the rest of a list is nil then
+   * the list has no more items in it.
+   */
+  public static final URI NIL = URI.create(BASE_URI + "nil");
+
+  /** The subject of the subject RDF statement. */
+  public static final URI SUBJECT = URI.create(BASE_URI + "subject");
+
+  /** The predicate of the subject RDF statement. */
+  public static final URI PREDICATE = URI.create(BASE_URI + "predicate");
+
+  /** The object of the subject RDF statement. */
+  public static final URI OBJECT = URI.create(BASE_URI + "object");
+
+  /** The subject is an instance of a class. */
+  public static final URI TYPE = URI.create(BASE_URI + "type");
+
+  /** Idiomatic property used for structured values. */
+  public static final URI VALUE = URI.create(BASE_URI + "value");
+
+  /** The first item in the subject RDF list. */
+  public static final URI FIRST = URI.create(BASE_URI + "first");
+
+  /** The rest of the subject RDF list after the first item. */
+  public static final URI REST = URI.create(BASE_URI + "rest");
+
+  static {
+    // Add Classes
+    resources.add(SEQ);
+    resources.add(BAG);
+    resources.add(ALT);
+    resources.add(STATEMENT);
+    resources.add(PROPERTY);
+    resources.add(XML_LITERAL);
+    resources.add(LIST);
+    resources.add(NIL);
+
+    resources.add(LI);
+
+    // Add Properties
+    resources.add(SUBJECT);
+    resources.add(PREDICATE);
+    resources.add(OBJECT);
+    resources.add(TYPE);
+    resources.add(VALUE);
+    resources.add(FIRST);
+    resources.add(REST);
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/vocabulary/RDFS.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/vocabulary/RDFS.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/vocabulary/RDFS.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,146 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.vocabulary;
+
+// Java 2 standard
+import java.net.URI;
+
+/**
+ * A set of constants for the standard RDFS vocabulary.
+ *
+ * @author Andrew Newman
+ */
+public abstract class RDFS extends Vocabulary {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 3344119222366953296L;
+
+  /** The URI of the RDFS name space. */
+  public static final URI BASE_URI = URI.create("http://www.w3.org/2000/01/rdf-schema#");
+
+  /** The class resource, everything. */
+  public static final URI RESOURCE = URI.create(BASE_URI + "Resource");
+
+  /** The class of classes. */
+  public static final URI CLASS = URI.create(BASE_URI + "Class");
+
+  /** The class of literal values, eg. textual strings and integers. */
+  public static final URI LITERAL = URI.create(BASE_URI + "Literal");
+
+  /** The class of RDF datatypes. */
+  public static final URI DATATYPE = URI.create(BASE_URI + "Datatype");
+
+  /** The class of RDF containers. */
+  public static final URI CONTAINER = URI.create(BASE_URI + "Container");
+
+  /**
+   * The class of container membership properties, rdf:_1, rdf:_2, ...,
+   * all of which are sub-properties of 'member'.
+   */
+  public static final URI CONTAINER_MEMBERSHIP_PROPERTY = URI.create(BASE_URI + "ContainerMembershipProperty");
+
+  /** A range of the subject property. */
+  public static final URI RANGE = URI.create(BASE_URI + "range");
+
+  /** A domain of the subject property. */
+  public static final URI DOMAIN = URI.create(BASE_URI + "domain");
+
+  /** The subject is a subclass of a class. */
+  public static final URI SUB_CLASS_OF = URI.create(BASE_URI + "subClassOf");
+
+  /** The subject is a subproperty of a property. */
+  public static final URI SUB_PROPERTY_OF = URI.create(BASE_URI + "subPropertyOf");
+
+  /** A human-readable name for the subject. */
+  public static final URI LABEL = URI.create(BASE_URI + "label");
+
+  /** A description of the subject resource. */
+  public static final URI COMMENT = URI.create(BASE_URI + "comment");
+
+  /** A member of the subject resource. */
+  public static final URI MEMBER = URI.create(BASE_URI + "member");
+
+  /** Further information about the subject resource. */
+  public static final URI SEE_ALSO = URI.create(BASE_URI + "seeAlso");
+
+  /** The defininition of the subject resource. */
+  public static final URI IS_DEFINED_BY = URI.create(BASE_URI + "isDefinedBy");
+
+  static {
+    // Add Classes
+    resources.add(RESOURCE);
+    resources.add(CLASS);
+    resources.add(LITERAL);
+    resources.add(DATATYPE);
+    resources.add(CONTAINER);
+    resources.add(CONTAINER_MEMBERSHIP_PROPERTY);
+
+    // Add Properties
+    resources.add(RANGE);
+    resources.add(DOMAIN);
+    resources.add(SUB_CLASS_OF);
+    resources.add(SUB_PROPERTY_OF);
+    resources.add(LABEL);
+    resources.add(COMMENT);
+    resources.add(MEMBER);
+    resources.add(SEE_ALSO);
+    resources.add(IS_DEFINED_BY);
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/vocabulary/Vocabulary.java
===================================================================
--- trunk/src/jar/query/java/org/jrdf/vocabulary/Vocabulary.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/vocabulary/Vocabulary.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,92 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The JRDF Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        the JRDF Project (http://jrdf.sf.net/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The JRDF Project" and "JRDF" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, please contact
+ *    newmana at users.sourceforge.net.
+ *
+ * 5. Products derived from this software may not be called "JRDF"
+ *    nor may "JRDF" appear in their names without prior written
+ *    permission of the JRDF Project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the JRDF Project.  For more
+ * information on JRDF, please see <http://jrdf.sourceforge.net/>.
+ */
+
+package org.jrdf.vocabulary;
+
+// Java 2 standard
+import java.io.Serializable;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A representation of a known vocabulary.
+ *
+ * @author Andrew Newman
+ */
+public abstract class Vocabulary implements Serializable {
+
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = -3602059929452647818L;
+
+  /** The set of URI references. */
+  protected static Set<URI> resources = new HashSet<URI>();
+
+  protected Vocabulary() {
+  }
+
+  /**
+   * Returns the resources in this vocabulary.
+   *
+   * @return the resource in this vocabulary.
+   */
+  public static Set<URI> getResources() {
+    return resources;
+  }
+}

Added: trunk/src/jar/query/java/org/jrdf/vocabulary/package.html
===================================================================
--- trunk/src/jar/query/java/org/jrdf/vocabulary/package.html	                        (rev 0)
+++ trunk/src/jar/query/java/org/jrdf/vocabulary/package.html	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,12 @@
+<html>
+<head>
+<title>Java RDF (JRDF) Vocabulary Package</title>
+</head>
+<body>
+<p>
+This package contains a pre-defined set of URIs to be used in constructing
+URI References that are used in RDF.  It defines the RDF and RDFS
+vocabularies.
+</p>
+</body>
+</html>

Modified: trunk/src/jar/query/java/org/mulgara/server/SessionFactoryFactory.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/server/SessionFactoryFactory.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/query/java/org/mulgara/server/SessionFactoryFactory.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -37,6 +37,7 @@
 // Locally written packages
 import org.mulgara.config.MulgaraConfig;
 import org.mulgara.server.SessionFactory;
+import org.mulgara.util.ClasspathDesc;
 
 import java.lang.reflect.Constructor;
 
@@ -174,8 +175,11 @@
 
       //instantiate
       return constructor.newInstance(args);
-    }
-    catch (Exception exception) {
+    } catch (ClassNotFoundException cnf) {
+      logger.error("Could not find TripleStoreImplementation class in: " +
+          ClasspathDesc.getPath());
+      throw new SessionFactoryException("Could not instantiate TripleStoreImplementation from configuration.", cnf);
+    } catch (Exception exception) {
 
       throw new SessionFactoryException("Could not instantiate " +
                                         "TripleStoreImplementation from " +

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSessionListQueryUnitTest.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSessionListQueryUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSessionListQueryUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -320,8 +320,8 @@
 
     //add some statements
     URIReference subject = null;
-    URIReference predicate = new URIReferenceImpl(new URI(RDF.baseURI + "type"));
-    URIReference object = new URIReferenceImpl(new URI(RDFS.baseURI + "Class"));
+    URIReference predicate = new URIReferenceImpl(new URI(RDF.BASE_URI + "type"));
+    URIReference object = new URIReferenceImpl(new URI(RDFS.BASE_URI + "Class"));
     for (int i = 0; i < NUM_STATEMENTS; i++) {
 
       subject = new URIReferenceImpl(URI.create(Mulgara.NAMESPACE + "subject" + i));

Modified: trunk/src/jar/resolver/java/org/mulgara/store/exporter/ModelXMLWriter.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/store/exporter/ModelXMLWriter.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/resolver/java/org/mulgara/store/exporter/ModelXMLWriter.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -967,8 +967,8 @@
 
     //default namespaces
     this.namespaces = new HashMap();
-    this.namespaces.put(RDF_PREFIX, RDF.baseURI);
-    this.namespaces.put(RDFS_PREFIX, RDFS.baseURI);
+    this.namespaces.put(RDF_PREFIX, RDF.BASE_URI);
+    this.namespaces.put(RDFS_PREFIX, RDFS.BASE_URI);
     this.namespaces.put("owl", "http://www.w3.org/2002/07/owl#");
     this.namespaces.put("dc", "http://purl.org/dc/elements/1.1/");
 

Modified: trunk/src/jar/resolver-relational/build.xml
===================================================================
--- trunk/src/jar/resolver-relational/build.xml	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/resolver-relational/build.xml	2008-08-28 23:44:40 UTC (rev 1199)
@@ -28,7 +28,7 @@
     <fileset file="${util.dist.dir}/${util.jar}"/>
     <fileset file="${resolver.dist.dir}/${resolver.jar}"/>
     <fileset file="${util-xa.dist.dir}/${util-xa.jar}"/>
-    <fileset file="${content-rio.dist.dir}/${content-rio.jar}"/>
+    <fileset file="${content-rdfxml.dist.dir}/${content-rdfxml.jar}"/>
     <fileset file="${server.dist.dir}/${server-base.jar}"/>
 
     <fileset file="${resolver-file.dist.dir}/${resolver-file.jar}"/>

Modified: trunk/src/jar/resolver-relational/java/org/mulgara/resolver/relational/RelationalResolverUnitTest.java
===================================================================
--- trunk/src/jar/resolver-relational/java/org/mulgara/resolver/relational/RelationalResolverUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/resolver-relational/java/org/mulgara/resolver/relational/RelationalResolverUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -249,7 +249,7 @@
                    tempResolverFactoryClassName,    // temporary models
                    null,                            // no dir for temp models
                    "",                              // no rule loader
-                   "org.mulgara.content.rio.RDFXMLContentHandler");
+                   "org.mulgara.content.rdfxml.RDFXMLContentHandler");
 
       database.addResolverFactory("org.mulgara.resolver.url.URLResolverFactory", null);
       database.addResolverFactory("org.mulgara.resolver.relational.RelationalResolverFactory", null);

Modified: trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java
===================================================================
--- trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -63,7 +63,6 @@
 import org.mortbay.jetty.Handler;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.handler.ContextHandler;
-import org.mortbay.jetty.handler.DefaultHandler;
 import org.mortbay.jetty.nio.BlockingChannelConnector;
 import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.jetty.webapp.WebAppClassLoader;

Modified: trunk/src/jar/sparql-protocol/java/org/mulgara/sparql/protocol/StreamAnswer.java
===================================================================
--- trunk/src/jar/sparql-protocol/java/org/mulgara/sparql/protocol/StreamAnswer.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/sparql-protocol/java/org/mulgara/sparql/protocol/StreamAnswer.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -164,7 +164,7 @@
             logger.debug("document element "+xmlStreamReader.getName());
           }
 
-          if (xmlStreamReader.getName().equals("{"+RDF.baseURI+"}RDF")) {
+          if (xmlStreamReader.getName().equals("{"+RDF.BASE_URI+"}RDF")) {
             throw new StreamFormatException("Document element is not RDF");
           }
 
@@ -533,9 +533,9 @@
 
     // Write the Answer's solutions
     xmlStreamWriter.writeStartElement("RDF");
-    xmlStreamWriter.setPrefix("rdf", RDF.baseURI.toString());
+    xmlStreamWriter.setPrefix("rdf", RDF.BASE_URI.toString());
     xmlStreamWriter.setDefaultNamespace(NAMESPACE);
-    xmlStreamWriter.writeNamespace("rdf", RDF.baseURI.toString());
+    xmlStreamWriter.writeNamespace("rdf", RDF.BASE_URI.toString());
     serializeSolutions(answer, xmlStreamWriter);
     xmlStreamWriter.writeEndElement();
 
@@ -602,7 +602,7 @@
 
           if (object instanceof Answer) {
             xmlStreamWriter.writeAttribute(
-              RDF.baseURI.toString(), "parseType", "Collection"
+              RDF.BASE_URI.toString(), "parseType", "Collection"
             );
             serializeMetadata((Answer) object, xmlStreamWriter);
             serializeSolutions((Answer) object, xmlStreamWriter);
@@ -611,7 +611,7 @@
             Literal literal = (Literal) object;
             if (literal.getDatatypeURI() != null) {
               xmlStreamWriter.writeAttribute(
-                RDF.baseURI.toString(),
+                RDF.BASE_URI.toString(),
                 "datatype",
                 literal.getDatatypeURI().toString()
               );
@@ -620,7 +620,7 @@
           }
           else if (object instanceof URIReference) {
             xmlStreamWriter.writeAttribute(
-              RDF.baseURI.toString(), "resource", object.toString()
+              RDF.BASE_URI.toString(), "resource", object.toString()
             );
           }
           else {

Modified: trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPXMLLiteralImpl.java
===================================================================
--- trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPXMLLiteralImpl.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPXMLLiteralImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -29,7 +29,6 @@
 
 //Java 2 standard packages
 import java.nio.ByteBuffer;
-import java.io.*;
 import java.net.URI;
 
 //apache packages
@@ -43,9 +42,6 @@
 import org.mulgara.store.stringpool.SPComparator;
 import org.mulgara.store.stringpool.SPObject;
 import org.mulgara.store.stringpool.SPTypedLiteral;
-import org.jrdf.graph.Graph;
-import org.jrdf.graph.mem.GraphImpl;
-import org.jrdf.parser.rdfxml.RdfXmlParser;
 
 /**
  * A class that represents the inbuilt RDF datatype XML Literal.  Based on
@@ -89,34 +85,10 @@
     if (str == null) {
       throw new IllegalArgumentException("Null \"str\" parameter");
     }
-    validate(str);
+    // validation is an unnecessary expense here, as the data must be accepted regardless
     this.str = str;
   }
 
-  /**
-   * Attempts to ensure that the given XML Literal value is valid.
-   *
-   * @param str the XML Literal.
-   * @throws IllegalArgumentException if the str does not validate.
-   */
-  private void validate(String str) {
-    String document =
-      "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n" +
-      "  <rdf:Description>\n" +
-      "    <rdf:value rdf:parseType='Literal'>" + str + "</rdf:value>\n" +
-      "  </rdf:Description>\n" +
-      "</rdf:RDF>";
-
-    try {
-      final Graph jrdfMem = new GraphImpl();
-      RdfXmlParser parser = new RdfXmlParser(jrdfMem.getElementFactory());
-      parser.parse(new StringReader(document), URI.create("urn:foo:bar").
-          toString());
-    } catch (Exception e) {
-      throw new IllegalArgumentException("Failed to validate: " + str, e);
-    }
-  }
-
   SPXMLLiteralImpl(ByteBuffer data) {
     this(CHARSET.decode(data).toString());
   }

Modified: trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPXMLLiteralUnitTest.java
===================================================================
--- trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPXMLLiteralUnitTest.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPXMLLiteralUnitTest.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -72,7 +72,6 @@
   public static Test suite() {
     TestSuite suite = new TestSuite();
     suite.addTest(new SPXMLLiteralUnitTest("testValid"));
-    suite.addTest(new SPXMLLiteralUnitTest("testInvalid"));
 
     return suite;
   }
@@ -160,33 +159,6 @@
     }
   }
 
-  /**
-   * Tests some invalid xsd:boolean values
-   *
-   * @throws Exception
-   */
-  public void testInvalid() throws Exception {
-
-    SPXMLLiteralFactory factory = new SPXMLLiteralFactory();
-
-    @SuppressWarnings("unused")
-    SPXMLLiteralImpl text;
-
-    // Test with a tag.
-    try {
-      text = (SPXMLLiteralImpl) factory.newSPTypedLiteral(RDF.XML_LITERAL, "<foo>Hello there</bar>");
-      fail("Should be invalid");
-    } catch (IllegalArgumentException iae) {
-    }
-
-    // Test nested tags
-    try {
-      text = (SPXMLLiteralImpl) factory.newSPTypedLiteral(RDF.XML_LITERAL, "<bar><foo>Hello there</bar></foo>");
-      fail("Should be invalid");
-    } catch (IllegalArgumentException iae) {
-    }
-  }
-
   //set up and tear down
 
   /**

Modified: trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java
===================================================================
--- trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -56,7 +56,7 @@
 import org.mulgara.store.xa.XAStringPool;
 import org.mulgara.store.xa.XAUtils;
 import org.mulgara.util.Constants;
-import org.mulgara.util.Pair;
+import org.mulgara.util.functional.Pair;
 
 import static org.mulgara.store.stringpool.xa11.DataStruct.*;
 

Modified: trunk/src/jar/store-xa/build.xml
===================================================================
--- trunk/src/jar/store-xa/build.xml	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/store-xa/build.xml	2008-08-28 23:44:40 UTC (rev 1199)
@@ -23,6 +23,7 @@
     <fileset file="${store-nodepool.dist.dir}/${store-nodepool.jar}"/>
     <fileset file="${store-stringpool.dist.dir}/${store-stringpool.jar}"/>
     <fileset file="${resolver-spi.dist.dir}/${resolver-spi.jar}"/>
+    <fileset file="${query.dist.dir}/${query.jar}"/>
   </path>
 
   <path id="store-xa-test-classpath">
@@ -49,7 +50,7 @@
 
   <target name="store-xa-compile"
           depends="-store-xa-prepare, store-jar, store-nodepool-jar,
-                   store-stringpool-jar, resolver-spi-jar"
+                   store-stringpool-jar, resolver-spi-jar, query-jar"
           description="Compiles all store-xa related files included generated
                        source code">
 

Deleted: trunk/src/jar/util/java/org/mulgara/util/C.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/C.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/C.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -1,181 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * Generic Collections utility class.
- * This class defines static methods for operating on Collections and the functors found in
- * {@link org.mulgara.util.Fn1} and {@link org.mulgara.util.Fn2}.
- *
- * @created Aug 4, 2008
- * @author Paul Gearon
- * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public class C {
-
-  /**
-   * Creates a new list by applying an operator to each element of an initial list.
-   * The final result meets the condition:
-   * <pre>result.get(i) == op( args.get(i) )   for 0 <= i < args.size()</pre>
-   * The operation in op may throw an exception.
-   * @param <T1> The type of the elements in the arg list, which is also the
-   *             argument type for the operation.
-   * @param <T2> The type of the elements in the result list, which is also
-   *             the return type of the operation.
-   * @param <E> The exception that my be thrown from {@link Fn1E#fn(Object)}.
-   * @param args The input list.
-   * @param op The operation to apply to the elements of the input list.
-   * @return A list whose elements are the result of applying op to each element of args.
-   * @throws E An exception that may be thrown from the {@link Fn1E#fn(Object)} method.
-   */
-  public static <T1,T2,E extends Exception> List<T2> map(Collection<T1> args, Fn1E<T1,T2,E> op) throws E {
-    List<T2> result = new LinkedList<T2>();
-    for (T1 a: args) result.add(op.fn(a));
-    return result;
-  }
-
-  /**
-   * The same method as {@link #map(Collection, Fn1E)} for arrays.
-   */
-  public static <T1,T2,E extends Exception> List<T2> map(T1[] args, Fn1E<T1,T2,E> op) throws E {
-    List<T2> result = new ArrayList<T2>(args.length);
-    for (T1 a: args) result.add(op.fn(a));
-    return result;
-  }
-
-  /**
-   * Creates a new list by applying an operator to each element of an initial list.
-   * The final result meets the condition:
-   * <pre>result.get(i) == op( args.get(i) )   for 0 <= i < args.size()</pre>
-   * The operation in op may <em>not</em> throw an exception.
-   * @param <T1> The type of the elements in the arg list, which is also the
-   *             argument type for the operation.
-   * @param <T2> The type of the elements in the result list, which is also
-   *             the return type of the operation.
-   * @param args The input list.
-   * @param op The operation to apply to the elements of the input list.
-   * @return A list whose elements are the result of applying op to each element of args.
-   */
-  public static <T1,T2> List<T2> map(Collection<T1> args, Fn1<T1,T2> op) {
-    return map(args, (Fn1E<T1,T2,RuntimeException>)op);
-  }
-
-  /**
-   * The same method as {@link #map(Collection, Fn1)} for arrays.
-   */
-  public static <T1,T2> List<T2> map(T1[] args, Fn1<T1,T2> op) {
-    List<T2> result = new ArrayList<T2>(args.length);
-    for (T1 a: args) result.add(op.fn(a));
-    return result;
-  }
-
-  ///////////////
-  // List methods
-  ///////////////
-
-  /**
-   * Returns the head of a linked list. This is a simple wrapper for {@link LinkedList#getFirst()}
-   * @param <T1> The list element type.
-   * @param arg The list.
-   * @return The first element in the list.
-   * @throws NoSuchElementException If the list is empty.
-   */
-  public static <T1> T1 head(LinkedList<T1> arg) throws NoSuchElementException {
-    return arg.getFirst();
-  }
-
-  /**
-   * Returns the head of a list.
-   * @param <T1> The list element type.
-   * @param arg The list.
-   * @return The first element in the list.
-   * @throws NoSuchElementException If the list is empty.
-   */
-  public static <T1> T1 head(List<T1> arg) throws NoSuchElementException {
-    if (arg instanceof LinkedList) return ((LinkedList<T1>)arg).getFirst();
-    if (arg.size() == 0) throw new NoSuchElementException("Empty list");
-    return arg.get(0);
-  }
-
-  /**
-   * Returns the head of a linked list, with a <code>null</code> for an empty list.
-   * @param <T1> The list element type.
-   * @param arg The list.
-   * @return The first element in the list, or <code>null</code> if the list is empty.
-   */
-  public static <T1> T1 headN(LinkedList<T1> arg) {
-    return arg.isEmpty() ? null : arg.getFirst();
-  }
-
-  /**
-   * Returns the head of a list.
-   * @param <T1> The list element type.
-   * @param arg The list.
-   * @return The first element in the list, or <code>null</code> if the list is empty.
-   */
-  public static <T1> T1 headN(List<T1> arg) {
-    return arg.isEmpty() ? null : (arg instanceof LinkedList) ? ((LinkedList<T1>)arg).getFirst() : arg.get(0);
-  }
-
-  /**
-   * Returns the tail of a linked list. This is a simple wrapper for {@link LinkedList#getLast()}.
-   * @param <T1> The list element type.
-   * @param arg The list.
-   * @return The last element in the list.
-   * @throws NoSuchElementException If the list is empty.
-   */
-  public static <T1> T1 tail(LinkedList<T1> arg) throws NoSuchElementException {
-    return arg.getLast();
-  }
-
-  /**
-   * Returns the tail of a list.
-   * @param <T1> The list element type.
-   * @param arg The list.
-   * @return The last element in the list.
-   * @throws IndexOutOfBoundsException If the list is empty.
-   */
-  public static <T1> T1 tail(List<T1> arg) throws NoSuchElementException {
-    if (arg instanceof LinkedList) return ((LinkedList<T1>)arg).getLast();
-    if (arg.size() == 0) throw new NoSuchElementException("Empty list");
-    return arg.get(arg.size() - 1);
-  }
-
-  /**
-   * Returns the tail of a list.
-   * @param <T1> The list element type.
-   * @param arg The list.
-   * @return The last element in the list, or <code>null</code> if the list is empty.
-   */
-  public static <T1> T1 tailN(LinkedList<T1> arg) {
-    return arg.isEmpty() ? null : arg.getLast();
-  }
-
-  /**
-   * Returns the tail of a list.
-   * @param <T1> The list element type.
-   * @param arg The list.
-   * @return The last element in the list, or <code>null</code> if the list is empty.
-   */
-  public static <T1> T1 tailN(List<T1> arg) {
-    return arg.isEmpty() ? null : arg.get(arg.size() - 1);
-  }
-
-}

Added: trunk/src/jar/util/java/org/mulgara/util/ClasspathDesc.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/ClasspathDesc.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/ClasspathDesc.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,72 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Utility for describing a classpath, and extracting elements if needed.
+ *
+ * @created Aug 28, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class ClasspathDesc {
+
+  /** The identifier for the system classpath property. */
+  private static final String JAVA_CLASS_PATH = "java.class.path";
+
+
+  /**
+   * @return The system classpath.
+   */
+  public static String getPath() {
+    return System.getProperty(JAVA_CLASS_PATH);
+  }
+
+
+  /**
+   * @return The elements of the classpath as an array of strings.
+   */
+  public static String[] getPaths() {
+    return System.getProperty(JAVA_CLASS_PATH).split(File.pathSeparator);
+  }
+
+
+  /**
+   * Looks in the classpath for a file that matches the <value>expected</value> parameter.
+   * @param expected This will be part of a filename to search for.
+   * @return The first filename in the classpath that contains <value>expected</value>.
+   *         <code>null</code> if not found.
+   */
+  public static String getPath(String expected) {
+    for (String path: getPaths()) if (path.contains(expected)) return path;
+    return null;
+  }
+
+  /**
+   * Creates a copy of a file from the classpath in a temporary directory.
+   * @param expected Part of the name of the file being looked for in the classpath.
+   * @return The path of the temporary file.
+   * @throws IOException If there was a problem reading or writing the file.
+   */
+  public static String createTempCopy(String expected) throws IOException {
+    String path = getPath(expected);
+    if (path == null) return null;
+    File dir = TempDir.getTempDir();
+    return FileUtil.copyFile(path, new File(dir,path));
+  }
+
+}

Deleted: trunk/src/jar/util/java/org/mulgara/util/F.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/F.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/F.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -1,33 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.util;
-
-/**
- * 
- *
- * @created Aug 16, 2008
- * @author Paul Gearon
- * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public class F {
-
-  static final <T1,T2> Fn<T2> curry(final Fn1<T1,T2> fna, final T1 arg) {
-    return new Fn<T2>() { public T2 fn() { return fna.fn(arg); } };
-  }
-
-  static final <T1,T2,R> Fn1<T2,R> curry(final Fn2<T1,T2,R> fna, final T1 arg) {
-    return new Fn1<T2,R>() { public R fn(T2 a) { return fna.fn(arg, a); } };
-  }
-
-}

Modified: trunk/src/jar/util/java/org/mulgara/util/FileUtil.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/FileUtil.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/FileUtil.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -29,6 +29,12 @@
 
 // Java 2 standard packages
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
 import org.apache.log4j.*;
 
 /**
@@ -37,16 +43,8 @@
  * @created 2003-11-27
  *
  * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
- *
- * @version $Revision: 1.9 $
- *
- * @modified $Date: 2005/01/05 04:59:29 $ by $Author: newmana $
- *
- * @maintenanceAuthor $Author: newmana $
- *
  * @copyright &copy;2003
  *   <a href="http://www.pisoftware.com/">Plugged In Software Pty Ltd</a>
- *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
 public abstract class FileUtil {
@@ -54,6 +52,9 @@
   /** Logger.  */
   private static Logger logger = Logger.getLogger(FileUtil.class.getName());
 
+  /** The size of the buffer used to read and write to files. 0.25MB. */
+  private static final int BUFFER_SIZE = 1024 * 256;
+
   /**
    * Recursively delete a file or directory.
    *
@@ -79,4 +80,58 @@
 
     return directory.delete();
   }
+
+
+  /**
+   * @see #copyFile(File, File)
+   * @param src The path for the source file.
+   * @param dest The destination file or directory.
+   */
+  public static String copyFile(String src, File dest) throws IOException {
+    return copyFile(new File(src), dest);
+  }
+
+
+  /**
+   * @see #copyFile(File, File)
+   * @param src The source file.
+   * @param dest The path for the destination file or directory.
+   */
+  public static String copyFile(File src, String dest) throws IOException {
+    return copyFile(src, new File(dest));
+  }
+
+
+  /**
+   * @see #copyFile(File, File)
+   * @param src The path for the source file.
+   * @param dest The path for the destination file or directory.
+   */
+  public static String copyFile(String src, String dest) throws IOException {
+    return copyFile(new File(src), new File(dest));
+  }
+
+
+  /**
+   * Copies a file from one place to another. This is similar to the "cp" utility.
+   * @param src The source file.
+   * @param dest The destination file or directory. If this specifies a directory,
+   *        then the filename part of <value>src</value> will be used.
+   * @return The path of the file that was written.
+   * @throws IOException If there was a problem reading or writing the file.
+   */
+  public static String copyFile(File src, File dest) throws IOException {
+    if (dest.isDirectory()) dest = new File(dest, src.getName());
+    InputStream in = new FileInputStream(src);
+    OutputStream out = new FileOutputStream(dest);
+    byte[] buffer = new byte[BUFFER_SIZE];
+    int len;
+    while ((len = in.read(buffer)) >= 0) {
+      if (len != 0) out.write(buffer, 0, len);
+    }
+    in.close();
+    out.close();
+    return dest.getPath();
+  }
+
 }

Deleted: trunk/src/jar/util/java/org/mulgara/util/Fn.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Fn.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/Fn.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -1,26 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.util;
-
-/**
- * Functor template for a function that takes no arguments and returns a value,
- * without throwing an exception.
- *
- * @created Aug 4, 2008
- * @author Paul Gearon
- * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public interface Fn<T1> extends FnE<T1,RuntimeException> {
-
-}

Deleted: trunk/src/jar/util/java/org/mulgara/util/Fn1.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Fn1.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/Fn1.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -1,26 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.util;
-
-/**
- * Functor template for a function that takes one type and returns another without
- * throwing an exception.
- *
- * @created Aug 4, 2008
- * @author Paul Gearon
- * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public interface Fn1<T1,T2> extends Fn1E<T1,T2,RuntimeException> {
-
-}

Deleted: trunk/src/jar/util/java/org/mulgara/util/Fn1E.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Fn1E.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/Fn1E.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -1,34 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.util;
-
-/**
- * Functor template for a function that takes one type and returns another.
- * An exception may be thrown.
- *
- * @created Aug 4, 2008
- * @author Paul Gearon
- * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public interface Fn1E<T1,T2,E extends Exception> {
-
-  /**
-   * Declares a function template that takes one argument and returns a value of
-   * another type.
-   * @param arg The single argument.
-   * @return A value based on arg.
-   * @throws E Can throw an exception of this type.
-   */
-  T2 fn(T1 arg) throws E;
-}

Deleted: trunk/src/jar/util/java/org/mulgara/util/Fn2.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Fn2.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/Fn2.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -1,26 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.util;
-
-/**
- * Functor template for a function that takes arguments of two different types
- * and returns a value of a third type, without throwing an exception.
- *
- * @created Aug 4, 2008
- * @author Paul Gearon
- * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public interface Fn2<T1,T2,T3> extends Fn2E<T1,T2,T3,RuntimeException>{
-
-}

Deleted: trunk/src/jar/util/java/org/mulgara/util/Fn2E.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Fn2E.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/Fn2E.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -1,35 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.util;
-
-/**
- * Functor template for a function that takes arguments of two different types
- * and returns a value of a third type, possibly throwing an exception.
- *
- * @created Aug 4, 2008
- * @author Paul Gearon
- * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public interface Fn2E<T1,T2,T3,E extends Exception> {
-
-  /**
-   * Declares a function template that takes two arguments and returns a value of
-   * another type.
-   * @param arg1 The first argument.
-   * @param arg2 The first argument.
-   * @return A value based on arg1 and arg2.
-   * @throws E An exception that may be thrown from this method.
-   */
-  T3 fn(T1 arg1, T2 arg2) throws E;
-}

Deleted: trunk/src/jar/util/java/org/mulgara/util/FnE.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/FnE.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/FnE.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -1,33 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.util;
-
-/**
- * Functor template for a function that accepts no parameters, and has a return type.
- * An exception may be thrown.
- *
- * @created Aug 4, 2008
- * @author Paul Gearon
- * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public interface FnE<T1,E extends Exception> {
-
-  /**
-   * Declares a function template that takes no arguments and returns a value.
-   * @return A calculated value.
-   * @throws E Can throw an exception of this type.
-   */
-  T1 fn() throws E;
-
-}

Deleted: trunk/src/jar/util/java/org/mulgara/util/Pair.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Pair.java	2008-08-28 23:42:46 UTC (rev 1198)
+++ trunk/src/jar/util/java/org/mulgara/util/Pair.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -1,44 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.util;
-
-import java.util.Map;
-
-/**
- * A pair of elements.
- *
- * @created Aug 5, 2008
- * @author Paul Gearon
- * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public class Pair<T1,T2> implements Map.Entry<T1,T2> {
-
-  private T1 first;
-
-  private T2 second;
-
-  public Pair(T1 f, T2 s) { first = f; second = s; }
-
-  public T1 first() { return first; }
-
-  public T2 second() { return second; }
-
-  public T1 getKey() { return first; }
-
-  public T2 getValue() { return second; }
-
-  public T2 setValue(T2 value) { throw new UnsupportedOperationException("Pairs are an immutable type"); }
-
-  public static <C1,C2> Pair<C1,C2> p(C1 c1, C2 c2) { return new Pair<C1,C2>(c1, c2); }
-}

Copied: trunk/src/jar/util/java/org/mulgara/util/functional/C.java (from rev 1182, trunk/src/jar/util/java/org/mulgara/util/C.java)
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/functional/C.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/functional/C.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,181 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util.functional;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * Generic Collections utility class.
+ * This class defines static methods for operating on Collections and the functors found in
+ * {@link org.mulgara.util.functional.Fn1} and {@link org.mulgara.util.functional.Fn2}.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class C {
+
+  /**
+   * Creates a new list by applying an operator to each element of an initial list.
+   * The final result meets the condition:
+   * <pre>result.get(i) == op( args.get(i) )   for 0 <= i < args.size()</pre>
+   * The operation in op may throw an exception.
+   * @param <T1> The type of the elements in the arg list, which is also the
+   *             argument type for the operation.
+   * @param <T2> The type of the elements in the result list, which is also
+   *             the return type of the operation.
+   * @param <E> The exception that my be thrown from {@link Fn1E#fn(Object)}.
+   * @param args The input list.
+   * @param op The operation to apply to the elements of the input list.
+   * @return A list whose elements are the result of applying op to each element of args.
+   * @throws E An exception that may be thrown from the {@link Fn1E#fn(Object)} method.
+   */
+  public static <T1,T2,E extends Exception> List<T2> map(Collection<T1> args, Fn1E<T1,T2,E> op) throws E {
+    List<T2> result = new LinkedList<T2>();
+    for (T1 a: args) result.add(op.fn(a));
+    return result;
+  }
+
+  /**
+   * The same method as {@link #map(Collection, Fn1E)} for arrays.
+   */
+  public static <T1,T2,E extends Exception> List<T2> map(T1[] args, Fn1E<T1,T2,E> op) throws E {
+    List<T2> result = new ArrayList<T2>(args.length);
+    for (T1 a: args) result.add(op.fn(a));
+    return result;
+  }
+
+  /**
+   * Creates a new list by applying an operator to each element of an initial list.
+   * The final result meets the condition:
+   * <pre>result.get(i) == op( args.get(i) )   for 0 <= i < args.size()</pre>
+   * The operation in op may <em>not</em> throw an exception.
+   * @param <T1> The type of the elements in the arg list, which is also the
+   *             argument type for the operation.
+   * @param <T2> The type of the elements in the result list, which is also
+   *             the return type of the operation.
+   * @param args The input list.
+   * @param op The operation to apply to the elements of the input list.
+   * @return A list whose elements are the result of applying op to each element of args.
+   */
+  public static <T1,T2> List<T2> map(Collection<T1> args, Fn1<T1,T2> op) {
+    return map(args, (Fn1E<T1,T2,RuntimeException>)op);
+  }
+
+  /**
+   * The same method as {@link #map(Collection, Fn1)} for arrays.
+   */
+  public static <T1,T2> List<T2> map(T1[] args, Fn1<T1,T2> op) {
+    List<T2> result = new ArrayList<T2>(args.length);
+    for (T1 a: args) result.add(op.fn(a));
+    return result;
+  }
+
+  ///////////////
+  // List methods
+  ///////////////
+
+  /**
+   * Returns the head of a linked list. This is a simple wrapper for {@link LinkedList#getFirst()}
+   * @param <T1> The list element type.
+   * @param arg The list.
+   * @return The first element in the list.
+   * @throws NoSuchElementException If the list is empty.
+   */
+  public static <T1> T1 head(LinkedList<T1> arg) throws NoSuchElementException {
+    return arg.getFirst();
+  }
+
+  /**
+   * Returns the head of a list.
+   * @param <T1> The list element type.
+   * @param arg The list.
+   * @return The first element in the list.
+   * @throws NoSuchElementException If the list is empty.
+   */
+  public static <T1> T1 head(List<T1> arg) throws NoSuchElementException {
+    if (arg instanceof LinkedList) return ((LinkedList<T1>)arg).getFirst();
+    if (arg.size() == 0) throw new NoSuchElementException("Empty list");
+    return arg.get(0);
+  }
+
+  /**
+   * Returns the head of a linked list, with a <code>null</code> for an empty list.
+   * @param <T1> The list element type.
+   * @param arg The list.
+   * @return The first element in the list, or <code>null</code> if the list is empty.
+   */
+  public static <T1> T1 headN(LinkedList<T1> arg) {
+    return arg.isEmpty() ? null : arg.getFirst();
+  }
+
+  /**
+   * Returns the head of a list.
+   * @param <T1> The list element type.
+   * @param arg The list.
+   * @return The first element in the list, or <code>null</code> if the list is empty.
+   */
+  public static <T1> T1 headN(List<T1> arg) {
+    return arg.isEmpty() ? null : (arg instanceof LinkedList) ? ((LinkedList<T1>)arg).getFirst() : arg.get(0);
+  }
+
+  /**
+   * Returns the tail of a linked list. This is a simple wrapper for {@link LinkedList#getLast()}.
+   * @param <T1> The list element type.
+   * @param arg The list.
+   * @return The last element in the list.
+   * @throws NoSuchElementException If the list is empty.
+   */
+  public static <T1> T1 tail(LinkedList<T1> arg) throws NoSuchElementException {
+    return arg.getLast();
+  }
+
+  /**
+   * Returns the tail of a list.
+   * @param <T1> The list element type.
+   * @param arg The list.
+   * @return The last element in the list.
+   * @throws IndexOutOfBoundsException If the list is empty.
+   */
+  public static <T1> T1 tail(List<T1> arg) throws NoSuchElementException {
+    if (arg instanceof LinkedList) return ((LinkedList<T1>)arg).getLast();
+    if (arg.size() == 0) throw new NoSuchElementException("Empty list");
+    return arg.get(arg.size() - 1);
+  }
+
+  /**
+   * Returns the tail of a list.
+   * @param <T1> The list element type.
+   * @param arg The list.
+   * @return The last element in the list, or <code>null</code> if the list is empty.
+   */
+  public static <T1> T1 tailN(LinkedList<T1> arg) {
+    return arg.isEmpty() ? null : arg.getLast();
+  }
+
+  /**
+   * Returns the tail of a list.
+   * @param <T1> The list element type.
+   * @param arg The list.
+   * @return The last element in the list, or <code>null</code> if the list is empty.
+   */
+  public static <T1> T1 tailN(List<T1> arg) {
+    return arg.isEmpty() ? null : arg.get(arg.size() - 1);
+  }
+
+}

Copied: trunk/src/jar/util/java/org/mulgara/util/functional/F.java (from rev 1182, trunk/src/jar/util/java/org/mulgara/util/F.java)
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/functional/F.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/functional/F.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,33 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util.functional;
+
+/**
+ * 
+ *
+ * @created Aug 16, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class F {
+
+  static final <T1,T2> Fn<T2> curry(final Fn1<T1,T2> fna, final T1 arg) {
+    return new Fn<T2>() { public T2 fn() { return fna.fn(arg); } };
+  }
+
+  static final <T1,T2,R> Fn1<T2,R> curry(final Fn2<T1,T2,R> fna, final T1 arg) {
+    return new Fn1<T2,R>() { public R fn(T2 a) { return fna.fn(arg, a); } };
+  }
+
+}

Copied: trunk/src/jar/util/java/org/mulgara/util/functional/Fn.java (from rev 1182, trunk/src/jar/util/java/org/mulgara/util/Fn.java)
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/functional/Fn.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/functional/Fn.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,26 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util.functional;
+
+/**
+ * Functor template for a function that takes no arguments and returns a value,
+ * without throwing an exception.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface Fn<T1> extends FnE<T1,RuntimeException> {
+
+}

Copied: trunk/src/jar/util/java/org/mulgara/util/functional/Fn1.java (from rev 1182, trunk/src/jar/util/java/org/mulgara/util/Fn1.java)
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/functional/Fn1.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/functional/Fn1.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,26 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util.functional;
+
+/**
+ * Functor template for a function that takes one type and returns another without
+ * throwing an exception.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface Fn1<T1,T2> extends Fn1E<T1,T2,RuntimeException> {
+
+}

Copied: trunk/src/jar/util/java/org/mulgara/util/functional/Fn1E.java (from rev 1182, trunk/src/jar/util/java/org/mulgara/util/Fn1E.java)
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/functional/Fn1E.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/functional/Fn1E.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,34 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util.functional;
+
+/**
+ * Functor template for a function that takes one type and returns another.
+ * An exception may be thrown.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface Fn1E<T1,T2,E extends Exception> {
+
+  /**
+   * Declares a function template that takes one argument and returns a value of
+   * another type.
+   * @param arg The single argument.
+   * @return A value based on arg.
+   * @throws E Can throw an exception of this type.
+   */
+  T2 fn(T1 arg) throws E;
+}

Copied: trunk/src/jar/util/java/org/mulgara/util/functional/Fn2.java (from rev 1182, trunk/src/jar/util/java/org/mulgara/util/Fn2.java)
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/functional/Fn2.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/functional/Fn2.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,26 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util.functional;
+
+/**
+ * Functor template for a function that takes arguments of two different types
+ * and returns a value of a third type, without throwing an exception.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface Fn2<T1,T2,T3> extends Fn2E<T1,T2,T3,RuntimeException>{
+
+}

Copied: trunk/src/jar/util/java/org/mulgara/util/functional/Fn2E.java (from rev 1182, trunk/src/jar/util/java/org/mulgara/util/Fn2E.java)
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/functional/Fn2E.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/functional/Fn2E.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,35 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util.functional;
+
+/**
+ * Functor template for a function that takes arguments of two different types
+ * and returns a value of a third type, possibly throwing an exception.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface Fn2E<T1,T2,T3,E extends Exception> {
+
+  /**
+   * Declares a function template that takes two arguments and returns a value of
+   * another type.
+   * @param arg1 The first argument.
+   * @param arg2 The first argument.
+   * @return A value based on arg1 and arg2.
+   * @throws E An exception that may be thrown from this method.
+   */
+  T3 fn(T1 arg1, T2 arg2) throws E;
+}

Copied: trunk/src/jar/util/java/org/mulgara/util/functional/FnE.java (from rev 1182, trunk/src/jar/util/java/org/mulgara/util/FnE.java)
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/functional/FnE.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/functional/FnE.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,33 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util.functional;
+
+/**
+ * Functor template for a function that accepts no parameters, and has a return type.
+ * An exception may be thrown.
+ *
+ * @created Aug 4, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface FnE<T1,E extends Exception> {
+
+  /**
+   * Declares a function template that takes no arguments and returns a value.
+   * @return A calculated value.
+   * @throws E Can throw an exception of this type.
+   */
+  T1 fn() throws E;
+
+}

Copied: trunk/src/jar/util/java/org/mulgara/util/functional/Pair.java (from rev 1182, trunk/src/jar/util/java/org/mulgara/util/Pair.java)
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/functional/Pair.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/functional/Pair.java	2008-08-28 23:44:40 UTC (rev 1199)
@@ -0,0 +1,44 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util.functional;
+
+import java.util.Map;
+
+/**
+ * A pair of elements.
+ *
+ * @created Aug 5, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class Pair<T1,T2> implements Map.Entry<T1,T2> {
+
+  private T1 first;
+
+  private T2 second;
+
+  public Pair(T1 f, T2 s) { first = f; second = s; }
+
+  public T1 first() { return first; }
+
+  public T2 second() { return second; }
+
+  public T1 getKey() { return first; }
+
+  public T2 getValue() { return second; }
+
+  public T2 setValue(T2 value) { throw new UnsupportedOperationException("Pairs are an immutable type"); }
+
+  public static <C1,C2> Pair<C1,C2> p(C1 c1, C2 c2) { return new Pair<C1,C2>(c1, c2); }
+}




More information about the Mulgara-svn mailing list