View Javadoc

1   /*
2    * $Id: Axis2Castor.java,v 1.11 2004/12/03 14:47:41 jdt Exp $
3    * 
4    * Created on 18-Mar-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.common.bean;
15  
16  import org.astrogrid.applications.beans.v1.ApplicationList;
17  import org.astrogrid.applications.beans.v1.Interface;
18  import org.astrogrid.applications.beans.v1.Parameters;
19  import org.astrogrid.applications.beans.v1.cea.castor.ExecutionSummaryType;
20  import org.astrogrid.applications.beans.v1.cea.castor.InputListType;
21  import org.astrogrid.applications.beans.v1.cea.castor.ResultListType;
22  import org.astrogrid.applications.beans.v1.cea.castor.types.ExecutionPhase;
23  import org.astrogrid.applications.beans.v1.parameters.ParameterValue;
24  import org.astrogrid.applications.beans.v1.parameters.XhtmlDocumentation;
25  import org.astrogrid.applications.beans.v1.parameters.types.ParameterTypes;
26  import org.astrogrid.community.beans.v1.Account;
27  import org.astrogrid.community.beans.v1.axis._Account;
28  
29  import java.util.Calendar;
30  
31  import org.astrogrid.jes.beans.v1.axis.executionrecord.JobURN;
32  import org.astrogrid.jes.beans.v1.axis.executionrecord.WorkflowSummaryType;
33  import org.astrogrid.jes.beans.v1.axis.executionrecord._extension;
34  import org.astrogrid.jes.types.v1.cea.axis.LogLevel;
35  import org.astrogrid.jes.types.v1.cea.axis.MessageType;
36  import org.astrogrid.workflow.beans.v1.Input;
37  import org.astrogrid.workflow.beans.v1.Output;
38  import org.astrogrid.workflow.beans.v1.Tool;
39  import org.astrogrid.workflow.beans.v1.axis._input;
40  import org.astrogrid.workflow.beans.v1.axis._output;
41  import org.astrogrid.workflow.beans.v1.execution.Extension;
42  
43  import org.apache.axis.types.NMToken;
44  
45  import sun.misc.Regexp;
46  
47  /***
48   * Class of static methods to convert axis beans to castor beans. Copied from the util package in the jes project and put in common.
49   * @author Noel Winstanley
50   * @author Paul Harrison (pah@jb.man.ac.uk) 18-Mar-2004
51   * @version $Name:  $
52   * @since iteration5
53   */
54  public class Axis2Castor {
55  
56      /***
57       * @param message
58       * @return
59       */
60      public static org.astrogrid.applications.beans.v1.cea.castor.MessageType[] convert(MessageType[] message) {
61          if (message == null) {
62              return null;
63          }
64          org.astrogrid.applications.beans.v1.cea.castor.MessageType[] castor = new   org.astrogrid.applications.beans.v1.cea.castor.MessageType[message.length];
65          for (int i = 0; i < message.length; i++) {
66              castor[i] = convert(message[i]);
67          }
68          return castor;
69      }  
70      
71      
72      /*** convert between castor and axis representations of the same schema object */
73      public static org.astrogrid.applications.beans.v1.cea.castor.MessageType convert(MessageType mt) {
74          if (mt == null) {
75              return null;
76          }
77          org.astrogrid.applications.beans.v1.cea.castor.MessageType result = new org.astrogrid.applications.beans.v1.cea.castor.MessageType();
78          result.setContent(mt.getContent());
79          result.setPhase(Axis2Castor.convert(mt.getPhase()));
80          result.setLevel(Axis2Castor.convert(mt.getLevel()));
81          result.setSource(mt.getSource());
82          Calendar cal =  mt.getTimestamp();
83          if (cal != null) {
84              result.setTimestamp(cal.getTime());
85          }
86          return result;
87      }
88  
89      /*** convert between castor and axis representations of the same schema object */
90      public static Account convert(_Account arg0) {
91          Account result = new Account();
92          result.setCommunity(arg0.getCommunity().getValue());
93          result.setName(arg0.getName().getValue());
94          return result;
95      }
96  
97      /*** convert between castor and axis representations of the same schema object */
98      public static org.astrogrid.applications.beans.v1.cea.castor.types.ExecutionPhase convert(org.astrogrid.jes.types.v1.cea.axis.ExecutionPhase phase) {
99          if (phase == null) {
100             return null;
101         } else {
102             return org.astrogrid.applications.beans.v1.cea.castor.types.ExecutionPhase.valueOf(phase.getValue());
103         }
104     }
105     
106     /***
107      * @param extension
108      * @return
109      */
110     public static Extension[] convert(_extension[] extension) {
111         if (extension == null) {
112             return null;
113         }
114         Extension[] castor = new Extension[extension.length];
115         for (int i = 0; i < extension.length; i++) {
116             castor[i] = convert(extension[i]);
117         }
118         return castor;
119     }
120     
121 
122     public static Extension convert(_extension extension) {
123         Extension castor = new Extension();
124         castor.setContent(extension.getValue());
125         castor.setKey(extension.getKey());
126         return castor;
127     }
128 
129        
130     
131     public static Tool convert(org.astrogrid.workflow.beans.v1.axis._tool tool)
132     {
133        Tool result = new Tool();
134        result.setInterface(tool.get_interface());
135        result.setName(tool.getName());
136        result.setInput(convert(tool.getInput()));
137        result.setOutput(convert(tool.getOutput()));
138        return result;
139     }
140 
141    //--type convertors/////////////////////////////////////////////////////////////////////////////////////////////////////////
142     
143        /***
144     * @param _output
145     * @return
146     */
147    public static Output convert(_output _output) {
148       Output result = new Output();
149       if ( _output != null) {
150           org.astrogrid.applications.beans.v1.axis.ceaparameters.ParameterValue[] params = _output.getParameter();
151           if (params != null) { // bit more code armour          
152               for (int i = 0; i < params.length; i++) {
153                   result.addParameter(convert(params[i]));
154               }
155           }
156       }
157       return result;
158    }
159 
160    /***
161        * @param value
162        * @return
163        */
164       public static ParameterValue convert(org.astrogrid.applications.beans.v1.axis.ceaparameters.ParameterValue value) {
165          ParameterValue result = new ParameterValue();
166          result.setName(value.getName());
167          result.setEncoding(value.getEncoding().toString());         
168          result.setIndirect(value.isIndirect());
169          result.setValue(value.getValue());
170          return result;
171       }
172 
173       /***
174     * @param types
175     * @return
176     */
177       /* not needed anymore..
178    public static ParameterTypes convert(org.astrogrid.applications.beans.v1.axis.ceaparameters.ParameterTypes types) {
179       ParameterTypes result = ParameterTypes.valueOf(types.toString());
180       return result;
181    }
182    */
183 
184    /***
185     * @param _input
186     * @return
187     */
188    public static Input convert(_input _input) {
189       Input result = new Input();
190       if (_input != null) {
191           org.astrogrid.applications.beans.v1.axis.ceaparameters.ParameterValue[] params = _input.getParameter();
192           if (params != null) {
193               for (int i = 0; i < params.length; i++) {
194                   result.addParameter(convert(params[i]));
195               }
196           }
197       }
198       return result;
199    }
200 
201    /*** convert between castor and axis representations of the same schema object */
202        public static org.astrogrid.workflow.beans.v1.execution.JobURN convert(JobURN jobURN) {
203            if (jobURN == null ) {
204                return null;
205            }
206            org.astrogrid.workflow.beans.v1.execution.JobURN result = new org.astrogrid.workflow.beans.v1.execution.JobURN();
207            result.setContent(jobURN.toString());
208            return result;
209        }
210 
211     /*** convert between castor and axis representations of the same schema object */
212     public static org.astrogrid.applications.beans.v1.cea.castor.types.LogLevel convert(LogLevel level) {
213         if (level == null) {
214             return null;
215         } else {
216             return org.astrogrid.applications.beans.v1.cea.castor.types.LogLevel.valueOf(level.getValue());
217         }
218     }
219     
220     /*** rsultListType */
221     public static ResultListType convert(org.astrogrid.jes.types.v1.cea.axis.ResultListType axis) {
222         if (axis == null) {
223             return null;
224         } else {
225             ResultListType castor = new ResultListType();
226             org.astrogrid.applications.beans.v1.axis.ceaparameters.ParameterValue[] axisRs = axis.getResult();
227             ParameterValue[] castorRs = convert(axisRs);
228             castor.setResult(castorRs);
229             return castor;
230             
231         }
232     }
233 
234     public static ParameterValue[] convert(
235         org.astrogrid.applications.beans.v1.axis.ceaparameters.ParameterValue[] axisRs) {
236 		         
237         final int axisRsLength = (axisRs==null ? 0 : axisRs.length);
238         ParameterValue[] castorRs = new ParameterValue[axisRsLength];
239 		for (int i = 0; i < axisRsLength; i++){
240             castorRs[i] = convert(axisRs[i]);
241         }
242         return castorRs;
243     }
244     
245 
246     
247     /*** execution summary type */
248     public static ExecutionSummaryType convert(org.astrogrid.jes.types.v1.cea.axis.ExecutionSummaryType axis) {
249         if (axis == null) {
250             return null;
251         } else {
252             ExecutionSummaryType castor = new ExecutionSummaryType();
253             castor.setApplicationName(axis.getApplicationName());
254             castor.setExecutionId(axis.getExecutionId());
255             org.astrogrid.applications.beans.v1.axis.ceaparameters.ParameterValue[] axisArr = axis.getInputList().getInput();
256             castor.setInputList(new InputListType());
257             castor.getInputList().setInput(convert(axisArr));
258             castor.setResultList(convert(axis.getResultList())); 
259             castor.setStatus(convert(axis.getStatus()));
260             return castor;
261         }
262     }
263     
264     
265     /*** convert a workflow summary between libraries.
266      * @param type
267      * @return
268      */
269     public static org.astrogrid.workflow.beans.v1.execution.WorkflowSummaryType convert(WorkflowSummaryType type) {
270         if (type == null) {
271             return null;
272         }
273         org.astrogrid.workflow.beans.v1.execution.WorkflowSummaryType castor = new org.astrogrid.workflow.beans.v1.execution.WorkflowSummaryType();
274         if (type.getDescription() != null) {
275             castor.setDescription(type.getDescription());
276         }
277         if (type.getExtension() != null) {
278             castor.setExtension(convert(type.getExtension()));
279         }
280         castor.setFinishTime(type.getFinishTime() == null ? null : type.getFinishTime().getTime());
281         if (type.getMessage() != null) {
282             castor.setMessage(convert(type.getMessage()));
283         }
284         castor.setJobId(Axis2Castor.convert(type.getJobId()));
285         castor.setStartTime(type.getStartTime() == null ? null : type.getStartTime().getTime());
286         if (type.getStatus() != null) {                
287         castor.setStatus(Axis2Castor.convert(type.getStatus()));
288         }
289         castor.setWorkflowName(type.getWorkflowName());
290         return castor;
291     }
292 
293 
294 
295 /* doesn't seem to be needed any more
296    private static org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition convert(BaseParameterDefinition inpar)
297    {
298       org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition  result=  new org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition();
299       result.setDefaultValue(inpar.getDefaultValue());
300       result.setName(inpar.getName());
301       result.setType(convert(inpar.getType()));
302       result.setSubType(inpar.getSubType());
303       String[] encodings = inpar.getAcceptEncodings().toString().split(" "); // @todo check this 
304       result.setAcceptEncodings(encodings);      
305       result.setUCD(inpar.getUCD());
306       
307       result.setUI_Description(convert(inpar.getUI_Description()));
308       result.setUI_Name(inpar.getUI_Name());
309       result.setUnits(inpar.getUnits());
310       return result;
311    }
312 
313 
314    private static XhtmlDocumentation convert(org.astrogrid.applications.beans.v1.axis.ceaparameters.XhtmlDocumentation documentation) {
315       XhtmlDocumentation result = new XhtmlDocumentation();
316       result.setContent(documentation.getValue());
317       return result;
318    }
319    */
320 }