You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/23 11:09:41 UTC

[06/54] [partial] incubator-taverna-engine git commit: Revert "temporarily empty repository"

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/annotations/PutIdentifiedOperation.java
----------------------------------------------------------------------
diff --git a/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/annotations/PutIdentifiedOperation.java b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/annotations/PutIdentifiedOperation.java
new file mode 100644
index 0000000..d05febe
--- /dev/null
+++ b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/annotations/PutIdentifiedOperation.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Applied to methods in Dao implementations which store or update data in the
+ * backing store.
+ * 
+ * @author Tom Oinn
+ */
+@Retention(RUNTIME)
+@Target(METHOD)
+public @interface PutIdentifiedOperation {
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/annotations/package.html
----------------------------------------------------------------------
diff --git a/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/annotations/package.html b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/annotations/package.html
new file mode 100644
index 0000000..0d38e1e
--- /dev/null
+++ b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/annotations/package.html
@@ -0,0 +1,4 @@
+<body>
+Annotations to make methods in the data access object implementations
+for cache injection.
+</body>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/HibernateComponentClass.java
----------------------------------------------------------------------
diff --git a/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/HibernateComponentClass.java b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/HibernateComponentClass.java
new file mode 100644
index 0000000..f8f2076
--- /dev/null
+++ b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/HibernateComponentClass.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.h3;
+
+/**
+ * A marker used to denote that the class should be pre-loaded into hibernate's
+ * class mapping. Used for component classes which are not going to be mapped to
+ * the RDBMS but which must be loadable for mapped classes to instantiate
+ * correctly. Basically if you refer to a class that isn't itself going to be
+ * mapped in hibernate within a mapping definition you'll need to add that
+ * component class to this SPI or hibernate won't be able to find it as it won't
+ * know that it should associate it with the appropriate class loader.
+ * <p>
+ * This should be used as an SPI marker, and set as the first SPI registry in
+ * the preloadRegistries property of the SpiRegistryAwareLocalSessionFactoryBean
+ * 
+ * @author Tom Oinn
+ */
+public interface HibernateComponentClass {
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/HibernateMappedEntity.java
----------------------------------------------------------------------
diff --git a/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/HibernateMappedEntity.java b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/HibernateMappedEntity.java
new file mode 100644
index 0000000..ae77e1d
--- /dev/null
+++ b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/HibernateMappedEntity.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.h3;
+
+import net.sf.taverna.t2.reference.ExternalReferenceSPI;
+import net.sf.taverna.t2.reference.ReferenceSet;
+
+/**
+ * A marker interface used to denote that the component should be registered
+ * with the Hibernate ORM system prior to any {@link ExternalReferenceSPI}
+ * implementations. This is here to allow implementations of e.g.
+ * {@link ReferenceSet} to be in the implementation package where they belong
+ * and still guarantee that they are registered before any other plugins.
+ * <p>
+ * This should be used as an SPI marker, and set as the first SPI registry in
+ * the spiRegistries property of the SpiRegistryAwareLocalSessionFactoryBean
+ * 
+ * @author Tom Oinn
+ */
+public interface HibernateMappedEntity {
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/package.html
----------------------------------------------------------------------
diff --git a/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/package.html b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/package.html
new file mode 100644
index 0000000..4ffba14
--- /dev/null
+++ b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/h3/package.html
@@ -0,0 +1,8 @@
+<body>
+Contains the marker interfaces used by the implementation package to
+ensure that all appropriate classes are mapped in hibernate
+<em>before</em>
+implementations of classes that depend upon them, and to ensure that
+'static' classes such as the implementations of reference set etc are
+mapped correctly.
+</body>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/package.html
----------------------------------------------------------------------
diff --git a/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/package.html b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/package.html
new file mode 100644
index 0000000..503dc3b
--- /dev/null
+++ b/taverna-reference-api/src/main/java/net/sf/taverna/t2/reference/package.html
@@ -0,0 +1,43 @@
+<body>
+<p>Interfaces for the Taverna 2 reference manager. This replaces the
+(badly named) DataManager and is, in effect, a version 2 of that system.
+While these APIs are implementation neutral the intent is heavily
+towards the use of an object relational mapping (ORM) tool such as
+Hibernate backed by a relational database to hold the various
+collection, external reference and error documents managed by the
+reference manager.</p>
+<p>For those familiar with the previous DataManager code the table
+below shows the old class names and the equivalent (where appropriate)
+in the new code:
+</p>
+<table>
+	<tr>
+		<td>DataDocument</td>
+		<td>{@link net.sf.taverna.t2.reference.ReferenceSet}</td>
+	</tr>
+	<tr>
+		<td>ReferenceScheme</td>
+		<td>{@link net.sf.taverna.t2.reference.ExternalReferenceSPI}</td>
+	</tr>
+	<tr>
+		<td>EntityIdentifier</td>
+		<td>{@link net.sf.taverna.t2.reference.T2Reference}</td>
+	</tr>
+	<tr>
+		<td colspan="2">...</td>
+	</tr>
+</table>
+<p>One fundamental change is a move to runtime exceptions rather
+than checked exceptions. This follows the pattern used by Spring and
+Hibernate. The rationale is the same as in those systems - in general
+checked exceptions are not handled properly by client code. The loss of
+compiler level functionality from moving to runtime exceptions is
+countered by much higher readability of code which in itself leads to
+more robust and reliable systems.</p>
+<p>A second change is the availability of asynchronous versions of
+all the critical APIs. Reference construction or translation in
+particular can be a costly process taking substantial time to complete.
+Synchronous versions of the get methods still exist but in general the
+simple callback based asynchronous ones are recommended over them for
+most applications.</p>
+</body>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-api/src/main/resources/net/sf/taverna/t2/reference/AbstractExternalReference.hbm.xml
----------------------------------------------------------------------
diff --git a/taverna-reference-api/src/main/resources/net/sf/taverna/t2/reference/AbstractExternalReference.hbm.xml b/taverna-reference-api/src/main/resources/net/sf/taverna/t2/reference/AbstractExternalReference.hbm.xml
new file mode 100644
index 0000000..e8851e9
--- /dev/null
+++ b/taverna-reference-api/src/main/resources/net/sf/taverna/t2/reference/AbstractExternalReference.hbm.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+                "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+                "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<!-- Hibernate mapping for the abstract superclass of -->
+<!-- ExternalReferenceSPI implementations             -->
+<hibernate-mapping>
+	<class name="net.sf.taverna.t2.reference.AbstractExternalReference"
+		abstract="true">
+		<!-- Let hibernate choose the primary key generation strategy -->
+		<id name="primaryKey" unsaved-value="0" column="bean_id">
+			<generator class="native" />
+		</id>
+	</class>
+</hibernate-mapping>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/.gitignore
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/.gitignore b/taverna-reference-impl/.gitignore
new file mode 100644
index 0000000..1298c5f
--- /dev/null
+++ b/taverna-reference-impl/.gitignore
@@ -0,0 +1 @@
+derby.log

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/pom.xml b/taverna-reference-impl/pom.xml
new file mode 100644
index 0000000..0eb9e8c
--- /dev/null
+++ b/taverna-reference-impl/pom.xml
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.taverna.engine</groupId>
+		<artifactId>taverna-engine</artifactId>
+		<version>3.1.0-incubating-SNAPSHOT</version>
+	</parent>
+	<artifactId>taverna-reference-impl</artifactId>
+	<packaging>bundle</packaging>
+	<name>Apache Taverna Reference Manager Implementation</name>
+	<description>
+		Implementations of the core APIs, not including extension point
+		implementations.
+		This package contains implementations of the data access objects, translator
+		infrastructure etc.
+		The extension point implementations that can be
+		considered as core functionality (files, URLs etc) are held in
+		the taverna-reference-types module.
+    </description>
+
+	<properties>
+		<aspectj.version>1.6.0</aspectj.version>
+	</properties>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Import-Package>
+							org.aspectj.lang,
+							org.springframework.orm.*,
+							org.hibernate.*,
+							org.hibernate.cfg,
+							org.hibernate.proxy, *
+						</Import-Package>
+						<!-- <Import-Package> org.aspectj.lang;resolution:=optional, org.springframework.orm.*;resolution:=optional,
+							org.hibernate.*;resolution:=optional, org.hibernate.proxy;resolution:=optional,
+							org.apache.derby.jdbc, * </Import-Package> -->
+					</instructions>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>${project.parent.groupId}</groupId>
+			<artifactId>taverna-reference-api</artifactId>
+			<version>${project.parent.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>${project.parent.groupId}</groupId>
+			<artifactId>taverna-database-configuration-api</artifactId>
+			<version>${project.parent.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>org.springframework.orm</artifactId>
+			<version>${spring.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>org.springframework.transaction</artifactId>
+			<version>${spring.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.aspectj</groupId>
+			<artifactId>com.springsource.org.aspectj.weaver</artifactId>
+			<version>${aspectj.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>${project.parent.groupId}</groupId>
+			<artifactId>taverna-reference-testhelpers</artifactId>
+			<version>${project.parent.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.hibernate</groupId>
+			<artifactId>com.springsource.org.hibernate</artifactId>
+			<version>${hibernate.version}</version>
+			<!-- <optional>true</optional> -->
+			<exclusions>
+				<exclusion>
+					<groupId>javax.transaction</groupId>
+					<artifactId>jta</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>net.sf.ehcache</groupId>
+					<artifactId>ehcache</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>asm</groupId>
+					<artifactId>asm-attrs</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>antlr</groupId>
+					<artifactId>antlr</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+		<dependency>
+			<groupId>javax.transaction</groupId>
+			<artifactId>com.springsource.javax.transaction</artifactId>
+			<version>${javax.transaction.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>${log4j.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+      <version>${junit.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.derby</groupId>
+			<artifactId>com.springsource.org.apache.derby</artifactId>
+			<version>${derby.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>geronimo-spec</groupId>
+			<artifactId>geronimo-spec-jta</artifactId>
+			<version>${geronimo.spec.jta.version}</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/platform/spring/jdbc/TemporaryJDBC.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/platform/spring/jdbc/TemporaryJDBC.java b/taverna-reference-impl/src/main/java/net/sf/taverna/platform/spring/jdbc/TemporaryJDBC.java
new file mode 100644
index 0000000..d041320
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/platform/spring/jdbc/TemporaryJDBC.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.platform.spring.jdbc;
+
+import static java.io.File.createTempFile;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Create JDBC connection strings for temporary use (ie. from tests)
+ * <p>
+ * {@link #getTemporaryDerbyJDBC()} creates a temporary directory that is used
+ * to construct the JDBC connection string for a local Derby database.
+ * </p>
+ * <p>
+ * This is most useful from a spring configuration, for example when using
+ * {@link InterpolatingDriverManagerDataSource}:
+ * </p>
+ * 
+ * <pre>
+ * &lt;!-- Apache Derby rooted at a temporary directory --&gt;
+ *  &lt;bean id=&quot;t2reference.jdbc.temporaryjdbc&quot;
+ *  class=&quot;net.sf.taverna.platform.spring.jdbc.TemporaryJDBC&quot;&gt;
+ *  &lt;/bean&gt;
+ *  &lt;bean id=&quot;t2reference.jdbc.url&quot; class=&quot;java.lang.String&quot;
+ *  factory-bean=&quot;t2reference.jdbc.temporaryjdbc&quot;
+ *  factory-method=&quot;getTemporaryDerbyJDBC&quot; /&gt;
+ *  &lt;bean id=&quot;t2reference.jdbc.datasource&quot;
+ *  class=&quot;net.sf.taverna.platform.spring.jdbc.InterpolatingDriverManagerDataSource&quot;&gt;
+ *  &lt;property name=&quot;driverClassName&quot;&gt;
+ *  &lt;value&gt;org.apache.derby.jdbc.EmbeddedDriver&lt;/value&gt;
+ *  &lt;/property&gt;
+ *  &lt;property name=&quot;url&quot;&gt;
+ *  &lt;ref bean=&quot;t2reference.jdbc.url&quot; /&gt;
+ *  &lt;/property&gt;
+ *  &lt;property name=&quot;repository&quot;&gt;
+ *  &lt;ref bean=&quot;raven.repository&quot; /&gt;
+ *  &lt;/property&gt;
+ *  &lt;property name=&quot;driverArtifact&quot;&gt;
+ *  &lt;value&gt;org.apache.derby:derby:10.4.1.3&lt;/value&gt;
+ *  &lt;/property&gt;
+ *  &lt;/bean&gt;
+ * </pre>
+ * 
+ * @author Stian Soiland-Reyes
+ */
+public class TemporaryJDBC {
+	public String getTemporaryDerbyJDBC() throws IOException {
+		File tmpDir = createTempFile("t2platform-", ".db");
+		tmpDir.delete();
+		if (!tmpDir.mkdir())
+			throw new IOException("Could not create temporary directory "
+					+ tmpDir);
+		return "jdbc:derby:" + tmpDir.getPath() + "/database;create=true";
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/platform/spring/jdbc/package.html
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/platform/spring/jdbc/package.html b/taverna-reference-impl/src/main/java/net/sf/taverna/platform/spring/jdbc/package.html
new file mode 100644
index 0000000..2355a14
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/platform/spring/jdbc/package.html
@@ -0,0 +1,6 @@
+<body>
+Extensions to the JDBC parts of Spring, and support for proxying of JDBC 
+drivers so we can load them dynamically from raven artifacts. The proxy 
+approach is inspired by http://www.jroller.com/tackline/entry/dynamically_loading_jdbc_drivers 
+with additions to build from raven rather than from existing jar files.
+</body>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractEntityImpl.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractEntityImpl.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractEntityImpl.java
new file mode 100644
index 0000000..8559607
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractEntityImpl.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import net.sf.taverna.t2.reference.T2Reference;
+
+/**
+ * Abstract superclass of ReferenceSetImpl, IdentifiedArrayList and
+ * ErrorDocumentImpl, manages the T2Reference field for these types and their
+ * hibernate backing.
+ * 
+ * @author Tom Oinn
+ */
+public class AbstractEntityImpl {
+	private T2ReferenceImpl id;
+	private String compactId = null;
+
+	public T2Reference getId() {
+		return id;
+	}
+
+	/**
+	 * This method is only ever called from within Hibernate, and is used to
+	 * initialize the unique ID of this reference set.
+	 */
+	public void setTypedId(T2ReferenceImpl newId) {
+		id = newId;
+	}
+
+	/**
+	 * Used because technically you can't accept and return implementation types
+	 * in the methods on a bean which implements an interface, but Hibernate
+	 * needs to construct concrete input and output types!
+	 */
+	public T2ReferenceImpl getTypedId() {
+		return id;
+	}
+
+	public void setInternalId(String newId) {
+		compactId = newId;
+	}
+
+	public final String getInternalId() {
+		if (compactId == null)
+			compactId = id.getCompactForm();
+		return compactId;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractErrorDocumentServiceImpl.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractErrorDocumentServiceImpl.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractErrorDocumentServiceImpl.java
new file mode 100644
index 0000000..ccabf5a
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractErrorDocumentServiceImpl.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import net.sf.taverna.t2.reference.DaoException;
+import net.sf.taverna.t2.reference.ErrorDocument;
+import net.sf.taverna.t2.reference.ErrorDocumentDao;
+import net.sf.taverna.t2.reference.ErrorDocumentService;
+import net.sf.taverna.t2.reference.ErrorDocumentServiceCallback;
+import net.sf.taverna.t2.reference.ErrorDocumentServiceException;
+import net.sf.taverna.t2.reference.ListServiceException;
+import net.sf.taverna.t2.reference.ReferenceContext;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.reference.T2ReferenceGenerator;
+
+/**
+ * Abstract implementation of ErrorDocumentService, inject with an appropriate
+ * ErrorDocumentDao and T2ReferenceGenerator to enable. Contains injectors for
+ * id generation and dao along with other bookkeeping, leaving the
+ * implementation of the actual service logic to the subclass.
+ * 
+ * @author Tom Oinn
+ */
+public abstract class AbstractErrorDocumentServiceImpl extends
+		AbstractServiceImpl implements ErrorDocumentService {
+	protected ErrorDocumentDao errorDao = null;
+	protected T2ReferenceGenerator t2ReferenceGenerator = null;
+
+	/**
+	 * Inject the error document data access object.
+	 */
+	public final void setErrorDao(ErrorDocumentDao dao) {
+		errorDao = dao;
+	}
+
+	/**
+	 * Inject the T2Reference generator used to allocate new IDs when
+	 * registering ErrorDocuments
+	 */
+	public final void setT2ReferenceGenerator(T2ReferenceGenerator t2rg) {
+		t2ReferenceGenerator = t2rg;
+	}
+
+	/**
+	 * Check that the list dao is configured
+	 * 
+	 * @throws ListServiceException
+	 *             if the dao is still null
+	 */
+	protected final void checkDao() throws ErrorDocumentServiceException {
+		if (errorDao == null)
+			throw new ErrorDocumentServiceException(
+					"ErrorDocumentDao not initialized, error document "
+							+ "service operations are not available");
+	}
+
+	/**
+	 * Check that the t2reference generator is configured
+	 * 
+	 * @throws ListServiceException
+	 *             if the generator is still null
+	 */
+	protected final void checkGenerator() throws ErrorDocumentServiceException {
+		if (t2ReferenceGenerator == null)
+			throw new ErrorDocumentServiceException(
+					"T2ReferenceGenerator not initialized, error document "
+							+ "service operations not available");
+	}
+
+	@Override
+	public final void getErrorAsynch(final T2Reference id,
+			final ErrorDocumentServiceCallback callback)
+			throws ErrorDocumentServiceException {
+		checkDao();
+		Runnable r = new Runnable() {
+			@Override
+			public void run() {
+				try {
+					ErrorDocument e = errorDao.get(id);
+					callback.errorRetrieved(e);
+				} catch (DaoException de) {
+					callback.errorRetrievalFailed(new ErrorDocumentServiceException(
+							de));
+				}
+			}
+		};
+		executeRunnable(r);
+	}
+
+	@Override
+	public final ErrorDocument registerError(String message, int depth,
+			ReferenceContext context) throws ErrorDocumentServiceException {
+		return registerError(message, (Throwable) null, depth, context);
+	}
+
+	@Override
+	public final ErrorDocument registerError(Throwable t, int depth,
+			ReferenceContext context) throws ErrorDocumentServiceException {
+		return registerError("", t, depth, context);
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractListServiceImpl.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractListServiceImpl.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractListServiceImpl.java
new file mode 100644
index 0000000..ad564fb
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractListServiceImpl.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import net.sf.taverna.t2.reference.ListDao;
+import net.sf.taverna.t2.reference.ListService;
+import net.sf.taverna.t2.reference.ListServiceCallback;
+import net.sf.taverna.t2.reference.ListServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.reference.T2ReferenceGenerator;
+
+/**
+ * Abstract implementation of ListService, inject with an appropriate ListDao
+ * and T2ReferenceGenerator to enable. Contains injectors for id generation and
+ * dao along with other bookkeeping, leaving the implementation of the actual
+ * service logic to the subclass.
+ * 
+ * @author Tom Oinn
+ * 
+ */
+public abstract class AbstractListServiceImpl extends AbstractServiceImpl
+		implements ListService {
+	protected ListDao listDao = null;
+	protected T2ReferenceGenerator t2ReferenceGenerator = null;
+
+	/**
+	 * Inject the list data access object.
+	 */
+	public final void setListDao(ListDao dao) {
+		listDao = dao;
+	}
+
+	/**
+	 * Inject the T2Reference generator used to allocate new IDs when
+	 * registering lists of T2Reference
+	 */
+	public final void setT2ReferenceGenerator(T2ReferenceGenerator t2rg) {
+		t2ReferenceGenerator = t2rg;
+	}
+
+	/**
+	 * Check that the list dao is configured
+	 * 
+	 * @throws ListServiceException
+	 *             if the dao is still null
+	 */
+	protected final void checkDao() throws ListServiceException {
+		if (listDao == null)
+			throw new ListServiceException("ListDao not initialized, list "
+					+ "service operations are not available");
+	}
+
+	/**
+	 * Check that the t2reference generator is configured
+	 * 
+	 * @throws ListServiceException
+	 *             if the generator is still null
+	 */
+	protected final void checkGenerator() throws ListServiceException {
+		if (t2ReferenceGenerator == null)
+			throw new ListServiceException(
+					"T2ReferenceGenerator not initialized, list "
+							+ "service operations not available");
+	}
+
+	@Override
+	public final void getListAsynch(final T2Reference id,
+			final ListServiceCallback callback) throws ListServiceException {
+		checkDao();
+		Runnable r = new Runnable() {
+			@Override
+			public void run() {
+				try {
+					callback.listRetrieved(getList(id));
+				} catch (ListServiceException lse) {
+					callback.listRetrievalFailed(lse);
+				}
+			}
+		};
+		executeRunnable(r);
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractReferenceServiceImpl.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractReferenceServiceImpl.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractReferenceServiceImpl.java
new file mode 100644
index 0000000..3ef8e9b
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractReferenceServiceImpl.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import java.util.List;
+import java.util.Set;
+
+import net.sf.taverna.t2.reference.ErrorDocumentService;
+import net.sf.taverna.t2.reference.ExternalReferenceSPI;
+import net.sf.taverna.t2.reference.ListService;
+import net.sf.taverna.t2.reference.ReferenceContext;
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.ReferenceServiceResolutionCallback;
+import net.sf.taverna.t2.reference.ReferenceSetService;
+import net.sf.taverna.t2.reference.StreamToValueConverterSPI;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.reference.ValueToReferenceConverterSPI;
+
+/**
+ * Implementation of ReferenceService, inject with ReferenceSetService,
+ * ErrorDocumentService and ListService to enable. Inject with an instance
+ * registry of ValueToReferenceConvertorSPI to enable on the fly registration of
+ * otherwise illegal object types. This class contains the basic injection
+ * functionality and the getters for the sub-services, mostly to isolate these
+ * mundane bits of code from the more interesting actual implementation of the
+ * reference service logic.
+ * 
+ * @author Tom Oinn
+ */
+public abstract class AbstractReferenceServiceImpl extends AbstractServiceImpl
+		implements ReferenceService {
+	protected ErrorDocumentService errorDocumentService = null;
+	protected ReferenceSetService referenceSetService = null;
+	protected ListService listService = null;
+	protected List<ValueToReferenceConverterSPI> converters = null;
+	@SuppressWarnings("rawtypes")
+	protected List<StreamToValueConverterSPI> valueBuilders = null;
+
+	/**
+	 * Inject value to reference convertor SPI
+	 */
+	public final void setConverters(
+			List<ValueToReferenceConverterSPI> converters) {
+		this.converters = converters;
+	}
+
+	/**
+	 * Inject stream to value converter SPI
+	 */
+	@SuppressWarnings("rawtypes")
+	public final void setValueBuilders(
+			List<StreamToValueConverterSPI> valueBuilders) {
+		this.valueBuilders = valueBuilders;
+	}
+
+	/**
+	 * Inject error document service
+	 */
+	public final void setErrorDocumentService(ErrorDocumentService eds) {
+		this.errorDocumentService = eds;
+	}
+
+	/**
+	 * Inject reference set service
+	 */
+	public final void setReferenceSetService(ReferenceSetService rss) {
+		this.referenceSetService = rss;
+	}
+
+	/**
+	 * Inject list service
+	 */
+	public final void setListService(ListService ls) {
+		this.listService = ls;
+	}
+
+	/**
+	 * Throw a ReferenceServiceException if methods in ReferenceService are
+	 * called without the necessary sub-services configured.
+	 */
+	protected final void checkServices() throws ReferenceServiceException {
+		if (errorDocumentService == null)
+			throw new ReferenceServiceException(
+					"Reference service must be configued with an "
+							+ "instance of ErrorDocumentService to function");
+		if (referenceSetService == null)
+			throw new ReferenceServiceException(
+					"Reference service must be configued with an "
+							+ "instance of ReferenceSetService to function");
+		if (listService == null)
+			throw new ReferenceServiceException(
+					"Reference service must be configued with an "
+							+ "instance of ListService to function");
+	}
+
+	/**
+	 * Check whether the converter registry has been defined, throw a
+	 * ReferenceServiceException if not
+	 */
+	protected final void checkConverterRegistry()
+			throws ReferenceServiceException {
+		if (converters == null)
+			throw new ReferenceServiceException(
+					"Reference service must be configued with an "
+							+ "instance registry of ValueToReferenceConvertorSPI "
+							+ "to enable on the fly mapping of arbitrary objects "
+							+ "during compound registration");
+	}
+
+	@Override
+	public final ErrorDocumentService getErrorDocumentService() {
+		checkServices();
+		return this.errorDocumentService;
+	}
+
+	@Override
+	public final ListService getListService() {
+		checkServices();
+		return this.listService;
+	}
+
+	@Override
+	public final ReferenceSetService getReferenceSetService() {
+		checkServices();
+		return this.referenceSetService;
+	}
+
+	/**
+	 * Wraps the synchronous form, using the executeRunnable method to schedule
+	 * it.
+	 */
+	@Override
+	public void resolveIdentifierAsynch(final T2Reference id,
+			final Set<Class<ExternalReferenceSPI>> ensureTypes,
+			final ReferenceContext context,
+			final ReferenceServiceResolutionCallback callback)
+			throws ReferenceServiceException {
+		checkServices();
+		Runnable r = new Runnable() {
+			@Override
+			public void run() {
+				try {
+					callback.identifierResolved(resolveIdentifier(id,
+							ensureTypes, context));
+				} catch (ReferenceServiceException rse) {
+					callback.resolutionFailed(rse);
+				}
+			}
+		};
+		executeRunnable(r);
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractReferenceSetServiceImpl.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractReferenceSetServiceImpl.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractReferenceSetServiceImpl.java
new file mode 100644
index 0000000..9c930a5
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractReferenceSetServiceImpl.java
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import java.util.Set;
+
+import net.sf.taverna.t2.reference.DaoException;
+import net.sf.taverna.t2.reference.ExternalReferenceSPI;
+import net.sf.taverna.t2.reference.ReferenceContext;
+import net.sf.taverna.t2.reference.ReferenceSet;
+import net.sf.taverna.t2.reference.ReferenceSetAugmentor;
+import net.sf.taverna.t2.reference.ReferenceSetDao;
+import net.sf.taverna.t2.reference.ReferenceSetService;
+import net.sf.taverna.t2.reference.ReferenceSetServiceCallback;
+import net.sf.taverna.t2.reference.ReferenceSetServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.reference.T2ReferenceGenerator;
+
+/**
+ * Abstract implementation of ReferenceSetService, inject with an appropriate
+ * ReferenceSetDao to enable. Implements translation functionality as long as an
+ * appropriate ReferenceSetAugmentor implementation is injected. Contains
+ * injectors for id generation and dao along with other bookkeeping, leaving the
+ * implementation of the actual service logic to the subclass.
+ * 
+ * @author Tom Oinn
+ */
+public abstract class AbstractReferenceSetServiceImpl extends
+		AbstractServiceImpl implements ReferenceSetService {
+	protected ReferenceSetDao referenceSetDao = null;
+	protected T2ReferenceGenerator t2ReferenceGenerator = null;
+	protected ReferenceSetAugmentor referenceSetAugmentor = null;
+
+	/**
+	 * Inject the reference set data access object.
+	 */
+	public final void setReferenceSetDao(ReferenceSetDao dao) {
+		this.referenceSetDao = dao;
+	}
+
+	/**
+	 * Inject the T2Reference generator used to allocate new IDs when
+	 * registering sets of ExternalReferenceSPI
+	 */
+	public final void setT2ReferenceGenerator(T2ReferenceGenerator t2rg) {
+		this.t2ReferenceGenerator = t2rg;
+	}
+
+	/**
+	 * Inject the ReferenceSetAugmentor used to translate or construct new
+	 * ExternalReferenceSPI instances within a ReferenceSet
+	 */
+	public final void setReferenceSetAugmentor(ReferenceSetAugmentor rse) {
+		this.referenceSetAugmentor = rse;
+	}
+
+	/**
+	 * Check that the reference set dao is configured
+	 * 
+	 * @throws ReferenceSetServiceException
+	 *             if the dao is still null
+	 */
+	protected final void checkDao() throws ReferenceSetServiceException {
+		if (referenceSetDao == null)
+			throw new ReferenceSetServiceException(
+					"ReferenceSetDao not initialized, reference set "
+							+ "service operations are not available");
+	}
+
+	/**
+	 * Check that the t2reference generator is configured
+	 * 
+	 * @throws ReferenceSetServiceException
+	 *             if the generator is still null
+	 */
+	protected final void checkGenerator() throws ReferenceSetServiceException {
+		if (t2ReferenceGenerator == null)
+			throw new ReferenceSetServiceException(
+					"T2ReferenceGenerator not initialized, reference "
+							+ "set service operations not available");
+	}
+
+	/**
+	 * Check that the reference set augmentor is configured
+	 * 
+	 * @throws ReferenceSetServiceException
+	 *             if the reference set augmentor is still null
+	 */
+	protected final void checkAugmentor() throws ReferenceSetServiceException {
+		if (referenceSetAugmentor == null)
+			throw new ReferenceSetServiceException(
+					"ReferenceSetAugmentor not initialized, reference "
+							+ "set service operations not available");
+	}
+
+	@Override
+	public final void getReferenceSetAsynch(final T2Reference id,
+			final ReferenceSetServiceCallback callback)
+			throws ReferenceSetServiceException {
+		checkDao();
+		Runnable r = new Runnable() {
+			@Override
+			public void run() {
+				try {
+					ReferenceSet rs = referenceSetDao.get(id);
+					callback.referenceSetRetrieved(rs);
+				} catch (DaoException de) {
+					callback.referenceSetRetrievalFailed(new ReferenceSetServiceException(
+							de));
+				}
+			}
+		};
+		executeRunnable(r);
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public final void getReferenceSetWithAugmentationAsynch(
+			final T2Reference id,
+			final Set<Class<ExternalReferenceSPI>> ensureTypes,
+			final ReferenceContext context,
+			final ReferenceSetServiceCallback callback)
+			throws ReferenceSetServiceException {
+		checkDao();
+		checkAugmentor();
+		Runnable r = new Runnable() {
+			@Override
+			public void run() {
+				try {
+					callback.referenceSetRetrieved(getReferenceSetWithAugmentation(
+							id, ensureTypes, context));
+				} catch (ReferenceSetServiceException rsse) {
+					callback.referenceSetRetrievalFailed(rsse);
+				}
+			}
+		};
+		executeRunnable(r);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractServiceImpl.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractServiceImpl.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractServiceImpl.java
new file mode 100644
index 0000000..c24981e
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractServiceImpl.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+/**
+ * Abstract superclass for all service implementation objects, will be used to
+ * allow injection of thread pooling logic as and when we implement it.
+ * 
+ * @author Tom Oinn
+ */
+public class AbstractServiceImpl {
+	/**
+	 * Schedule a runnable for execution - current naive implementation uses a
+	 * new thread and executes immediately, but this is where any thread pool
+	 * logic would go if we wanted to add that.
+	 * 
+	 * @param r
+	 */
+	protected void executeRunnable(Runnable r) {
+		makeExecutionThread(r).start();
+	}
+
+	protected Thread makeExecutionThread(Runnable r) {
+		return new Thread(r);
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractT2ReferenceGenerator.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractT2ReferenceGenerator.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractT2ReferenceGenerator.java
new file mode 100644
index 0000000..dedcc67
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/AbstractT2ReferenceGenerator.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import static net.sf.taverna.t2.reference.T2ReferenceType.ErrorDocument;
+import static net.sf.taverna.t2.reference.T2ReferenceType.IdentifiedList;
+import static net.sf.taverna.t2.reference.T2ReferenceType.ReferenceSet;
+
+import java.util.List;
+
+import net.sf.taverna.t2.reference.ReferenceContext;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.reference.T2ReferenceGenerator;
+import net.sf.taverna.t2.reference.WorkflowRunIdEntity;
+
+/**
+ * An abstract class for implementing simple {@link T2ReferenceGenerator}s.
+ * 
+ * @author Stian Soiland-Reyes
+ */
+public abstract class AbstractT2ReferenceGenerator implements
+		T2ReferenceGenerator {
+	public AbstractT2ReferenceGenerator() {
+		super();
+	}
+
+	private void initReferenceNamespace(T2ReferenceImpl r, ReferenceContext context) {
+		if (context == null) {
+			// this is not good, just use the default namespace
+			r.setNamespacePart(getNamespace());
+			return;
+		}
+
+		List<WorkflowRunIdEntity> workflowRunIdEntities = context
+				.getEntities(WorkflowRunIdEntity.class);
+		if (workflowRunIdEntities == null || workflowRunIdEntities.isEmpty()) {
+			// this is not good, just use the default namespace
+			r.setNamespacePart(getNamespace());
+			return;
+		}
+
+		// there should be only one wf run id entity
+		String workflowRunId = ((WorkflowRunIdEntity) workflowRunIdEntities
+				.get(0)).getWorkflowRunId();
+		r.setNamespacePart(workflowRunId);
+	}
+
+	@Override
+	public synchronized T2Reference nextReferenceSetReference(
+			ReferenceContext context) {
+		T2ReferenceImpl r = new T2ReferenceImpl();
+		initReferenceNamespace(r, context);
+		r.setLocalPart(getNextLocalPart());
+		r.setReferenceType(ReferenceSet);
+		r.setDepth(0);
+		r.setContainsErrors(false);
+		return r;
+	}
+
+	/**
+	 * Generate a new local part for a new {@link T2Reference reference}. The
+	 * local part should be unique within this
+	 * {@link T2ReferenceGenerator#getNamespace() namespace}.
+	 * 
+	 * @return A new, unique local part to identify a new reference.
+	 */
+	protected abstract String getNextLocalPart();
+
+	@Override
+	public T2Reference nextListReference(boolean containsErrors, int listDepth,
+			ReferenceContext context) {
+		T2ReferenceImpl r = new T2ReferenceImpl();
+		initReferenceNamespace(r, context);
+		r.setLocalPart(getNextLocalPart());
+		r.setReferenceType(IdentifiedList);
+		r.setDepth(listDepth);
+		r.setContainsErrors(containsErrors);
+		return r;
+	}
+
+	@Override
+	public T2Reference nextErrorDocumentReference(int depth,
+			ReferenceContext context) {
+		T2ReferenceImpl r = new T2ReferenceImpl();
+		initReferenceNamespace(r, context);
+		r.setLocalPart(getNextLocalPart());
+		r.setReferenceType(ErrorDocument);
+		r.setDepth(depth);
+		// This is an error document, it contains errors by definition
+		r.setContainsErrors(true);
+		return r;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/CacheAspect.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/CacheAspect.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/CacheAspect.java
new file mode 100644
index 0000000..59b5e04
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/CacheAspect.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import net.sf.taverna.t2.reference.DaoException;
+import net.sf.taverna.t2.reference.Identified;
+import net.sf.taverna.t2.reference.ReferenceServiceCacheProvider;
+import net.sf.taverna.t2.reference.T2Reference;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+
+/**
+ * An aspect used to intercept calls to the various data access objects and
+ * divert through a write-through cache provider
+ * 
+ * @author Tom Oinn
+ */
+public class CacheAspect {
+	private ReferenceServiceCacheProvider cacheProvider;
+
+	/**
+	 * Return an injected ReferenceServiceCacheProvider
+	 */
+	private final ReferenceServiceCacheProvider getCacheProvider() {
+		return cacheProvider;
+	}
+
+	/**
+	 * Inject an instance of ReferenceServiceCacheProvider
+	 * 
+	 * @param cacheProvider
+	 *            the cache provider to use
+	 */
+	public final void setCacheProvider(
+			final ReferenceServiceCacheProvider cacheProvider) {
+		this.cacheProvider = cacheProvider;
+	}
+
+	/**
+	 * Handle a 'get by T2Reference' operation on a Dao
+	 * 
+	 * @param pjp
+	 *            the join point representing the ongoing method call to the dao
+	 * @return the entity identified by the T2Reference supplied to the method
+	 *         to which this advice applies
+	 * @throws DaoException
+	 *             if anything goes wrong
+	 */
+	public final Identified getObject(final ProceedingJoinPoint pjp)
+			throws DaoException {
+		Identified result = null;
+
+		// Get the T2Reference from the argument to the get method
+		T2Reference id = (T2Reference) pjp.getArgs()[0];
+		if (id != null) {
+			result = getCacheProvider().get(id);
+			if (result != null)
+				return result;
+		}
+		// If we miss the cache then call the method as usual
+		try {
+			result = (Identified) pjp.proceed();
+		} catch (DaoException e) {
+			throw e;
+		} catch (Throwable e) {
+			throw new DaoException("Unexpected exception type during aspect "
+					+ "based invocation", e);
+		}
+
+		// Write back to the cache
+		if (result != null)
+			getCacheProvider().put(result);
+
+		return result;
+	}
+
+	/**
+	 * Called around a write or update operation on the backing store, writes
+	 * through to the cache after modifying the state of the backing store and
+	 * before returning from the dao method
+	 * 
+	 * @param pjp
+	 *            join point representing the ongoing method invocation to cache
+	 * @throws DaoException
+	 *             if anything goes wrong
+	 */
+	public void putObject(final ProceedingJoinPoint pjp) throws DaoException {
+		// Get the Identified being stored by the method we're advising
+		Identified storedObject = (Identified) pjp.getArgs()[0];
+
+		try {
+			// Run the store or update method
+			pjp.proceed();
+		} catch (DaoException e) {
+			throw e;
+		} catch (Throwable e) {
+			throw new DaoException("Unexpected exception type during aspect "
+					+ "based invocation", e);
+		}
+
+		/*
+		 * Assuming the method isn't null and has an identifier (which it will
+		 * if we haven't thrown an exception before now) write it back to the
+		 * cache provider
+		 */
+		if (storedObject != null && storedObject.getId() != null)
+			getCacheProvider().put(storedObject);
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ContextualizedT2ReferenceImpl.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ContextualizedT2ReferenceImpl.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ContextualizedT2ReferenceImpl.java
new file mode 100644
index 0000000..30d8492
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ContextualizedT2ReferenceImpl.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import net.sf.taverna.t2.reference.ContextualizedT2Reference;
+import net.sf.taverna.t2.reference.T2Reference;
+
+/**
+ * Simple implementation of ContextualizedT2Reference
+ * 
+ * @author Tom Oinn
+ */
+public class ContextualizedT2ReferenceImpl implements ContextualizedT2Reference {
+	private T2Reference reference;
+	private int[] index;
+
+	public ContextualizedT2ReferenceImpl(T2Reference ref, int[] context) {
+		this.reference = ref;
+		this.index = context;
+	}
+
+	@Override
+	public int[] getIndex() {
+		return this.index;
+	}
+
+	@Override
+	public T2Reference getReference() {
+		return this.reference;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder sb = new StringBuilder("[");
+		String sep = "";
+		for (int idx : index) {
+			sb.append(sep).append(idx);
+			sep = ",";
+		}
+		return sb.append("]").append(reference).toString();
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/EmptyReferenceContext.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/EmptyReferenceContext.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/EmptyReferenceContext.java
new file mode 100644
index 0000000..6af0430
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/EmptyReferenceContext.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.taverna.t2.reference.ReferenceContext;
+
+/**
+ * A trivial implementation of ReferenceContext, used if the context parameter
+ * to any service method is null.
+ * 
+ * @author Tom Oinn
+ */
+public class EmptyReferenceContext implements ReferenceContext {
+	/**
+	 * Return an empty entity set for all queries.
+	 */
+	@Override
+	public <T> List<T> getEntities(Class<T> arg0) {
+		return new ArrayList<>();
+	}
+
+	@Override
+	public void addEntity(Object entity) {
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ErrorDocumentImpl.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ErrorDocumentImpl.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ErrorDocumentImpl.java
new file mode 100644
index 0000000..da00d59
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ErrorDocumentImpl.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import net.sf.taverna.t2.reference.ErrorDocument;
+import net.sf.taverna.t2.reference.StackTraceElementBean;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.reference.h3.HibernateMappedEntity;
+
+/**
+ * Simple bean implementation of ErrorDocument
+ * 
+ * @author Tom Oinn
+ */
+public class ErrorDocumentImpl extends AbstractEntityImpl implements
+		ErrorDocument, HibernateMappedEntity {
+	private String exceptionMessage = "";
+	private String message = "";
+	List<StackTraceElementBean> stackTrace;
+	Set<T2Reference> errorReferences = new HashSet<>();
+	
+	public ErrorDocumentImpl() {
+		this.stackTrace = new ArrayList<>();
+	}
+
+	@Override
+	public String getExceptionMessage() {
+		return this.exceptionMessage;
+	}
+
+	public void setExceptionMessage(String exceptionMessage) {
+		this.exceptionMessage = exceptionMessage;
+	}
+
+	@Override
+	public String getMessage() {
+		return this.message;
+	}
+
+	public void setMessage(String message) {
+		this.message = message;
+	}
+
+	/**
+	 * From interface, not used by hibernate internally
+	 */
+	@Override
+	public List<StackTraceElementBean> getStackTraceStrings() {
+		return this.stackTrace;
+	}
+
+	/**
+	 * Used by Hibernate to bodge around problems with interface types in the
+	 * API
+	 */
+	@SuppressWarnings({ "unchecked", "rawtypes" })
+	public void setStackTraceList(List newList) {
+		this.stackTrace = newList;
+	}
+
+	/**
+	 * Used by Hibernate to bodge around problems with interface types in the
+	 * API
+	 */
+	@SuppressWarnings("rawtypes")
+	public List getStackTraceList() {
+		return this.stackTrace;
+	}
+
+	@Override
+	public Set<T2Reference> getErrorReferences() {
+		return errorReferences;
+	}
+
+	/**
+	 * Used by Hibernate to bodge around problems with interface types in the
+	 * API
+	 */
+	@SuppressWarnings({ "unchecked", "rawtypes" })
+	public void setErrorReferenceSet(Set errorReferenceSet) {
+		this.errorReferences = errorReferenceSet;
+	}
+	
+	/**
+	 * Used by Hibernate to bodge around problems with interface types in the
+	 * API
+	 */
+	@SuppressWarnings("rawtypes")
+	public Set getErrorReferenceSet() {
+		return this.errorReferences;
+	}
+	
+	@Override
+	public String toString() {
+		return getMessage();
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ErrorDocumentServiceImpl.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ErrorDocumentServiceImpl.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ErrorDocumentServiceImpl.java
new file mode 100644
index 0000000..1e78f92
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/ErrorDocumentServiceImpl.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import static net.sf.taverna.t2.reference.impl.T2ReferenceImpl.getAsImpl;
+
+import java.util.Set;
+
+import net.sf.taverna.t2.reference.ErrorDocument;
+import net.sf.taverna.t2.reference.ErrorDocumentService;
+import net.sf.taverna.t2.reference.ErrorDocumentServiceException;
+import net.sf.taverna.t2.reference.ReferenceContext;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+
+/**
+ * Implementation of ErrorDocumentService, inject with an appropriate
+ * ErrorDocumentDao and T2ReferenceGenerator to enable.
+ * 
+ * @author Tom Oinn
+ */
+public class ErrorDocumentServiceImpl extends AbstractErrorDocumentServiceImpl
+		implements ErrorDocumentService {
+	@Override
+	public ErrorDocument getError(T2Reference id)
+			throws ErrorDocumentServiceException {
+		checkDao();
+		try {
+			return errorDao.get(id);
+		} catch (Throwable t) {
+			throw new ErrorDocumentServiceException(t);
+		}
+	}
+
+	/**
+	 * Register the specified error and any child errors (which have the same
+	 * namespace and local part but a lower depth, down to depth of zero
+	 */
+	@Override
+	public ErrorDocument registerError(String message, Throwable t, int depth,
+			ReferenceContext context) throws ErrorDocumentServiceException {
+		checkDao();
+		checkGenerator();
+
+		T2Reference ref = t2ReferenceGenerator.nextErrorDocumentReference(
+				depth, context);
+		T2ReferenceImpl typedId = getAsImpl(ref);
+
+		ErrorDocument docToReturn = null;
+		for (; depth >= 0; depth--) {
+			ErrorDocumentImpl edi = new ErrorDocumentImpl();
+			if (docToReturn == null)
+				docToReturn = edi;
+			edi.setTypedId(typedId);
+			if (message != null)
+				edi.setMessage(message);
+			else
+				edi.setMessage("");
+			if (t != null) {
+				edi.setExceptionMessage(t.toString());
+				for (StackTraceElement ste : t.getStackTrace()) {
+					StackTraceElementBeanImpl stebi = new StackTraceElementBeanImpl();
+					stebi.setClassName(ste.getClassName());
+					stebi.setFileName(ste.getFileName());
+					stebi.setLineNumber(ste.getLineNumber());
+					stebi.setMethodName(ste.getMethodName());
+					edi.stackTrace.add(stebi);
+				}
+			} else
+				edi.setExceptionMessage("");
+			try {
+				errorDao.store(edi);
+			} catch (Throwable t2) {
+				throw new ErrorDocumentServiceException(t2);
+			}
+			if (depth > 0)
+				typedId = typedId.getDeeperErrorReference();
+		}
+		return docToReturn;
+	}
+
+	@Override
+	public ErrorDocument registerError(String message, Set<T2Reference> errors,
+			int depth, ReferenceContext context)
+			throws ErrorDocumentServiceException {
+		checkDao();
+		checkGenerator();
+
+		T2Reference ref = t2ReferenceGenerator.nextErrorDocumentReference(
+				depth, context);
+		T2ReferenceImpl typedId = T2ReferenceImpl.getAsImpl(ref);
+
+		ErrorDocument docToReturn = null;
+		for (; depth >= 0; depth--) {
+			ErrorDocumentImpl edi = new ErrorDocumentImpl();
+			if (docToReturn == null)
+				docToReturn = edi;
+			edi.setTypedId(typedId);
+			if (message != null)
+				edi.setMessage(message);
+			else
+				edi.setMessage("");
+			if (errors != null)
+				edi.setErrorReferenceSet(errors);
+			edi.setExceptionMessage("");
+
+			try {
+				errorDao.store(edi);
+			} catch (Throwable t2) {
+				throw new ErrorDocumentServiceException(t2);
+			}
+			if (depth > 0)
+				typedId = typedId.getDeeperErrorReference();
+		}
+		return docToReturn;
+	}
+
+	@Override
+	public T2Reference getChild(T2Reference errorId)
+			throws ErrorDocumentServiceException {
+		T2ReferenceImpl refImpl = getAsImpl(errorId);
+		try {
+			return refImpl.getDeeperErrorReference();
+		} catch (Throwable t) {
+			throw new ErrorDocumentServiceException(t);
+		}
+	}
+
+	@Override
+	public boolean delete(T2Reference reference)
+			throws ReferenceServiceException {
+		checkDao();
+		ErrorDocument doc = errorDao.get(reference);
+		if (doc == null)
+			return false;
+		return errorDao.delete(doc);
+	}
+
+	@Override
+	public void deleteErrorDocumentsForWorkflowRun(String workflowRunId)
+			throws ReferenceServiceException {
+		checkDao();
+		errorDao.deleteErrorDocumentsForWFRun(workflowRunId);
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/HibernateErrorDocumentDao.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/HibernateErrorDocumentDao.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/HibernateErrorDocumentDao.java
new file mode 100644
index 0000000..470a82e
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/HibernateErrorDocumentDao.java
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import static net.sf.taverna.t2.reference.T2ReferenceType.ErrorDocument;
+
+import java.util.List;
+
+import net.sf.taverna.t2.reference.DaoException;
+import net.sf.taverna.t2.reference.ErrorDocument;
+import net.sf.taverna.t2.reference.ErrorDocumentDao;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.reference.annotations.DeleteIdentifiedOperation;
+import net.sf.taverna.t2.reference.annotations.GetIdentifiedOperation;
+import net.sf.taverna.t2.reference.annotations.PutIdentifiedOperation;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+/**
+ * An implementation of ErrorDocumentDao based on Spring's HibernateDaoSupport.
+ * To use this in spring inject a property 'sessionFactory' with either a
+ * {@link org.springframework.orm.hibernate3.LocalSessionFactoryBean
+ * LocalSessionFactoryBean} or the equivalent class from the T2Platform module
+ * to add SPI based implementation discovery and mapping. To use outside of
+ * Spring ensure you call the setSessionFactory(..) method before using this
+ * (but really, use it from Spring, so much easier).
+ * 
+ * @author Tom Oinn
+ */
+public class HibernateErrorDocumentDao extends HibernateDaoSupport implements
+		ErrorDocumentDao {
+	private static final String GET_ERRORS_FOR_RUN = "FROM ErrorDocumentImpl WHERE namespacePart = :workflow_run_id";
+
+	/**
+	 * Fetch an ErrorDocument list by id
+	 * 
+	 * @param ref
+	 *            the T2Reference to fetch
+	 * @return a retrieved identified list of T2 references
+	 * @throws DaoException
+	 *             if the supplied reference is of the wrong type or if
+	 *             something goes wrong fetching the data or connecting to the
+	 *             database
+	 */
+	@Override
+	@GetIdentifiedOperation
+	public ErrorDocument get(T2Reference ref) throws DaoException {
+		if (ref == null)
+			throw new DaoException(
+					"Supplied reference is null, can't retrieve.");
+		if (!ref.getReferenceType().equals(ErrorDocument))
+			throw new DaoException(
+					"This dao can only retrieve reference of type T2Reference.ErrorDocument");
+		if (!(ref instanceof T2ReferenceImpl))
+			throw new DaoException(
+					"Reference must be an instance of T2ReferenceImpl");
+
+		try {
+			return (ErrorDocumentImpl) getHibernateTemplate().get(
+					ErrorDocumentImpl.class,
+					((T2ReferenceImpl) ref).getCompactForm());
+		} catch (Exception ex) {
+			throw new DaoException(ex);
+		}
+	}
+
+	@Override
+	@PutIdentifiedOperation
+	public void store(ErrorDocument theDocument) throws DaoException {
+		if (theDocument.getId() == null)
+			throw new DaoException(
+					"Supplied error document set has a null ID, allocate "
+							+ "an ID before calling the store method in the dao.");
+		if (!theDocument.getId().getReferenceType().equals(ErrorDocument))
+			throw new DaoException("Strangely the list ID doesn't have type "
+					+ "T2ReferenceType.ErrorDocument, something has probably "
+					+ "gone badly wrong somewhere earlier!");
+		if (!(theDocument instanceof ErrorDocumentImpl))
+			throw new DaoException(
+					"Supplied ErrorDocument not an instance of ErrorDocumentImpl");
+
+		try {
+			getHibernateTemplate().save(theDocument);
+		} catch (Exception ex) {
+			throw new DaoException(ex);
+		}
+	}
+
+	@Override
+	@DeleteIdentifiedOperation
+	public boolean delete(ErrorDocument theDocument) throws DaoException {
+		if (theDocument.getId() == null)
+			throw new DaoException(
+					"Supplied error document set has a null ID, allocate "
+							+ "an ID before calling the store method in the dao.");
+		if (!theDocument.getId().getReferenceType()
+				.equals(ErrorDocument))
+			throw new DaoException("Strangely the list ID doesn't have type "
+					+ "T2ReferenceType.ErrorDocument, something has probably "
+					+ "gone badly wrong somewhere earlier!");
+		if (!(theDocument instanceof ErrorDocumentImpl))
+			throw new DaoException(
+					"Supplied ErrorDocument not an instance of ErrorDocumentImpl");
+
+		try {
+			getHibernateTemplate().delete(theDocument);
+			return true;
+		} catch (Exception ex) {
+			throw new DaoException(ex);
+		}
+	}
+
+	@Override
+	@SuppressWarnings("unchecked")
+	@DeleteIdentifiedOperation
+	public synchronized void deleteErrorDocumentsForWFRun(String workflowRunId)
+			throws DaoException {
+		try {
+			// Select all ErrorDocuments for this wf run
+			Session session = getSession();
+			Query selectQuery = session.createQuery(GET_ERRORS_FOR_RUN);
+			selectQuery.setString("workflow_run_id", workflowRunId);
+			List<ErrorDocument> errorDocuments = selectQuery.list();
+			session.close();
+			/*
+			 * need to close before we do delete otherwise hibernate complains
+			 * that two sessions are accessing collection
+			 */
+			getHibernateTemplate().deleteAll(errorDocuments);
+		} catch (Exception ex) {
+			throw new DaoException(ex);
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/HibernateListDao.java
----------------------------------------------------------------------
diff --git a/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/HibernateListDao.java b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/HibernateListDao.java
new file mode 100644
index 0000000..62ba83f
--- /dev/null
+++ b/taverna-reference-impl/src/main/java/net/sf/taverna/t2/reference/impl/HibernateListDao.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester   
+ * 
+ *  Modifications to the initial code base are copyright of their
+ *  respective authors, or their employers as appropriate.
+ * 
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1 of
+ *  the License, or (at your option) any later version.
+ *    
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *    
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.reference.impl;
+
+import static net.sf.taverna.t2.reference.T2ReferenceType.IdentifiedList;
+
+import java.util.List;
+
+import net.sf.taverna.t2.reference.DaoException;
+import net.sf.taverna.t2.reference.IdentifiedList;
+import net.sf.taverna.t2.reference.ListDao;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.reference.annotations.DeleteIdentifiedOperation;
+import net.sf.taverna.t2.reference.annotations.GetIdentifiedOperation;
+import net.sf.taverna.t2.reference.annotations.PutIdentifiedOperation;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+/**
+ * An implementation of ListDao based on Spring's HibernateDaoSupport. To use
+ * this in spring inject a property 'sessionFactory' with either a
+ * {@link org.springframework.orm.hibernate3.LocalSessionFactoryBean
+ * LocalSessionFactoryBean} or the equivalent class from the T2Platform module
+ * to add SPI based implementation discovery and mapping. To use outside of
+ * Spring ensure you call the setSessionFactory(..) method before using this
+ * (but really, use it from Spring, so much easier).
+ * 
+ * @author Tom Oinn
+ */
+public class HibernateListDao extends HibernateDaoSupport implements ListDao {
+	private static final String GET_LISTS_FOR_RUN = "FROM T2ReferenceListImpl WHERE namespacePart = :workflow_run_id";
+
+	/**
+	 * Fetch a t2reference list by id
+	 * 
+	 * @param ref
+	 *            the T2Reference to fetch
+	 * @return a retrieved identified list of T2 references
+	 * @throws DaoException
+	 *             if the supplied reference is of the wrong type or if
+	 *             something goes wrong fetching the data or connecting to the
+	 *             database
+	 */
+	@Override
+	@GetIdentifiedOperation
+	public IdentifiedList<T2Reference> get(T2Reference ref) throws DaoException {
+		if (ref == null)
+			throw new DaoException(
+					"Supplied reference is null, can't retrieve.");
+		if (!ref.getReferenceType().equals(IdentifiedList))
+			throw new DaoException(
+					"This dao can only retrieve reference of type T2Reference.IdentifiedList");
+		if (!(ref instanceof T2ReferenceImpl))
+			throw new DaoException(
+					"Reference must be an instance of T2ReferenceImpl");
+
+		try {
+			return (T2ReferenceListImpl) getHibernateTemplate().get(
+					T2ReferenceListImpl.class,
+					((T2ReferenceImpl) ref).getCompactForm());
+		} catch (Exception ex) {
+			throw new DaoException(ex);
+		}
+	}
+
+	@Override
+	@PutIdentifiedOperation
+	public void store(IdentifiedList<T2Reference> theList) throws DaoException {
+		if (theList.getId() == null)
+			throw new DaoException("Supplied list set has a null ID, allocate "
+					+ "an ID before calling the store method in the dao.");
+		if (!theList.getId().getReferenceType().equals(IdentifiedList))
+			throw new DaoException("Strangely the list ID doesn't have type "
+					+ "T2ReferenceType.IdentifiedList, something has probably "
+					+ "gone badly wrong somewhere earlier!");
+		if (!(theList instanceof T2ReferenceListImpl))
+			throw new DaoException(
+					"Supplied identifier list not an instance of T2ReferenceList");
+
+		try {
+			getHibernateTemplate().save(theList);
+		} catch (Exception ex) {
+			throw new DaoException(ex);
+		}
+	}
+
+	@Override
+	public boolean delete(IdentifiedList<T2Reference> theList)
+			throws DaoException {
+		if (theList.getId() == null)
+			throw new DaoException("Supplied list set has a null ID, allocate "
+					+ "an ID before calling the store method in the dao.");
+		if (!theList.getId().getReferenceType().equals(IdentifiedList))
+			throw new DaoException("Strangely the list ID doesn't have type "
+					+ "T2ReferenceType.IdentifiedList, something has probably "
+					+ "gone badly wrong somewhere earlier!");
+		if (!(theList instanceof T2ReferenceListImpl))
+			throw new DaoException(
+					"Supplied identifier list not an instance of T2ReferenceList");
+
+		try {
+			getHibernateTemplate().delete(theList);
+			return true;
+		} catch (Exception ex) {
+			throw new DaoException(ex);
+		}
+	}
+
+	@Override
+	@SuppressWarnings("unchecked")
+	@DeleteIdentifiedOperation
+	public synchronized void deleteIdentifiedListsForWFRun(String workflowRunId)
+			throws DaoException {
+		try {
+			// Select all T2Reference lists for this wf run
+			Session session = getSession();
+			Query selectQuery = session.createQuery(GET_LISTS_FOR_RUN);
+			selectQuery.setString("workflow_run_id", workflowRunId);
+			List<IdentifiedList<T2Reference>> identifiedLists = selectQuery
+					.list();
+			session.close();
+			/*
+			 * need to close before we do delete otherwise hibernate complains
+			 * that two sessions are accessing collection
+			 */
+			getHibernateTemplate().deleteAll(identifiedLists);
+		} catch (Exception ex) {
+			throw new DaoException(ex);
+		}
+	}
+}