Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/embl/ebi/escience/talisman/scuflsupport/PopulatePortList.java


1   /**
2    * This file is a component of the Taverna project,
3    * and is licensed under the GNU LGPL.
4    * Copyright Tom Oinn, EMBL-EBI
5    */
6   package org.embl.ebi.escience.talisman.scuflsupport;
7   
8   import javax.servlet.http.HttpServletRequest;
9   import javax.servlet.http.HttpServletResponse;
10  import org.embl.ebi.escience.scufl.Port;
11  import org.embl.ebi.escience.scufl.Processor;
12  import org.embl.ebi.escience.scufl.UnknownProcessorException;
13  import org.embl.ebi.escience.talisman.*;
14  
15  
16  
17  
18  /**
19   * Populates a named SelectionList with names of ports within
20   * a given processor in the model. The 'model' parameter
21   * specified the ScuflModel to use, the 'processor' parameter
22   * the name of a processor within that model, the 'type' parameter should be
23   * either 'source', 'sink' or 'all' depending on the type of
24   * ports you want included in the list, and the 'list' parameter
25   * must be the name of a selection list in the Talisman page.
26   * @author Tom Oinn
27   */
28  public class PopulatePortList extends AbstractScuflAction implements ActionWorker {
29      
30      public void process(HttpServletRequest request , HttpServletResponse response, Action action) 
31    throws AbortActionException, NodeResolutionException, UnknownResolutionProtocolException {
32    super.process(request, response, action);
33    
34    Trigger trigger = (Trigger)action.getParent();
35    
36    // Require the following parameters (model is redundant here,
37    // retained for clarity. The superclass has already checked it)
38    action.requireParameters("list,processor,type,model");
39  
40    // Get the selection list
41    SelectionList theList = Resolver.getSelection(action.props.getProperty("list"),action);
42    
43    // Get the properties of the search
44    String typeRequired = Resolver.getFieldValue(action.props.getProperty("type"),action).toLowerCase();
45    String processorName = Resolver.getFieldValue(action.props.getProperty("processor"),action);
46    
47    // Locate the Processor
48    Processor p = null;
49    try {
50        p = model.locateProcessor(processorName);
51    }
52    catch (UnknownProcessorException upe) {
53        trigger.addError(upe.getMessage());
54        throw new AbortActionException();
55    }
56  
57    // Clear the selection list
58    theList.clearOptions();
59    
60    // Get the port array from the model
61    Port[] ports = null;
62    if (typeRequired.equals("source")) {
63        ports = p.getOutputPorts();
64    }
65    else { 
66        if (typeRequired.equals("sink")) {
67      ports = p.getInputPorts();
68        }
69        else {
70      if (typeRequired.equals("all")) {
71          ports = p.getPorts();
72      }
73        }
74    }
75    for (int i = 0; i<ports.length; i++) {
76        theList.addOption(ports[i].getName());
77    }
78  
79      }
80  
81  }