KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3  * EJTools, the Enterprise Java Tools
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms of license at www.gnu.org.
10
11  */

12
13 package org.ejtools.jmx.browser.state;
14
15
16
17 import java.beans.beancontext.BeanContext JavaDoc;
18
19 import java.io.File JavaDoc;
20
21 import java.net.URL JavaDoc;
22
23
24
25 import javax.xml.parsers.DocumentBuilder JavaDoc;
26
27 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
28
29 import javax.xml.parsers.SAXParser JavaDoc;
30
31 import javax.xml.parsers.SAXParserFactory JavaDoc;
32
33 import javax.xml.transform.Result JavaDoc;
34
35 import javax.xml.transform.Source JavaDoc;
36
37 import javax.xml.transform.Transformer JavaDoc;
38
39 import javax.xml.transform.TransformerFactory JavaDoc;
40
41 import javax.xml.transform.dom.DOMSource JavaDoc;
42
43 import javax.xml.transform.stream.StreamResult JavaDoc;
44
45
46
47 import org.ejtools.graph.frame.GraphInternalFrame;
48
49 import org.ejtools.jmx.browser.Browser;
50
51 import org.ejtools.jmx.browser.frame.ServerInternalFrame;
52
53 import org.ejtools.jmx.browser.model.Domain;
54
55 import org.ejtools.jmx.browser.model.Resource;
56
57 import org.ejtools.jmx.browser.model.Server;
58
59 import org.ejtools.jmx.browser.state.rules.GraphInternalFrameRule;
60
61 import org.ejtools.jmx.browser.state.rules.ResourceGraphRule;
62
63 import org.ejtools.jmx.browser.state.rules.ResourceRule;
64
65 import org.ejtools.jmx.browser.state.rules.ServerInternalFrameRule;
66
67 import org.ejtools.jmx.browser.state.rules.ServerRule;
68
69 import org.ejtools.util.service.ProfileRule;
70
71 import org.ejtools.util.state.LoadHandler;
72
73 import org.ejtools.util.state.StoreVisitor;
74
75 import org.w3c.dom.Document JavaDoc;
76
77
78
79
80
81 /**
82
83  * @author Laurent Etiemble
84
85  * @created 3 juin 2003
86
87  * @version $Revision: 1.2 $
88
89  */

90
91 public class WorkbenchState
92
93 {
94
95    /** Description of the Field */
96
97    private BeanContext JavaDoc context;
98
99    /** Description of the Field */
100
101    private Document JavaDoc document;
102
103    /** Description of the Field */
104
105    private URL JavaDoc workbenchURL;
106
107
108
109
110
111    /**
112
113     *Constructor for the FilePersistenceStore object
114
115     *
116
117     * @param context Description of the Parameter
118
119     */

120
121    public WorkbenchState(BeanContext JavaDoc context)
122
123    {
124
125       this.context = context;
126
127    }
128
129
130
131
132
133    /**
134
135     * Gets the workbenchFile attribute of the WorkbenchStore object
136
137     *
138
139     * @return The workbenchFile value
140
141     */

142
143    public URL JavaDoc getWorkbenchURL()
144
145    {
146
147       return this.workbenchURL;
148
149    }
150
151
152
153
154
155    /** Description of the Method */
156
157    public void load()
158
159    {
160
161       // Check that the URL is not null andthat URL is a file
162

163       if ((this.workbenchURL == null) && (!this.workbenchURL.getProtocol().equals("file")))
164
165       {
166
167          return;
168
169       }
170
171
172
173       try
174
175       {
176
177          LoadHandler handler = new LoadHandler();
178
179          handler.getContext().put("CONTAINER", this.context);
180
181
182
183          handler.addRule("/workbench/graph-frame", new GraphInternalFrameRule());
184
185          handler.addRule("/workbench/jmx-frame", new ServerInternalFrameRule());
186
187          handler.addRule("/workbench/jmx-frame/profile", new ProfileRule());
188
189          handler.addRule("/workbench/jmx-frame/profile/property", new ProfileRule.ProfilePropertyRule());
190
191          handler.addRule("/workbench/jmx-frame/jmx-server", new ServerRule());
192
193          handler.addRule("/workbench/jmx-frame/jmx-server/jmx-resource", new ResourceRule());
194
195          handler.addRule("/workbench/jmx-frame/jmx-server/jmx-resource/jmx-graph", new ResourceGraphRule());
196
197
198
199          SAXParserFactory JavaDoc factory = SAXParserFactory.newInstance();
200
201          SAXParser JavaDoc parser = factory.newSAXParser();
202
203          File JavaDoc file = new File JavaDoc(this.workbenchURL.getFile());
204
205          parser.parse(file, handler);
206
207       }
208
209       catch (Exception JavaDoc e)
210
211       {
212
213          e.printStackTrace();
214
215       }
216
217    }
218
219
220
221
222
223    /**
224
225     * Sets the workbenchFile attribute of the WorkbenchStore object
226
227     *
228
229     * @param workbenchURL The new workbenchURL value
230
231     */

232
233    public void setWorkbenchURL(URL JavaDoc workbenchURL)
234
235    {
236
237       this.workbenchURL = workbenchURL;
238
239    }
240
241
242
243
244
245    /** Description of the Method */
246
247    public void store()
248
249    {
250
251       // Check that the URL is not null andthat URL is a file
252

253       if ((this.workbenchURL == null) && (!this.workbenchURL.getProtocol().equals("file")))
254
255       {
256
257          return;
258
259       }
260
261
262
263       try
264
265       {
266
267          DocumentBuilderFactory JavaDoc dbFactory = DocumentBuilderFactory.newInstance();
268
269          DocumentBuilder JavaDoc builder = dbFactory.newDocumentBuilder();
270
271          this.document = builder.newDocument();
272
273
274
275          StoreVisitor visitor = new WorkbenchStoreVisitor(this.document);
276
277          visitor.registerForPersistence(Browser.class);
278
279          visitor.registerForPersistence(ServerInternalFrame.class);
280
281          visitor.registerForPersistence(GraphInternalFrame.class);
282
283          visitor.registerForPersistence(Server.class);
284
285          visitor.registerForPersistence(Domain.class);
286
287          visitor.registerForPersistence(Resource.class);
288
289          visitor.persist(this.context);
290
291
292
293          TransformerFactory JavaDoc tFactory = TransformerFactory.newInstance();
294
295          Transformer JavaDoc transformer = tFactory.newTransformer();
296
297          transformer.setOutputProperty("indent", "true");
298
299
300
301          Source JavaDoc source = new DOMSource JavaDoc(this.document);
302
303          File JavaDoc file = new File JavaDoc(this.workbenchURL.getFile());
304
305          Result JavaDoc result = new StreamResult JavaDoc(file);
306
307          transformer.transform(source, result);
308
309       }
310
311       catch (Exception JavaDoc e)
312
313       {
314
315          e.printStackTrace();
316
317       }
318
319    }
320
321 }
322
323
Popular Tags