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

Quick Search    Search Deep

Source code: org/embl/ebi/escience/scufl/talisman/AbstractScuflAction.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.scufl.talisman;
7   
8   import javax.servlet.http.HttpServletRequest;
9   import javax.servlet.http.HttpServletResponse;
10  import org.embl.ebi.escience.scufl.ScuflModel;
11  import org.embl.ebi.escience.talisman.*;
12  
13  import org.embl.ebi.escience.scufl.talisman.ScuflModelBean;
14  import java.lang.ClassCastException;
15  
16  
17  
18  /**
19   * The superclass of all actions that operate on ScuflModel
20   * instances contained within ScuflModelBean objects in Talisman
21   * fields. The process method sets up a member variable 'model'
22   * which points to the actual ScuflModel without having to go through
23   * all the layers of indirection every time. It throws appropriate
24   * exceptions if the model can't be found. All actions that subclass
25   * this expect to find a parameter 'model' in their input that points
26   * to the beanfield containing the ScuflModelBean
27   * @author Tom Oinn
28   */
29  public abstract class AbstractScuflAction implements ActionWorker {
30      
31      ScuflModel model = null;
32  
33      public void process(HttpServletRequest request , HttpServletResponse response, Action action) 
34    throws AbortActionException, NodeResolutionException, UnknownResolutionProtocolException {
35    // All subclasses require the model parameter
36    action.requireParameters("model");
37    // Get the trigger for error reporting
38    Trigger trigger = (Trigger)action.getParent();
39    // Locate the model and set it up in the model member
40    IBeanField beanField = null;
41    try {
42        beanField = (IBeanField)Resolver.getField(action.props.getProperty("model"),action);
43    }
44    catch (ClassCastException cce) {
45        trigger.addError("Supplied model field must implement IBeanField.");
46        throw new AbortActionException();
47    }
48    ScuflModelBean scuflBean = null;
49    try {
50        scuflBean = (ScuflModelBean)beanField.getBean();
51    }
52    catch (ClassCastException cce) {
53        trigger.addError("The model BeanField must contain an instance of a ScuflModelBean.");
54        throw new AbortActionException();
55    }
56    if (scuflBean == null) {
57        trigger.addError("The model BeanField must contain a bean, it is null.");
58        throw new AbortActionException();
59    }
60    // Set the model for this execution of the action.
61    this.model = scuflBean.getModel();
62      }
63  
64  }