View Javadoc

1   /* $Id: IdentityPreprocessor.java,v 1.2 2004/09/01 15:42:26 jdt Exp $
2    *
3    * Copyright (C) AstroGrid. All rights reserved.
4    *
5    * This software is published under the terms of the AstroGrid 
6    * Software License version 1.2, a copy of which has been included 
7    * with this distribution in the LICENSE.txt file. 
8    * Created on Aug 11, 2004
9   
10   */
11  package org.astrogrid.applications.http.script;
12  
13  import java.util.Enumeration;
14  
15  import org.astrogrid.applications.beans.v1.SimpleParameter;
16  import org.astrogrid.applications.beans.v1.WebHttpCall;
17  import org.astrogrid.applications.beans.v1.parameters.ParameterValue;
18  import org.astrogrid.registry.beans.cea.CeaHttpApplicationType;
19  import org.astrogrid.workflow.beans.v1.Input;
20  import org.astrogrid.workflow.beans.v1.Tool;
21  
22  /***
23   * A default preprocessor that simply programatically changes the format from Tool and CeaHttpApplicationType to WebHttpCall
24   * without any actual processing.  Should be deprecated by the default version of XSLTPreprocessor, if I can
25   * get it working.
26   * @author jdt
27   */
28  public final class IdentityPreprocessor implements Preprocessor {
29  
30      /* (non-Javadoc)
31       * @see org.astrogrid.applications.http.script.Preprocessor#process(org.astrogrid.workflow.beans.v1.Tool, org.astrogrid.registry.beans.cea.CeaHttpApplicationType)
32       */
33      public WebHttpCall process(final Tool tool, final CeaHttpApplicationType app) {
34          final WebHttpCall webCall = new WebHttpCall();
35          webCall.setURL(app.getCeaHttpAdapterSetup().getURL());
36          final Input inputs = tool.getInput();
37          final Enumeration enum = inputs.enumerateParameter();
38  
39          while (enum.hasMoreElements()) {
40              final ParameterValue parameter = (ParameterValue) enum.nextElement();
41              final SimpleParameter simpleParameter = new ConstructableSimpleParameter(parameter);
42              webCall.addSimpleParameter(simpleParameter);
43          }
44          
45          return webCall;
46      }
47      
48      /***
49       * Just another SimpleParameter (which is generated) with an extra constructor 
50       * @author jdt
51       */
52      private static class ConstructableSimpleParameter extends SimpleParameter {
53          public ConstructableSimpleParameter(ParameterValue parameter) {
54              this.setName(parameter.getName().trim());
55              this.setValue(parameter.getValue().trim());
56          }
57      }
58  
59  }