1
2
3
4
5
6
7
8
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192