KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > state > WorkbenchStoreVisitor


1 /*
2
3  * ianRR, is a new RR
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms at http://opensource.org/licenses/lgpl-license.php
10
11  */

12
13 package org.ejtools.jmx.browser.state;
14
15
16
17 import java.util.Iterator JavaDoc;
18
19 import org.w3c.dom.Document JavaDoc;
20
21 import org.w3c.dom.Element JavaDoc;
22
23
24
25 import org.apache.log4j.Logger;
26
27 import org.ejtools.beans.Sort;
28
29 import org.ejtools.graph.frame.GraphInternalFrame;
30
31 import org.ejtools.graph.service.GraphConsumer;
32
33 import org.ejtools.graph.service.GraphProducer;
34
35 import org.ejtools.jmx.browser.Browser;
36
37 import org.ejtools.jmx.browser.frame.ServerInternalFrame;
38
39 import org.ejtools.jmx.browser.model.Domain;
40
41 import org.ejtools.jmx.browser.model.Resource;
42
43 import org.ejtools.jmx.browser.model.Server;
44
45 import org.ejtools.util.service.Profile;
46
47 import org.ejtools.util.state.DefaultStoreVisitor;
48
49
50
51
52
53 /**
54
55  * @version $Revision: 1.2 $
56
57  * @author Laurent Etiemble
58
59  * @created 3 juin 2003
60
61  */

62
63 public class WorkbenchStoreVisitor extends DefaultStoreVisitor {
64
65    private Document JavaDoc document;
66
67    private static Logger logger = Logger.getLogger(WorkbenchStoreVisitor.class);
68
69
70
71
72
73    /**
74
75     * Constructor for the WorkbenchStoreVisitor object
76
77     *
78
79     * @param document Description of the Parameter
80
81     */

82
83    public WorkbenchStoreVisitor(Document JavaDoc document) {
84
85       this.document = document;
86
87       this.pushCurrentNode(this.document);
88
89    }
90
91
92
93
94
95    /**
96
97     * Description of the Method
98
99     *
100
101     * @param o Description of the Parameter
102
103     */

104
105    public void persist(ServerInternalFrame o) {
106
107       logger.debug("ServerInternalFrame");
108
109
110
111       Element JavaDoc eFrame = this.document.createElement("jmx-frame");
112
113       eFrame.setAttribute("title", o.getTitle());
114
115       Element JavaDoc eProfile = this.document.createElement("profile");
116
117       eFrame.appendChild(eProfile);
118
119
120
121       Profile profile = o.getProfile();
122
123       for (Iterator JavaDoc iterator = profile.keySet().iterator(); iterator.hasNext(); ) {
124
125          String JavaDoc key = (String JavaDoc) iterator.next();
126
127          Element JavaDoc property = this.document.createElement("property");
128
129          property.setAttribute("key", key);
130
131          property.appendChild(this.document.createTextNode(profile.getProperty(key)));
132
133          eProfile.appendChild(property);
134
135       }
136
137
138
139       this.peekCurrentNode().appendChild(eFrame);
140
141       this.pushCurrentNode(eFrame);
142
143       this.persist(o.iterator());
144
145       this.popCurrentNode();
146
147    }
148
149
150
151
152
153    /**
154
155     * Description of the Method
156
157     *
158
159     * @param o Description of the Parameter
160
161     */

162
163    public void persist(GraphInternalFrame o) {
164
165       logger.debug("GraphInternalFrame");
166
167
168
169       Element JavaDoc eFrame = this.document.createElement("graph-frame");
170
171       eFrame.setAttribute("name", o.getName());
172
173       eFrame.setAttribute("delay", String.valueOf(o.getDelay()));
174
175       eFrame.setAttribute("scale", String.valueOf(o.getScale()));
176
177
178
179       this.peekCurrentNode().appendChild(eFrame);
180
181       this.pushCurrentNode(eFrame);
182
183       this.persist(o.iterator());
184
185       this.popCurrentNode();
186
187    }
188
189
190
191
192
193    /**
194
195     * Description of the Method
196
197     *
198
199     * @param o Description of the Parameter
200
201     */

202
203    public void persist(Server o) {
204
205       logger.debug("Server");
206
207
208
209       Element JavaDoc server = this.document.createElement("jmx-server");
210
211       server.setAttribute("name", o.getName());
212
213       server.setAttribute("connected", "" + o.isConnected());
214
215
216
217       this.peekCurrentNode().appendChild(server);
218
219       this.pushCurrentNode(server);
220
221       this.persist(o.iterator());
222
223       this.popCurrentNode();
224
225    }
226
227
228
229
230
231    /**
232
233     * Description of the Method
234
235     *
236
237     * @param o Description of the Parameter
238
239     */

240
241    public void persist(Domain o) {
242
243       this.persist(o.iterator());
244
245    }
246
247
248
249
250
251    /**
252
253     * Description of the Method
254
255     *
256
257     * @param o Description of the Parameter
258
259     */

260
261    public void persist(Browser o) {
262
263       logger.debug("Browser");
264
265
266
267       Element JavaDoc workbench = this.document.createElement("workbench");
268
269
270
271       this.peekCurrentNode().appendChild(workbench);
272
273       this.pushCurrentNode(workbench);
274
275       this.persist(Sort.getChildrenByClass(o.iterator(), GraphInternalFrame.class));
276
277       this.persist(Sort.getChildrenByClass(o.iterator(), ServerInternalFrame.class));
278
279       this.popCurrentNode();
280
281    }
282
283
284
285
286
287    /**
288
289     * Description of the Method
290
291     *
292
293     * @param o Description of the Parameter
294
295     */

296
297    public void persist(Resource o) {
298
299       try {
300
301          int g = o.getGraphProducers().size();
302
303          boolean notif = o.isRegisteredForNotifications();
304
305
306
307          if ((g > 0) || notif) {
308
309             Element JavaDoc resource = this.document.createElement("jmx-resource");
310
311             resource.setAttribute("objectName", o.getCanonicalName());
312
313
314
315             if (notif) {
316
317                resource.setAttribute("listen", "true");
318
319             }
320
321             if (g > 0) {
322
323                GraphConsumer[] consumers = o.getGraphConsumers();
324
325
326
327                for (Iterator JavaDoc iterator = o.getGraphProducers().keySet().iterator(); iterator.hasNext(); ) {
328
329                   String JavaDoc attribute = (String JavaDoc) iterator.next();
330
331                   GraphProducer producer = (GraphProducer) o.getGraphProducers().get(attribute);
332
333
334
335                   GraphConsumer consumer = null;
336
337                   for (int i = 0; i < consumers.length; i++) {
338
339                      GraphConsumer gc = consumers[i];
340
341                      if (gc.containsGraphProducer(producer)) {
342
343                         consumer = gc;
344
345                      }
346
347                   }
348
349                   if (consumer != null) {
350
351                      Element JavaDoc graph = this.document.createElement("jmx-graph");
352
353                      graph.setAttribute("attribute", attribute);
354
355                      graph.setAttribute("target", consumer.toString());
356
357                      resource.appendChild(graph);
358
359                   }
360
361                   //else
362

363                   //{
364

365                   // logger.warn("A graph producer is not linked to a graph consumer !!!");
366

367                   //}
368

369                }
370
371             }
372
373             this.peekCurrentNode().appendChild(resource);
374
375             this.pushCurrentNode(resource);
376
377             this.persist(o.iterator());
378
379             this.popCurrentNode();
380
381          }
382
383       } catch (Exception JavaDoc e) {
384
385          e.printStackTrace();
386
387       }
388
389    }
390
391 }
392
393
Popular Tags