View Javadoc

1   /*$Id: HttpApplicationDescription.java,v 1.6 2004/12/18 15:43:57 jdt Exp $
2    * Created on Jul 24, 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.http;
12  
13  import java.util.Enumeration;
14  
15  import org.apache.commons.logging.Log;
16  import org.apache.commons.logging.LogFactory;
17  import org.astrogrid.applications.Application;
18  import org.astrogrid.applications.DefaultIDs;
19  import org.astrogrid.applications.beans.v1.Interface;
20  import org.astrogrid.applications.beans.v1.InterfacesType;
21  import org.astrogrid.applications.beans.v1.ParameterRef;
22  import org.astrogrid.applications.beans.v1.parameters.types.ParameterTypes;
23  import org.astrogrid.applications.description.ApplicationInterface;
24  import org.astrogrid.applications.description.base.AbstractApplicationDescription;
25  import org.astrogrid.applications.description.base.ApplicationDescriptionEnvironment;
26  import org.astrogrid.applications.description.base.BaseApplicationInterface;
27  import org.astrogrid.applications.description.base.BaseParameterDescription;
28  import org.astrogrid.applications.description.exception.ParameterDescriptionNotFoundException;
29  import org.astrogrid.community.User;
30  import org.astrogrid.registry.beans.cea.ApplicationDefinition;
31  import org.astrogrid.registry.beans.cea.CeaHttpApplicationType;
32  import org.astrogrid.workflow.beans.v1.Tool;
33  
34  /***
35   * application description for an HttpApplication
36   * 
37   * @author jdt
38   *  
39   */
40  public class HttpApplicationDescription extends AbstractApplicationDescription {
41  
42      Log log = LogFactory.getLog(HttpApplicationDescription.class);
43  
44      /***
45       * Constructor
46       */
47      public HttpApplicationDescription(CeaHttpApplicationType application, 
48              final ApplicationDescriptionEnvironment env) {
49          super(env);
50          if (log.isTraceEnabled()) {
51              log.trace("HttpApplicationDescription(CeaHttpApplicationType application = " + application
52                      + ", String communityName = " + env.getAuthIDResolver().getAuthorityID() + ", ApplicationDescriptionEnvironment env = " + env
53                      + ") - start");
54          }
55  
56          this.application = application;
57          createMetadata(env.getAuthIDResolver().getAuthorityID());
58  
59          if (log.isTraceEnabled()) {
60              log.trace("HttpApplicationDescription(WebHttpApplication, String, ApplicationDescriptionEnvironment) - end");
61          }
62      }
63  
64      protected final CeaHttpApplicationType application;
65  
66      /***
67       * populates this object with parameterDescriptions by reflecting on
68       * application method
69       * 
70       * @TODO - currently assumes a single interface....change this
71       */
72      protected final void createMetadata(String communityName) {
73          if (log.isTraceEnabled()) {
74              log.trace("createMetadata(String communityName = " + communityName + ") - start");
75          }
76  
77          setName(communityName + "/" + application.getIdentifier().getResourceKey());
78          log.debug("Name: " + getName());
79  
80          final ApplicationDefinition applicationDefinition = application.getApplicationDefinition();
81  
82          InterfacesType interfaces = applicationDefinition.getInterfaces();
83          log.debug("Found " + interfaces.get_interfaceCount() + " interfaces for this application");
84  
85          Enumeration enumerator = interfaces.enumerate_interface();
86          while (enumerator.hasMoreElements()) {
87              Interface oneInterface = (Interface) enumerator.nextElement();
88  
89              BaseApplicationInterface singleInterface = new BaseApplicationInterface(oneInterface.getName(), this);
90              
91              //For each interface set up inputs
92              ParameterRef[] inputs = oneInterface.getInput().getPref();
93              class ConstructableBaseParameterDescription extends BaseParameterDescription {
94                   public ConstructableBaseParameterDescription(ParameterRef param) {
95                    setName(param.getRef());
96                    //  They'll all be Strings for http apps, but this should really be done properly
97                    setType(ParameterTypes.TEXT);
98                }
99              };
100             for (int i = 0; i < inputs.length; i++) {
101                 ParameterRef input = inputs[i];
102                 BaseParameterDescription param = new ConstructableBaseParameterDescription(input);
103                 this.addParameterDescription(param);
104                 try {
105                     singleInterface.addInputParameter(param.getName());
106                 } catch (ParameterDescriptionNotFoundException e) {
107                     // impossible.
108                     log.error("createMetadata(String)", e);
109                     assert false : "we'll see about that";
110                 }
111             }
112             
113             //and the same for outputs
114             ParameterRef[] outputs = oneInterface.getOutput().getPref();
115 
116             log.debug("createMetadata() - Found  " + outputs.length+" output parameters");
117             assert outputs.length == 1 :"http apps can only really have one output"; //possibly not true if we allow post processing
118 
119             ParameterRef output = outputs[0];
120             BaseParameterDescription result = new ConstructableBaseParameterDescription(output);
121             this.addParameterDescription(result);
122             try {
123                 singleInterface.addOutputParameter(result.getName());
124             } catch (ParameterDescriptionNotFoundException e) {
125                 // can't happen.
126                 log.error("createMetadata(String)", e);
127                 assert false : "never say never";
128             }
129             // add parameters to interface.
130             this.addInterface(singleInterface);
131         }
132 
133         if (log.isTraceEnabled()) {
134             log.trace("createMetadata(String) - end");
135         }
136     }
137 
138     /***
139      * @see org.astrogrid.applications.description.ApplicationDescription#initializeApplication(java.lang.String,
140      *      org.astrogrid.community.User, org.astrogrid.workflow.beans.v1.Tool)
141      */
142     public Application initializeApplication(String jobStepID, User user, Tool tool) throws Exception {
143         if (log.isTraceEnabled()) {
144             log.trace("initializeApplication(String jobStepID = " + jobStepID + ", User user = " + user
145                     + ", Tool tool = " + tool + ") - start");
146         }
147 
148         String newID = env.getIdGen().getNewID();
149         final DefaultIDs ids = new DefaultIDs(jobStepID, newID, user);
150         
151         ApplicationInterface appInterface = this.getInterface(tool.getInterface());
152         if (appInterface == null) { // go for default then..
153             appInterface = this.getInterfaces()[0];
154             log.debug("Interface not found - using default");
155         }
156         log.debug("Using interface "+appInterface);
157         
158         Application returnApplication = new HttpApplication(ids, tool, appInterface, env.getProtocolLib());
159         
160         
161         if (log.isTraceEnabled()) {
162             log.trace("initializeApplication(String, User, Tool) - end - return value = " + returnApplication);
163         }
164         return returnApplication;
165     }
166 
167     /***
168      * Return the URL of this Webapp.
169      * 
170      * @return
171      */
172     public String getUrl() {
173         return application.getCeaHttpAdapterSetup().getURL().getContent();
174     }
175 
176     /***
177      * Get the underlying description as returned by the registry
178      * 
179      * @TODO think about the overlap between HttpApplicationDescription and
180      *       WebHttpApplication
181      * @return Returns the application.
182      */
183     public CeaHttpApplicationType getApplication() {
184         return application;
185     }
186 }
187 
188 /*
189  * $Log: HttpApplicationDescription.java,v $
190  * Revision 1.6  2004/12/18 15:43:57  jdt
191  * merge from  cea_pah_561b
192  *
193  * Revision 1.5.48.1  2004/12/07 07:32:27  pah
194  * update to pass band information properly
195  *
196  * Revision 1.5  2004/09/01 15:42:26  jdt
197  * Merged in Case 3
198  *
199  * Revision 1.1.4.11  2004/08/11 22:55:35  jdt
200  * Refactoring, and a lot of new unit tests.
201  *
202  * Revision 1.1.4.10  2004/08/10 13:44:23  jdt
203  * Following new workflow-object types...and a safety checkin.
204  *
205  * Revision 1.1.4.9  2004/08/09 16:37:13  jdt
206  * Brought into line following pah's suggested schema changes
207  * Revision 1.1.4.8 2004/08/06
208  * 13:30:22 jdt safety checkin
209  * 
210  * Revision 1.1.4.7 2004/08/02 18:05:28 jdt Added more tests and refactored the
211  * test apps to be set up from xml.
212  * 
213  * Revision 1.1.4.6 2004/07/30 16:59:50 jdt limping along.
214  * 
215  * Revision 1.1.4.5 2004/07/30 11:02:30 jdt Added unit tests, refactored the
216  * RegistryQuerier anf finished off HttpApplicationCEAComponentManager.
217  * 
218  * Revision 1.1.4.4 2004/07/29 21:30:47 jdt ** empty log message ***
219  * 
220  * Revision 1.1.4.3 2004/07/29 17:08:22 jdt Think about how I'm going to get
221  * stuff out of the registry
222  * 
223  * Revision 1.1.4.2 2004/07/29 16:35:21 jdt Safety checkin, while I think about
224  * what happens next.
225  * 
226  * Revision 1.1.4.1 2004/07/27 17:20:25 jdt merged from applications_JDT_case3
227  * 
228  * Revision 1.1.2.1 2004/07/24 17:16:16 jdt Borrowed from javaclass
229  * application....stealing is always quicker.
230  * 
231  * 
232  *  
233  */