1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.astrogrid.common.bean;
15
16 import java.util.Calendar;
17
18 import org.apache.axis.types.NMToken;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.astrogrid.applications.beans.v1.axis.ceaparameters.ParameterValue;
22 import org.astrogrid.applications.beans.v1.cea.castor.MessageType;
23 import org.astrogrid.jes.beans.v1.axis.executionrecord.JobURN;
24 import org.astrogrid.jes.beans.v1.axis.executionrecord._extension;
25 import org.astrogrid.jes.types.v1.cea.axis.ExecutionPhase;
26 import org.astrogrid.jes.types.v1.cea.axis.ExecutionSummaryType;
27 import org.astrogrid.jes.types.v1.cea.axis.InputListType;
28 import org.astrogrid.jes.types.v1.cea.axis.ResultListType;
29 import org.astrogrid.workflow.beans.v1.Input;
30 import org.astrogrid.workflow.beans.v1.Output;
31 import org.astrogrid.workflow.beans.v1.Tool;
32 import org.astrogrid.workflow.beans.v1.axis._input;
33 import org.astrogrid.workflow.beans.v1.axis._output;
34 import org.astrogrid.workflow.beans.v1.axis._tool;
35 import org.astrogrid.workflow.beans.v1.execution.Extension;
36
37 /***
38 * Static methods to convert Castor to Axis objects.
39 * @author Paul Harrison (pah@jb.man.ac.uk) 11-Mar-2004
40 * @version $Name: $
41 * @since iteration5
42 * @TODO - this is rather fragile to changes in the schema - would be better perhaps to use castor serialization in axis directly...or get the axis object marshalling - anything please!!!
43 */
44 public class Castor2Axis {
45 static public org.apache.commons.logging.Log logger =
46 org.apache.commons.logging.LogFactory.getLog(Castor2Axis.class);
47
48 /***
49 *
50 */
51 public Castor2Axis() {
52 }
53
54 public static _tool convert(Tool ctool) {
55 _tool result = new _tool();
56 result.set_interface(ctool.getInterface());
57 result.setName(ctool.getName());
58 result.setInput(convert(ctool.getInput()));
59 result.setOutput(convert(ctool.getOutput()));
60
61 return result;
62 }
63 /*** convert between castor and axis representations of the same schema object */
64 public static JobURN convert(org.astrogrid.workflow.beans.v1.execution.JobURN jobURN) {
65 if (jobURN == null) {
66 return null;
67 }
68 return new JobURN(jobURN.getContent());
69 }
70 /***
71 * @param output
72 * @return
73 */
74 public static _output convert(Output output) {
75
76 org.astrogrid.applications.beans.v1.parameters.ParameterValue[] inpars = output.getParameter();
77 _output result = new _output();
78 result.setParameter(transformParameters(inpars));
79 return result;
80 }
81
82 /***
83 * @param input
84 * @return
85 */
86 public static _input convert(Input input) {
87 _input result = new _input();
88 org.astrogrid.applications.beans.v1.parameters.ParameterValue[] inpars = input.getParameter();
89 result.setParameter(transformParameters(inpars));
90 return result;
91 }
92
93 public static ParameterValue[] transformParameters(org.astrogrid.applications.beans.v1.parameters.ParameterValue[] inpars)
94 {
95 ParameterValue[] result = new ParameterValue[inpars.length];
96
97 for (int i = 0; i < inpars.length; i++) {
98
99 result[i] = convert(inpars[i]);
100 }
101
102 return result;
103 }
104
105 public static ParameterValue convert(org.astrogrid.applications.beans.v1.parameters.ParameterValue parameterValue)
106 {
107 ParameterValue result = new ParameterValue();
108 result.setName(parameterValue.getName());
109 if (parameterValue.getEncoding() != null) {
110 result.setEncoding(new NMToken(parameterValue.getEncoding()));
111 } else {
112 result.setEncoding(new NMToken());
113 }
114 result.setIndirect(parameterValue.getIndirect());
115 result.setValue(parameterValue.getValue());
116
117 return result;
118 }
119
120 /***
121 * @param types
122 * @return
123 */
124
125
126
127
128
129
130
131
132
133
134
135
136 /***
137 * @param definitions
138 * @return
139 */
140
141
142
143
144
145
146
147
148
149
150 /***
151 * @param definition
152 * @return
153 */
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179 /***
180 * convert between the documentation elements. This is very messy just to get between two "any" elements!
181 * @param documentation
182 * @return
183 * @TODO FIXME this really needs a better implementation - it does not work - do not really understand how castor/axis deal with any - the schema has been converted to a type derived from string for now to make things easier...
184 *
185 */
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 /***
216 * @param mess
217 * @return
218 */
219 public static org.astrogrid.jes.types.v1.cea.axis.MessageType convert(MessageType mess) {
220 org.astrogrid.jes.types.v1.cea.axis.MessageType result = new org.astrogrid.jes.types.v1.cea.axis.MessageType();
221 result.setContent(mess.getContent());
222 result.setLevel(convert(mess.getLevel()));
223 result.setPhase(convert(mess.getPhase()));
224 result.setSource(mess.getSource());
225 Calendar cal = Calendar.getInstance();
226 cal.setTime(mess.getTimestamp());
227 result.setTimestamp(cal);
228 return result;
229 }
230
231 public static org.astrogrid.jes.types.v1.cea.axis.MessageType[] convert(MessageType[] mess) {
232 org.astrogrid.jes.types.v1.cea.axis.MessageType[] axis = new org.astrogrid.jes.types.v1.cea.axis.MessageType[mess.length];
233 for (int i = 0; i < mess.length; i++) {
234 axis[i] = convert(mess[i]);
235 }
236 return axis;
237 }
238
239 public static _extension convert(Extension ext) {
240 _extension axis = new _extension();
241 axis.setKey(ext.getKey());
242 axis.setValue(ext.getContent());
243 return axis;
244 }
245
246 public static _extension[] convert(Extension[] ext) {
247 _extension[] axis = new _extension[ext.length];
248 for ( int i = 0; i < ext.length; i++) {
249 axis[i] = convert(ext[i]);
250 }
251 return axis;
252 }
253
254 public static ExecutionPhase convert(org.astrogrid.applications.beans.v1.cea.castor.types.ExecutionPhase ep)
255 {
256 ExecutionPhase result = ExecutionPhase.fromValue(ep.toString());
257 return result;
258 }
259
260
261 public static org.astrogrid.jes.types.v1.cea.axis.LogLevel convert(org.astrogrid.applications.beans.v1.cea.castor.types.LogLevel ll)
262 {
263 return org.astrogrid.jes.types.v1.cea.axis.LogLevel.fromString(ll.toString());
264 }
265
266 public static ExecutionSummaryType convert(org.astrogrid.applications.beans.v1.cea.castor.ExecutionSummaryType castor) {
267 ExecutionSummaryType axis = new ExecutionSummaryType();
268 axis.setApplicationName(castor.getApplicationName());
269 axis.setExecutionId(castor.getExecutionId());
270 axis.setResultList(convert(castor.getResultList()));
271 axis.setInputList(new InputListType());
272 axis.getInputList().setInput(convert(castor.getInputList().getInput()));
273 axis.setStatus(convert(castor.getStatus()));
274 return axis;
275 }
276
277 public static ResultListType convert(org.astrogrid.applications.beans.v1.cea.castor.ResultListType castor) {
278 ResultListType axis = new ResultListType();
279 axis.setResult(convert(castor.getResult()));
280 return axis;
281 }
282
283 public static ParameterValue[] convert(org.astrogrid.applications.beans.v1.parameters.ParameterValue[] castor) {
284 ParameterValue[] axis = new ParameterValue[castor.length];
285 for (int i = 0; i < axis.length; i++) {
286 axis[i] = convert(castor[i]);
287 }
288 return axis;
289 }
290
291
292 }