1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.http;
12
13 import java.io.IOException;
14 import java.util.Collection;
15 import java.util.Iterator;
16
17 import org.apache.commons.logging.Log;
18 import org.apache.commons.logging.LogFactory;
19 import org.astrogrid.applications.description.BaseApplicationDescriptionLibrary;
20 import org.astrogrid.applications.description.base.ApplicationDescriptionEnvironment;
21 import org.astrogrid.applications.http.registry.RegistryQuerier;
22 import org.astrogrid.component.descriptor.ComponentDescriptor;
23 import org.astrogrid.registry.beans.cea.CeaHttpApplicationType;
24
25 /***
26 * library of HttpApplication application descriptions.
27 * @author JDT
28 *
29 */
30 public class HttpApplicationDescriptionLibrary extends BaseApplicationDescriptionLibrary implements ComponentDescriptor{
31 /***
32 * Commons Logger for this class
33 */
34 private static final Log log = LogFactory.getLog(HttpApplicationDescriptionLibrary.class);
35 private RegistryQuerier querier;
36
37 /*** Construct a new HttpApplicationDescriptionLibrary, based on methods of parameter class
38 * @param querier does all the hard work of talking to the registry and getting the stuff we need to create HttpAppplicationDescriptions
39 * @throws IOException if there was a problem in the querier. Typically this will be a failure of the
40 * querier to contact the registry
41 *
42 */
43 public HttpApplicationDescriptionLibrary(RegistryQuerier querier, ApplicationDescriptionEnvironment env) throws IOException {
44 super(env);
45 if (log.isTraceEnabled()) {
46 log.trace("HttpApplicationDescriptionLibrary(RegistryQuerier querier = " + querier
47 + ", ApplicationDescriptionEnvironment env = " + env
48 + ") - start");
49 }
50
51 this.querier = querier;
52 populate();
53
54 if (log.isTraceEnabled()) {
55 log.trace("HttpApplicationDescriptionLibrary(RegistryQuerier, Community, ApplicationDescriptionEnvironment) - end");
56 }
57 }
58
59
60 /***
61 * Populate the library
62 * @throws IOException if there was a problem in the querier. Typically this will be a failure of the
63 * querier to contact the registry
64 */
65 protected final void populate() throws IOException {
66 if (log.isTraceEnabled()) {
67 log.trace("populate() - start");
68 }
69
70 final Collection apps = querier.getHttpApplications();
71 assert apps!=null;
72
73 final Iterator it = apps.iterator();
74 while (it.hasNext()) {
75 final CeaHttpApplicationType app = (CeaHttpApplicationType) it.next();
76 super.addApplicationDescription(new HttpApplicationDescription(app, env));
77 }
78
79 if (log.isTraceEnabled()) {
80 log.trace("populate() - end");
81 }
82 }
83
84 /***
85 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
86 */
87 public String getDescription() {
88 String returnString = "HttpApplication server serving applications found by RegistryQuerier" + querier + "\n"
89 + super.getDescription();
90 return returnString;
91 }
92
93 /***
94 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
95 */
96 public String getName() {
97 return "HttpApplication Library";
98 }
99
100 public String toString() {
101 StringBuffer buffer = new StringBuffer();
102 buffer.append("[HttpApplicationDescriptionLibrary:");
103 buffer.append(" logger: ");
104 buffer.append(log);
105 buffer.append(" querier: ");
106 buffer.append(querier);
107 buffer.append(super.toString());
108 buffer.append("]");
109 String returnString = buffer.toString();
110 return returnString;
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
151
152
153
154
155
156
157
158
159
160