KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > monitor > data > MonitorData


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.monitor.data;
21
22 import org.w3c.dom.*;
23 import org.xml.sax.InputSource JavaDoc;
24 import org.netbeans.modules.schema2beans.*;
25 import java.beans.*;
26 import java.util.*;
27 import java.io.*;
28
29 public class MonitorData extends BaseBean implements DataRecord {
30
31     private final static boolean debug = false;
32
33     static Vector comparators = new Vector();
34
35     static public final String JavaDoc CLIENTDATA = "ClientData"; // NOI18N
36
static public final String JavaDoc SESSIONDATA = "SessionData"; // NOI18N
37
static public final String JavaDoc COOKIESDATA = "CookiesData"; // NOI18N
38
static public final String JavaDoc REQUESTDATA = "RequestData"; // NOI18N
39
static public final String JavaDoc SERVLETDATA = "ServletData"; // NOI18N
40
static public final String JavaDoc CONTEXTDATA = "ContextData"; // NOI18N
41
static public final String JavaDoc ENGINEDATA = "EngineData"; // NOI18N
42
static public final String JavaDoc MONITORDATA = "MonitorData"; // NOI18N
43
static public final String JavaDoc DISPATCHES = "Dispatches"; // NOI18N
44

45     public MonitorData() {
46     this(null, Common.USE_DEFAULT_VALUES);
47     }
48
49     public MonitorData(Node doc, int options) {
50     this(Common.NO_DEFAULT_VALUES);
51     if (doc == null)
52         {
53         doc = GraphManager.createRootElementNode(MONITORDATA);
54         if (doc == null)
55             throw new RuntimeException JavaDoc("failed to create a new DOM root!"); // NOI18N
56
}
57     Node n = GraphManager.getElementNode(MONITORDATA, doc);
58     if (n == null)
59         throw new RuntimeException JavaDoc("doc root not found in the DOM graph!"); // NOI18N
60

61     this.graphManager.setXmlDocument(doc);
62
63     // Entry point of the createBeans() recursive calls
64
this.createBean(n, this.graphManager());
65     this.initialize(options);
66     }
67     
68     public MonitorData(int options) {
69     super(MonitorData.comparators, new org.netbeans.modules.schema2beans.Version(1, 0, 6));
70     // The graph manager is allocated in the bean root
71
this.graphManager = new GraphManager(this);
72
73     this.createRoot(MONITORDATA, MONITORDATA,
74             Common.TYPE_1 | Common.TYPE_BEAN, MonitorData.class);
75
76     // Properties (see root bean comments for the bean graph)
77
this.createProperty("ClientData", CLIENTDATA, // NOI18N
78
Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY,
79                 ClientData.class);
80     this.createAttribute(CLIENTDATA, "protocol", "Protocol", // NOI18N
81
AttrProp.CDATA | AttrProp.REQUIRED,
82                  null, null);
83     this.createAttribute(CLIENTDATA, "remoteAddress", "RemoteAddress", // NOI18N
84
AttrProp.CDATA | AttrProp.REQUIRED,
85                  null, null);
86     this.createAttribute(CLIENTDATA, "software", "Software", // NOI18N
87
AttrProp.CDATA | AttrProp.IMPLIED,
88                  null, null);
89     this.createAttribute(CLIENTDATA, "locale", "Locale", // NOI18N
90
AttrProp.CDATA | AttrProp.IMPLIED,
91                  null, null);
92     this.createAttribute(CLIENTDATA, "formatsAccepted", "FormatsAccepted", // NOI18N
93
AttrProp.CDATA | AttrProp.IMPLIED,
94                  null, null);
95     this.createAttribute(CLIENTDATA, "encodingsAccepted", "EncodingsAccepted", // NOI18N
96
AttrProp.CDATA | AttrProp.IMPLIED,
97                  null, null);
98     this.createAttribute(CLIENTDATA, "charsetsAccepted", "CharsetsAccepted", // NOI18N
99
AttrProp.CDATA | AttrProp.IMPLIED,
100                  null, null);
101     this.createProperty("SessionData", SESSIONDATA, // NOI18N
102
Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY,
103                 SessionData.class);
104     this.createAttribute(SESSIONDATA, "before", "Before", // NOI18N
105
AttrProp.ENUM | AttrProp.REQUIRED,
106                  new String JavaDoc[] {
107                  "false", // NOI18N
108
"true" // NOI18N
109
}, "false"); // NOI18N
110
this.createAttribute(SESSIONDATA, "after", "After", // NOI18N
111
AttrProp.ENUM | AttrProp.REQUIRED,
112                  new String JavaDoc[] {
113                  "false", // NOI18N
114
"true" // NOI18N
115
}, "false"); // NOI18N
116
this.createAttribute(SESSIONDATA, "id", "Id", // NOI18N
117
AttrProp.CDATA | AttrProp.IMPLIED,
118                  null, null);
119     this.createAttribute(SESSIONDATA, "created", "Created", // NOI18N
120
AttrProp.CDATA | AttrProp.IMPLIED,
121                  null, null);
122     this.createProperty("CookiesData", COOKIESDATA, // NOI18N
123
Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY,
124                 CookiesData.class);
125
126     // PENDING - I think I need to move this to the request data
127
// class to make it an independent class that can be handled
128
// on its own (if I want to pass less data about).
129
this.createProperty("RequestData", REQUESTDATA, // NOI18N
130
Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY,
131                 RequestData.class);
132     this.createAttribute(REQUESTDATA, "uri", "Uri", // NOI18N
133
AttrProp.CDATA | AttrProp.REQUIRED,
134                  null, null);
135     this.createAttribute(REQUESTDATA, "method", "Method", // NOI18N
136
AttrProp.CDATA | AttrProp.REQUIRED,
137                  null, null);
138     this.createAttribute(REQUESTDATA, "urlencoded", "Urlencoded", // NOI18N
139
AttrProp.CDATA | AttrProp.IMPLIED,
140                  null, null);
141     this.createAttribute(REQUESTDATA, "queryString", "QueryString", // NOI18N
142
AttrProp.CDATA | AttrProp.IMPLIED,
143                  null, null);
144     this.createAttribute(REQUESTDATA, "replace", "Replace", // NOI18N
145
AttrProp.CDATA | AttrProp.IMPLIED,
146                  null, null);
147     this.createAttribute(REQUESTDATA, "protocol", "Protocol", // NOI18N
148
AttrProp.CDATA | AttrProp.IMPLIED,
149                  null, null);
150     this.createAttribute(REQUESTDATA, "ipaddress", "Ipaddress", // NOI18N
151
AttrProp.CDATA | AttrProp.IMPLIED,
152                  null, null);
153     this.createAttribute(REQUESTDATA, "scheme", "Scheme", // NOI18N
154
AttrProp.CDATA | AttrProp.IMPLIED,
155                  null, null);
156     this.createAttribute(REQUESTDATA, "status", "Status", // NOI18N
157
AttrProp.CDATA | AttrProp.IMPLIED,
158                  null, null);
159
160     this.createProperty("ServletData", SERVLETDATA, // NOI18N
161
Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY,
162                 ServletData.class);
163     this.createAttribute(SERVLETDATA, "name", "Name", // NOI18N
164
AttrProp.CDATA | AttrProp.IMPLIED,
165                  null, null);
166     this.createAttribute(SERVLETDATA, "className", "ClassName", // NOI18N
167
AttrProp.CDATA | AttrProp.IMPLIED,
168                  null, null);
169     this.createAttribute(SERVLETDATA, "packageName", "PackageName", // NOI18N
170
AttrProp.CDATA | AttrProp.IMPLIED,
171                  null, null);
172     this.createAttribute(SERVLETDATA, "servletInfo", "ServletInfo", // NOI18N
173
AttrProp.CDATA | AttrProp.IMPLIED,
174                  null, null);
175     this.createAttribute(SERVLETDATA, "relPath", "RelPath", // NOI18N
176
AttrProp.CDATA | AttrProp.IMPLIED,
177                  null, null);
178     this.createAttribute(SERVLETDATA, "transPath", "TransPath", // NOI18N
179
AttrProp.CDATA | AttrProp.IMPLIED,
180                  null, null);
181     this.createAttribute(SERVLETDATA, "contextName", "ContextName", // NOI18N
182
AttrProp.CDATA | AttrProp.IMPLIED,
183                  null, null);
184     this.createAttribute(SERVLETDATA, "absPath", "AbsPath", // NOI18N
185
AttrProp.CDATA | AttrProp.IMPLIED,
186                  null, null);
187     this.createAttribute(SERVLETDATA, "jre", "Jre", // NOI18N
188
AttrProp.CDATA | AttrProp.IMPLIED,
189                  null, null);
190     this.createAttribute(SERVLETDATA, "platform", "Platform", // NOI18N
191
AttrProp.CDATA | AttrProp.IMPLIED,
192                  null, null);
193     this.createAttribute(SERVLETDATA, "serverPort", "ServerPort", // NOI18N
194
AttrProp.NMTOKEN | AttrProp.IMPLIED,
195                  null, null);
196     this.createAttribute(SERVLETDATA, "serverName", "ServerName", // NOI18N
197
AttrProp.CDATA | AttrProp.IMPLIED,
198                  null, null);
199
200     this.createAttribute(SERVLETDATA, "collected", "Collected", // NOI18N
201
AttrProp.CDATA | AttrProp.IMPLIED,
202                  null, null);
203
204     this.createProperty("ContextData", CONTEXTDATA, // NOI18N
205
Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY,
206                 ContextData.class);
207     this.createAttribute(CONTEXTDATA, "contextName", "ContextName", // NOI18N
208
AttrProp.CDATA | AttrProp.IMPLIED,
209                  null, null);
210     this.createAttribute(CONTEXTDATA, "absPath", "AbsPath", // NOI18N
211
AttrProp.CDATA | AttrProp.IMPLIED,
212                  null, null);
213
214     this.createProperty("EngineData", ENGINEDATA, // NOI18N
215
Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY,
216                 EngineData.class);
217
218     this.createAttribute(ENGINEDATA, "jre", "Jre", // NOI18N
219
AttrProp.CDATA | AttrProp.IMPLIED,
220                  null, null);
221     this.createAttribute(ENGINEDATA, "platform", "Platform", // NOI18N
222
AttrProp.CDATA | AttrProp.IMPLIED,
223                  null, null);
224     this.createAttribute(ENGINEDATA, "serverPort", "ServerPort", // NOI18N
225
AttrProp.NMTOKEN | AttrProp.IMPLIED,
226                  null, null);
227     this.createAttribute(ENGINEDATA, "serverName", "ServerName", // NOI18N
228
AttrProp.CDATA | AttrProp.IMPLIED,
229                  null, null);
230
231     this.createAttribute("resource", "Resource", // NOI18N
232
AttrProp.CDATA | AttrProp.REQUIRED,
233                  null, null);
234     this.createAttribute("timestamp", "Timestamp", // NOI18N
235
AttrProp.CDATA | AttrProp.REQUIRED,
236                  null, null);
237     this.createAttribute("id", "Id", // NOI18N
238
AttrProp.CDATA | AttrProp.REQUIRED,
239                  null, null);
240     this.createAttribute("method", "Metod", // NOI18N
241
AttrProp.CDATA | AttrProp.REQUIRED,
242                  null, null);
243
244     this.createProperty("Dispatches", DISPATCHES, // NOI18N
245
Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY,
246                 Dispatches.class);
247
248
249     this.initialize(options);
250     }
251
252     // Setting the default values of the properties
253
void initialize(int options) {
254     }
255
256     // This attribute is mandatory
257
public void setClientData(ClientData value) {
258     this.setValue(CLIENTDATA, value);
259     }
260
261     //
262
public ClientData getClientData() {
263     return (ClientData)this.getValue(CLIENTDATA);
264     }
265
266     // This attribute is optional
267
public void setSessionData(SessionData value) {
268     this.setValue(SESSIONDATA, value);
269     }
270
271     //
272
public SessionData getSessionData() {
273     return (SessionData)this.getValue(SESSIONDATA);
274     }
275
276     // This attribute is optional
277
public void setCookiesData(CookiesData value) {
278     this.setValue(COOKIESDATA, value);
279     }
280
281     //
282
public CookiesData getCookiesData() {
283     return (CookiesData)this.getValue(COOKIESDATA);
284     }
285
286     // This attribute is optional
287
public void setDispatches(Dispatches value) {
288     this.setValue(DISPATCHES, value);
289     }
290
291     //
292
public Dispatches getDispatches() {
293     if(debug) System.out.println("Running getDispatches"); //NOI18N
294
return (Dispatches)this.getValue(DISPATCHES);
295     }
296
297     // This attribute is mandatory
298
public void setRequestData(RequestData value) {
299     this.setValue(REQUESTDATA, value);
300     }
301
302     //
303
public RequestData getRequestData() {
304     return (RequestData)this.getValue(REQUESTDATA);
305     }
306
307     // This attribute is optional
308
public void setServletData(ServletData value) {
309     this.setValue(SERVLETDATA, value);
310     }
311
312     //
313
public ServletData getServletData() {
314     return (ServletData)this.getValue(SERVLETDATA);
315     }
316
317     // This attribute is optional
318
public void setEngineData(EngineData value) {
319     this.setValue(ENGINEDATA, value);
320     }
321
322     //
323
public EngineData getEngineData() {
324     return (EngineData)this.getValue(ENGINEDATA);
325     }
326
327     // This attribute is optional
328
public void setContextData(ContextData value) {
329     this.setValue(CONTEXTDATA, value);
330     }
331
332     //
333
public ContextData getContextData() {
334     return (ContextData)this.getValue(CONTEXTDATA);
335     }
336
337     // This method verifies that the mandatory properties are set
338
public boolean verify() {
339     return true;
340     }
341
342     public String JavaDoc getServerAndPort()
343     {
344     String JavaDoc server = null;
345     String JavaDoc port = null;
346         
347     try {
348         server = getEngineData().getAttributeValue("serverName"); // NOI18N
349
port = getEngineData().getAttributeValue("serverPort"); // NOI18N
350
return server.concat(":").concat(port); //NOI18N
351
}
352     catch(NullPointerException JavaDoc npe) {
353     }
354         
355     // Backwards compatibility
356
server = getServletData().getAttributeValue("serverName"); // NOI18N
357
port = getServletData().getAttributeValue("serverPort"); // NOI18N
358
return server.concat(":").concat(port); //NOI18N
359
}
360
361
362     public String JavaDoc getServerName() {
363     
364     try {
365         return getEngineData().getAttributeValue("serverName"); // NOI18N
366
}
367     catch(NullPointerException JavaDoc npe) {
368     }
369         
370     // Backwards compatibility
371
return getServletData().getAttributeValue("serverName"); // NOI18N
372
}
373
374     public int getServerPort() {
375     
376     String JavaDoc portS = null;
377     try {
378         portS = getEngineData().getAttributeValue("serverPort"); // NOI18N
379
}
380     catch(NullPointerException JavaDoc npe) {
381     }
382     if(portS == null)
383         portS = getServletData().getAttributeValue("serverPort"); // NOI18N
384
return Integer.parseInt(portS);
385     }
386
387
388     public String JavaDoc getServerPortAsString() {
389     
390     String JavaDoc portS = null;
391     try {
392         portS = getEngineData().getAttributeValue("serverPort"); // NOI18N
393
}
394     catch(NullPointerException JavaDoc npe) {
395     }
396     if(portS == null)
397         portS = getServletData().getAttributeValue("serverPort"); // NOI18N
398
return portS;
399     
400     
401     }
402
403
404     public void setServerName(String JavaDoc server) {
405     
406     try {
407         getEngineData().setAttributeValue("serverName", server); // NOI18N
408
return;
409     }
410     catch(NullPointerException JavaDoc npe) {
411     }
412         
413     try {
414         getServletData().getAttributeValue("serverName, server"); // NOI18N
415
return;
416     }
417     catch(NullPointerException JavaDoc npe) {
418     }
419     }
420
421     public void setServerPort(int port) {
422     
423     try {
424         getEngineData().setAttributeValue("serverPort", // NOI18N
425
String.valueOf(port));
426         return;
427     }
428     catch(NullPointerException JavaDoc npe) {
429     }
430     
431
432     try {
433         getServletData().setAttributeValue("serverPort", // NOI18N
434
String.valueOf(port));
435         return;
436     }
437     catch(NullPointerException JavaDoc npe) {
438     }
439     }
440
441     public void setServerPort(String JavaDoc port) {
442     
443     try {
444         getEngineData().setAttributeValue("serverPort", // NOI18N
445
port);
446         return;
447     }
448     catch(NullPointerException JavaDoc npe) {
449     }
450     
451
452     try {
453         getServletData().setAttributeValue("serverPort", // NOI18N
454
port);
455         return;
456     }
457     catch(NullPointerException JavaDoc npe) {
458     }
459     }
460     
461
462     //
463
static public void addComparator(BeanComparator c) {
464     MonitorData.comparators.add(c);
465     }
466
467     //
468
static public void removeComparator(BeanComparator c) {
469     MonitorData.comparators.remove(c);
470     }
471     //
472
public void addPropertyChangeListener(PropertyChangeListener l) {
473     BeanProp p = this.beanProp();
474     if (p != null)
475         p.addPCListener(l);
476     }
477
478     //
479
public void removePropertyChangeListener(PropertyChangeListener l) {
480     BeanProp p = this.beanProp();
481     if (p != null)
482         p.removePCListener(l);
483     }
484
485     //
486
public void addPropertyChangeListener(String JavaDoc n, PropertyChangeListener l){
487     BeanProp p = this.beanProp(n);
488     if (p != null)
489         p.addPCListener(l);
490     }
491
492     //
493
public void removePropertyChangeListener(String JavaDoc n,
494                          PropertyChangeListener l) {
495     BeanProp p = this.beanProp(n);
496     if (p != null)
497         p.removePCListener(l);
498     }
499
500     //
501
// This method returns the root of the bean graph
502
// Each call creates a new bean graph from the specified DOM graph
503
//
504
public static MonitorData createGraph(Node doc) {
505     return new MonitorData(doc, Common.NO_DEFAULT_VALUES);
506     }
507
508     public static MonitorData createGraph(java.io.Reader JavaDoc reader)
509     throws IOException {
510     try {
511         return MonitorData.createGraph(reader, false);
512     }
513     catch(IOException ioe) {
514         throw ioe;
515     }
516     }
517
518     public static MonitorData createGraph(java.io.Reader JavaDoc reader,
519                       boolean validate) throws IOException {
520     try {
521         InputSource JavaDoc insource = new InputSource JavaDoc(reader);
522         insource.setEncoding("UTF-8"); // NOI18N
523
Document doc =
524         GraphManager.createXmlDocument(insource, validate);
525         return MonitorData.createGraph(doc);
526     }
527     catch (Throwable JavaDoc t) {
528         throw new IOException();
529     }
530     }
531
532     //
533
// This method returns the root for a new empty bean graph
534
//
535
public static MonitorData createGraph() {
536     return new MonitorData();
537     }
538
539     public void write(OutputStream out) throws IOException {
540     throw new RuntimeException JavaDoc("Don't do this!"); // NOI18N
541
}
542     
543     public void write(Writer writer) throws IOException {
544         try {
545             this.write(writer, "UTF-8"); // NOI18N
546
} catch (Exception JavaDoc e) {
547             throw new RuntimeException JavaDoc(e.getMessage());
548         }
549     }
550     
551     // Dump the content of this bean returning it as a String
552
public void dump(StringBuffer JavaDoc str, String JavaDoc indent) {
553     String JavaDoc s;
554     BaseBean n;
555     str.append(indent);
556     str.append("ClientData"); // NOI18N
557
n = this.getClientData();
558     if (n != null)
559         n.dump(str, indent + "\t"); // NOI18N
560
else
561         str.append(indent+"\tnull"); // NOI18N
562
this.dumpAttributes(CLIENTDATA, 0, str, indent);
563
564     str.append(indent);
565     str.append("SessionData"); // NOI18N
566
n = this.getSessionData();
567     if (n != null)
568         n.dump(str, indent + "\t"); // NOI18N
569
else
570         str.append(indent+"\tnull"); // NOI18N
571
this.dumpAttributes(SESSIONDATA, 0, str, indent);
572
573     str.append(indent);
574     str.append("CookiesData"); // NOI18N
575
n = this.getCookiesData();
576     if (n != null)
577         n.dump(str, indent + "\t"); // NOI18N
578
else
579         str.append(indent+"\tnull"); // NOI18N
580
this.dumpAttributes(COOKIESDATA, 0, str, indent);
581
582     str.append(indent);
583     str.append("RequestData"); // NOI18N
584
n = this.getRequestData();
585     if (n != null)
586         n.dump(str, indent + "\t"); // NOI18N
587
else
588         str.append(indent+"\tnull"); // NOI18N
589
this.dumpAttributes(REQUESTDATA, 0, str, indent);
590
591     str.append(indent);
592     str.append("ServletData"); // NOI18N
593
n = this.getServletData();
594     if (n != null)
595         n.dump(str, indent + "\t"); // NOI18N
596
else
597         str.append(indent+"\tnull"); // NOI18N
598
this.dumpAttributes(SERVLETDATA, 0, str, indent);
599
600     str.append("ContextData"); // NOI18N
601
n = this.getContextData();
602     if (n != null)
603         n.dump(str, indent + "\t"); // NOI18N
604
else
605         str.append(indent+"\tnull"); // NOI18N
606
this.dumpAttributes(CONTEXTDATA, 0, str, indent);
607
608     str.append(indent);
609     str.append("Dispatches"); // NOI18N
610
n = this.getDispatches();
611     if (n != null)
612         n.dump(str, indent + "\t"); // NOI18N
613
else
614         str.append(indent+"\tnull"); // NOI18N
615
this.dumpAttributes(DISPATCHES, 0, str, indent);
616     }
617
618     public String JavaDoc dumpBeanNode() {
619     StringBuffer JavaDoc str = new StringBuffer JavaDoc();
620     str.append("MonitorData\n"); // NOI18N
621
this.dump(str, "\n "); // NOI18N
622
return str.toString();
623     }
624
625     /** Writes the data to a temp file.
626      * @param filename The name of the file to which the data is
627      * written
628      * @return the absolute path to the file as a String
629      *
630      */

631     public String JavaDoc createTempFile(String JavaDoc filename) {
632
633     StringBuffer JavaDoc buf = new StringBuffer JavaDoc
634         (System.getProperty("java.io.tmpdir")); // NOI18N
635
buf.append(System.getProperty("file.separator")); // NOI18N
636
buf.append(filename);
637
638     try {
639         File file = new File(buf.toString());
640         FileOutputStream fout = new FileOutputStream(file);
641         PrintWriter pw = new PrintWriter(fout);
642         this.write(pw);
643         pw.close();
644         fout.close();
645         return file.getAbsolutePath();
646     }
647     catch(Throwable JavaDoc throwable) {
648         return "null"; //NOI18N
649
}
650     }
651
652     /*
653     public TransactionNode createTransactionNode(boolean current) {
654     TransactionNode node =
655         new TransactionNode(this.getAttributeValue("id"), // NOI18N
656                 this.getAttributeValue("method"), // NOI18N
657                 this.getAttributeValue("resource")); // NOI18N
658     node.setCurrent(current);
659     return node;
660     }
661     */

662 }
663
Popular Tags