1 12 13 package org.ejtools.jmx.browser.mbean; 14 15 16 17 import java.beans.beancontext.BeanContextSupport ; 18 19 import java.util.Collection ; 20 21 import java.util.Iterator ; 22 23 import java.util.Vector ; 24 25 26 27 import javax.management.MBeanFeatureInfo ; 28 29 import javax.management.ObjectName ; 30 31 32 33 import org.apache.log4j.Logger; 34 35 import org.ejtools.beans.Sort; 36 37 import org.ejtools.jmx.MBeanAccessor; 38 39 40 41 42 43 58 59 public class View extends BeanContextSupport 60 61 { 62 63 64 65 protected String displayName = "<undefined>"; 66 67 68 69 protected String name = "<undefined>"; 70 71 72 73 private static Logger logger = Logger.getLogger(View.class); 74 75 76 77 public final static int ATTRIBUTE_TYPE = 0; 78 79 80 81 public final static int OPERATION_TYPE = 1; 82 83 84 85 86 87 88 89 public View() { } 90 91 92 93 94 95 106 107 public void addAttributeLine(ObjectName objectName, String name) 108 109 { 110 111 ViewLine line = new ViewLine(); 112 113 line.setType(View.ATTRIBUTE_TYPE); 114 115 line.setObjectName(objectName); 116 117 line.setName(name); 118 119 add(line); 120 121 logger.debug("Atrribute Line added (" + objectName + " => " + name + ")"); 122 123 } 124 125 126 127 128 129 140 141 public void addAttributeLine(String expression, String name) 142 143 { 144 145 try 146 147 { 148 149 ObjectName objectName = new ObjectName (expression); 150 151 addAttributeLine(objectName, name); 152 153 } 154 155 catch (Exception e) 156 157 { 158 159 logger.error("Exception while creating Attribute Line : " + e.getMessage()); 160 161 } 162 163 } 164 165 166 167 168 169 180 181 public void addAttributeResult(MBeanAccessor accessor, MBeanFeatureInfo info) 182 183 { 184 185 ResultLine line = new ResultLine(); 186 187 line.setType(View.ATTRIBUTE_TYPE); 188 189 line.setAccessor(accessor); 190 191 line.setInfo(info); 192 193 add(line); 194 195 logger.debug("Atrribute Result added (" + accessor + " => " + info + ")"); 196 197 } 198 199 200 201 202 203 214 215 public void addOperationLine(ObjectName objectName, String name) 216 217 { 218 219 ViewLine line = new ViewLine(); 220 221 line.setType(View.OPERATION_TYPE); 222 223 line.setObjectName(objectName); 224 225 line.setName(name); 226 227 add(line); 228 229 logger.debug("Operation Line added (" + objectName + " => " + name + ")"); 230 231 } 232 233 234 235 236 237 248 249 public void addOperationLine(String expression, String name) 250 251 { 252 253 try 254 255 { 256 257 ObjectName objectName = new ObjectName (expression); 258 259 addOperationLine(objectName, name); 260 261 } 262 263 catch (Exception e) 264 265 { 266 267 logger.error("Exception while creating Operation Line : " + e.getMessage()); 268 269 } 270 271 } 272 273 274 275 276 277 288 289 public void addOperationResult(MBeanAccessor accessor, MBeanFeatureInfo info) 290 291 { 292 293 ResultLine line = new ResultLine(); 294 295 line.setType(View.OPERATION_TYPE); 296 297 line.setAccessor(accessor); 298 299 line.setInfo(info); 300 301 add(line); 302 303 logger.debug("Operation Result added (" + accessor + " => " + info + ")"); 304 305 } 306 307 308 309 310 311 320 321 public Collection getAttributeLines() 322 323 { 324 325 Vector result = new Vector (); 326 327 Iterator iterator = Sort.getChildrenByClass(iterator(), ViewLine.class); 328 329 while (iterator.hasNext()) 330 331 { 332 333 ViewLine line = (ViewLine) iterator.next(); 334 335 if (line.getType() == View.ATTRIBUTE_TYPE) 336 337 { 338 339 result.add(line); 340 341 } 342 343 } 344 345 return result; 346 347 } 348 349 350 351 352 353 362 363 public Collection getAttributeResults() 364 365 { 366 367 Vector result = new Vector (); 368 369 Iterator iterator = Sort.getChildrenByClass(iterator(), ResultLine.class); 370 371 while (iterator.hasNext()) 372 373 { 374 375 ResultLine line = (ResultLine) iterator.next(); 376 377 if (line.getType() == View.ATTRIBUTE_TYPE) 378 379 { 380 381 result.add(line); 382 383 } 384 385 } 386 387 return result; 388 389 } 390 391 392 393 394 395 404 405 public String getDisplayName() 406 407 { 408 409 return this.displayName; 410 411 } 412 413 414 415 416 417 426 427 public String getName() 428 429 { 430 431 return this.name; 432 433 } 434 435 436 437 438 439 448 449 public Collection getOperationLines() 450 451 { 452 453 Vector result = new Vector (); 454 455 Iterator iterator = Sort.getChildrenByClass(iterator(), ViewLine.class); 456 457 while (iterator.hasNext()) 458 459 { 460 461 ViewLine line = (ViewLine) iterator.next(); 462 463 if (line.getType() == View.OPERATION_TYPE) 464 465 { 466 467 result.add(line); 468 469 } 470 471 } 472 473 return result; 474 475 } 476 477 478 479 480 481 490 491 public Collection getOperationResults() 492 493 { 494 495 Vector result = new Vector (); 496 497 Iterator iterator = Sort.getChildrenByClass(iterator(), ResultLine.class); 498 499 while (iterator.hasNext()) 500 501 { 502 503 ResultLine line = (ResultLine) iterator.next(); 504 505 if (line.getType() == View.OPERATION_TYPE) 506 507 { 508 509 result.add(line); 510 511 } 512 513 } 514 515 return result; 516 517 } 518 519 520 521 522 523 532 533 public Iterator iterator() 534 535 { 536 537 return Sort.sortByName(super.iterator()); 538 539 } 540 541 542 543 544 545 546 547 556 557 public void setDisplayName(String displayName) 558 559 { 560 561 this.displayName = displayName; 562 563 } 564 565 566 567 568 569 578 579 public void setName(String name) 580 581 { 582 583 this.name = name; 584 585 } 586 587 588 589 590 591 600 601 public String toString() 602 603 { 604 605 return this.displayName; 606 607 } 608 609 } 610 611 | Popular Tags |