1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.description;
12
13 import org.astrogrid.applications.description.base.ApplicationDescriptionEnvironment;
14 import org.astrogrid.applications.description.exception.ApplicationDescriptionNotFoundException;
15 import org.astrogrid.component.descriptor.ComponentDescriptor;
16
17 import org.apache.commons.logging.Log;
18 import org.apache.commons.logging.LogFactory;
19
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.Map;
23
24 import junit.framework.Test;
25
26 /*** Basic implementation of an {@link org.astrogrid.applications.description.ApplicationDescriptionLibrary}
27 * <p />
28 * Unsurprisingly, based on a map. Provides methods to add descriptions to the library.
29 * @author Noel Winstanley nw@jb.man.ac.uk 17-Jun-2004
30 *
31 */
32 public class BaseApplicationDescriptionLibrary implements ApplicationDescriptionLibrary, ComponentDescriptor {
33 /***
34 * Commons Logger for this class
35 */
36 private static final Log logger = LogFactory.getLog(BaseApplicationDescriptionLibrary.class);
37
38 /*** configuration interface - defines the name of the authority the applications will be added to.
39 * @TODO - this should probably not be here - there is of course a tie in with the @see org.astrogrid.applications.manager.MetadataService and @see org.astrogrid.applications.component.ProvidesVODescription - they all need refactoring slightly to make clear which has overall control, when the exact interaction with the registry is determined - what protocol is to be used to detemine the authorityid that will be allowed?*/
40
41 public interface AppAuthorityIDResolver {
42 String getAuthorityID();
43 }
44
45
46 /***Construct a new BaseApplicationDescriptionLibrary
47 * @param env2
48 */
49 public BaseApplicationDescriptionLibrary(ApplicationDescriptionEnvironment env2) {
50
51 this.env = env2;
52 }
53
54 /***
55 * @see org.astrogrid.applications.description.ApplicationDescriptionLibrary#getDescription(java.lang.String)
56 */
57 public ApplicationDescription getDescription(String name) throws ApplicationDescriptionNotFoundException {
58 ApplicationDescription ad = (ApplicationDescription) descMap.get(name);
59 if (ad == null) {
60 throw new ApplicationDescriptionNotFoundException(name);
61 }
62 return ad;
63 }
64 /***
65 * @see org.astrogrid.applications.description.ApplicationDescriptionLibrary#getApplicationNames()
66 */
67 public String[] getApplicationNames() {
68 return (String[])descMap.keySet().toArray(new String[0]);
69 }
70 private final Map descMap = new HashMap();
71
72 /*** add an application description to the library
73 * <p> if an application with the same name already exists, it will be overridden.
74 * @param desc the application description, which will be stored under key <tt>desc.getName()</tt>*/
75 public void addApplicationDescription(ApplicationDescription desc) {
76 logger.info("Adding description for " + desc.getName());
77 descMap.put(desc.getName(),desc);
78 }
79 /***
80 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
81 */
82 public String getName() {
83 return "Basic Application Description Library";
84 }
85 /***
86 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
87 */
88 public String getDescription() {
89 return this.toString();
90 }
91
92 public String toString() {
93 StringBuffer appList = new StringBuffer();
94 for (Iterator i = descMap.values().iterator(); i.hasNext(); ) {
95 ApplicationDescription desc = (ApplicationDescription)i.next();
96 appList.append("\n");
97 appList.append(desc.toString());
98 appList.append("\n");
99 }
100 return "Applications in Library:'" + appList.toString();
101 }
102 /***
103 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
104 */
105 public Test getInstallationTest() {
106 return null;
107 }
108 protected final ApplicationDescriptionEnvironment env;
109 }
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150