package Specification;
import FileOps.Generator;
import FileOps.Parser;
import FileOps.XStream.XStreamWrapper;
import LONI.tree.workflow.Pipeline;
import Specification.Taverna.LazyParser;
import Taverna.Tree.*;
import Taverna.Tree.Annotation.AnnotationAssertionImpl;
import Taverna.Tree.Annotation.AnnotationAssertions;
import Taverna.Tree.Annotation.AnnotationBean;
import Taverna.Tree.Annotation.AnnotationChain;
import Taverna.Tree.Annotation.AnnotationChainImpl;
import Taverna.Tree.Annotation.Annotations;
import Taverna.Tree.DataFlowImpl.AnnotatedGranularDepthPort;
import Taverna.Tree.DataFlowImpl.AnnotatedGranularDepthInputPorts;
import Taverna.Tree.DataFlowImpl.AnnotatedGranularDepthOutputPorts;
import Taverna.Tree.DataFlowImpl.AnnotatedPort;
import Taverna.Tree.DataFlowImpl.AnnotatedPorts;
import Taverna.Tree.DataFlowImpl.DataLink;
import Taverna.Tree.DataFlowImpl.Dataflow;
import Taverna.Tree.DataFlowImpl.Datalinks;
import Taverna.Tree.DataFlowImpl.DepthPort;
import Taverna.Tree.DataFlowImpl.DepthPorts;
import Taverna.Tree.DataFlowImpl.GranularDepthPort;
import Taverna.Tree.DataFlowImpl.GranularDepthPorts;
import Taverna.Tree.DataFlowImpl.Link;
import Taverna.Tree.DataFlowImpl.OutputPorts;
import Taverna.Tree.DataFlowImpl.PortProduct;
import Taverna.Tree.Processor.Null;
import Taverna.Tree.Processor.ParallelizeConfig;
import Taverna.Tree.Processor.RetryConfig;
import Taverna.Tree.Processor.Activities;
import Taverna.Tree.Processor.Activity;
import Taverna.Tree.Processor.ActivityInputPortDefinitionBean;
import Taverna.Tree.Processor.ActivityOutputPortDefinitionBean;
import Taverna.Tree.Processor.ConfigBean;
import Taverna.Tree.Processor.InputPorts;
import Taverna.Tree.Processor.LocalWorkerActivityConfigurationBean;
import Taverna.Tree.Processor.Mapping;
import Taverna.Tree.Processor.MimeTypes;
import Taverna.Tree.Processor.Processor;
import Taverna.Tree.Processor.Processors;
import Taverna.Tree.Processor.lWACBInputs;
import Taverna.Tree.Processor.lWACBOutputs;
/**
* @author johnny5550822, Nick, Rouel
* TThe binding specfication for Taverna
*
*/
/**
* Important Keys and Assumption in bindings
* 1. Even if you don't bind the class that it is found in a class, the xmlParese can still parse that class. But, if you don't bind the attribute, you will not see it in the output file. Anyway, to have a better structure, we should bind everything for a flow chart.
* 2. First comes from class field name, second is from .xsd file
* 3. There is a tricky things going on here. Although the .t2flow xml defines different types of DepthPort, but the only different is only whether the port contains some information or not. So, to simplify our structure, we will consider all the ports to AnnotatedDepthPorts, which contain the most elements. Through this, the # of classes can be reduced. And the structure interface can be more simple. Hopefully, this works when we develop the codes in more depth. (We omit Annotated Port, etc)
*
*/
public class TavernaSpecification {
private static XStreamWrapper<Workflow> xstream = new XStreamWrapper<Workflow>();
private static boolean initialized = false;
private static void init(){
initXML();
initialized = true;
}
private static void bindData(){
// Workflow bindings
xstream.bindElementToClass(Workflow.class, "workflow");
xstream.bindAttributeToClassField(Workflow.class, "dataflow", "dataflow");
xstream.bindAttributeToClassField(Workflow.class, "producedBy", "producedBy");
xstream.bindAttributeToClassField(Workflow.class, "version", "version");
xstream.bindAttributeToClassField(Workflow.class, "xmlns", "xmlns");
// Dataflow bindings
xstream.bindElementToClass(Dataflow.class, "dataflow");
xstream.bindElementToClassField(Dataflow.class, "name", "name");
xstream.bindElementToClassField(Dataflow.class, "inputPorts", "inputPorts");
xstream.bindElementToClassField(Dataflow.class, "outputPorts", "outputPorts");
xstream.bindElementToClassField(Dataflow.class, "processors", "processors");
xstream.bindElementToClassField(Dataflow.class, "conditions", "conditions");
xstream.bindAttributeToClassField(Dataflow.class, "id", "id");
xstream.bindAttributeToClassField(Dataflow.class, "role", "role");
//AnnotatedGranularDepthPorts (inputPorts) Binding
xstream.bindGroupToList(AnnotatedGranularDepthInputPorts.class, "ports", AnnotatedGranularDepthPort.class);
xstream.bindGroupToList(AnnotatedGranularDepthOutputPorts.class, "ports", AnnotatedGranularDepthPort.class);
xstream.bindElementToClass(AnnotatedGranularDepthPort.class, "port");
//AnnotatedGranularDepthPort (port) Binding
xstream.bindElementToClassField(AnnotatedGranularDepthPort.class, "name", "name");
xstream.bindElementToClassField(AnnotatedGranularDepthPort.class, "depth", "depth");
xstream.bindElementToClassField(AnnotatedGranularDepthPort.class, "granularDepth", "granularDepth");
xstream.bindElementToClassField(AnnotatedGranularDepthPort.class, "annotations", "annotations");
// Datalinks bindings
xstream.bindElementToClass(Datalinks.class, "datalinks");
xstream.bindGroupToList(Datalinks.class, "datalinks",DataLink.class);
// DataLink bindings
xstream.bindElementToClass(DataLink.class, "datalink");
xstream.bindElementToClassField(DataLink.class, "source", "source");
xstream.bindElementToClassField(DataLink.class, "sink", "sink");
// Link bindings
xstream.bindElementToClass(Link.class, "link");
xstream.bindAttributeToClassField(Link.class, "linkType", "type");
xstream.bindElementToClassField(Link.class, "processor", "processor");
xstream.bindElementToClassField(Link.class, "port", "port");
}
private static void bindAnnotations(){
//Annotations Binding to Dataflow
xstream.bindElementToClassField(Dataflow.class, "annotations", "annotations");
//Annotations Binding (Binding a list)
xstream.bindElementToClass(Annotations.class, "annotations");
xstream.bindGroupToList(Annotations.class, "annotation_chain", AnnotationChain.class);
xstream.bindElementToClass(AnnotationChain.class, "annotation_chain");
xstream.bindElementToClass(AnnotationChain.class, "annotation_chain_2_2");
//AnnotationChain Binding
xstream.bindElementToClass(AnnotationChain.class, "annotation_chain"); //<--this may not needed if we have xstream.bindElementToClassField(Annotations.class,"annotation_chain" , "annotation_chain"); the xmLParser is powerful!
xstream.bindAttributeToClassField(AnnotationChain.class, "encoding", "encoding");
xstream.bindElementToClassField(AnnotationChain.class, "annotationChainImpl", "net.sf.taverna.t2.annotation.AnnotationChainImpl");
//AnnotationChainImpl Binding
xstream.bindAttributeToClassField(AnnotationChainImpl.class, "xmlns", "xmlns");
xstream.bindElementToClassField(AnnotationAssertions.class, "annotationAssertions", "annotationAssertions");
//AnnotationAssertions Binding
xstream.bindElementToClass(AnnotationAssertions.class, "annotationAssertions");
xstream.bindElementToClassField(AnnotationAssertions.class, "annotationAssertionImpl", "net.sf.taverna.t2.annotation.AnnotationAssertionImpl");
//AnnotationAssertionImpl Binding
xstream.bindElementToClass(AnnotationAssertionImpl.class, "net.sf.taverna.t2.annotation.AnnotationAssertionImpl");
xstream.bindElementToClassField(AnnotationAssertionImpl.class, "annotationBean", "annotationBean");
xstream.bindElementToClassField(AnnotationAssertionImpl.class, "date", "date");
xstream.bindElementToClassField(AnnotationAssertionImpl.class, "creators", "creators");
xstream.bindElementToClassField(AnnotationAssertionImpl.class, "curationEventList", "curationEventList");
//AnnotationBean Binding
xstream.bindElementToClass(AnnotationBean.class, "annotationBean");
xstream.specialBindAttributeToClassField(AnnotationBean.class, "myClass", "class");
xstream.bindElementToClassField(AnnotationBean.class,"myClassText","text");
xstream.bindElementToClassField(AnnotationBean.class, "myClassIdentification", "identification");
}
private static void bindMisc(){
//InputPorts
xstream.bindElementToClass(InputPorts.class, "inputPorts");
xstream.bindElementToClassField(InputPorts.class, "port", "port");
xstream.bindElementToClassField(InputPorts.class, "name", "name");
xstream.bindElementToClassField(InputPorts.class, "depth", "depth");
xstream.bindElementToClassField(InputPorts.class, "granularDepth", "granularDepth");
xstream.bindElementToClassField(InputPorts.class, "annotations", "annotations");
//OuputPorts
xstream.bindElementToClass(OutputPorts.class, "outputPorts");
xstream.bindElementToClassField(OutputPorts.class, "port", "port");
xstream.bindElementToClassField(OutputPorts.class, "annotations", "annotations");
}
private static void bindProcessors(){
LazyParser lazy = new LazyParser(null);
// Processors Bindings
xstream.bindElementToClass(Processors.class, "processors");
xstream.bindGroupToList(Processors.class, "processors");
// Processor Bindings
xstream.bindElementToClass(Processor.class, "processor");
xstream.bindElementToClassField(Processor.class, "processorName", "name");
xstream.bindElementToClassField(Processor.class, "inputPorts", "inputPorts");
xstream.bindElementToClassField(Processor.class, "outputPorts", "outputPorts");
xstream.bindElementToClassField(Processor.class, "annotations", "annotations");
xstream.bindElementToClassField(Processor.class, "activities", "activities");
xstream.bindElementToClassField(Processor.class, "dispatchStack", "dispatchStack");
xstream.bindElementToClassField(Processor.class, "iterationStrategyStack", "iterationStrategyStack");
// Activities Bindings
xstream.bindElementToClass(Activities.class, "activities");
xstream.bindGroupToList(Activities.class, "activities");
// Activity Bindings
xstream.bindElementToClass(Activity.class, "activity");
xstream.bindElementToClassField(Activity.class, "raven", "raven");
xstream.bindElementToClassField(Activity.class, "theClass", "class");
xstream.bindElementToClassField(Activity.class, "inputMap", "inputMap");
xstream.bindElementToClassField(Activity.class, "outputMap", "outputMap");
xstream.bindElementToClassField(Activity.class, "configBean", "configBean");
xstream.bindElementToClassField(Activity.class, "annotations", "annotations");
// Map Bindings
xstream.bindGroupToList(TavMap.class, "mappings", Mapping.class);
xstream.bindElementToClass(Mapping.class, "map");
xstream.bindAttributeToClassField(Mapping.class, "from", "from");
xstream.bindAttributeToClassField(Mapping.class, "to", "to");
// DispatchStack Bindings
xstream.bindElementToClass(DispatchStack.class, "dispatchStack");
xstream.bindGroupToList(DispatchStack.class, "dispatchLayers");
// DispatchLayer Bindings
xstream.bindElementToClass(DispatchLayer.class, "dispatchLayer");
xstream.bindElementToClassField(DispatchLayer.class, "raven", "raven");
xstream.bindElementToClassField(DispatchLayer.class, "className", "class");
xstream.bindElementToClassField(DispatchLayer.class, "configBean", "configBean");
// Raven Bindings
xstream.bindElementToClass(Raven.class, "raven");
xstream.bindElementToClassField(Raven.class, "group", "group");
xstream.bindElementToClassField(Raven.class, "artifact", "artifact");
xstream.bindElementToClassField(Raven.class, "version", "version");
// IterationStrategyStack Bindings
xstream.bindElementToClass(IterationStrategyStack.class, "iterationStrategyStack");
xstream.bindGroupToList(IterationStrategyStack.class, "iterations");
xstream.bindElementToClass(Iteration.class, "iteration");
xstream.bindGroupToList(Iteration.class, "strategies");
// Iteration Strategy Node Bindings
xstream.bindElementToClass(IterationNode.class, "strategy");
xstream.bindElementToClassField(IterationNode.class, "cross", "cross");
xstream.bindElementToClassField(IterationNode.class, "dot", "dot");
xstream.bindElementToClassField(IterationNode.class, "port", "port");
// Cross Product Bindings
xstream.bindElementToClass(Cross.class, "cross");
xstream.bindGroupToList(Cross.class, "crosses", PortProduct.class);
// Port Product Bindings
xstream.bindElementToClass(PortProduct.class, "port");
xstream.bindAttributeToClassField(PortProduct.class, "portName", "name");
xstream.bindAttributeToClassField(PortProduct.class, "depth", "depth");
xstream.bindElementToClass(IterationNode.class, "cross");
// ConfigBean Bindings
xstream.bindElementToClass(ConfigBean.class, "configBean");
xstream.bindAttributeToClassField(ConfigBean.class, "encoding", "encoding");
xstream.bindElementToClassField(ConfigBean.class, "lWACB", "net.sf.taverna.t2.activities.localworker.LocalworkerActivityConfigurationBean");
xstream.bindElementToClassField(ConfigBean.class, "pC", "net.sf.taverna.t2.workflowmodel.processor.dispatch.layers.ParallelizeConfig");
xstream.bindElementToClassField(ConfigBean.class, "configBeanNull", "null");
xstream.bindElementToClassField(ConfigBean.class, "rC", "net.sf.taverna.t2.workflowmodel.processor.dispatch.layers.RetryConfig");
xstream.bindElementToClass(ParallelizeConfig.class, "net.sf.taverna.t2.workflowmodel.processor.dispatch.layers.ParallelizeConfig");
xstream.bindAttributeToClassField(ParallelizeConfig.class, "xmlns", "xmlns");
xstream.bindElementToClassField(ParallelizeConfig.class, "maxJobs", "maxJobs");
xstream.bindElementToClass(RetryConfig.class, "net.sf.taverna.t2.workflowmodel.processor.dispatch.layers.RetryConfig");
xstream.bindAttributeToClassField(RetryConfig.class, "xmlns", "xmlns");
xstream.bindElementToClassField(RetryConfig.class, "backoffFactor", "backoffFactor");
xstream.bindElementToClassField(RetryConfig.class, "initialDelay", "initialDelay");
xstream.bindElementToClassField(RetryConfig.class, "maxDelay", "maxDelay");
xstream.bindElementToClassField(RetryConfig.class, "maxRetries", "maxRetries");
xstream.bindElementToClass(Null.class, "null");
xstream.bindAttributeToClassField(Null.class, "xmlns", "xmlns");
xstream.bindElementToClass(LocalWorkerActivityConfigurationBean.class, "net.sf.taverna.t2.activities.localworker.LocalworkerActivityConfigurationBean");
xstream.bindAttributeToClassField(LocalWorkerActivityConfigurationBean.class, "xmlns", "xmlns");
xstream.bindElementToClassField(LocalWorkerActivityConfigurationBean.class, "iWACBIn", "inputs");
xstream.bindElementToClassField(LocalWorkerActivityConfigurationBean.class, "iWACBOut", "outputs");
xstream.bindElementToClassField(LocalWorkerActivityConfigurationBean.class, "classLoaderSharing","classLoaderSharing");
xstream.bindElementToClassField(LocalWorkerActivityConfigurationBean.class, "localDependencies","localDependencies");
xstream.bindElementToClassField(LocalWorkerActivityConfigurationBean.class, "artifactDependencies","artifactDependencies");
xstream.bindElementToClassField(LocalWorkerActivityConfigurationBean.class, "script","script");
xstream.bindElementToClassField(LocalWorkerActivityConfigurationBean.class, "dependencies","dependencies");
xstream.bindElementToClassField(LocalWorkerActivityConfigurationBean.class, "localworkerName","localworkerName");
xstream.bindElementToClass(lWACBInputs.class, "inputs");
xstream.bindGroupToList(lWACBInputs.class, "iWACBInputs", ActivityInputPortDefinitionBean.class);
xstream.bindElementToClass(lWACBOutputs.class, "outputs");
xstream.bindGroupToList(lWACBOutputs.class, "iWACBOutputs", ActivityOutputPortDefinitionBean.class);
xstream.bindElementToClass(ActivityInputPortDefinitionBean.class, "net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityInputPortDefinitionBean");
xstream.bindElementToClass(ActivityOutputPortDefinitionBean.class, "net.sf.taverna.t2.workflowmodel.processor.activity.config.ActivityOutputPortDefinitionBean");
xstream.bindElementToClassField(ActivityInputPortDefinitionBean.class, "name", "name");
xstream.bindElementToClassField(ActivityInputPortDefinitionBean.class, "depth", "depth");
xstream.bindElementToClassField(ActivityInputPortDefinitionBean.class, "mimeTypes", "mimeTypes");
xstream.bindElementToClassField(MimeTypes.class, "text", "string");
xstream.bindElementToClassField(ActivityInputPortDefinitionBean.class, "handledReferenceSchemes", "handledReferenceSchemes");
xstream.bindElementToClassField(ActivityInputPortDefinitionBean.class, "translatedElementType", "translatedElementType");
xstream.bindElementToClassField(ActivityInputPortDefinitionBean.class, "allowsLiteralValues", "allowsLiteralValues");
}
public static void bindConditions(){
// Conditions Bindings
xstream.bindElementToClass(Conditions.class, "conditions");
xstream.bindGroupToList(Conditions.class, "conditions");
// Condition Bindings
xstream.bindElementToClass(Condition.class, "condition");
xstream.bindAttributeToClassField(Condition.class, "control", "control");
xstream.bindAttributeToClassField(Condition.class, "target", "target");
}
public static void initXML(){
bindData();
bindMisc();
bindAnnotations();
bindProcessors();
bindConditions();
}
public static Parser<Workflow> getXMLParser(){
if(!initialized)
init();
return xstream;
}
public static Generator<Workflow> getXMLGenerator(){
if(!initialized)
init();
return xstream;
}
}