package edu.vt.vbi.pathport.client.plugin.taverna; import java.util.Collection; import java.util.Iterator; import java.util.Map; import edu.vt.vbi.pathport.client.toolbus.*; import edu.vt.vbi.util.Debug; import org.embl.ebi.escience.baclava.DataThing; import org.embl.ebi.escience.scuflui.workbench.Workbench; import org.embl.ebi.escience.scufl.*; import org.embl.ebi.escience.scufl.enactor.*; import org.embl.ebi.escience.scufl.enactor.event.UserChangedDataEvent; import org.embl.ebi.escience.scufl.enactor.event.WorkflowCompletionEvent; import org.embl.ebi.escience.scufl.enactor.implementation.WorkflowEventDispatcher; /** * A simple Model with no real functions. This is used as * a tutorial for developers wishing to create a new * ToolBus visualization plugin. */ public class TavernaModel extends Model implements ScuflModelEventListener { /** * Name of this Model Type. */ private static String modelName = "TavernaModel"; private ScuflModel scuflModel; /** * Constructor that accepts a data String. * This Model ignores the data String. * * @param data String of data for the Model. */ public TavernaModel(String data) throws NotParseableException { super(); System.out.println("TavernaModel constructor called"); Debug.msg(Debug.MISCELLANEOUS, Debug.VISUAL_PLUGINS, "TavernaModel constructor called"); setInstanceName(modelName); } /** * Carries out initializations required when Model is * chosen to be created. In this version, the method * is empty. */ public void finisher() { System.out.println("TavernaModel finisher called"); setViewManager(new TavernaViewManager(this)); System.out.println("try to create workbench"); //set some System properties used by Taverna. These are being //hard-coded now, but need to be passed to ToolBus at startup //eventually System.setProperty("taverna.dotlocation", "/home/agbiotec/Apps/bin/dot"); System.setProperty("taverna.home", "/home/agbiotec/BioInfo_Apps/taverna-1.4"); Workbench.main(new String[]{}); System.out.println("&*&*&*&*&*&*& created workbench"); scuflModel = Workbench.model; System.out.println("&*&*&*&*&*&*& got scuflModel"); scuflModel.addListener(this); System.out.println("&*&*&*&*&*&*& added listener"); WorkflowEventDispatcher.DISPATCHER.addListener(new ToolBusWorkflowEventAdapter());; System.out.println("&*&*&*&*&*&*& exit finisher()"); } public void receiveModelEvent(ScuflModelEvent sme) { System.out.println("&*&*&*&*&*&*& ScuflModelEvent received "); System.out.println(sme.getMessage()); } /** * Returns the name of this Model subclass. * * @return Model name - "TavernaModel" */ public static String getModelName() { return modelName; } protected void sendToToolBus(String xmlData) { super.processXML(xmlData); } private class ToolBusWorkflowEventAdapter extends WorkflowEventAdapter { /* (non-Javadoc) * @see org.embl.ebi.escience.scufl.enactor.WorkflowEventListener#dataChanged(org.embl.ebi.escience.scufl.enactor.event.UserChangedDataEvent) */ public void dataChanged(UserChangedDataEvent arg0) { System.out.println("&*&*&*&* TavernaModel." + "ToolBusWorkFlowEventAdapter.dataChanged()"); System.out.println(arg0.toString()); } /** * Called when a previously scheduled workflow completes * successfuly. This is called after results are available, * so storage plugins may rely on the getResults method * on the workflow instance references within the event * being valid. */ public void workflowCompleted(WorkflowCompletionEvent e) { System.out.println("&*&*&*&* TavernaModel." + "ToolBusWorkFlowEventAdapter.workFlowCompleted()"); System.out.println(e.toString()); String resultString = null; Map outputs = e.getWorkflowInstance().getOutput(); StringBuffer sb = new StringBuffer("&*&*&*&*:"); for (Iterator i = outputs.keySet().iterator(); i.hasNext();) { String outputName = (String)i.next(); DataThing outputValue = (DataThing)outputs.get(outputName); String outputLSID = outputValue.getLSID(outputValue.getDataObject()); Object dataObject = outputValue.getDataObject(); if(dataObject instanceof Collection) { System.out.println("&*&*&*&* data object is a Collection"); StringBuffer sb2 = new StringBuffer(); Collection c = (Collection) dataObject; Iterator it = c.iterator(); while (it.hasNext()) { sb2.append(it.next().toString()); } resultString = sb2.toString(); } else { resultString = dataObject.toString(); } sb.append(" "+outputLSID+"->'"+outputName+"'\n"); sb.append(" " + resultString + "->'" + outputName + "'\n"); } System.out.println(""); System.out.println(sb); System.out.println(""); TavernaModel.this.sendToToolBus(resultString); } } }