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:05:54 UTC
[69/79] incubator-taverna-language git commit: taverna-scufl2-rdfxml
-> taverna-scufl2-wfbundle
taverna-scufl2-rdfxml -> taverna-scufl2-wfbundle
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/commit/e27d1dbe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/tree/e27d1dbe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/diff/e27d1dbe
Branch: refs/heads/master
Commit: e27d1dbe0fe4ea26cbb22cb588fe6d6e8d24a8cf
Parents: dc6413a
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Feb 22 12:47:57 2015 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Feb 22 12:47:57 2015 +0000
----------------------------------------------------------------------
pom.xml | 2 +-
taverna-databundle/pom.xml | 2 +-
taverna-scufl2-examples/pom.xml | 2 +-
.../src/main/ruby/processors.rb | 4 +-
taverna-scufl2-integration-tests/pom.xml | 2 +-
taverna-scufl2-rdfxml/.gitignore | 1 -
taverna-scufl2-rdfxml/pom.xml | 97 ---
.../taverna/scufl2/rdfxml/AbstractParser.java | 120 ---
.../taverna/scufl2/rdfxml/ParserState.java | 127 ---
.../taverna/scufl2/rdfxml/ProfileParser.java | 356 --------
.../taverna/scufl2/rdfxml/RDFXMLReader.java | 80 --
.../taverna/scufl2/rdfxml/RDFXMLSerializer.java | 860 -------------------
.../taverna/scufl2/rdfxml/RDFXMLWriter.java | 164 ----
.../taverna/scufl2/rdfxml/RevisionParser.java | 173 ----
.../scufl2/rdfxml/WorkflowBundleParser.java | 190 ----
.../taverna/scufl2/rdfxml/WorkflowParser.java | 381 --------
.../impl/NamespacePrefixMapperJAXB_RI.java | 54 --
...e.taverna.scufl2.api.io.WorkflowBundleReader | 1 -
...e.taverna.scufl2.api.io.WorkflowBundleWriter | 1 -
.../spring/scufl2-rdfxml-context-osgi.xml | 32 -
.../META-INF/spring/scufl2-rdfxml-context.xml | 31 -
.../taverna/scufl2/rdfxml/DummyParserTest.java | 100 ---
.../scufl2/rdfxml/TestProfileParser.java | 179 ----
.../taverna/scufl2/rdfxml/TestRDFXMLReader.java | 235 -----
.../scufl2/rdfxml/TestRDFXMLSerializer.java | 490 -----------
.../taverna/scufl2/rdfxml/TestRDFXMLWriter.java | 158 ----
.../scufl2/rdfxml/TestResourcesInZip.java | 98 ---
.../scufl2/rdfxml/TestRevisionParsing.java | 118 ---
.../taverna/scufl2/rdfxml/example.wfbundle | Bin 40331 -> 0 bytes
.../rdfxml/example/META-INF/container.xml | 34 -
.../scufl2/rdfxml/example/META-INF/manifest.xml | 45 -
.../rdfxml/example/Thumbnails/thumbnail.png | Bin 19064 -> 0 bytes
.../rdfxml/example/Thumbnails/thumbnail.svg | 91 --
.../example/annotation/workflow/HelloWorld.rdf | 70 --
.../example/annotation/workflowBundle.rdf | 39 -
.../example/diagram/workflow/HelloWorld.png | Bin 10243 -> 0 bytes
.../example/diagram/workflow/HelloWorld.svg | 91 --
.../taverna/scufl2/rdfxml/example/mimetype | 1 -
.../rdfxml/example/ontologies/taverna2.2.rdf | 55 --
.../rdfxml/example/profile/tavernaServer.rdf | 87 --
.../rdfxml/example/profile/tavernaWorkbench.rdf | 85 --
.../rdfxml/example/workflow/HelloWorld.rdf | 161 ----
.../scufl2/rdfxml/example/workflowBundle.rdf | 59 --
.../taverna/scufl2/rdfxml/megaProfile.rdf | 696 ---------------
.../apache/taverna/scufl2/rdfxml/roevo-test.xml | 71 --
.../taverna/scufl2/rdfxml/update-bundle.sh | 26 -
taverna-scufl2-t2flow/pom.xml | 2 +-
taverna-scufl2-wfbundle/pom.xml | 97 +++
.../taverna/scufl2/rdfxml/AbstractParser.java | 120 +++
.../taverna/scufl2/rdfxml/ParserState.java | 127 +++
.../taverna/scufl2/rdfxml/ProfileParser.java | 356 ++++++++
.../taverna/scufl2/rdfxml/RDFXMLReader.java | 80 ++
.../taverna/scufl2/rdfxml/RDFXMLSerializer.java | 860 +++++++++++++++++++
.../taverna/scufl2/rdfxml/RDFXMLWriter.java | 164 ++++
.../taverna/scufl2/rdfxml/RevisionParser.java | 173 ++++
.../scufl2/rdfxml/WorkflowBundleParser.java | 190 ++++
.../taverna/scufl2/rdfxml/WorkflowParser.java | 381 ++++++++
.../impl/NamespacePrefixMapperJAXB_RI.java | 54 ++
...e.taverna.scufl2.api.io.WorkflowBundleReader | 1 +
...e.taverna.scufl2.api.io.WorkflowBundleWriter | 1 +
.../spring/scufl2-rdfxml-context-osgi.xml | 32 +
.../META-INF/spring/scufl2-rdfxml-context.xml | 31 +
.../taverna/scufl2/rdfxml/DummyParserTest.java | 100 +++
.../scufl2/rdfxml/TestProfileParser.java | 179 ++++
.../taverna/scufl2/rdfxml/TestRDFXMLReader.java | 235 +++++
.../scufl2/rdfxml/TestRDFXMLSerializer.java | 490 +++++++++++
.../taverna/scufl2/rdfxml/TestRDFXMLWriter.java | 158 ++++
.../scufl2/rdfxml/TestResourcesInZip.java | 98 +++
.../scufl2/rdfxml/TestRevisionParsing.java | 118 +++
.../taverna/scufl2/rdfxml/example.wfbundle | Bin 0 -> 40331 bytes
.../rdfxml/example/META-INF/container.xml | 34 +
.../scufl2/rdfxml/example/META-INF/manifest.xml | 45 +
.../rdfxml/example/Thumbnails/thumbnail.png | Bin 0 -> 19064 bytes
.../rdfxml/example/Thumbnails/thumbnail.svg | 91 ++
.../example/annotation/workflow/HelloWorld.rdf | 70 ++
.../example/annotation/workflowBundle.rdf | 39 +
.../example/diagram/workflow/HelloWorld.png | Bin 0 -> 10243 bytes
.../example/diagram/workflow/HelloWorld.svg | 91 ++
.../taverna/scufl2/rdfxml/example/mimetype | 1 +
.../rdfxml/example/ontologies/taverna2.2.rdf | 55 ++
.../rdfxml/example/profile/tavernaServer.rdf | 87 ++
.../rdfxml/example/profile/tavernaWorkbench.rdf | 85 ++
.../rdfxml/example/workflow/HelloWorld.rdf | 161 ++++
.../scufl2/rdfxml/example/workflowBundle.rdf | 59 ++
.../taverna/scufl2/rdfxml/megaProfile.rdf | 696 +++++++++++++++
.../apache/taverna/scufl2/rdfxml/roevo-test.xml | 71 ++
.../taverna/scufl2/rdfxml/update-bundle.sh | 26 +
87 files changed, 5663 insertions(+), 5664 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index df18cec..19c1777 100644
--- a/pom.xml
+++ b/pom.xml
@@ -295,7 +295,7 @@
<module>taverna-scufl2-ucfpackage</module>
<module>taverna-scufl2-api</module>
<module>taverna-scufl2-examples</module>
- <module>taverna-scufl2-rdfxml</module>
+ <module>taverna-scufl2-wfbundle</module>
<module>taverna-scufl2-t2flow</module>
<module>taverna-scufl2-scufl</module>
<module>taverna-scufl2-validation</module>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-databundle/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-databundle/pom.xml b/taverna-databundle/pom.xml
index a5fe0e1..86e3305 100644
--- a/taverna-databundle/pom.xml
+++ b/taverna-databundle/pom.xml
@@ -33,7 +33,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>taverna-scufl2-rdfxml</artifactId>
+ <artifactId>taverna-scufl2-wfbundle</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-examples/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-scufl2-examples/pom.xml b/taverna-scufl2-examples/pom.xml
index 68609d1..f3e12f0 100644
--- a/taverna-scufl2-examples/pom.xml
+++ b/taverna-scufl2-examples/pom.xml
@@ -38,7 +38,7 @@
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
- <artifactId>taverna-scufl2-rdfxml</artifactId>
+ <artifactId>taverna-scufl2-wfbundle</artifactId>
<version>${project.parent.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-examples/src/main/ruby/processors.rb
----------------------------------------------------------------------
diff --git a/taverna-scufl2-examples/src/main/ruby/processors.rb b/taverna-scufl2-examples/src/main/ruby/processors.rb
index e3de933..8e92c5c 100644
--- a/taverna-scufl2-examples/src/main/ruby/processors.rb
+++ b/taverna-scufl2-examples/src/main/ruby/processors.rb
@@ -27,10 +27,10 @@ require 'zip/zipfilesystem'
scufl2 = RDF::Vocabulary.new("http://ns.taverna.org.uk/2010/scufl2#")
dc = RDF::Vocabulary.new("http://purl.org/dc/elements/1.1/")
-graph = RDF::Graph.load("../../../../taverna-scufl2-rdfxml/src/test/resources/org/apache/taverna/scufl2/rdfxml/example/workflowBundle.rdf")
+graph = RDF::Graph.load("../../../../taverna-scufl2-wfbundle/src/test/resources/org/apache/taverna/scufl2/rdfxml/example/workflowBundle.rdf")
graph = RDF::Graph.new()
-Zip::ZipFile.open("../../../../taverna-scufl2-rdfxml/src/test/resources/org/apache/taverna/scufl2/rdfxml/example.wfbundle") {
+Zip::ZipFile.open("../../../../taverna-scufl2-wfbundle/src/test/resources/org/apache/taverna/scufl2/rdfxml/example.wfbundle") {
|zipfile|
a = zipfile.file.read("workflowBundle.rdf")
RDF::Reader.for(:rdfxml).new(a) do |reader|
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-integration-tests/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-scufl2-integration-tests/pom.xml b/taverna-scufl2-integration-tests/pom.xml
index a3aab52..7ef587c 100644
--- a/taverna-scufl2-integration-tests/pom.xml
+++ b/taverna-scufl2-integration-tests/pom.xml
@@ -45,7 +45,7 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>taverna-scufl2-rdfxml</artifactId>
+ <artifactId>taverna-scufl2-wfbundle</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-rdfxml/.gitignore
----------------------------------------------------------------------
diff --git a/taverna-scufl2-rdfxml/.gitignore b/taverna-scufl2-rdfxml/.gitignore
deleted file mode 100644
index ea8c4bf..0000000
--- a/taverna-scufl2-rdfxml/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/target
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-rdfxml/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-scufl2-rdfxml/pom.xml b/taverna-scufl2-rdfxml/pom.xml
deleted file mode 100644
index ba1b5f2..0000000
--- a/taverna-scufl2-rdfxml/pom.xml
+++ /dev/null
@@ -1,97 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.taverna.language</groupId>
- <artifactId>taverna-language</artifactId>
- <version>0.15.0-incubating-SNAPSHOT</version>
- </parent>
- <artifactId>taverna-scufl2-rdfxml</artifactId>
- <packaging>bundle</packaging>
- <name>Apache Taverna Scufl 2 RDF/XML</name>
- <description>XSD based XML serialisation which is RDF/XML compatible</description>
- <dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>taverna-scufl2-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>taverna-scufl2-schemas</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>taverna-scufl2-api</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>taverna-scufl2-ucfpackage</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>${commons.io.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jdom</groupId>
- <artifactId>com.springsource.org.jdom</artifactId>
- <version>${jdom.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-repository-sail</artifactId>
- <version>${sesame.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-sail-memory</artifactId>
- <version>${sesame.version}</version>
- <scope>test</scope>
- </dependency>
- <!--
- <dependency>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-impl</artifactId>
- <version>${jaxb.version}</version>
- <optional>true</optional>
- </dependency>
- -->
- <dependency>
- <groupId>com.sun.xml.bind</groupId>
- <artifactId>jaxb-osgi</artifactId>
- <version>${jaxb.version}</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.jaxen</groupId>
- <artifactId>com.springsource.org.jaxen</artifactId>
- <version>${jaxen.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/AbstractParser.java
----------------------------------------------------------------------
diff --git a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/AbstractParser.java b/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/AbstractParser.java
deleted file mode 100644
index bc4ce6f..0000000
--- a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/AbstractParser.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package org.apache.taverna.scufl2.rdfxml;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.net.URI;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-
-import org.apache.taverna.scufl2.api.common.Scufl2Tools;
-import org.apache.taverna.scufl2.api.common.URITools;
-import org.apache.taverna.scufl2.api.common.WorkflowBean;
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-import org.apache.taverna.scufl2.api.io.ReaderException;
-
-import org.apache.taverna.scufl2.rdfxml.jaxb.ObjectFactory;
-
-public class AbstractParser {
- protected JAXBContext jaxbContext;
- protected final ThreadLocal<ParserState> parserState;
- protected Scufl2Tools scufl2Tools = new Scufl2Tools();
- protected Unmarshaller unmarshaller;
- protected URITools uriTools = new URITools();
-
- /**
- * A static class for the thread-local parser state.
- */
- private static class ThreadLocalParserState extends ThreadLocal<ParserState> {
- @Override
- protected ParserState initialValue() {
- return new ParserState();
- };
- }
-
- public AbstractParser() {
- this(new ThreadLocalParserState());
- }
-
- public AbstractParser(ThreadLocal<ParserState> parserState) {
- this.parserState = parserState;
- createMarshaller();
- }
-
- protected void clearParserState() {
- parserState.remove();
- }
-
- private void createMarshaller() {
- try {
- jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
- unmarshaller = jaxbContext.createUnmarshaller();
- } catch (JAXBException e) {
- throw new IllegalStateException(
- "Can't create JAXBContext/unmarshaller", e);
- }
- }
-
- protected ParserState getParserState() {
- return parserState.get();
- }
-
- protected void mapBean(String about, WorkflowBean bean) {
- if (about == null)
- return;
- URI aboutUri = getParserState().getCurrentBase().resolve(about);
- mapBean(aboutUri, bean);
- }
-
- protected void mapBean(URI uri, WorkflowBean bean) {
- getParserState().getUriToBean().put(uri, bean);
- getParserState().getBeanToUri().put(bean, uri);
- }
-
- protected URI resolve(String uri) {
- return getParserState().getCurrentBase().resolve(uri);
- }
-
- protected <T extends WorkflowBean> T resolveBeanUri(String resource,
- Class<T> beanType) throws ReaderException {
- URI uri = resolve(resource);
- WorkflowBean bean = resolveBeanUri(uri);
- if (bean == null)
- throw new ReaderException("Can't find workflow bean for resource "
- + resource);
- if (!beanType.isInstance(bean))
- throw new ReaderException("Wrong type for workflow bean "
- + resource + ", expected " + beanType.getSimpleName()
- + " but was " + bean.getClass().getSimpleName());
- return beanType.cast(bean);
- }
-
- protected WorkflowBean resolveBeanUri(URI uri) {
- WorkflowBean workflowBean = getParserState().getUriToBean().get(uri);
- if (workflowBean != null)
- return workflowBean;
- uri = getParserState().getCurrentBase().resolve(uri);
- return uriTools.resolveUri(uri,
- getParserState().getCurrent(WorkflowBundle.class));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/ParserState.java
----------------------------------------------------------------------
diff --git a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/ParserState.java b/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/ParserState.java
deleted file mode 100644
index cc54bc6..0000000
--- a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/ParserState.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package org.apache.taverna.scufl2.rdfxml;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Stack;
-
-import org.apache.taverna.scufl2.api.common.WorkflowBean;
-import org.apache.taverna.scufl2.api.core.Processor;
-import org.apache.taverna.scufl2.ucfpackage.UCFPackage;
-
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-public class ParserState {
- private Map<WorkflowBean, URI> beanToUri = new HashMap<>();
- private URI currentBase;
- private URI location;
- private Stack<WorkflowBean> stack = new Stack<>();
- private UCFPackage ucfPackage;
- private Map<URI, WorkflowBean> uriToBean = new HashMap<>();
- private Map<Processor, ObjectNode> dispatchConfigs = new HashMap<>();
-
- public Map<WorkflowBean, URI> getBeanToUri() {
- return beanToUri;
- }
-
- public <T extends WorkflowBean> T getCurrent(Class<T> beanType) {
- if (getStack().isEmpty())
- throw new IllegalStateException("Parser stack is empty");
- if (beanType.isInstance(getStack().peek()))
- return beanType.cast(getStack().peek());
- T candidate = null;
- for (WorkflowBean bean : getStack())
- if (beanType.isInstance(bean))
- // Don't return - we want the *last* candidate
- candidate = beanType.cast(bean);
- if (candidate == null)
- throw new IllegalStateException("Could not find a " + beanType + " on parser stack");
- return candidate;
- }
-
- public URI getCurrentBase() {
- return currentBase;
- }
-
- public URI getLocation() {
- return location;
- }
-
- public Stack<WorkflowBean> getStack() {
- return stack;
- }
-
- public UCFPackage getUcfPackage() {
- return ucfPackage;
- }
-
- public Map<URI, WorkflowBean> getUriToBean() {
- return uriToBean;
- }
-
- public WorkflowBean peek() {
- return getStack().peek();
- }
-
- public WorkflowBean pop() {
- return getStack().pop();
- }
-
- public void push(WorkflowBean workflowBean) {
- getStack().push(workflowBean);
- }
-
- public void setBeanToUri(Map<WorkflowBean, URI> beanToUri) {
- this.beanToUri = beanToUri;
- }
-
- public void setCurrentBase(URI currentBase) {
- this.currentBase = currentBase;
- }
-
- public void setLocation(URI location) {
- this.location = location;
- }
-
- public void setStack(Stack<WorkflowBean> currentIterationStrategyNode) {
- stack = currentIterationStrategyNode;
- }
-
- public void setUcfPackage(UCFPackage ucfPackage) {
- this.ucfPackage = ucfPackage;
- }
-
- public void setUriToBean(Map<URI, WorkflowBean> uriToBean) {
- this.uriToBean = uriToBean;
- }
-
- public Map<Processor, ObjectNode> getDispatchConfigs() {
- return dispatchConfigs;
- }
-
- public void setDispatchConfigs(Map<Processor, ObjectNode> dispatchConfigs) {
- this.dispatchConfigs = dispatchConfigs;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/ProfileParser.java
----------------------------------------------------------------------
diff --git a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/ProfileParser.java b/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/ProfileParser.java
deleted file mode 100644
index 1c22929..0000000
--- a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/ProfileParser.java
+++ /dev/null
@@ -1,356 +0,0 @@
-package org.apache.taverna.scufl2.rdfxml;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.Iterator;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-
-import org.apache.taverna.scufl2.api.activity.Activity;
-import org.apache.taverna.scufl2.api.common.Configurable;
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-import org.apache.taverna.scufl2.api.core.Processor;
-import org.apache.taverna.scufl2.api.io.ReaderException;
-import org.apache.taverna.scufl2.api.port.InputActivityPort;
-import org.apache.taverna.scufl2.api.port.InputProcessorPort;
-import org.apache.taverna.scufl2.api.port.OutputActivityPort;
-import org.apache.taverna.scufl2.api.port.OutputProcessorPort;
-import org.apache.taverna.scufl2.api.profiles.ProcessorBinding;
-import org.apache.taverna.scufl2.api.profiles.ProcessorInputPortBinding;
-import org.apache.taverna.scufl2.api.profiles.ProcessorOutputPortBinding;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.apache.taverna.scufl2.rdfxml.jaxb.Configuration;
-import org.apache.taverna.scufl2.rdfxml.jaxb.ProcessorBinding.InputPortBinding;
-import org.apache.taverna.scufl2.rdfxml.jaxb.ProcessorBinding.OutputPortBinding;
-import org.apache.taverna.scufl2.rdfxml.jaxb.Profile;
-import org.apache.taverna.scufl2.rdfxml.jaxb.ProfileDocument;
-
-public class ProfileParser extends AbstractParser {
- private static Logger logger = Logger.getLogger(ProfileParser.class
- .getCanonicalName());
-
- public ProfileParser() {
- super();
- }
-
- public ProfileParser(ThreadLocal<ParserState> parserState) {
- super(parserState);
- }
-
- @SuppressWarnings("unused")
- private Element getChildElement(Element element) {
- for (Node node : nodeIterable(element.getChildNodes()))
- if (node instanceof Element)
- return (Element) node;
- return null;
- }
-
- private Iterable<Node> nodeIterable(final NodeList childNodes) {
- return new Iterable<Node>() {
- @Override
- public Iterator<Node> iterator() {
- return new Iterator<Node>() {
- int position = 0;
-
- @Override
- public boolean hasNext() {
- return childNodes.getLength() > position;
- }
-
- @Override
- public Node next() {
- return childNodes.item(position++);
- }
-
- @Override
- public void remove() {
- Node node = childNodes.item(position);
- node.getParentNode().removeChild(node);
- }
- };
- }
- };
- }
-
- protected void parseActivity(
- org.apache.taverna.scufl2.rdfxml.jaxb.Activity original) {
- Activity activity = new Activity();
-
- getParserState().push(activity);
- try {
- mapBean(original.getAbout(), activity);
- if (original.getName() != null)
- activity.setName(original.getName());
- activity.setParent(getParserState().getCurrent(
- org.apache.taverna.scufl2.api.profiles.Profile.class));
- if (original.getType() != null)
- activity.setType(resolve(original.getType().getResource()));
- for (org.apache.taverna.scufl2.rdfxml.jaxb.Activity.InputActivityPort inputActivityPort : original
- .getInputActivityPort())
- parseInputActivityPort(inputActivityPort.getInputActivityPort());
- for (org.apache.taverna.scufl2.rdfxml.jaxb.Activity.OutputActivityPort outputActivityPort : original
- .getOutputActivityPort())
- parseOutputActivityPort(outputActivityPort
- .getOutputActivityPort());
- } finally {
- getParserState().pop();
- }
- }
-
- private static final URI INTERNAL_DISPATCH_PREFIX = URI.create("http://ns.taverna.org.uk/2010/scufl2/taverna/dispatchlayer/");
-
- protected void parseConfiguration(Configuration original)
- throws ReaderException {
- org.apache.taverna.scufl2.api.configurations.Configuration config = new org.apache.taverna.scufl2.api.configurations.Configuration();
-
- boolean ignoreConfig = false;
-
- if (original.getType() != null) {
- URI type = resolve(original.getType().getResource());
- if (! INTERNAL_DISPATCH_PREFIX.relativize(type).isAbsolute()) {
- logger.fine("Ignoring unsupported Dispatch stack configuration (SCUFL2-130)");
- logger.finest(original.getAbout());
- ignoreConfig = true;
- }
- config.setType(type);
- }
-
- if (original.getName() != null)
- config.setName(original.getName());
-
- if (!ignoreConfig) {
- mapBean(original.getAbout(), config);
-
- if (original.getConfigure() != null) {
- Configurable configurable = resolveBeanUri(original
- .getConfigure().getResource(), Configurable.class);
- config.setConfigures(configurable);
- }
- config.setParent(getParserState().getCurrent(
- org.apache.taverna.scufl2.api.profiles.Profile.class));
- }
-
- getParserState().push(config);
-
- if (original.getSeeAlso() != null) {
- String about = original.getSeeAlso().getResource();
- if (about != null) {
- URI resource = resolve(about);
- URI bundleBase = parserState .get().getLocation();
- URI path = uriTools.relativePath(bundleBase, resource);
- if (ignoreConfig) {
- logger.finest("Deleting " + path + " (SCUFL2-130)");
- parserState.get().getUcfPackage().removeResource(path.getRawPath());
- } else {
- try {
- // TODO: Should the path in the UCF Package be %-escaped or not?
- // See TestRDFXMLWriter.awkwardFilenames
- config.setJson(parserState.get().getUcfPackage().getResourceAsString(path.getRawPath()));
- } catch (IllegalArgumentException e) {
- logger.log(Level.WARNING, "Could not parse JSON configuration " + path, e);
- } catch (IOException e) {
- logger.log(Level.WARNING, "Could not load JSON configuration " + path, e);
- }
- }
- }
- }
-
- for (Object o : original.getAny()) {
- // Legacy SCUFL2 <= 0.11.0 PropertyResource configuration
- // Just ignoring it for now :(
- //
- // TODO: Parse and represent as JSON-LD?
- logger.warning("Ignoring unsupported PropertyResource (from wfbundle 0.2.0 or older) for " + config + " " + o);
- }
-
- getParserState().pop();
- }
-
- protected void parseInputActivityPort(
- org.apache.taverna.scufl2.rdfxml.jaxb.InputActivityPort original) {
- InputActivityPort port = new InputActivityPort();
- mapBean(original.getAbout(), port);
- port.setParent(getParserState().getCurrent(Activity.class));
-
- port.setName(original.getName());
- if (original.getPortDepth() != null)
- port.setDepth(original.getPortDepth().getValue());
- }
-
- protected void parseInputPortBinding(
- org.apache.taverna.scufl2.rdfxml.jaxb.InputPortBinding original)
- throws ReaderException {
- ProcessorInputPortBinding binding = new ProcessorInputPortBinding();
- mapBean(original.getAbout(), binding);
-
- binding.setBoundActivityPort(resolveBeanUri(original
- .getBindInputActivityPort().getResource(),
- InputActivityPort.class));
- binding.setBoundProcessorPort(resolveBeanUri(original
- .getBindInputProcessorPort().getResource(),
- InputProcessorPort.class));
- binding.setParent(getParserState().getCurrent(ProcessorBinding.class));
- }
-
- protected void parseOutputActivityPort(
- org.apache.taverna.scufl2.rdfxml.jaxb.OutputActivityPort original) {
- OutputActivityPort port = new OutputActivityPort();
- mapBean(original.getAbout(), port);
- port.setParent(getParserState().getCurrent(Activity.class));
-
- port.setName(original.getName());
- if (original.getPortDepth() != null)
- port.setDepth(original.getPortDepth().getValue());
- if (original.getGranularPortDepth() != null)
- port.setGranularDepth(original.getGranularPortDepth().getValue());
- }
-
- protected void parseOutputPortBinding(
- org.apache.taverna.scufl2.rdfxml.jaxb.OutputPortBinding original)
- throws ReaderException {
- ProcessorOutputPortBinding binding = new ProcessorOutputPortBinding();
- mapBean(original.getAbout(), binding);
-
- binding.setBoundActivityPort(resolveBeanUri(original
- .getBindOutputActivityPort().getResource(),
- OutputActivityPort.class));
- binding.setBoundProcessorPort(resolveBeanUri(original
- .getBindOutputProcessorPort().getResource(),
- OutputProcessorPort.class));
- binding.setParent(getParserState().getCurrent(ProcessorBinding.class));
- }
-
- protected void parseProcessorBinding(
- org.apache.taverna.scufl2.rdfxml.jaxb.ProcessorBinding original)
- throws ReaderException {
- org.apache.taverna.scufl2.api.profiles.ProcessorBinding binding = new org.apache.taverna.scufl2.api.profiles.ProcessorBinding();
- binding.setParent(getParserState().getCurrent(
- org.apache.taverna.scufl2.api.profiles.Profile.class));
- mapBean(original.getAbout(), binding);
- getParserState().push(binding);
-
- if (original.getName() != null)
- binding.setName(original.getName());
- if (original.getActivityPosition() != null)
- binding.setActivityPosition(original.getActivityPosition()
- .getValue());
-
- URI processorUri = resolve(original.getBindProcessor().getResource());
- URI activityUri = resolve(original.getBindActivity().getResource());
-
- binding.setBoundProcessor((Processor) resolveBeanUri(processorUri));
- binding.setBoundActivity((Activity) resolveBeanUri(activityUri));
-
- for (InputPortBinding inputPortBinding : original.getInputPortBinding())
- parseInputPortBinding(inputPortBinding.getInputPortBinding());
- for (OutputPortBinding outputPortBinding : original
- .getOutputPortBinding())
- parseOutputPortBinding(outputPortBinding.getOutputPortBinding());
-
- getParserState().pop();
- }
-
- protected void parseProfile(Profile original, URI profileUri) {
- org.apache.taverna.scufl2.api.profiles.Profile p = new org.apache.taverna.scufl2.api.profiles.Profile();
- p.setParent(getParserState().getCurrent(WorkflowBundle.class));
-
- getParserState().push(p);
-
- if (original.getAbout() != null) {
- URI about = getParserState().getCurrentBase().resolve(
- original.getAbout());
- mapBean(about, p);
- } else
- mapBean(profileUri, p);
-
- if (original.getName() != null)
- p.setName(original.getName());
- // Note - we'll pop() in profileSecond() instead
- }
-
- protected void parseProfileSecond(Profile profileElem) {
- // TODO: Parse activates config etc.
- getParserState().pop();
- }
-
- protected void readProfile(URI profileUri, URI source)
- throws ReaderException, IOException {
- if (source.isAbsolute())
- throw new ReaderException("Can't read external profile source "
- + source);
- InputStream bundleStream = getParserState().getUcfPackage()
- .getResourceAsInputStream(source.getRawPath());
- if (bundleStream == null)
- throw new ReaderException("Can't find profile " + source.getPath());
- readProfile(profileUri, source, bundleStream);
- }
-
- @SuppressWarnings("unchecked")
- protected void readProfile(URI profileUri, URI source,
- InputStream bundleStream) throws ReaderException, IOException {
- JAXBElement<ProfileDocument> elem;
- try {
- elem = (JAXBElement<ProfileDocument>) unmarshaller
- .unmarshal(bundleStream);
- } catch (JAXBException e) {
- throw new ReaderException("Can't parse profile document " + source,
- e);
- }
-
- URI base = getParserState().getLocation().resolve(source);
- if (elem.getValue().getBase() != null)
- base = base.resolve(elem.getValue().getBase());
-
- getParserState().setCurrentBase(base);
-
- org.apache.taverna.scufl2.rdfxml.jaxb.Profile profileElem = null;
- for (Object any : elem.getValue().getAny())
- if (any instanceof org.apache.taverna.scufl2.rdfxml.jaxb.Profile) {
- if (profileElem != null)
- throw new ReaderException("More than one <Profile> found");
- profileElem = (org.apache.taverna.scufl2.rdfxml.jaxb.Profile) any;
- parseProfile(profileElem, profileUri);
- } else if (any instanceof org.apache.taverna.scufl2.rdfxml.jaxb.Activity) {
- if (profileElem == null)
- throw new ReaderException("No <Profile> found");
- parseActivity((org.apache.taverna.scufl2.rdfxml.jaxb.Activity) any);
- } else if (any instanceof org.apache.taverna.scufl2.rdfxml.jaxb.ProcessorBinding) {
- if (profileElem == null)
- throw new ReaderException("No <Profile> found");
- parseProcessorBinding((org.apache.taverna.scufl2.rdfxml.jaxb.ProcessorBinding) any);
- } else if (any instanceof org.apache.taverna.scufl2.rdfxml.jaxb.Configuration) {
- if (profileElem == null)
- throw new ReaderException("No <Profile> found");
- parseConfiguration((org.apache.taverna.scufl2.rdfxml.jaxb.Configuration) any);
- }
- parseProfileSecond(profileElem);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLReader.java
----------------------------------------------------------------------
diff --git a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLReader.java b/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLReader.java
deleted file mode 100644
index dd81ba0..0000000
--- a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLReader.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.apache.taverna.scufl2.rdfxml;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.Set;
-
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-import org.apache.taverna.scufl2.api.io.ReaderException;
-import org.apache.taverna.scufl2.api.io.WorkflowBundleReader;
-import org.apache.taverna.scufl2.ucfpackage.UCFPackage;
-
-
-public class RDFXMLReader implements WorkflowBundleReader {
- public static final String APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE = "application/vnd.taverna.scufl2.workflow-bundle";
- public static final String APPLICATION_RDF_XML = "application/rdf+xml";
-
- @Override
- public Set<String> getMediaTypes() {
- return Collections.singleton(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);
- }
-
- @Override
- public WorkflowBundle readBundle(File bundleFile, String mediaType)
- throws ReaderException, IOException {
- UCFPackage ucfPackage = new UCFPackage(bundleFile);
- WorkflowBundleParser deserializer = new WorkflowBundleParser();
- return deserializer.readWorkflowBundle(ucfPackage, bundleFile.toURI());
- }
-
- @Override
- public WorkflowBundle readBundle(InputStream inputStream, String mediaType)
- throws ReaderException, IOException {
- UCFPackage ucfPackage = new UCFPackage(inputStream);
- WorkflowBundleParser deserializer = new WorkflowBundleParser();
- return deserializer.readWorkflowBundle(ucfPackage, URI.create(""));
- }
-
- @Override
- public String guessMediaTypeForSignature(byte[] firstBytes) {
- if (firstBytes.length < 100)
- return null;
- Charset latin1 = Charset.forName("ISO-8859-1");
- String pk = new String(firstBytes, 0, 2, latin1);
- if (!pk.equals("PK"))
- return null;
- String mimetype = new String(firstBytes, 30, 8, latin1);
- if (!mimetype.equals("mimetype"))
- return null;
- String bundle = new String(firstBytes, 38,
- APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE.length(), latin1);
- if (!bundle.equals(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE))
- return null;
- return APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLSerializer.java
----------------------------------------------------------------------
diff --git a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLSerializer.java b/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLSerializer.java
deleted file mode 100644
index 3ab7501..0000000
--- a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLSerializer.java
+++ /dev/null
@@ -1,860 +0,0 @@
-package org.apache.taverna.scufl2.rdfxml;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import static java.lang.Boolean.TRUE;
-import static java.util.logging.Level.FINE;
-import static java.util.logging.Level.WARNING;
-import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;
-import static javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Stack;
-import java.util.logging.Logger;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-
-import org.apache.taverna.scufl2.api.activity.Activity;
-import org.apache.taverna.scufl2.api.annotation.Annotation;
-import org.apache.taverna.scufl2.api.common.Typed;
-import org.apache.taverna.scufl2.api.common.URITools;
-import org.apache.taverna.scufl2.api.common.Visitor;
-import org.apache.taverna.scufl2.api.common.WorkflowBean;
-import org.apache.taverna.scufl2.api.configurations.Configuration;
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-import org.apache.taverna.scufl2.api.core.BlockingControlLink;
-import org.apache.taverna.scufl2.api.core.DataLink;
-import org.apache.taverna.scufl2.api.core.Processor;
-import org.apache.taverna.scufl2.api.core.Workflow;
-import org.apache.taverna.scufl2.api.io.WriterException;
-import org.apache.taverna.scufl2.api.iterationstrategy.CrossProduct;
-import org.apache.taverna.scufl2.api.iterationstrategy.DotProduct;
-import org.apache.taverna.scufl2.api.iterationstrategy.IterationStrategyStack;
-import org.apache.taverna.scufl2.api.iterationstrategy.IterationStrategyTopNode;
-import org.apache.taverna.scufl2.api.iterationstrategy.PortNode;
-import org.apache.taverna.scufl2.api.port.InputActivityPort;
-import org.apache.taverna.scufl2.api.port.InputProcessorPort;
-import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
-import org.apache.taverna.scufl2.api.port.OutputActivityPort;
-import org.apache.taverna.scufl2.api.port.OutputProcessorPort;
-import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
-import org.apache.taverna.scufl2.api.profiles.ProcessorBinding;
-import org.apache.taverna.scufl2.api.profiles.ProcessorInputPortBinding;
-import org.apache.taverna.scufl2.api.profiles.ProcessorOutputPortBinding;
-import org.apache.taverna.scufl2.api.profiles.Profile;
-import org.apache.taverna.scufl2.rdfxml.impl.NamespacePrefixMapperJAXB_RI;
-import org.apache.taverna.scufl2.ucfpackage.UCFPackage;
-import org.w3._1999._02._22_rdf_syntax_ns_.RDF;
-import org.w3._1999._02._22_rdf_syntax_ns_.Resource;
-import org.w3._1999._02._22_rdf_syntax_ns_.Type;
-import org.w3._2000._01.rdf_schema_.SeeAlso;
-import org.xml.sax.SAXException;
-
-import org.apache.taverna.scufl2.rdfxml.jaxb.Blocking;
-import org.apache.taverna.scufl2.rdfxml.jaxb.Control;
-import org.apache.taverna.scufl2.rdfxml.jaxb.DataLink.MergePosition;
-import org.apache.taverna.scufl2.rdfxml.jaxb.DataLinkEntry;
-import org.apache.taverna.scufl2.rdfxml.jaxb.GranularPortDepth;
-import org.apache.taverna.scufl2.rdfxml.jaxb.IterationStrategyStack.IterationStrategies;
-import org.apache.taverna.scufl2.rdfxml.jaxb.ObjectFactory;
-import org.apache.taverna.scufl2.rdfxml.jaxb.PortDepth;
-import org.apache.taverna.scufl2.rdfxml.jaxb.PortNode.DesiredDepth;
-import org.apache.taverna.scufl2.rdfxml.jaxb.ProcessorBinding.ActivityPosition;
-import org.apache.taverna.scufl2.rdfxml.jaxb.ProcessorBinding.InputPortBinding;
-import org.apache.taverna.scufl2.rdfxml.jaxb.ProcessorBinding.OutputPortBinding;
-import org.apache.taverna.scufl2.rdfxml.jaxb.ProductOf;
-import org.apache.taverna.scufl2.rdfxml.jaxb.ProfileDocument;
-import org.apache.taverna.scufl2.rdfxml.jaxb.SeeAlsoType;
-import org.apache.taverna.scufl2.rdfxml.jaxb.WorkflowBundleDocument;
-import org.apache.taverna.scufl2.rdfxml.jaxb.WorkflowDocument;
-
-public class RDFXMLSerializer {
- private static final String DOT_RDF = ".rdf";
- protected static final URI OA = URI.create("http://www.w3.org/ns/oa#");
- protected static final URI PAV = URI.create("http://purl.org/pav/");
- private static boolean warnedOnce = false;
-
- public class ProfileSerialisationVisitor implements Visitor {
- private org.apache.taverna.scufl2.rdfxml.jaxb.Activity activity;
- private final ProfileDocument doc;
- private org.apache.taverna.scufl2.rdfxml.jaxb.Profile profileElem;
- private Profile profile;
- private org.apache.taverna.scufl2.rdfxml.jaxb.ProcessorBinding processorBindingElem;
-
- public ProfileSerialisationVisitor(ProfileDocument doc) {
- this.doc = doc;
- }
-
- private void activity(Activity node) {
- activity = objectFactory.createActivity();
- activity.setAbout(uri(node));
- activity.setType(type(node));
- activity.setName(node.getName());
- doc.getAny().add(activity);
- }
-
- private void configuration(Configuration node) {
- org.apache.taverna.scufl2.rdfxml.jaxb.Configuration configuration = objectFactory
- .createConfiguration();
- configuration.setConfigure(resource(uri(node.getConfigures())));
- configuration.setName(node.getName());
- configuration.setType(type(node));
-
- URI configUri = uriTools.relativeUriForBean(node, profile);
- String jsonPath = configUri.toString().replaceFirst("/$", ".json");
-
- URI profilePath = uriTools.relativeUriForBean(profile, profile.getParent());
-
- String bundlePath = profilePath + jsonPath;
-
- UCFPackage bundle = profile.getParent().getResources();
- try {
- bundle.addResource(node.getJsonAsString(), bundlePath, "application/json");
- } catch (IOException e) {
- logger.log(WARNING, "Can't save JSON to " + bundlePath, e);
- }
- configuration.setAbout(configUri.toString());
-
- SeeAlso seeAlso = rdfsObjectFactory.createSeeAlso();
- seeAlso.setResource(jsonPath);
- configuration.setSeeAlso(seeAlso);
-
- // TODO: No way in API to mark non-activated configurations
- profileElem.getActivateConfiguration().add(resource(uri(node)));
- doc.getAny().add(configuration);
- }
-
- private GranularPortDepth granularPortDepth(Integer integer) {
- if (integer == null)
- return null;
- GranularPortDepth p = objectFactory.createGranularPortDepth();
- p.setValue(integer);
- p.setDatatype(p.getDatatype());
- return p;
- }
-
- private void inputActivityPort(InputActivityPort node) {
- org.apache.taverna.scufl2.rdfxml.jaxb.InputActivityPort inputActivityPort = objectFactory
- .createInputActivityPort();
- inputActivityPort.setAbout(uri(node));
- inputActivityPort.setName(node.getName());
- inputActivityPort.setPortDepth(portDepth(node.getDepth()));
-
- org.apache.taverna.scufl2.rdfxml.jaxb.Activity.InputActivityPort wrapper = objectFactory
- .createActivityInputActivityPort();
- wrapper.setInputActivityPort(inputActivityPort);
- activity.getInputActivityPort().add(wrapper);
- }
-
- private void outputActivityPort(OutputActivityPort node) {
- org.apache.taverna.scufl2.rdfxml.jaxb.OutputActivityPort outputActivityPort = objectFactory
- .createOutputActivityPort();
- outputActivityPort.setAbout(uri(node));
- outputActivityPort.setName(node.getName());
- outputActivityPort.setPortDepth(portDepth(node.getDepth()));
- outputActivityPort.setGranularPortDepth(granularPortDepth(node
- .getGranularDepth()));
-
- org.apache.taverna.scufl2.rdfxml.jaxb.Activity.OutputActivityPort wrapper = objectFactory
- .createActivityOutputActivityPort();
- wrapper.setOutputActivityPort(outputActivityPort);
- activity.getOutputActivityPort().add(wrapper);
- }
-
- private PortDepth portDepth(Integer integer) {
- if (integer == null)
- return null;
- PortDepth p = objectFactory.createPortDepth();
- p.setValue(integer);
- p.setDatatype(p.getDatatype());
- return p;
- }
-
- private void processorBinding(ProcessorBinding node) {
- processorBindingElem = objectFactory.createProcessorBinding();
- processorBindingElem.setAbout(uri(node));
- processorBindingElem.setName(node.getName());
- processorBindingElem.setBindActivity(resource(uri(node
- .getBoundActivity())));
- processorBindingElem.setBindProcessor(resource(uri(node
- .getBoundProcessor())));
- if (node.getActivityPosition() != null) {
- ActivityPosition value = new ActivityPosition();
- value.setDatatype(value.getDatatype());
- value.setValue(node.getActivityPosition());
- processorBindingElem.setActivityPosition(value);
- }
-
- profileElem.getProcessorBinding().add(resource(uri(node)));
- doc.getAny().add(processorBindingElem);
- }
-
- private void processorInputPortBinding(ProcessorInputPortBinding node) {
- org.apache.taverna.scufl2.rdfxml.jaxb.InputPortBinding inputBinding = objectFactory
- .createInputPortBinding();
- inputBinding.setAbout(uri(node));
- inputBinding.setBindInputActivityPort(resource(uri(node
- .getBoundActivityPort())));
- inputBinding.setBindInputProcessorPort(resource(uri(node
- .getBoundProcessorPort())));
- InputPortBinding b = objectFactory
- .createProcessorBindingInputPortBinding();
- b.setInputPortBinding(inputBinding);
- processorBindingElem.getInputPortBinding().add(b);
- }
-
- private void processorOutputPortBinding(ProcessorOutputPortBinding node) {
- org.apache.taverna.scufl2.rdfxml.jaxb.OutputPortBinding outputBinding = objectFactory
- .createOutputPortBinding();
- outputBinding.setAbout(uri(node));
- outputBinding.setBindOutputActivityPort(resource(uri(node
- .getBoundActivityPort())));
- outputBinding.setBindOutputProcessorPort(resource(uri(node
- .getBoundProcessorPort())));
- OutputPortBinding b = objectFactory
- .createProcessorBindingOutputPortBinding();
- b.setOutputPortBinding(outputBinding);
- processorBindingElem.getOutputPortBinding().add(b);
- }
-
- private void profile(Profile node) {
- profile = node;
- profileElem = objectFactory.createProfile();
- profileElem.setAbout(uri(node));
- profileElem.setName(node.getName());
- doc.getAny().add(profileElem);
- }
-
- private String uri(WorkflowBean node) {
- return uriTools.relativeUriForBean(node, profile).toASCIIString();
- }
-
- @Override
- public boolean visit(WorkflowBean node) {
- if (node instanceof Profile)
- profile((Profile) node);
- else if (node instanceof Activity)
- activity((Activity) node);
- else if (node instanceof InputActivityPort)
- inputActivityPort((InputActivityPort) node);
- else if (node instanceof OutputActivityPort)
- outputActivityPort((OutputActivityPort) node);
- else if (node instanceof ProcessorBinding)
- processorBinding((ProcessorBinding) node);
- else if (node instanceof ProcessorInputPortBinding)
- processorInputPortBinding((ProcessorInputPortBinding) node);
- else if (node instanceof ProcessorOutputPortBinding)
- processorOutputPortBinding((ProcessorOutputPortBinding) node);
- else if (node instanceof Configuration)
- configuration((Configuration) node);
- else
- throw new IllegalStateException("Unexpected node " + node);
- return true;
- }
-
- @Override
- public boolean visitEnter(WorkflowBean node) {
- return visit(node);
- }
-
- @Override
- public boolean visitLeave(WorkflowBean node) {
- return true;
- }
- }
-
- public class WorkflowSerialisationVisitor implements Visitor {
- private final org.apache.taverna.scufl2.rdfxml.jaxb.Workflow workflow;
- private org.apache.taverna.scufl2.rdfxml.jaxb.Processor proc;
- private Workflow wf;
- @SuppressWarnings("unused")
- private org.apache.taverna.scufl2.rdfxml.jaxb.DispatchStack dispatchStack;
- private org.apache.taverna.scufl2.rdfxml.jaxb.IterationStrategyStack iterationStrategyStack;
- private IterationStrategies iterationStrategies;
- private Stack<List<Object>> productStack;
-
- public WorkflowSerialisationVisitor(
- org.apache.taverna.scufl2.rdfxml.jaxb.Workflow workflow) {
- this.workflow = workflow;
- }
-
- private GranularPortDepth makeGranularPortDepth(Integer granularDepth) {
- if (granularDepth == null)
- return null;
- GranularPortDepth portDepth = objectFactory
- .createGranularPortDepth();
- portDepth.setValue(granularDepth);
- portDepth.setDatatype(portDepth.getDatatype());
- return portDepth;
- }
-
- private PortDepth makePortDepth(Integer depth) {
- if (depth == null)
- return null;
- PortDepth portDepth = objectFactory.createPortDepth();
- portDepth.setValue(depth);
- portDepth.setDatatype(portDepth.getDatatype());
- return portDepth;
- }
-
- private Resource makeResource(URI uri) {
- Resource resource = rdfObjectFactory.createResource();
- resource.setResource(uri.toASCIIString());
- return resource;
- }
-
- @Override
- public boolean visit(WorkflowBean node) {
- if (node instanceof Workflow) {
- wf = (Workflow) node;
- workflow.setAbout("");
- workflow.setName(wf.getName());
-
- if (wf.getIdentifier() != null) {
- Resource wfId = rdfObjectFactory.createResource();
- wfId.setResource(wf.getIdentifier().toASCIIString());
- workflow.setWorkflowIdentifier(wfId);
- }
- }
-
- URI uri = uriTools.relativeUriForBean(node, wf);
-
- if (node instanceof InputWorkflowPort) {
- InputWorkflowPort ip = (InputWorkflowPort) node;
- org.apache.taverna.scufl2.rdfxml.jaxb.Workflow.InputWorkflowPort inP = objectFactory
- .createWorkflowInputWorkflowPort();
- org.apache.taverna.scufl2.rdfxml.jaxb.InputWorkflowPort inPort = objectFactory
- .createInputWorkflowPort();
- inP.setInputWorkflowPort(inPort);
- inPort.setName(ip.getName());
-
- URI portURI = uriTools.relativeUriForBean(ip, ip.getParent());
- inPort.setAbout(portURI.toASCIIString());
-
- PortDepth portDepth = makePortDepth(ip.getDepth());
- inPort.setPortDepth(portDepth);
- workflow.getInputWorkflowPort().add(inP);
- }
- if (node instanceof OutputWorkflowPort) {
- OutputWorkflowPort op = (OutputWorkflowPort) node;
- org.apache.taverna.scufl2.rdfxml.jaxb.Workflow.OutputWorkflowPort inP = objectFactory
- .createWorkflowOutputWorkflowPort();
- org.apache.taverna.scufl2.rdfxml.jaxb.OutputWorkflowPort outPort = objectFactory
- .createOutputWorkflowPort();
- inP.setOutputWorkflowPort(outPort);
- outPort.setName(op.getName());
-
- URI portURI = uriTools.relativeUriForBean(op, op.getParent());
- outPort.setAbout(portURI.toASCIIString());
- workflow.getOutputWorkflowPort().add(inP);
- }
- if (node instanceof Processor) {
- Processor processor = (Processor) node;
- org.apache.taverna.scufl2.rdfxml.jaxb.Workflow.Processor wfProc = objectFactory
- .createWorkflowProcessor();
- proc = objectFactory.createProcessor();
- wfProc.setProcessor(proc);
- proc.setName(processor.getName());
- URI procUri = uriTools.relativeUriForBean(processor, wf);
- proc.setAbout(procUri.toASCIIString());
- wfProc.setProcessor(proc);
- workflow.getProcessor().add(wfProc);
- }
- if (node instanceof InputProcessorPort) {
- InputProcessorPort inPort = (InputProcessorPort) node;
- org.apache.taverna.scufl2.rdfxml.jaxb.InputProcessorPort port = objectFactory
- .createInputProcessorPort();
- port.setAbout(uri.toASCIIString());
- port.setName(inPort.getName());
- port.setPortDepth(makePortDepth(inPort.getDepth()));
- org.apache.taverna.scufl2.rdfxml.jaxb.Processor.InputProcessorPort inputProcessorPort = objectFactory
- .createProcessorInputProcessorPort();
- inputProcessorPort.setInputProcessorPort(port);
- proc.getInputProcessorPort().add(inputProcessorPort);
- }
- if (node instanceof OutputProcessorPort) {
- org.apache.taverna.scufl2.rdfxml.jaxb.OutputProcessorPort port;
- OutputProcessorPort outPort = (OutputProcessorPort) node;
- port = objectFactory.createOutputProcessorPort();
- port.setAbout(uri.toASCIIString());
- port.setName(outPort.getName());
- port.setPortDepth(makePortDepth(outPort.getDepth()));
- port.setGranularPortDepth(makeGranularPortDepth(outPort
- .getGranularDepth()));
-
- org.apache.taverna.scufl2.rdfxml.jaxb.Processor.OutputProcessorPort outputProcessorPort = objectFactory
- .createProcessorOutputProcessorPort();
- outputProcessorPort.setOutputProcessorPort(port);
- proc.getOutputProcessorPort().add(outputProcessorPort);
- }
- if (node instanceof IterationStrategyStack) {
- iterationStrategyStack = objectFactory
- .createIterationStrategyStack();
- iterationStrategyStack.setAbout(uri.toASCIIString());
- org.apache.taverna.scufl2.rdfxml.jaxb.Processor.IterationStrategyStack processorIterationStrategyStack = objectFactory
- .createProcessorIterationStrategyStack();
- processorIterationStrategyStack
- .setIterationStrategyStack(iterationStrategyStack);
- proc.setIterationStrategyStack(processorIterationStrategyStack);
- productStack = new Stack<List<Object>>();
- }
- if (node instanceof IterationStrategyTopNode
- && productStack.isEmpty()) {
- iterationStrategies = objectFactory
- .createIterationStrategyStackIterationStrategies();
- iterationStrategyStack
- .setIterationStrategies(iterationStrategies);
- iterationStrategies.setParseType(iterationStrategies
- .getParseType());
- List<Object> dotProductOrCrossProduct = iterationStrategies
- .getDotProductOrCrossProduct();
- productStack.add(dotProductOrCrossProduct);
- }
- if (node instanceof CrossProduct) {
- org.apache.taverna.scufl2.rdfxml.jaxb.CrossProduct crossProduct = objectFactory
- .createCrossProduct();
- crossProduct.setAbout(uri.toASCIIString());
- productStack.peek().add(crossProduct);
- ProductOf productOf = objectFactory.createProductOf();
- productOf.setParseType(productOf.getParseType());
- crossProduct.setProductOf(productOf);
- productStack.add(crossProduct.getProductOf().getCrossProductOrDotProductOrPortNode());
- }
- if (node instanceof DotProduct) {
- org.apache.taverna.scufl2.rdfxml.jaxb.DotProduct dotProduct = objectFactory
- .createDotProduct();
- dotProduct.setAbout(uri.toASCIIString());
- productStack.peek().add(dotProduct);
- ProductOf productOf = objectFactory.createProductOf();
- productOf.setParseType(productOf.getParseType());
- dotProduct.setProductOf(productOf);
- productStack.add(dotProduct.getProductOf()
- .getCrossProductOrDotProductOrPortNode());
- }
- if (node instanceof PortNode) {
- PortNode portNode = (PortNode) node;
- InputProcessorPort inPort = portNode.getInputProcessorPort();
- URI portUri = uriTools.relativeUriForBean(inPort, wf);
- org.apache.taverna.scufl2.rdfxml.jaxb.PortNode port = objectFactory.createPortNode();
- port.setAbout(uri.toASCIIString());
- if (portNode.getDesiredDepth() != null) {
- DesiredDepth value = objectFactory.createPortNodeDesiredDepth();
- value.setDatatype(value.getDatatype());
- value.setValue(portNode.getDesiredDepth());
- port.setDesiredDepth(value);
- }
- port.setIterateOverInputPort(makeResource(portUri));
- productStack.peek().add(port);
- }
- if (node instanceof DataLink) {
- DataLink dataLink = (DataLink) node;
- org.apache.taverna.scufl2.rdfxml.jaxb.DataLink link = objectFactory
- .createDataLink();
- link.setAbout(uri.toASCIIString());
- URI fromUri = uriTools.relativeUriForBean(
- dataLink.getReceivesFrom(), wf);
- URI toUri = uriTools.relativeUriForBean(dataLink.getSendsTo(),
- wf);
- link.setReceiveFrom(makeResource(fromUri));
- link.setSendTo(makeResource(toUri));
-
- if (dataLink.getMergePosition() != null) {
- MergePosition value = objectFactory.createDataLinkMergePosition();
- value.setValue(dataLink
- .getMergePosition());
- value.setDatatype(value.getDatatype());
- link.setMergePosition(value);
- }
-
- DataLinkEntry linkEntry = objectFactory.createDataLinkEntry();
- linkEntry.setDataLink(link);
- workflow.getDatalink().add(linkEntry);
- }
- if (node instanceof BlockingControlLink) {
- BlockingControlLink controlLink = (BlockingControlLink) node;
- URI blockUri = uriTools.relativeUriForBean(
- controlLink.getBlock(), wf);
- URI untilUri = uriTools.relativeUriForBean(
- controlLink.getUntilFinished(), wf);
-
- Blocking blocking = objectFactory.createBlocking();
- blocking.setAbout(uri.toASCIIString());
- blocking.setBlock(makeResource(blockUri));
- blocking.setUntilFinished(makeResource(untilUri));
-
- Control control = objectFactory.createControl();
- control.setBlocking(blocking);
- workflow.getControl().add(control);
- }
-
- // TODO: Datalinks
-
- return true;
- }
-
- @Override
- public boolean visitEnter(WorkflowBean node) {
- return visit(node);
- }
-
- @Override
- public boolean visitLeave(WorkflowBean node) {
- if (node instanceof IterationStrategyTopNode)
- // Actually for any Cross/Dot product
- productStack.pop();
- return true;
- }
- }
-
- protected synchronized static JAXBContext getJAxbContextStatic()
- throws JAXBException {
- if (jaxbContextStatic == null) {
- Class<?>[] packages = { ObjectFactory.class,
- org.w3._1999._02._22_rdf_syntax_ns_.ObjectFactory.class,
- org.w3._2000._01.rdf_schema_.ObjectFactory.class };
- jaxbContextStatic = JAXBContext.newInstance(packages);
- }
- return jaxbContextStatic;
- }
-
- public void annotation(final Annotation ann) {
- URI wfBundleURI = uriTools.uriForBean(wfBundle);
- URI annUri = uriTools.uriForBean(ann);
- URI bodyURI = ann.getBody();
- if (bodyURI == null || bodyURI.isAbsolute())
- // Workaround with separate file for the annotation alone
- bodyURI = annUri.resolve(uriTools.validFilename(ann.getName()) + DOT_RDF);
- URI pathUri = uriTools.relativePath(wfBundleURI, bodyURI);
- if (ann.getBody() == null || ann.getBody().equals(wfBundleURI.resolve(pathUri)))
- // Set the relative path
- ann.setBody(pathUri);
-
- // TODO: Add annotation to RO manifest
-
-// // Miniature OA description for now
-// // See http://openannotation.org/spec/core/20130205/
-// final PropertyResource annProv = new PropertyResource();
-// annProv.setResourceURI(annUri);
-// annProv.setTypeURI(OA.resolve("#Annotation"));
-//
-// if (ann.getAnnotatedAt() != null) {
-// annProv.addProperty(OA.resolve("#annotedAt"),
-// new PropertyLiteral(ann.getAnnotatedAt()));
-// }
-// if (ann.getSerializedAt() != null) {
-// annProv.addProperty(OA.resolve("#serializedAt"),
-// new PropertyLiteral(ann.getSerializedAt()));
-// }
-//
-// if (ann.getAnnotatedBy() != null) {
-// annProv.addPropertyReference(OA.resolve("#annotatedBy"),
-// ann.getAnnotatedBy());
-// }
-// if (ann.getSerializedBy() != null) {
-// annProv.addPropertyReference(OA.resolve("#serializedBy"),
-// ann.getSerializedBy());
-// }
-//
-// if (ann.getBody() != null) {
-// annProv.addPropertyReference(OA.resolve("#hasBody"), ann.getBody());
-// } else if (! ann.getBodyStatements().isEmpty()){
-// // FIXME: Hack - Our body is also the annotation!
-// annProv.addPropertyReference(OA.resolve("#hasBody"), pathUri);
-// }
-//
-// // CHECK: should this be a relative reference instead?
-// annProv.addPropertyReference(OA.resolve("#hasTarget"),
-// uriTools.uriForBean(ann.getTarget()));
-// // Serialize the metadata
-//
-//
-// try {
-// /*
-// * TODO: Serialize manually with nicer indentation/namespaces etc.,
-// * as done for our other RDF/XML documents
-// */
-// wfBundle.getResources()
-// .addResource(visitor.getDoc(), pathUri.toASCIIString(), APPLICATION_RDF_XML);
-// } catch (IOException e) {
-// logger.log(Level.WARNING, "Can't write annotation to " + pathUri, e);
-// }
-
- }
-
- private ObjectFactory objectFactory = new ObjectFactory();
-
- private org.w3._2000._01.rdf_schema_.ObjectFactory rdfsObjectFactory = new org.w3._2000._01.rdf_schema_.ObjectFactory();
- private org.w3._1999._02._22_rdf_syntax_ns_.ObjectFactory rdfObjectFactory = new org.w3._1999._02._22_rdf_syntax_ns_.ObjectFactory();
- private URITools uriTools = new URITools();
- private boolean usingSchema = false;
-
- private WorkflowBundle wfBundle;
-
- private JAXBContext jaxbContext;
-
- private Map<WorkflowBean, URI> seeAlsoUris = new HashMap<>();
- private static JAXBContext jaxbContextStatic;
- private static Logger logger = Logger.getLogger(RDFXMLSerializer.class
- .getCanonicalName());
- public RDFXMLSerializer() {
- }
-
- public RDFXMLSerializer(WorkflowBundle wfBundle) {
- setWfBundle(wfBundle);
- }
-
- public JAXBContext getJaxbContext() throws JAXBException {
- if (jaxbContext == null)
- return getJAxbContextStatic();
- return jaxbContext;
- }
-
- public Marshaller getMarshaller() {
- String schemaPath = "xsd/scufl2.xsd";
- Marshaller marshaller;
- try {
- marshaller = getJaxbContext().createMarshaller();
-
- if (isUsingSchema()) {
- SchemaFactory schemaFactory = SchemaFactory
- .newInstance(W3C_XML_SCHEMA_NS_URI);
- Schema schema = schemaFactory.newSchema(getClass().getResource(
- schemaPath));
- // FIXME: re-enable schema
- marshaller.setSchema(schema);
- }
- marshaller.setProperty(JAXB_FORMATTED_OUTPUT, TRUE);
- marshaller
- .setProperty(
- "jaxb.schemaLocation",
- "http://ns.taverna.org.uk/2010/scufl2# http://ns.taverna.org.uk/2010/scufl2/scufl2.xsd "
- + "http://www.w3.org/1999/02/22-rdf-syntax-ns# http://ns.taverna.org.uk/2010/scufl2/rdf.xsd");
- } catch (JAXBException e) {
- throw new IllegalStateException(e);
- } catch (SAXException e) {
- throw new IllegalStateException("Could not load schema "
- + schemaPath, e);
- }
- setPrefixMapper(marshaller);
- return marshaller;
- }
-
- public WorkflowBundle getWfBundle() {
- return wfBundle;
- }
-
- public boolean isUsingSchema() {
- return usingSchema;
- }
-
- protected ProfileDocument makeProfile(Profile pf, URI path) {
- ProfileDocument doc = objectFactory.createProfileDocument();
-
- objectFactory.createProfile();
- pf.accept(new ProfileSerialisationVisitor(doc) {
- });
- return doc;
- }
-
- protected org.apache.taverna.scufl2.rdfxml.jaxb.Workflow makeWorkflow(
- Workflow wf, URI documentPath) {
- org.apache.taverna.scufl2.rdfxml.jaxb.Workflow workflow = objectFactory
- .createWorkflow();
- wf.accept(new WorkflowSerialisationVisitor(workflow) {
- });
- return workflow;
- }
-
- protected org.apache.taverna.scufl2.rdfxml.jaxb.WorkflowBundle makeWorkflowBundleElem() {
- org.apache.taverna.scufl2.rdfxml.jaxb.WorkflowBundle bundle = objectFactory
- .createWorkflowBundle();
- // FIXME: Support other URIs
- bundle.setAbout("");
- bundle.setName(wfBundle.getName());
-
- if (wfBundle.getGlobalBaseURI() != null) {
- Resource globalBaseURI = rdfObjectFactory.createResource();
- globalBaseURI.setResource(wfBundle.getGlobalBaseURI().toASCIIString());
- bundle.setGlobalBaseURI(globalBaseURI);
- }
-
- for (Workflow wf : wfBundle.getWorkflows()) {
- org.apache.taverna.scufl2.rdfxml.jaxb.WorkflowBundle.Workflow wfElem = objectFactory
- .createWorkflowBundleWorkflow();
- SeeAlsoType seeAlsoElem = objectFactory.createSeeAlsoType();
- seeAlsoElem.setAbout(uriTools.relativeUriForBean(wf, wfBundle)
- .toASCIIString());
-
- if (seeAlsoUris.containsKey(wf)) {
- SeeAlso seeAlso = rdfsObjectFactory.createSeeAlso();
- seeAlso.setResource(seeAlsoUris.get(wf).toASCIIString());
- seeAlsoElem.setSeeAlso(seeAlso);
- } else
- logger.warning("Can't find bundle URI for workflow document "
- + wf.getName());
-
- wfElem.setWorkflow(seeAlsoElem);
- bundle.getWorkflow().add(wfElem);
-
- if (wfBundle.getMainWorkflow() == wf) {
- Resource mainWorkflow = rdfObjectFactory.createResource();
- mainWorkflow.setResource(seeAlsoElem.getAbout());
- bundle.setMainWorkflow(mainWorkflow);
- }
- }
-
- for (Profile pf : wfBundle.getProfiles()) {
- org.apache.taverna.scufl2.rdfxml.jaxb.WorkflowBundle.Profile wfElem = objectFactory
- .createWorkflowBundleProfile();
- SeeAlsoType seeAlsoElem = objectFactory.createSeeAlsoType();
- seeAlsoElem.setAbout(uriTools.relativeUriForBean(pf, wfBundle)
- .toASCIIString());
-
- if (seeAlsoUris.containsKey(pf)) {
- SeeAlso seeAlso = rdfsObjectFactory.createSeeAlso();
- seeAlso.setResource(seeAlsoUris.get(pf).toASCIIString());
- seeAlsoElem.setSeeAlso(seeAlso);
- } else
- logger.warning("Can't find bundle URI for profile document "
- + pf.getName());
-
- wfElem.setProfile(seeAlsoElem);
- bundle.getProfile().add(wfElem);
-
- if (wfBundle.getMainProfile() == pf) {
- Resource mainProfile = rdfObjectFactory.createResource();
- mainProfile.setResource(seeAlsoElem.getAbout());
- bundle.setMainProfile(mainProfile);
- }
- }
-
- for (Annotation ann : wfBundle.getAnnotations())
- annotation(ann);
-
- return bundle;
- }
-
- public void profileDoc(OutputStream outputStream, Profile pf, URI path)
- throws JAXBException, WriterException {
- ProfileDocument doc = makeProfile(pf, path);
-
- URI wfUri = uriTools.relativeUriForBean(pf, wfBundle);
- doc.setBase(uriTools.relativePath(path, wfUri).toASCIIString());
-
- JAXBElement<RDF> element = rdfObjectFactory.createRDF(doc);
- getMarshaller().marshal(element, outputStream);
- seeAlsoUris.put(pf, path);
- }
-
- private Resource resource(String uri) {
- Resource r = rdfObjectFactory.createResource();
- r.setResource(uri);
- return r;
- }
-
- public void setJaxbContext(JAXBContext jaxbContext) {
- this.jaxbContext = jaxbContext;
- }
-
- protected void setPrefixMapper(Marshaller marshaller) {
- boolean setPrefixMapper = false;
-
- try {
- /*
- * This only works with JAXB RI, in which case we can set the
- * namespace prefix mapper
- */
- Class.forName("com.sun.xml.bind.marshaller.NamespacePrefixMapper");
- marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
- new NamespacePrefixMapperJAXB_RI());
- /*
- * Note: A similar mapper for the built-in java
- * (com.sun.xml.bind.internal.namespacePrefixMapper) is no longer
- * included here, as it will not (easily) compile with Maven.
- */
- setPrefixMapper = true;
- } catch (Exception e) {
- logger.log(FINE, "Can't find NamespacePrefixMapper", e);
- }
-
- if (!setPrefixMapper && ! warnedOnce) {
- logger.info("Could not set prefix mapper (missing or incompatible JAXB) "
- + "- will use prefixes ns0, ns1, ..");
- warnedOnce = true;
- }
- }
-
- public void setUsingSchema(boolean usingSchema) {
- this.usingSchema = usingSchema;
- }
-
- public void setWfBundle(WorkflowBundle wfBundle) {
- this.wfBundle = wfBundle;
- }
-
- private Type type(Typed typed) {
- if (typed.getType() == null)
- return null;
- Type t = rdfObjectFactory.createType();
- t.setResource(typed.getType().toASCIIString());
- return t;
- }
-
- public void workflowBundleDoc(OutputStream outputStream, URI path)
- throws JAXBException, WriterException {
- org.apache.taverna.scufl2.rdfxml.jaxb.WorkflowBundle bundle = makeWorkflowBundleElem();
- WorkflowBundleDocument doc = objectFactory
- .createWorkflowBundleDocument();
- doc.getAny().add(bundle);
-
- doc.setBase(path.relativize(URI.create("./")).toASCIIString());
- JAXBElement<RDF> element = rdfObjectFactory.createRDF(doc);
-
- getMarshaller().marshal(element, outputStream);
- seeAlsoUris.put(wfBundle, path);
- }
-
- public void workflowDoc(OutputStream outputStream, Workflow wf, URI path)
- throws JAXBException, WriterException {
- org.apache.taverna.scufl2.rdfxml.jaxb.Workflow wfElem = makeWorkflow(wf,
- path);
- WorkflowDocument doc = objectFactory.createWorkflowDocument();
- doc.getAny().add(wfElem);
-
- URI wfUri = uriTools.relativeUriForBean(wf, wfBundle);
- doc.setBase(uriTools.relativePath(path, wfUri).toASCIIString());
-
- JAXBElement<RDF> element = rdfObjectFactory.createRDF(doc);
- getMarshaller().marshal(element, outputStream);
- seeAlsoUris.put(wf, path);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLWriter.java
----------------------------------------------------------------------
diff --git a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLWriter.java b/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLWriter.java
deleted file mode 100644
index 3670898..0000000
--- a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLWriter.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package org.apache.taverna.scufl2.rdfxml;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import static org.apache.taverna.scufl2.rdfxml.RDFXMLReader.APPLICATION_RDF_XML;
-import static org.apache.taverna.scufl2.rdfxml.RDFXMLReader.APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URI;
-import java.util.Collections;
-import java.util.Set;
-
-import javax.xml.bind.JAXBException;
-
-import org.apache.taverna.scufl2.api.annotation.Revision;
-import org.apache.taverna.scufl2.api.annotation.Revisioned;
-import org.apache.taverna.scufl2.api.common.URITools;
-import org.apache.taverna.scufl2.api.container.WorkflowBundle;
-import org.apache.taverna.scufl2.api.core.Workflow;
-import org.apache.taverna.scufl2.api.io.WorkflowBundleWriter;
-import org.apache.taverna.scufl2.api.io.WriterException;
-import org.apache.taverna.scufl2.api.profiles.Profile;
-import org.apache.taverna.scufl2.ucfpackage.UCFPackage;
-
-
-public class RDFXMLWriter implements WorkflowBundleWriter {
- private static final String WF = "wf-";
- private static final String REVISIONS = "-revisions";
- protected static final String RDF = ".rdf";
- protected static final String WORKFLOW = "workflow/";
- protected static final String HISTORY = "history/";
- protected static final String PROFILE = "profile/";
- protected static final String WORKFLOW_BUNDLE_RDF = "workflowBundle.rdf";
-
- private static URITools uriTools = new URITools();
-
- public static final URITools getUriTools() {
- return uriTools;
- }
-
- public static final void setUriTools(URITools uriTools) {
- RDFXMLWriter.uriTools = uriTools;
- }
-
- /**
- * Version of Workflow Bundle format
- */
- public final String WORKFLOW_BUNDLE_VERSION = "0.4.0";
-
- @Override
- public Set<String> getMediaTypes() {
- return Collections
- .singleton(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);
- }
-
- @Override
- public void writeBundle(WorkflowBundle wfBundle, File destination,
- String mediaType) throws WriterException, IOException {
- UCFPackage ucfPackage = makeUCFPackage(wfBundle);
- ucfPackage.save(destination);
- }
-
- protected UCFPackage makeUCFPackage(WorkflowBundle wfBundle)
- throws IOException, WriterException {
- //UCFPackage ucfPackage = new UCFPackage();
- UCFPackage ucfPackage = wfBundle.getResources();
- if (ucfPackage.getPackageMediaType() == null)
- ucfPackage
- .setPackageMediaType(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);
-
- RDFXMLSerializer serializer = new RDFXMLSerializer(wfBundle);
-
- for (Workflow wf : wfBundle.getWorkflows()) {
- String path = WORKFLOW + uriTools.validFilename(wf.getName()) + RDF;
-
- try (OutputStream outputStream = ucfPackage
- .addResourceUsingOutputStream(path, APPLICATION_RDF_XML)) {
- serializer.workflowDoc(outputStream, wf, URI.create(path));
- } catch (JAXBException e) {
- throw new WriterException("Can't generate " + path, e);
- }
-
- path = HISTORY + WF +
- uriTools.validFilename(wf.getName()) + REVISIONS + RDF;
- addRevisions(wf, path, wfBundle);
- }
-
- for (Profile pf : wfBundle.getProfiles()) {
- String path = PROFILE + uriTools.validFilename(pf.getName()) + RDF;
- try (OutputStream outputStream = ucfPackage
- .addResourceUsingOutputStream(path, APPLICATION_RDF_XML)) {
- serializer.profileDoc(outputStream, pf, URI.create(path));
- } catch (JAXBException e) {
- throw new WriterException("Can't generate " + path, e);
- }
- path = HISTORY + "pf-" +
- uriTools.validFilename(pf.getName()) + REVISIONS + RDF;
- addRevisions(pf, path, wfBundle);
- }
-
- try (OutputStream outputStream = ucfPackage
- .addResourceUsingOutputStream(WORKFLOW_BUNDLE_RDF,
- APPLICATION_RDF_XML)) {
- serializer.workflowBundleDoc(outputStream,
- URI.create(WORKFLOW_BUNDLE_RDF));
- } catch (JAXBException e) {
- throw new WriterException("Can't generate " + WORKFLOW_BUNDLE_RDF,
- e);
- }
-
- if (ucfPackage.getPackageMediaType().equals(
- APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE))
- ucfPackage
- .setRootFile(WORKFLOW_BUNDLE_RDF, WORKFLOW_BUNDLE_VERSION);
-
- String path = HISTORY + "wfbundle" + REVISIONS + RDF;
- addRevisions(wfBundle, path, wfBundle);
-
- return ucfPackage;
- }
-
-
- protected void addRevisions(Revisioned revisioned, String path, WorkflowBundle wfBundle) throws WriterException {
- @SuppressWarnings("unused")
- URI uriBase = uriTools.uriForBean(wfBundle).resolve(path);
- Revision currentRevision = revisioned.getCurrentRevision();
- if (currentRevision == null)
- return;
-// try {
-// wfBundle.getResources()
-// .addResource(visitor.getDoc(), path, APPLICATION_RDF_XML);
-// } catch (IOException e) {
-// throw new WriterException("Can't write revisions to " + path, e);
-// }
- }
-
- @Override
- public void writeBundle(WorkflowBundle wfBundle, OutputStream output,
- String mediaType) throws WriterException, IOException {
- UCFPackage ucfPackage = makeUCFPackage(wfBundle);
- ucfPackage.save(output);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/e27d1dbe/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RevisionParser.java
----------------------------------------------------------------------
diff --git a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RevisionParser.java b/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RevisionParser.java
deleted file mode 100644
index 366069b..0000000
--- a/taverna-scufl2-rdfxml/src/main/java/org/apache/taverna/scufl2/rdfxml/RevisionParser.java
+++ /dev/null
@@ -1,173 +0,0 @@
-package org.apache.taverna.scufl2.rdfxml;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.io.InputStream;
-import java.net.URI;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.datatype.XMLGregorianCalendar;
-
-import org.apache.taverna.scufl2.api.annotation.Revision;
-import org.apache.taverna.scufl2.api.io.ReaderException;
-import org.purl.wf4ever.roevo.jaxb.Change;
-import org.purl.wf4ever.roevo.jaxb.ChangeSpecification;
-import org.purl.wf4ever.roevo.jaxb.ChangeSpecification.HasChange;
-import org.purl.wf4ever.roevo.jaxb.RoEvoDocument;
-import org.purl.wf4ever.roevo.jaxb.VersionableResource;
-import org.w3._1999._02._22_rdf_syntax_ns_.Resource;
-
-
-public class RevisionParser {
- private JAXBContext jaxbContext;
-
- protected JAXBContext getJaxbContext() throws JAXBException {
- if (jaxbContext == null) {
- Class<?>[] packages = {
- org.purl.wf4ever.roevo.jaxb.ObjectFactory.class,
- org.w3.prov.jaxb.ObjectFactory.class,
- org.w3._1999._02._22_rdf_syntax_ns_.ObjectFactory.class,
- org.w3._2000._01.rdf_schema_.ObjectFactory.class };
- jaxbContext = JAXBContext.newInstance(packages);
- }
- return jaxbContext;
- }
-
- @SuppressWarnings({ "unchecked" })
- public Map<URI, Revision> readRevisionChain(
- InputStream revisionDocumentStream, URI base)
- throws ReaderException {
- JAXBElement<RoEvoDocument> roEvoDoc;
- try {
- Unmarshaller unmarshaller = getJaxbContext().createUnmarshaller();
- roEvoDoc = (JAXBElement<RoEvoDocument>) unmarshaller
- .unmarshal(revisionDocumentStream);
- } catch (JAXBException e) {
- throw new ReaderException(e);
- }
-
- RoEvoDocument document = roEvoDoc.getValue();
- if (document.getBase() != null)
- base = base.resolve(document.getBase());
- Map<URI, Revision> revisions = new LinkedHashMap<>();
- // NOTE: Silly hack to iterate/cast in one go.. will it work?
- for (VersionableResource verResource : document.getAny().toArray(
- new VersionableResource[0]))
- parse(base, verResource, revisions);
- return revisions;
- }
-
- private Revision parse(URI base, VersionableResource verResource,
- Map<URI, Revision> revisions) throws ReaderException {
- URI uri = base.resolve(verResource.getAbout());
- Revision revision = addOrExisting(uri, revisions);
-
- if (verResource.getGeneratedAtTime() != null) {
- XMLGregorianCalendar xmlCal = verResource.getGeneratedAtTime()
- .getValue();
- revision.setGeneratedAtTime(xmlCal.toGregorianCalendar());
- }
-
- Resource wasRevisionOf = verResource.getWasRevisionOf();
- if (wasRevisionOf != null) {
- // TODO Put these in a map
- Revision r = addOrExisting(
- base.resolve(wasRevisionOf.getResource()), revisions);
- revision.setPreviousRevision(r);
- }
-
- if (verResource.getWasChangedBy() != null) {
- ChangeSpecification changeSpec = verResource.getWasChangedBy()
- .getChangeSpecification();
- if (changeSpec.getFromVersion() != null) {
- Revision r = addOrExisting(
- base.resolve(changeSpec.getFromVersion().getResource()),
- revisions);
- if (revision.getPreviousRevision() != null
- && revision.getPreviousRevision() != r)
- throw new ReaderException(
- "Inconsistent previous revision: "
- + revision.getPreviousRevision()
- .getIdentifier() + " or "
- + r.getIdentifier());
- revision.setPreviousRevision(r);
- }
-
- if (changeSpec.getType() != null)
- revision.setChangeSpecificationType(base.resolve(changeSpec
- .getType().getResource()));
-
- for (HasChange hasChange : changeSpec.getHasChange()) {
- if (hasChange.getAddition() != null) {
- Set<URI> additions = parse(hasChange.getAddition(), base);
- // Note: Use addAll in case a buggy XML has multiple
- // <hasChange><Addition>
- revision.getAdditionOf().addAll(additions);
- }
- if (hasChange.getModification() != null) {
- Set<URI> modifications = parse(hasChange.getModification(),
- base);
- revision.getModificationsOf().addAll(modifications);
- }
- if (hasChange.getRemoval() != null) {
- Set<URI> removals = parse(hasChange.getRemoval(), base);
- revision.getRemovalOf().addAll(removals);
- }
- }
- }
-
- for (Resource assoc : verResource.getWasAttributedTo())
- revision.getWasAttributedTo()
- .add(base.resolve(assoc.getResource()));
-
- for (Resource assoc : verResource.getHadOriginalSource()) {
- Revision r = addOrExisting(base.resolve(assoc.getResource()),
- revisions);
- revision.getHadOriginalSources().add(r);
- }
-
- return revision;
- }
-
- private Revision addOrExisting(URI uri, Map<URI, Revision> revisions) {
- Revision rev = revisions.get(uri);
- if (rev != null)
- return rev;
- rev = new Revision(uri, null);
- revisions.put(uri, rev);
- return rev;
- }
-
- private Set<URI> parse(Change addition, URI base) {
- Set<URI> uris = new LinkedHashSet<>();
- for (Resource r : addition.getRelatedResource())
- uris.add(base.resolve(r.getResource()));
- return uris;
- }
-}