/* (non-Javadoc)
* @see Taverna.Visitor.DataFlowImplVisitor#visit(Taverna.Tree.DataFlowImpl.AnnotatedGranularDepthPort, boolean)
*/
public Object visit(AnnotatedGranularDepthPort port, boolean sourceBoolean){
DataModule dataModule = new DataModule();
dataModule.setName(port.getName());
dataModule.setId(port.getName());
dataModule.setMyPackage("Default package");
dataModule.setVersion("Default version");
//Store Annotation of the ports
try{
AnnotationConverter annotationVisitor = new AnnotationConverter();
AnnotationContent annotationContent=new AnnotationContent();
annotationContent=(AnnotationContent) annotationVisitor.visit(port.getAnnotations());
if (annotationContent.description!=null){
dataModule.setDescription(annotationContent.description);
}
}catch (Exception e) {
Printer.log("DataFlowImplConverter.java---No Description in Ports");
dataModule.setDescription("");
}
changeCoordinateSystem();
Printer.log(port.getName()+":"+getPosX()+","+getPosY());
dataModule.setPosX(getPosX());
dataModule.setPosY(getPosY());
dataModule.setRotation(0);
// Hard coding this for now, the data module needs to go through all the data links
// in the dataflow and see what types of things the input parameter port is
// connected to, and determine what type of thing the data module needs
dataModule.setType("File");
// May want to change the code so that there is an input port and output port class
// to make it easier to tell what kind of Port that port is
//To make the distinguish the "shape" of sink and source in LONI. true=Source; false=Sink
dataModule.setSource(sourceBoolean);
dataModule.setDirSource(false);
dataModule.setDirDump(false);
dataModule.setUseDirSourceFilters(false);
dataModule.setRecursive(false);
dataModule.setMetadata(new Metadata(new Data()));
dataModule.getFileTypes().addFileType(new FileType(TavernaType,"",""));
// Figure out whether the data module will have inputs or outputs by going through the
// DataLinks and figuring out if one of their source or sink names matches the
// ports name. Then you can generate inputs or outputs for the data module depending
// on what you need
Datalinks dl = tavernaContext.getDatalinks();
List<DataLink> datalinks = dl.getDataLinks();
String inputPortName = port.getName();
String datalinkPortName = "";
String sourceLinkType = "";
String sourcePort = "";
String sourceProcessor = "";
String sinkLinkType = "";
String sinkPort = "";
String sinkProcessor = "";
Link source;
Link sink;
Parameter parameter = null;
Output output = null;
Format format;
FileTypes fileTypes;
for(DataLink d : datalinks){
source = d.getSource();
sourceLinkType = source.getLinkType();
sourcePort = source.getPort();
sourceProcessor = source.getProcessor();
sink = d.getSink();
sinkLinkType = sink.getLinkType();
sinkPort = sink.getPort();
sinkProcessor = sink.getProcessor();
// Even if the Taverna port is a SOURCE, that will correspond to Output.class in LONI. It's weird, but you have to be careful. In side the Input of LONI, the dataModule actually contains <output>, not <input>!
if(sinkPort == inputPortName){
parameter = new Parameter();
parameter.setId(dataModule.getId() +".Input");
parameter.setName(inputPortName);
parameter.setDescription("Input description");
parameter.setRequired(true);
parameter.setEnabled(true);
parameter.setOrder(tavernaContext.getNextOrder());
parameter.setLink("");
parameter.setValues(new Values());
// Create a new Format for parameter
format = new Format();
format.setType("File");
format.setCardinality(1);
format.setCardinalityBase("");
format.setTransformationBase("");
// Create and fill in file types for format
fileTypes = new FileTypes();
fileTypes.addFileType(new FileType(TavernaType, "", ""));
format.setFileTypes(fileTypes);
// Give parameter the newly created Format object
parameter.setFileFormat(format);
dataModule.addInput(parameter);
break;
}
else if(sourcePort == inputPortName){
output = new Output();
output.setId(dataModule.getId() +".Output");
output.setName(inputPortName);
output.setDescription("Output description");
output.setRequired(true);
output.setEnabled(true);
output.setOrder(tavernaContext.getNextOrder());
output.setLink("");
output.setValues(new Values());
// Create a new Format for output
output.setFormat(new Format());
output.getFormat().setType("File");
output.getFormat().setCardinality(1);
output.getFormat().setCardinalityBase("");
output.getFormat().setTransformationBase("");
// Create and fill in file types for format
output.getFormat().getFileTypes().addFileType(new FileType(TavernaType, "", ""));
output.getValues().addValue(new Value("hi", "there"));
dataModule.addOutput(output);
break;
}
}
return dataModule;
}