View Javadoc

1   /*$Id: FileApplicationRegistry.java,v 1.4 2004/11/12 18:14:43 clq2 Exp $
2    * Created on 09-Mar-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.portal.workflow.impl;
12  
13  import org.astrogrid.applications.beans.v1.ApplicationBase;
14  import org.astrogrid.applications.beans.v1.ApplicationList;
15  import org.astrogrid.applications.beans.v1.Interface;
16  import org.astrogrid.portal.workflow.intf.ApplicationDescription;
17  import org.astrogrid.portal.workflow.intf.ApplicationDescriptionSummary;
18  import org.astrogrid.portal.workflow.intf.ApplicationRegistry;
19  import org.astrogrid.portal.workflow.intf.WorkflowInterfaceException;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.exolab.castor.xml.CastorException;
24  
25  import java.io.IOException;
26  import java.io.InputStreamReader;
27  import java.io.Reader;
28  import java.net.URL;
29  import java.util.HashMap;
30  import java.util.Iterator;
31  import java.util.Map;
32  
33  /*** Implememntation of an Application Registry based on a flat xml file. 
34   * @see test-tool-list.xml for example of file.
35   * @author Noel Winstanley nw@jb.man.ac.uk 09-Mar-2004
36   *
37   */
38  public class FileApplicationRegistry implements ApplicationRegistry {
39      private static final Log log = LogFactory.getLog(FileApplicationRegistry.class);
40  
41      /*** Construct a new FileApplicationRegistry
42       */
43      public FileApplicationRegistry(URL regFile)  throws IOException, CastorException{
44          log.info("Creating File-based Application Registry, from " + regFile.toString());
45          Reader reader = new InputStreamReader(regFile.openStream());
46          ApplicationList list = ApplicationList.unmarshalApplicationList(reader);       
47          reader.close();  
48          // populate a map, so its easier to look up later..
49          map  = new HashMap();
50          ApplicationBase[] arr = list.getApplicationDefn(); // todo get this from the application list, once its been fixed
51          for (int i = 0; i < arr.length; i++) {
52              map.put(arr[i].getName(),arr[i]);
53          }  
54      }
55      protected final Map map;
56         
57      /***
58       * @see org.astrogrid.portal.workflow.intf.ApplicationRegistry#listApplications()
59       */
60      public String[] listApplications() throws WorkflowInterfaceException {
61          int size = map.keySet().size();
62          String[] result = new String[size];
63          Iterator i = map.keySet().iterator();
64          for (int ix = 0; i.hasNext(); ix++) {
65              result[ix] = i.next().toString(); // pretty sure they're strings already.
66          } 
67          return result;
68      }
69      /***
70       * @see org.astrogrid.portal.workflow.intf.ApplicationRegistry#getDescriptionFor(java.lang.String)
71       */
72      public ApplicationDescription getDescriptionFor(String applicationName)  throws WorkflowInterfaceException{
73          ApplicationBase result = (ApplicationBase)map.get(applicationName);
74          if (result == null) {
75              throw new WorkflowInterfaceException("Could not find description for " + applicationName);
76          }
77          return new ApplicationDescription(result);
78      }
79      /***
80       * @see org.astrogrid.portal.workflow.intf.ApplicationRegistry#listUIApplications()
81       */
82      public ApplicationDescriptionSummary[] listUIApplications() throws WorkflowInterfaceException {
83          int size = map.keySet().size();
84          ApplicationDescriptionSummary[]  result = new ApplicationDescriptionSummary[size];
85          Iterator i = map.entrySet().iterator();
86          for (int ix = 0; i.hasNext(); ix++) {
87              Map.Entry e = (Map.Entry)i.next();
88              ApplicationBase b = (ApplicationBase)e.getValue();
89              Interface[] intfs = b.getInterfaces().get_interface();
90              String[] interfaces = new String[intfs.length];
91              for (int j = 0; j < intfs.length; j++) {
92                  interfaces[j] =intfs[j].getName();
93              }
94              result[ix] = new ApplicationDescriptionSummary((String)e.getKey(),(String)e.getKey(),interfaces);
95          }
96          return result;
97      }
98  }
99  
100 
101 /* 
102 $Log: FileApplicationRegistry.java,v $
103 Revision 1.4  2004/11/12 18:14:43  clq2
104 nww-itn07-590b again.
105 
106 Revision 1.2.116.1  2004/11/10 13:33:32  nw
107 added new method to ApplicationRegistry - listUIApplications
108 
109 Revision 1.2  2004/03/11 13:53:36  nw
110 merged in branch bz#236 - implementation of interfaces
111 
112 Revision 1.1.2.2  2004/03/11 13:36:10  nw
113 added implementations for the workflow interfaces
114 
115 Revision 1.1.2.1  2004/03/09 17:41:59  nw
116 created a bunch of implementations,
117  
118 */