View Javadoc

1   /*$Id: DescriptionUtils.java,v 1.7 2004/09/22 10:52:50 pah 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.description;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  import org.astrogrid.applications.beans.v1.ApplicationBase;
16  import org.astrogrid.applications.beans.v1.Input;
17  import org.astrogrid.applications.beans.v1.Interface;
18  import org.astrogrid.applications.beans.v1.InterfacesType;
19  import org.astrogrid.applications.beans.v1.Output;
20  import org.astrogrid.applications.beans.v1.ParameterRef;
21  import org.astrogrid.applications.beans.v1.parameters.BaseParameterDefinition;
22  import org.astrogrid.applications.beans.v1.parameters.XhtmlDocumentation;
23  import org.astrogrid.applications.description.exception.ParameterNotInInterfaceException;
24  
25  /*** Class of static helper methods for working wih descriptions.
26   * @author Noel Winstanley nw@jb.man.ac.uk 08-Jun-2004
27   * 
28   *
29   */
30  public class DescriptionUtils {
31      /***
32       * Commons Logger for this class
33       */
34      private static final Log logger = LogFactory.getLog(DescriptionUtils.class);
35  
36      /*** Construct a new DescriptionUtils
37       * 
38       */
39      private DescriptionUtils() {
40          super();
41      }
42      /*** maps between internal type ({@link ApplicationDescription}) and castor object type used in registry schema ({@link ApplicationBase})
43       * <p/>
44       * These types are structurally very similar - just differ on type names.
45     * @param descr
46     * @return
47     */
48    public static ApplicationBase applicationDescription2ApplicationBase(ApplicationDescription descr) {
49        ApplicationBase base = new ApplicationBase();
50        base.setName(descr.getName());
51        // interface.
52        ApplicationInterface[] ifaces = descr.getInterfaces();
53        InterfacesType interfacesType = new InterfacesType();
54        base.setInterfaces(interfacesType);
55        for (int i = 0; i < ifaces.length; i++) {
56            Interface iface = new Interface();
57            ApplicationInterface appIface = ifaces[i];
58            iface.setName(appIface.getName());
59            Input input = new Input();
60            Output output = new Output();
61            iface.setInput(input);
62            iface.setOutput(output);
63            String[] inputRefs = appIface.getArrayofInputs();
64            for (int j = 0; j < inputRefs.length; j++) {
65                ParameterRef pref = new ParameterRef();
66                pref.setRef(inputRefs[j]);
67                try {
68                    Cardinality c = appIface.getParameterCardinality(inputRefs[j]);
69                    pref.setMaxoccurs(c.getMaxOccurs());
70                    pref.setMinoccurs(c.getMinOccurs());
71                } catch (ParameterNotInInterfaceException e) {
72                    // minor problem. not worth halting for.
73                    logger.warn("Problem with representation of " + inputRefs[j],e);
74                }
75                input.addPref(pref);
76            }
77            String[] outputRefs = appIface.getArrayofOutputs();
78            for (int j = 0; j < outputRefs.length; j++) {
79                ParameterRef pref = new ParameterRef();
80                pref.setRef(outputRefs[j]);
81                try {
82                    Cardinality c = appIface.getParameterCardinality(outputRefs[j]);
83                    pref.setMaxoccurs(c.getMaxOccurs());
84                    pref.setMinoccurs(c.getMinOccurs());
85                } catch (ParameterNotInInterfaceException e) {
86                    // minor problem. not worth halting for.
87                    logger.warn("Problem with representation of " + outputRefs[j],e);
88                }
89                output.addPref(pref);
90            }        
91            interfacesType.add_interface(iface);
92        }
93        // now parameters.
94        ParameterDescription[] params = descr.getParameterDescriptions();
95        org.astrogrid.applications.beans.v1.Parameters parameters = new org.astrogrid.applications.beans.v1.Parameters();
96        base.setParameters(parameters);
97        for (int i = 0; i < params.length; i++) {
98            BaseParameterDefinition paramDef = new BaseParameterDefinition();
99            ParameterDescription paramDesc = params[i];
100           XhtmlDocumentation xhtmldoc = new XhtmlDocumentation();
101           xhtmldoc.setContent(paramDesc.getDisplayDescription());
102           paramDef.setUI_Description( xhtmldoc); 
103           paramDef.setUI_Name(  paramDesc.getDisplayName());
104           paramDef.setName(  paramDesc.getName());
105           paramDef.setUCD( paramDesc.getUcd());
106           paramDef.setType(paramDesc.getType());
107           paramDef.setSubType(paramDesc.getSubType());
108           paramDef.setDefaultValue(paramDesc.getDefaultValue());
109           paramDef.setUnits(paramDesc.getUnits());
110           paramDef.setAcceptEncodings(paramDesc.getAcceptEncodings());
111          parameters.addParameter(paramDef);
112       }
113     
114       // blerght. glad that's over
115       return base;
116     
117   }    
118 }
119 
120 
121 /* 
122 $Log: DescriptionUtils.java,v $
123 Revision 1.7  2004/09/22 10:52:50  pah
124 getting rid of some unused imports
125 
126 Revision 1.6  2004/09/09 13:21:09  pah
127 schema change
128 
129 Revision 1.5  2004/08/17 15:08:26  nw
130 fixed but I introduced previously.
131 
132 Revision 1.4  2004/08/16 11:03:07  nw
133 added classes to model cardinality of prefs.
134 
135 Revision 1.3  2004/07/26 00:57:46  nw
136 javadoc
137 
138 Revision 1.2  2004/07/01 11:16:22  nw
139 merged in branch
140 nww-itn06-componentization
141 
142 Revision 1.1.2.3  2004/07/01 01:42:46  nw
143 final version, before merge
144 
145 Revision 1.1.2.2  2004/06/17 09:21:23  nw
146 finished all major functionality additions to core
147 
148 Revision 1.1.2.1  2004/06/14 08:56:58  nw
149 factored applications into sub-projects,
150 got packaging of wars to work again
151  
152 */