View Javadoc

1   /*
2    * $Id: HyperZ.java,v 1.6 2004/12/18 15:43:57 jdt Exp $
3    * 
4    * Created on 16-Jan-2004 by Paul Harrison (pah@jb.man.ac.uk)
5    *
6    * Copyright 2004 AstroGrid. All rights reserved.
7    *
8    * This software is published under the terms of the AstroGrid 
9    * Software License version 1.2, a copy of which has been included 
10   * with this distribution in the LICENSE.txt file.  
11   *
12   */ 
13  
14  package org.astrogrid.applications.commandline.hyperz;
15  
16  import org.astrogrid.applications.beans.v1.parameters.ParameterValue;
17  import org.astrogrid.applications.commandline.CommandLineApplication;
18  import org.astrogrid.applications.commandline.CommandLineApplicationEnvironment;
19  import org.astrogrid.applications.commandline.CommandLineParameterDescription;
20  import org.astrogrid.applications.description.ApplicationInterface;
21  import org.astrogrid.applications.description.ParameterDescription;
22  import org.astrogrid.applications.parameter.ParameterAdapter;
23  import org.astrogrid.applications.parameter.protocol.ExternalValue;
24  import org.astrogrid.applications.parameter.protocol.ProtocolLibrary;
25  import org.astrogrid.workflow.beans.v1.Tool;
26  
27  import cds.savot.model.SavotVOTable;
28  
29  /***
30   * Specialization for HyperZ. This needs to take a VOTable and convert it to suitable form for native input into hyperZ, and then create a 
31   * @author Paul Harrison (pah@jb.man.ac.uk)
32   * @version $Name:  $
33   * @since iteration4.1
34   * @TODO there are dependencies on the AVO DEMO setup file paths that need to be removed
35   */
36  public class HyperZ extends CommandLineApplication {
37     
38     /*** Construct a new HyperZ
39       * @param id
40       * @param jobStepId
41       * @param user
42       * @param description
43       */
44      public HyperZ(String id, String jobStepId, Tool tool, ApplicationInterface description, CommandLineApplicationEnvironment env,ProtocolLibrary lib) {
45          super(jobStepId, tool,description,env,lib);
46      }
47  
48      private SavotVOTable inputVOTable;
49  
50     
51  
52   
53  /*
54     protected void preWritebackHook() {
55        // TODO convert the output file 
56        HyperZVOTableWriter wrt = new HyperZVOTableWriter(inputVOTable, (FileReferenceCommandLineParameterAdapter)findParameterAdapter("output_catalog"), applicationEnvironment);
57        wrt.write();
58        
59     }
60     */
61  
62     /* (non-Javadoc)
63      * @see org.astrogrid.applications.commandline.CmdLineApplication#postParamSetupHook()
64      */
65      /*
66     protected void postParamSetupHook() {
67        // create read the input file from the VOTable
68        HyperZVOTableReader conv = new HyperZVOTableReader((FileReferenceCommandLineParameterAdapter) findParameterAdapter("input_catalog"),applicationEnvironment);
69        inputVOTable = conv.read();
70     }*/
71     
72     
73  
74     protected final VOTableSourceIndirector votableSource = new VOTableSourceIndirector(); // necessary, as we may see output param before input param!        
75     
76      /*** specialized parameter adapter factory, that will build custom parameter adapters for the input and output files - 
77       * more structured than the previous technique of hacking with pre and post- hooks.     
78       * @author Noel Winstanley nw@jb.man.ac.uk 07-Jun-2004
79       * @author Paul Harrison (pah@jb.man.ac.uk)
80       *
81       */
82    
83          protected ParameterAdapter instantiateAdapter( ParameterValue pval, ParameterDescription desr, ExternalValue indirectVal) {
84              if (pval.getName().equals("input_catalog")) {
85                  String bands = findInputParameter("BAND_ORDER").getValue(); //TODO this is a bit hacky - will not allow indirect parameter setting - but need a quick fix...
86                  HyperZVOTableReader reader = new HyperZVOTableReader(getApplicationInterface(),pval, (CommandLineParameterDescription) desr,applicationEnvironment,indirectVal, bands);
87                  votableSource.setSource(reader);
88                  return reader;
89              } else if (pval.getName().equals("output_catalog")) {
90                  return new HyperZVOTableWriter(getApplicationInterface(), pval,(CommandLineParameterDescription)desr,applicationEnvironment,indirectVal,votableSource);
91              } else { // default behaviour                
92                  return super.instantiateAdapter(pval,desr,indirectVal);
93              }            
94            }        
95  
96  
97      /* inderector - allows late binding between reader and writer */
98      static class VOTableSourceIndirector implements HyperZVOTableWriter.VOTableSource {
99          public SavotVOTable getVOTable() {
100             return source.getVOTable();
101         }
102         private HyperZVOTableWriter.VOTableSource source;
103         public void setSource(HyperZVOTableWriter.VOTableSource source) {
104             this.source = source;
105         }
106     }
107 
108 
109 
110 }