1 12 13 package org.ejtools.jmx.browser.web.taglib; 14 15 16 17 import java.beans.PropertyEditor ; 18 19 20 21 import javax.management.MBeanParameterInfo ; 22 23 import javax.servlet.jsp.JspException ; 24 25 import javax.servlet.jsp.tagext.TagSupport ; 26 27 28 29 import org.apache.log4j.Logger; 30 31 import org.apache.struts.util.MessageResources; 32 33 import org.apache.struts.util.RequestUtils; 34 35 import org.apache.struts.util.ResponseUtils; 36 37 import org.ejtools.beans.CustomPropertyEditorManager; 38 39 import org.ejtools.util.ClassTools; 40 41 42 43 60 61 public class MBeanParameterEditorTag extends TagSupport 62 63 { 64 65 66 67 protected boolean filter = true; 68 69 70 71 protected String id = null; 72 73 74 75 protected boolean ignore = false; 76 77 78 79 protected String name = null; 80 81 82 83 protected String scope = null; 84 85 86 87 private static Logger logger = Logger.getLogger(MBeanAttributeEditorTag.class); 88 89 90 91 private static MessageResources messages = MessageResources.getMessageResources("org.ejtools.jmx.browser.web.taglib.MBeanAttributeInfoEditor"); 92 93 94 95 96 97 108 109 public int doStartTag() 110 111 throws JspException 112 113 { 114 115 117 MBeanParameterInfo info = (MBeanParameterInfo ) RequestUtils.lookup(pageContext, name, scope); 118 119 120 121 if (ignore) 122 123 { 124 125 if (info == null) 126 127 { 128 129 return (SKIP_BODY); 130 131 } 132 133 135 } 136 137 138 139 PropertyEditor propertyeditor = null; 140 141 Class c = ClassTools.getClass(info.getType()); 142 143 144 145 logger.debug("Parameter class " + c); 146 147 148 149 if (c == null) 150 151 { 152 153 this.addUnsupportedParameter(); 154 155 } 156 157 else 158 159 { 160 161 if (c.isArray()) 162 163 { 164 165 this.addUnsupportedArrayParameter(); 166 167 } 168 169 else 170 171 { 172 173 propertyeditor = CustomPropertyEditorManager.findEditor(c); 174 175 176 177 logger.debug("Property Editor " + propertyeditor); 178 179 180 181 if (propertyeditor == null) 182 183 { 184 185 this.addUnsupportedParameter(); 186 187 } 188 189 else 190 191 { 192 193 this.addParameter(propertyeditor, info); 194 195 } 196 197 } 198 199 } 200 201 202 203 205 return (SKIP_BODY); 206 207 } 208 209 210 211 212 213 224 225 public boolean getFilter() 226 227 { 228 229 return (this.filter); 230 231 } 232 233 234 235 236 237 244 245 public String getId() 246 247 { 248 249 return (this.id); 250 251 } 252 253 254 255 256 257 268 269 public boolean getIgnore() 270 271 { 272 273 return (this.ignore); 274 275 } 276 277 278 279 280 281 292 293 public String getName() 294 295 { 296 297 return (this.name); 298 299 } 300 301 302 303 304 305 316 317 public String getScope() 318 319 { 320 321 return (this.scope); 322 323 } 324 325 326 327 328 329 330 331 public void release() 332 333 { 334 335 super.release(); 336 337 filter = true; 338 339 ignore = false; 340 341 name = null; 342 343 scope = null; 344 345 id = null; 346 347 } 348 349 350 351 352 353 362 363 public void setFilter(boolean filter) 364 365 { 366 367 this.filter = filter; 368 369 } 370 371 372 373 374 375 384 385 public void setId(String id) 386 387 { 388 389 this.id = id; 390 391 } 392 393 394 395 396 397 406 407 public void setIgnore(boolean ignore) 408 409 { 410 411 this.ignore = ignore; 412 413 } 414 415 416 417 418 419 428 429 public void setName(String name) 430 431 { 432 433 this.name = name; 434 435 } 436 437 438 439 440 441 450 451 public void setScope(String scope) 452 453 { 454 455 this.scope = scope; 456 457 } 458 459 460 461 462 463 476 477 protected void addParameter(PropertyEditor propertyeditor, MBeanParameterInfo info) 478 479 throws JspException 480 481 { 482 483 StringBuffer buffer = new StringBuffer (); 484 485 int id = -1; 486 487 488 489 logger.debug("addParameter " + propertyeditor + " " + info.getName()); 490 491 492 493 try 494 495 { 496 497 Integer value = (Integer ) pageContext.getAttribute(getId()); 498 499 id = value.intValue(); 500 501 } 502 503 catch (Exception e) 504 505 { 506 507 logger.error("Exception during numbering reading " + e.getMessage()); 508 509 throw new JspException (e.getMessage()); 510 511 } 512 513 514 515 buffer.append("<input type=\"hidden\" name=\":parameter:"); 516 517 buffer.append(id); 518 519 buffer.append("\" value=\""); 520 521 buffer.append(info.getType()); 522 523 buffer.append("\"/>"); 524 525 526 527 buffer.append("<input type=\"hidden\" name=\":editor:"); 528 529 buffer.append(id); 530 531 buffer.append("\" value=\""); 532 533 buffer.append(propertyeditor.getClass().getName()); 534 535 buffer.append("\"/>"); 536 537 538 539 541 if (("java.lang.Boolean".equals(info.getType())) || ("boolean".equals(info.getType()))) 542 543 { 544 545 buffer.append("<select name=\":value:"); 546 547 buffer.append(id); 548 549 buffer.append("\">"); 550 551 552 553 buffer.append("<option value=\"true\">"); 554 555 buffer.append(messages.getMessage("boolean.true")); 556 557 buffer.append("</option>"); 558 559 560 561 buffer.append("<option value=\"false\">"); 562 563 buffer.append(messages.getMessage("boolean.false")); 564 565 buffer.append("</option>"); 566 567 568 569 buffer.append("</select>"); 570 571 } 572 573 575 else 576 577 { 578 579 buffer.append("<input type=\"text\" name=\":value:"); 580 581 buffer.append(id); 582 583 buffer.append("\"/>"); 584 585 } 586 587 588 589 ResponseUtils.write(pageContext, buffer.toString()); 590 591 } 592 593 594 595 596 597 608 609 protected void addUnsupportedArrayParameter() 610 611 throws JspException 612 613 { 614 615 String output = "Unsupported Array Paramater"; 616 617 618 619 if (filter) 620 621 { 622 623 output = "<i>" + ResponseUtils.filter(output) + "</i>"; 624 625 } 626 627 else 628 629 { 630 631 output = "<i>" + output + "</i>"; 632 633 } 634 635 636 637 ResponseUtils.write(pageContext, output); 638 639 } 640 641 642 643 644 645 656 657 protected void addUnsupportedParameter() 658 659 throws JspException 660 661 { 662 663 String output = "Unsupported Parameter"; 664 665 666 667 if (filter) 668 669 { 670 671 output = "<i>" + ResponseUtils.filter(output) + "</i>"; 672 673 } 674 675 else 676 677 { 678 679 output = "<i>" + output + "</i>"; 680 681 } 682 683 684 685 ResponseUtils.write(pageContext, output); 686 687 } 688 689 } 690 691 | Popular Tags |