View Javadoc

1   /*$Id: JavaClassParameterAdapter.java,v 1.5 2004/07/26 12:07:38 nw Exp $
2    * Created on 08-Jun-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
9    *
10  **/
11  package org.astrogrid.applications.javaclass;
12  
13  import org.astrogrid.applications.CeaException;
14  import org.astrogrid.applications.beans.v1.parameters.ParameterValue;
15  import org.astrogrid.applications.description.ParameterDescription;
16  import org.astrogrid.applications.parameter.DefaultParameterAdapter;
17  import org.astrogrid.applications.parameter.protocol.ExternalValue;
18  
19  import org.apache.commons.beanutils.ConvertUtils;
20  
21  /*** A {@link org.astrogrid.applications.parameter.ParameterAdapter} for a {@link org.astrogrid.applications.javaclass.JavaClassParameterDescription}
22   * 
23   * <p>uses the additional information in the description to convert the parameter value from a string
24   * to an instance of the correct type for the java method parameter.
25   * @author Noel Winstanley nw@jb.man.ac.uk 08-Jun-2004
26   * @see org.apache.commons.beanutils.ConvertUtils
27   * @see org.astrogrid.applications.javaclass.JavaClassParameterDescription
28   *
29   */
30  public class JavaClassParameterAdapter extends DefaultParameterAdapter {
31  
32      /*** Construct a new JavaClassParameterAdapter
33       * @param val
34       * @param description
35       */
36      public JavaClassParameterAdapter(ParameterValue val, ParameterDescription description, ExternalValue ipVal) {
37          super(val, description,ipVal);
38      }
39  
40  /***
41   * Calls the super class implementation (which will always return a string), and then uses beanUtils library to convert to type expected by java method 
42   * @see org.astrogrid.applications.parameter.ParameterAdapter#process()
43   * @todo add handling for other types - e.g. URI / URL / Document / Node.
44   */
45      public Object process() throws CeaException {
46          String result = (String)super.process(); // we know super always returns a string.
47          Class targetClass = ((JavaClassParameterDescription)description).getTargetClass();
48          return ConvertUtils.convert(result.trim(),targetClass); //remove trailing white space, as it seems to change the conversion process. (e.g. '2/n' => 0), which isn't good.
49      }
50  
51  }
52  
53  
54  /* 
55  $Log: JavaClassParameterAdapter.java,v $
56  Revision 1.5  2004/07/26 12:07:38  nw
57  renamed indirect package to protocol,
58  renamed classes and methods within protocol package
59  javadocs
60  
61  Revision 1.4  2004/07/26 10:21:47  nw
62  javadoc
63  
64  Revision 1.3  2004/07/23 08:03:05  nw
65  fixed bug in conversion from string
66  
67  Revision 1.2  2004/07/01 11:16:22  nw
68  merged in branch
69  nww-itn06-componentization
70  
71  Revision 1.1.2.3  2004/07/01 01:42:46  nw
72  final version, before merge
73  
74  Revision 1.1.2.2  2004/06/17 09:21:23  nw
75  finished all major functionality additions to core
76  
77  Revision 1.1.2.1  2004/06/14 08:56:58  nw
78  factored applications into sub-projects,
79  got packaging of wars to work again
80   
81  */