View Javadoc

1   /*$Id: BaseApplicationDescriptionLibrary.java,v 1.15 2006/03/17 17:50:58 clq2 Exp $
2    * Created on 17-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  import org.astrogrid.applications.description.base.ApplicationDescriptionEnvironment;
13  import org.astrogrid.applications.description.exception.ApplicationDescriptionNotFoundException;
14  import org.astrogrid.component.descriptor.ComponentDescriptor;
15  
16  import org.apache.commons.logging.Log;
17  import org.apache.commons.logging.LogFactory;
18  
19  import java.util.HashMap;
20  import java.util.Iterator;
21  import java.util.Map;
22  
23  import junit.framework.Test;
24  import junit.framework.TestCase;
25  import junit.framework.TestSuite;
26  
27  /*** Basic implementation of an {@link org.astrogrid.applications.description.ApplicationDescriptionLibrary}
28   * <p />
29   * Unsurprisingly, based on a map. Provides methods to add descriptions to the library. 
30   * @author Noel Winstanley nw@jb.man.ac.uk 17-Jun-2004
31   *
32   */
33  public class BaseApplicationDescriptionLibrary implements ApplicationDescriptionLibrary, ComponentDescriptor {
34      /***
35       * Commons Logger for this class
36       */
37      private static final Log logger = LogFactory.getLog(BaseApplicationDescriptionLibrary.class);
38      
39      /***Construct a new BaseApplicationDescriptionLibrary
40      * @param env2
41      */
42     public BaseApplicationDescriptionLibrary(ApplicationDescriptionEnvironment env2) {
43        
44       this.env = env2;
45     }
46  
47     /***
48           * @see org.astrogrid.applications.description.ApplicationDescriptionLibrary#getDescription(java.lang.String)
49           */
50      public ApplicationDescription getDescription(String name) throws ApplicationDescriptionNotFoundException {
51          ApplicationDescription ad = (ApplicationDescription) descMap.get(name);
52          if (ad == null) {
53              throw new ApplicationDescriptionNotFoundException(name);
54          }
55          return ad;
56      }
57      /***
58           * @see org.astrogrid.applications.description.ApplicationDescriptionLibrary#getApplicationNames()
59           */
60      public String[] getApplicationNames() {
61      return (String[])descMap.keySet().toArray(new String[0]);
62        }
63      private final Map descMap = new HashMap();
64      
65      /*** add an application description to the library
66       * <p> if an application with the same name already exists, it will be overridden. 
67       * @param desc the application description, which will be stored under key <tt>desc.getName()</tt>*/
68      public void addApplicationDescription(ApplicationDescription desc) {
69         
70         
71          logger.info("Adding description for " + desc.getName());
72          descMap.put(desc.getName(),desc);
73      }
74      /***
75       * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
76       */
77      public String getName() {
78          return "Basic Application Description Library";
79      }
80      /***
81       * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
82       */
83      public String getDescription() {
84          return this.toString();
85      }
86       
87     public String toString() {     
88          StringBuffer appList = new StringBuffer();
89          for (Iterator i = descMap.values().iterator(); i.hasNext(); ) {
90              ApplicationDescription desc = (ApplicationDescription)i.next();
91              appList.append("\n");
92              appList.append(desc.toString());
93              appList.append("\n");
94          }
95          return "Applications in Library:'"  + appList.toString();
96      }
97      /***
98       * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
99       */
100     public Test getInstallationTest() {
101           
102           return new InstallationTest("testApplicationsDefined");
103     }
104     
105     public class InstallationTest extends TestCase {
106        
107        /***
108        * @param arg0
109        */
110       public InstallationTest(String arg0) {
111          super(arg0);
112          
113       }
114       public InstallationTest(){super();}
115       
116       public void testApplicationsDefined()
117       {
118          if(descMap.isEmpty())
119          {
120             fail("there are no applications defined in this Library");
121          }
122       }
123       
124 }
125     
126    protected final ApplicationDescriptionEnvironment env;    
127 }
128 
129 
130 /* 
131 $Log: BaseApplicationDescriptionLibrary.java,v $
132 Revision 1.15  2006/03/17 17:50:58  clq2
133 gtr_1489_cea correted version
134 
135 Revision 1.13  2006/03/07 21:45:26  clq2
136 gtr_1489_cea
137 
138 Revision 1.10.38.1  2005/12/18 14:48:24  gtr
139 Refactored to allow the component managers to pass their unit tests and the fingerprint JSP to work. See BZ1492.
140 
141 Revision 1.10  2005/07/05 08:27:02  clq2
142 paul's 559b and 559c for wo/apps and jes
143 
144 Revision 1.9.66.1  2005/06/09 08:47:33  pah
145 result of merging branch cea_pah_559b into HEAD
146 
147 Revision 1.9.52.3  2005/06/08 22:10:46  pah
148 make http applications v10 compliant
149 
150 Revision 1.9.52.2  2005/06/03 16:01:48  pah
151 first try at getting commandline execution log bz#1058
152 
153 Revision 1.9.52.1  2005/06/02 14:57:29  pah
154 merge the ProvidesVODescription interface into the MetadataService interface
155 
156 Revision 1.9  2004/12/03 15:37:05  jdt
157 restored it how it was....change PAL instead.
158 
159 Revision 1.8  2004/12/03 15:33:39  jdt
160 restored the default ctor, otherwise PAL breaks.
161 
162 Revision 1.7  2004/11/27 13:20:02  pah
163 result of merge of pah_cea_bz561 branch
164 
165 Revision 1.6.28.1  2004/11/09 09:21:16  pah
166 initial attempt to rationalise authorityID use & self registering
167 
168 Revision 1.6  2004/09/07 08:06:39  pah
169 todo added - need to remove confusion between community and authorityid
170 
171 Revision 1.5  2004/09/01 15:42:26  jdt
172 Merged in Case 3
173 
174 Revision 1.4.2.1  2004/08/09 16:36:25  jdt
175 pulled up an interface so I can use it in http apps
176 
177 Revision 1.4  2004/07/26 12:07:38  nw
178 renamed indirect package to protocol,
179 renamed classes and methods within protocol package
180 javadocs
181 
182 Revision 1.3  2004/07/26 00:57:46  nw
183 javadoc
184 
185 Revision 1.2  2004/07/01 11:16:22  nw
186 merged in branch
187 nww-itn06-componentization
188 
189 Revision 1.1.2.1  2004/07/01 01:42:46  nw
190 final version, before merge
191  
192 */