1 19 20 package org.netbeans.modules.web.monitor.data; 21 22 import org.w3c.dom.*; 23 import org.xml.sax.InputSource ; 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 CLIENTDATA = "ClientData"; static public final String SESSIONDATA = "SessionData"; static public final String COOKIESDATA = "CookiesData"; static public final String REQUESTDATA = "RequestData"; static public final String SERVLETDATA = "ServletData"; static public final String CONTEXTDATA = "ContextData"; static public final String ENGINEDATA = "EngineData"; static public final String MONITORDATA = "MonitorData"; static public final String DISPATCHES = "Dispatches"; 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 ("failed to create a new DOM root!"); } 57 Node n = GraphManager.getElementNode(MONITORDATA, doc); 58 if (n == null) 59 throw new RuntimeException ("doc root not found in the DOM graph!"); 61 this.graphManager.setXmlDocument(doc); 62 63 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 this.graphManager = new GraphManager(this); 72 73 this.createRoot(MONITORDATA, MONITORDATA, 74 Common.TYPE_1 | Common.TYPE_BEAN, MonitorData.class); 75 76 this.createProperty("ClientData", CLIENTDATA, Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 79 ClientData.class); 80 this.createAttribute(CLIENTDATA, "protocol", "Protocol", AttrProp.CDATA | AttrProp.REQUIRED, 82 null, null); 83 this.createAttribute(CLIENTDATA, "remoteAddress", "RemoteAddress", AttrProp.CDATA | AttrProp.REQUIRED, 85 null, null); 86 this.createAttribute(CLIENTDATA, "software", "Software", AttrProp.CDATA | AttrProp.IMPLIED, 88 null, null); 89 this.createAttribute(CLIENTDATA, "locale", "Locale", AttrProp.CDATA | AttrProp.IMPLIED, 91 null, null); 92 this.createAttribute(CLIENTDATA, "formatsAccepted", "FormatsAccepted", AttrProp.CDATA | AttrProp.IMPLIED, 94 null, null); 95 this.createAttribute(CLIENTDATA, "encodingsAccepted", "EncodingsAccepted", AttrProp.CDATA | AttrProp.IMPLIED, 97 null, null); 98 this.createAttribute(CLIENTDATA, "charsetsAccepted", "CharsetsAccepted", AttrProp.CDATA | AttrProp.IMPLIED, 100 null, null); 101 this.createProperty("SessionData", SESSIONDATA, Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 103 SessionData.class); 104 this.createAttribute(SESSIONDATA, "before", "Before", AttrProp.ENUM | AttrProp.REQUIRED, 106 new String [] { 107 "false", "true" }, "false"); this.createAttribute(SESSIONDATA, "after", "After", AttrProp.ENUM | AttrProp.REQUIRED, 112 new String [] { 113 "false", "true" }, "false"); this.createAttribute(SESSIONDATA, "id", "Id", AttrProp.CDATA | AttrProp.IMPLIED, 118 null, null); 119 this.createAttribute(SESSIONDATA, "created", "Created", AttrProp.CDATA | AttrProp.IMPLIED, 121 null, null); 122 this.createProperty("CookiesData", COOKIESDATA, Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 124 CookiesData.class); 125 126 this.createProperty("RequestData", REQUESTDATA, Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 131 RequestData.class); 132 this.createAttribute(REQUESTDATA, "uri", "Uri", AttrProp.CDATA | AttrProp.REQUIRED, 134 null, null); 135 this.createAttribute(REQUESTDATA, "method", "Method", AttrProp.CDATA | AttrProp.REQUIRED, 137 null, null); 138 this.createAttribute(REQUESTDATA, "urlencoded", "Urlencoded", AttrProp.CDATA | AttrProp.IMPLIED, 140 null, null); 141 this.createAttribute(REQUESTDATA, "queryString", "QueryString", AttrProp.CDATA | AttrProp.IMPLIED, 143 null, null); 144 this.createAttribute(REQUESTDATA, "replace", "Replace", AttrProp.CDATA | AttrProp.IMPLIED, 146 null, null); 147 this.createAttribute(REQUESTDATA, "protocol", "Protocol", AttrProp.CDATA | AttrProp.IMPLIED, 149 null, null); 150 this.createAttribute(REQUESTDATA, "ipaddress", "Ipaddress", AttrProp.CDATA | AttrProp.IMPLIED, 152 null, null); 153 this.createAttribute(REQUESTDATA, "scheme", "Scheme", AttrProp.CDATA | AttrProp.IMPLIED, 155 null, null); 156 this.createAttribute(REQUESTDATA, "status", "Status", AttrProp.CDATA | AttrProp.IMPLIED, 158 null, null); 159 160 this.createProperty("ServletData", SERVLETDATA, Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 162 ServletData.class); 163 this.createAttribute(SERVLETDATA, "name", "Name", AttrProp.CDATA | AttrProp.IMPLIED, 165 null, null); 166 this.createAttribute(SERVLETDATA, "className", "ClassName", AttrProp.CDATA | AttrProp.IMPLIED, 168 null, null); 169 this.createAttribute(SERVLETDATA, "packageName", "PackageName", AttrProp.CDATA | AttrProp.IMPLIED, 171 null, null); 172 this.createAttribute(SERVLETDATA, "servletInfo", "ServletInfo", AttrProp.CDATA | AttrProp.IMPLIED, 174 null, null); 175 this.createAttribute(SERVLETDATA, "relPath", "RelPath", AttrProp.CDATA | AttrProp.IMPLIED, 177 null, null); 178 this.createAttribute(SERVLETDATA, "transPath", "TransPath", AttrProp.CDATA | AttrProp.IMPLIED, 180 null, null); 181 this.createAttribute(SERVLETDATA, "contextName", "ContextName", AttrProp.CDATA | AttrProp.IMPLIED, 183 null, null); 184 this.createAttribute(SERVLETDATA, "absPath", "AbsPath", AttrProp.CDATA | AttrProp.IMPLIED, 186 null, null); 187 this.createAttribute(SERVLETDATA, "jre", "Jre", AttrProp.CDATA | AttrProp.IMPLIED, 189 null, null); 190 this.createAttribute(SERVLETDATA, "platform", "Platform", AttrProp.CDATA | AttrProp.IMPLIED, 192 null, null); 193 this.createAttribute(SERVLETDATA, "serverPort", "ServerPort", AttrProp.NMTOKEN | AttrProp.IMPLIED, 195 null, null); 196 this.createAttribute(SERVLETDATA, "serverName", "ServerName", AttrProp.CDATA | AttrProp.IMPLIED, 198 null, null); 199 200 this.createAttribute(SERVLETDATA, "collected", "Collected", AttrProp.CDATA | AttrProp.IMPLIED, 202 null, null); 203 204 this.createProperty("ContextData", CONTEXTDATA, Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 206 ContextData.class); 207 this.createAttribute(CONTEXTDATA, "contextName", "ContextName", AttrProp.CDATA | AttrProp.IMPLIED, 209 null, null); 210 this.createAttribute(CONTEXTDATA, "absPath", "AbsPath", AttrProp.CDATA | AttrProp.IMPLIED, 212 null, null); 213 214 this.createProperty("EngineData", ENGINEDATA, Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 216 EngineData.class); 217 218 this.createAttribute(ENGINEDATA, "jre", "Jre", AttrProp.CDATA | AttrProp.IMPLIED, 220 null, null); 221 this.createAttribute(ENGINEDATA, "platform", "Platform", AttrProp.CDATA | AttrProp.IMPLIED, 223 null, null); 224 this.createAttribute(ENGINEDATA, "serverPort", "ServerPort", AttrProp.NMTOKEN | AttrProp.IMPLIED, 226 null, null); 227 this.createAttribute(ENGINEDATA, "serverName", "ServerName", AttrProp.CDATA | AttrProp.IMPLIED, 229 null, null); 230 231 this.createAttribute("resource", "Resource", AttrProp.CDATA | AttrProp.REQUIRED, 233 null, null); 234 this.createAttribute("timestamp", "Timestamp", AttrProp.CDATA | AttrProp.REQUIRED, 236 null, null); 237 this.createAttribute("id", "Id", AttrProp.CDATA | AttrProp.REQUIRED, 239 null, null); 240 this.createAttribute("method", "Metod", AttrProp.CDATA | AttrProp.REQUIRED, 242 null, null); 243 244 this.createProperty("Dispatches", DISPATCHES, Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 246 Dispatches.class); 247 248 249 this.initialize(options); 250 } 251 252 void initialize(int options) { 254 } 255 256 public void setClientData(ClientData value) { 258 this.setValue(CLIENTDATA, value); 259 } 260 261 public ClientData getClientData() { 263 return (ClientData)this.getValue(CLIENTDATA); 264 } 265 266 public void setSessionData(SessionData value) { 268 this.setValue(SESSIONDATA, value); 269 } 270 271 public SessionData getSessionData() { 273 return (SessionData)this.getValue(SESSIONDATA); 274 } 275 276 public void setCookiesData(CookiesData value) { 278 this.setValue(COOKIESDATA, value); 279 } 280 281 public CookiesData getCookiesData() { 283 return (CookiesData)this.getValue(COOKIESDATA); 284 } 285 286 public void setDispatches(Dispatches value) { 288 this.setValue(DISPATCHES, value); 289 } 290 291 public Dispatches getDispatches() { 293 if(debug) System.out.println("Running getDispatches"); return (Dispatches)this.getValue(DISPATCHES); 295 } 296 297 public void setRequestData(RequestData value) { 299 this.setValue(REQUESTDATA, value); 300 } 301 302 public RequestData getRequestData() { 304 return (RequestData)this.getValue(REQUESTDATA); 305 } 306 307 public void setServletData(ServletData value) { 309 this.setValue(SERVLETDATA, value); 310 } 311 312 public ServletData getServletData() { 314 return (ServletData)this.getValue(SERVLETDATA); 315 } 316 317 public void setEngineData(EngineData value) { 319 this.setValue(ENGINEDATA, value); 320 } 321 322 public EngineData getEngineData() { 324 return (EngineData)this.getValue(ENGINEDATA); 325 } 326 327 public void setContextData(ContextData value) { 329 this.setValue(CONTEXTDATA, value); 330 } 331 332 public ContextData getContextData() { 334 return (ContextData)this.getValue(CONTEXTDATA); 335 } 336 337 public boolean verify() { 339 return true; 340 } 341 342 public String getServerAndPort() 343 { 344 String server = null; 345 String port = null; 346 347 try { 348 server = getEngineData().getAttributeValue("serverName"); port = getEngineData().getAttributeValue("serverPort"); return server.concat(":").concat(port); } 352 catch(NullPointerException npe) { 353 } 354 355 server = getServletData().getAttributeValue("serverName"); port = getServletData().getAttributeValue("serverPort"); return server.concat(":").concat(port); } 360 361 362 public String getServerName() { 363 364 try { 365 return getEngineData().getAttributeValue("serverName"); } 367 catch(NullPointerException npe) { 368 } 369 370 return getServletData().getAttributeValue("serverName"); } 373 374 public int getServerPort() { 375 376 String portS = null; 377 try { 378 portS = getEngineData().getAttributeValue("serverPort"); } 380 catch(NullPointerException npe) { 381 } 382 if(portS == null) 383 portS = getServletData().getAttributeValue("serverPort"); return Integer.parseInt(portS); 385 } 386 387 388 public String getServerPortAsString() { 389 390 String portS = null; 391 try { 392 portS = getEngineData().getAttributeValue("serverPort"); } 394 catch(NullPointerException npe) { 395 } 396 if(portS == null) 397 portS = getServletData().getAttributeValue("serverPort"); return portS; 399 400 401 } 402 403 404 public void setServerName(String server) { 405 406 try { 407 getEngineData().setAttributeValue("serverName", server); return; 409 } 410 catch(NullPointerException npe) { 411 } 412 413 try { 414 getServletData().getAttributeValue("serverName, server"); return; 416 } 417 catch(NullPointerException npe) { 418 } 419 } 420 421 public void setServerPort(int port) { 422 423 try { 424 getEngineData().setAttributeValue("serverPort", String.valueOf(port)); 426 return; 427 } 428 catch(NullPointerException npe) { 429 } 430 431 432 try { 433 getServletData().setAttributeValue("serverPort", String.valueOf(port)); 435 return; 436 } 437 catch(NullPointerException npe) { 438 } 439 } 440 441 public void setServerPort(String port) { 442 443 try { 444 getEngineData().setAttributeValue("serverPort", port); 446 return; 447 } 448 catch(NullPointerException npe) { 449 } 450 451 452 try { 453 getServletData().setAttributeValue("serverPort", port); 455 return; 456 } 457 catch(NullPointerException npe) { 458 } 459 } 460 461 462 static public void addComparator(BeanComparator c) { 464 MonitorData.comparators.add(c); 465 } 466 467 static public void removeComparator(BeanComparator c) { 469 MonitorData.comparators.remove(c); 470 } 471 public void addPropertyChangeListener(PropertyChangeListener l) { 473 BeanProp p = this.beanProp(); 474 if (p != null) 475 p.addPCListener(l); 476 } 477 478 public void removePropertyChangeListener(PropertyChangeListener l) { 480 BeanProp p = this.beanProp(); 481 if (p != null) 482 p.removePCListener(l); 483 } 484 485 public void addPropertyChangeListener(String n, PropertyChangeListener l){ 487 BeanProp p = this.beanProp(n); 488 if (p != null) 489 p.addPCListener(l); 490 } 491 492 public void removePropertyChangeListener(String n, 494 PropertyChangeListener l) { 495 BeanProp p = this.beanProp(n); 496 if (p != null) 497 p.removePCListener(l); 498 } 499 500 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 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 reader, 519 boolean validate) throws IOException { 520 try { 521 InputSource insource = new InputSource (reader); 522 insource.setEncoding("UTF-8"); Document doc = 524 GraphManager.createXmlDocument(insource, validate); 525 return MonitorData.createGraph(doc); 526 } 527 catch (Throwable t) { 528 throw new IOException(); 529 } 530 } 531 532 public static MonitorData createGraph() { 536 return new MonitorData(); 537 } 538 539 public void write(OutputStream out) throws IOException { 540 throw new RuntimeException ("Don't do this!"); } 542 543 public void write(Writer writer) throws IOException { 544 try { 545 this.write(writer, "UTF-8"); } catch (Exception e) { 547 throw new RuntimeException (e.getMessage()); 548 } 549 } 550 551 public void dump(StringBuffer str, String indent) { 553 String s; 554 BaseBean n; 555 str.append(indent); 556 str.append("ClientData"); n = this.getClientData(); 558 if (n != null) 559 n.dump(str, indent + "\t"); else 561 str.append(indent+"\tnull"); this.dumpAttributes(CLIENTDATA, 0, str, indent); 563 564 str.append(indent); 565 str.append("SessionData"); n = this.getSessionData(); 567 if (n != null) 568 n.dump(str, indent + "\t"); else 570 str.append(indent+"\tnull"); this.dumpAttributes(SESSIONDATA, 0, str, indent); 572 573 str.append(indent); 574 str.append("CookiesData"); n = this.getCookiesData(); 576 if (n != null) 577 n.dump(str, indent + "\t"); else 579 str.append(indent+"\tnull"); this.dumpAttributes(COOKIESDATA, 0, str, indent); 581 582 str.append(indent); 583 str.append("RequestData"); n = this.getRequestData(); 585 if (n != null) 586 n.dump(str, indent + "\t"); else 588 str.append(indent+"\tnull"); this.dumpAttributes(REQUESTDATA, 0, str, indent); 590 591 str.append(indent); 592 str.append("ServletData"); n = this.getServletData(); 594 if (n != null) 595 n.dump(str, indent + "\t"); else 597 str.append(indent+"\tnull"); this.dumpAttributes(SERVLETDATA, 0, str, indent); 599 600 str.append("ContextData"); n = this.getContextData(); 602 if (n != null) 603 n.dump(str, indent + "\t"); else 605 str.append(indent+"\tnull"); this.dumpAttributes(CONTEXTDATA, 0, str, indent); 607 608 str.append(indent); 609 str.append("Dispatches"); n = this.getDispatches(); 611 if (n != null) 612 n.dump(str, indent + "\t"); else 614 str.append(indent+"\tnull"); this.dumpAttributes(DISPATCHES, 0, str, indent); 616 } 617 618 public String dumpBeanNode() { 619 StringBuffer str = new StringBuffer (); 620 str.append("MonitorData\n"); this.dump(str, "\n "); return str.toString(); 623 } 624 625 631 public String createTempFile(String filename) { 632 633 StringBuffer buf = new StringBuffer 634 (System.getProperty("java.io.tmpdir")); buf.append(System.getProperty("file.separator")); 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 throwable) { 648 return "null"; } 650 } 651 652 662 } 663 | Popular Tags |