1 23 24 28 29 package com.sun.enterprise.tools.admingui.handlers; 30 31 import java.io.IOException ; 32 import java.io.InputStream ; 33 import java.lang.reflect.UndeclaredThrowableException ; 34 import java.text.DateFormat ; 35 import java.util.ArrayList ; 36 import java.util.Date ; 37 import java.util.List ; 38 import java.util.Stack ; 39 import java.util.EventObject ; 40 import java.util.StringTokenizer ; 41 import java.util.Enumeration ; 42 import java.util.HashMap ; 43 import java.util.Map ; 44 import java.util.Properties ; 45 46 import com.iplanet.jato.RequestContext; 47 import com.iplanet.jato.RequestContextImpl; 48 import com.iplanet.jato.RequestManager; 49 import com.iplanet.jato.ViewBeanManager; 50 import com.iplanet.jato.model.DefaultModel; 51 import com.iplanet.jato.model.Model; 52 import com.iplanet.jato.ModelManager; 53 import com.iplanet.jato.util.RootCauseException; 54 import com.iplanet.jato.view.ContainerView; 55 import com.iplanet.jato.view.ContainerViewBase; 56 import com.iplanet.jato.view.View; 57 import com.iplanet.jato.view.DisplayFieldImpl; 58 import com.iplanet.jato.view.DisplayField; 59 import com.iplanet.jato.view.ViewBase; 60 import com.iplanet.jato.view.ViewBean; 61 import com.iplanet.jato.view.html.SelectableGroup; 62 import com.iplanet.jato.view.html.OptionList; 63 import com.iplanet.jato.view.html.HREF; 64 import com.iplanet.jato.view.event.RequestInvocationEvent; 65 import com.iplanet.jato.view.event.ViewRequestInvocationEvent; 66 import com.iplanet.jato.view.event.ViewCommandEvent; 67 import com.iplanet.jato.view.event.ChildContentDisplayEvent; 68 69 import javax.management.MBeanException ; 70 import javax.management.ObjectName ; 71 import javax.management.AttributeList ; 72 import javax.management.Attribute ; 73 74 import javax.servlet.ServletException ; 75 import javax.servlet.ServletRequest ; 76 import javax.servlet.http.HttpServletRequest ; 77 import javax.servlet.http.HttpSession ; 78 79 import com.sun.appserv.management.util.misc.ExceptionUtil; 80 81 import com.sun.enterprise.tools.guiframework.view.descriptors.CCPropertySheetDescriptor; 82 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 83 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle; 84 import com.sun.enterprise.tools.guiframework.view.DescriptorCCTabs; 85 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 86 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 87 import com.sun.enterprise.tools.guiframework.view.ViewDescriptorManager; 88 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 89 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent; 90 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent; 91 92 import com.sun.web.ui.model.CCActionTableModelInterface; 93 import com.sun.web.ui.model.CCPropertySheetModelInterface; 94 import com.sun.web.ui.taglib.html.CCDropDownMenuTag; 95 import com.sun.web.ui.taglib.pagetitle.CCPageTitleTag; 96 import com.sun.web.ui.view.html.CCButton; 97 import com.sun.web.ui.view.html.CCCheckBox; 98 import com.sun.web.ui.view.html.CCTextField; 99 import com.sun.web.ui.view.html.CCOption; 100 import com.sun.web.ui.view.html.CCOptionGroup; 101 import com.sun.web.ui.view.html.CCOptionSeparator; 102 import com.sun.web.ui.view.propertysheet.CCPropertySheet; 103 import com.sun.web.ui.view.tabs.CCTabs; 104 105 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 106 import com.sun.enterprise.tools.admingui.util.Util; 107 import com.sun.enterprise.tools.admingui.ConfigProperties; 108 import com.iplanet.jato.view.CommandFieldBase; 109 110 113 public class CommonHandlers { 114 115 public void invokeMBean(RequestContext ctx, HandlerContext handlerCtx) { 116 View view = handlerCtx.getView(); 117 118 Object objectName = handlerCtx.getInputValue("objectName"); 119 if (objectName == null) { 120 throw new FrameworkException("'objectName' is null in CommonHandlers.invokeMBean"); 121 } 122 String methodName = (String )handlerCtx.getInputValue("methodName"); 123 if (methodName == null) { 124 throw new FrameworkException("'methodName' is null in CommonHandlers.invokeMBean"); 125 } 126 ArrayList types = (ArrayList )handlerCtx.getInputValue("types"); 127 ArrayList params = (ArrayList )handlerCtx.getInputValue("params"); 128 129 130 Object [] paramsAndTypes = MBeanUtil.getParamsAndTypes(params, types); 131 132 Object returnValue = null; 133 try { 134 returnValue = MBeanUtil.invoke(objectName.toString(), methodName, 150 (Object [])(paramsAndTypes[0]), (String [])(paramsAndTypes[1])); 151 152 } catch (Exception ex) { 153 if (ex.getCause().getCause() instanceof javax.management.InstanceNotFoundException ) { 154 if (Util.isLoggableFINE()) { 157 Util.logFINE("caught: InstanceNotFoundException"); 158 } 159 } else { 160 while (!(view instanceof DescriptorContainerView) && 161 (view != null)) { 162 view = view.getParent(); 163 } 164 ViewDescriptor vd = (view != null) ? 165 ((DescriptorContainerView)view).getViewDescriptor(): null; 166 throw new FrameworkException(ex, vd, view); 170 } 171 } 172 handlerCtx.setOutputValue(VALUE, returnValue); 173 handlerCtx.setOutputValue("hasValue", new Boolean (returnValue != null).toString()); 174 } 176 177 public void getMBeanAttribute(RequestContext ctx, HandlerContext handlerCtx) { 178 String objectName = (String ) handlerCtx.getInputValue("objectName"); 179 if (objectName == null) { 180 throw new FrameworkException("'objectName' is null in CommonHandlers.getMBeanAttribute"); 181 } 182 String attributeName = (String )handlerCtx.getInputValue("attributeName"); 183 if (attributeName == null) { 184 throw new FrameworkException("'attributeName' is null in CommonHandlers.getMBeanAttribute"); 185 } 186 Object value = null; 187 try { 188 value = MBeanUtil.getAttribute(objectName, attributeName); 189 } catch (Exception ex) { 190 throw new FrameworkException("Error in CommonHandlers.getMBeanAttribute: ", ex); 191 } 192 handlerCtx.setOutputValue(VALUE, value); 193 } 194 195 public void getCurrentPageName(RequestContext ctx, HandlerContext handlerCtx) { 197 handlerCtx.setOutputValue(VALUE, Util.getCurrentViewURL(ctx)); 198 } 199 200 private boolean firstObjectSet = false; 201 202 private boolean addOption(String objectName, OptionList optionList, 203 CCOptionGroup optionGroup, HandlerContext ctx) { 204 boolean itemsAdded = false; 205 try { 206 Object [] stats = (Object []) MBeanUtil.invoke( 209 objectName, "getStatistics", null, null); 210 if (stats == null || stats.length == 0) 212 return itemsAdded; } catch (Exception ex) { 214 return itemsAdded; 216 } 217 if (firstObjectSet == false) { 219 firstObjectSet = true; 220 ctx.setOutputValue("objectName", objectName); 221 } 222 223 String name = (String ) MBeanUtil.invoke( 226 objectName, "getName", null, null); 227 if (optionGroup != null) { 229 optionGroup.add(new CCOption(name, objectName)); 230 itemsAdded = true; 231 } else { 233 optionList.add(new CCOption(name, objectName)); 234 } 237 return itemsAdded; 238 } 239 240 private boolean fillMenuOptions(String objectName, OptionList optionList, 241 CCOptionGroup optionGroup, Stack ogStack, boolean doGrouping, 242 HandlerContext ctx) { 243 boolean itemsAdded = false; 244 245 ObjectName [] childObjects = null; 246 try { 247 childObjects = (ObjectName [])MBeanUtil.invoke( 249 objectName, "getChildren", null, null); 250 } catch (Exception ex) { 252 } 255 if (childObjects != null && childObjects.length > 0) { 256 CCOptionGroup og = optionGroup; 257 if (doGrouping) { 258 String name = (String ) MBeanUtil.invoke( 259 objectName, "getName", null, null); 260 og = new CCOptionGroup(name, name); 261 } 263 itemsAdded = addOption(objectName, optionList, og, ctx); 265 for (int i=0; i<childObjects.length; i++) { 267 if (childObjects[i] != null) { 269 itemsAdded |= fillMenuOptions(childObjects[i].toString(), 270 optionList, og, ogStack, doGrouping, ctx); 271 } 272 } 273 if (itemsAdded && doGrouping) { 274 ogStack.push(og); return false; 279 } 280 } else { 281 itemsAdded = addOption(objectName, optionList, optionGroup, ctx); 283 } 284 return itemsAdded; 285 } 286 287 public void populateMonitorDropDown(RequestContext ctx, HandlerContext handlerCtx) { 288 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 290 291 ArrayList objs = (ArrayList ) handlerCtx.getInputValue("monitorObjects"); 292 Boolean doGrouping = (Boolean ) handlerCtx.getInputValue("doGrouping"); 293 OptionList optionList = new OptionList(); 294 Stack optGroupStack = new Stack (); 295 firstObjectSet = false; 296 boolean itemsAdded = false; 297 298 for ( int i=0; i<objs.size(); i++) { 299 String objectName = (String )objs.get(i); 300 if (objectName == null) 301 continue; 302 if (itemsAdded) 303 optionList.add(new CCOptionSeparator()); 304 itemsAdded = fillMenuOptions(objectName, optionList, null, 305 optGroupStack, doGrouping.booleanValue(), handlerCtx); 306 while (optGroupStack.empty() == false) { 307 optionList.add((CCOptionGroup)optGroupStack.pop()); 308 } 309 } 310 dropDownChild.setOptions(optionList); 311 } 312 313 public void populateMonitorAppsDropDown(RequestContext ctx, HandlerContext handlerCtx) { 314 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 316 317 String appsObject = (String ) handlerCtx.getInputValue("appsObjectName"); 318 ObjectName [] objs = null; 319 try { 320 objs = (ObjectName [])MBeanUtil.invoke( 321 appsObject, "getChildren", null, null); 322 } catch (Exception ex) { 323 } 325 OptionList optionList = new OptionList(); 326 optionList.add(new CCOption("","")); 327 if (objs != null) { 328 for ( int i=0; i<objs.length; i++) { 329 String name = null; 330 try { 331 name = (String ) MBeanUtil.invoke(objs[i], "getName", null, null); 333 } catch (Exception ex) { 334 continue; } 336 optionList.add(new CCOption(name, objs[i].toString())); 337 } 338 } 339 dropDownChild.setOptions(optionList); 340 } 341 342 public void populateNodeAgentsDropDown(RequestContext ctx, HandlerContext handlerCtx) { 343 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 344 DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent(); 346 347 ViewDescriptor vd = parent.getViewDescriptor(); 349 ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName()); 350 351 String methodName = (String )handlerCtx.getInputValue("dropDownMethodName"); 352 String objectName = (String )handlerCtx.getInputValue("dropDownObjectName"); 353 ArrayList params = (ArrayList )handlerCtx.getInputValue("params"); 354 ArrayList types = (ArrayList )handlerCtx.getInputValue("types"); 355 356 if (objectName == null || methodName == null) { 357 throw new FrameworkException("objectName or methodName is null", 358 cvd, handlerCtx.getView()); 359 } 360 try { 361 Object [] objs = getNodeAgentsAsDropDown(methodName,objectName, params, types); 362 String []naNames = (String []) objs[0]; 363 String []naNamesWithHosts = (String []) objs[1]; 364 OptionList optionList = new OptionList(naNamesWithHosts, naNames); 365 dropDownChild.setOptions(optionList); 366 } catch (Exception ex) { 367 throw new FrameworkException(ex, cvd, handlerCtx.getView()); 368 } 369 370 } 371 372 public void getNodeAgentsWithHosts(RequestContext ctx, HandlerContext handlerCtx) { 373 374 String methodName = (String )handlerCtx.getInputValue("methodName"); 375 String objectName = (String )handlerCtx.getInputValue("objectName"); 376 ArrayList params = (ArrayList )handlerCtx.getInputValue("params"); 377 ArrayList types = (ArrayList )handlerCtx.getInputValue("types"); 378 379 if (objectName == null || methodName == null) { 380 throw new FrameworkException("objectName or methodName is null", null, handlerCtx.getView()); 381 } 382 try { 383 Object [] objs = getNodeAgentsAsDropDown(methodName,objectName, params, types); 384 handlerCtx.setOutputValue("naNames", objs[0]); 385 handlerCtx.setOutputValue("naNamesWithHosts", objs[1]); 386 }catch (Exception ex){ 387 throw new FrameworkException(ex, null, handlerCtx.getView()); 388 } 389 } 390 391 public void addWebAppsFromEntApps(RequestContext ctx, HandlerContext handlerCtx) { 392 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 395 OptionList options = dropDownChild.getOptions(); 396 397 try { 398 ObjectName [] objectNames = (ObjectName [])MBeanUtil.invoke( 399 "com.sun.appserv:type=applications,category=config", 400 "getAllDeployedJ2EEApplications", 401 null, null); 402 403 for (int i = 0; i < objectNames.length; i++) { 404 String appName = objectNames[i].getKeyProperty("name"); 406 407 String [] modules = (String [])MBeanUtil.invoke( 408 "com.sun.appserv:type=applications,category=config", 409 "getModuleComponents", 410 new Object []{appName}, 411 new String []{"java.lang.String"}); 412 413 for (int j = 0; j < modules.length; j++) { 414 ObjectName moduleName = new ObjectName (modules[j]); 416 417 String type = moduleName.getKeyProperty("j2eeType"); 418 if (type != null && type.equalsIgnoreCase("WebModule")) { 419 String name = moduleName.getKeyProperty("name"); 420 String entry = appName+"#"+name; 421 options.add(entry, entry); 422 } 423 } 424 } 425 } catch (Exception ex) { 426 if (Util.isLoggableFINE()) { 427 Util.logFINE(ex); 428 } 429 } 430 } 431 432 public void populateDropDown(RequestContext ctx, HandlerContext handlerCtx) { 434 435 SelectableGroup dropDownChild = (SelectableGroup) getSelectableGroup(handlerCtx); 436 populateDropDown(handlerCtx, dropDownChild); 437 String initialValue = (String )handlerCtx.getInputValue("initialValue"); 438 if (initialValue == null || initialValue.length() == 0) { 439 dropDownChild.setLabelForNoneSelected(" "); 440 } else { 441 if (dropDownChild.getValue() == null) { 443 dropDownChild.setValue(initialValue); 444 } 445 } 446 } 447 448 private SelectableGroup getSelectableGroup(HandlerContext handlerCtx){ 449 Object displayField = handlerCtx.getInputValue("displayField"); 450 if (displayField == null) 451 displayField = handlerCtx.getView(); 452 453 if (! (displayField instanceof SelectableGroup)){ 454 throw new FrameworkException("No displayField specified and current view is NOT a dropdown in populateDropDown"); 455 } 456 return (SelectableGroup) displayField; 457 } 458 459 private void populateDropDown(HandlerContext handlerCtx, SelectableGroup dropDownChild){ 460 461 DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent(); 463 ViewDescriptor vd = parent.getViewDescriptor(); 465 ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName()); 466 467 String methodName = (String )handlerCtx.getInputValue("dropDownMethodName"); 468 String objectName = (String )handlerCtx.getInputValue("dropDownObjectName"); 469 String attributeName = (String )handlerCtx.getInputValue("dropDownAttributeName"); 470 ArrayList params = (ArrayList )handlerCtx.getInputValue("params"); 471 ArrayList types = (ArrayList )handlerCtx.getInputValue("types"); 472 473 474 if (objectName == null || methodName == null) { 475 throw new FrameworkException("dropDownObjectName or dropDownMethodName is null in populateDropDown"); 476 } 477 478 Object [] paramsAndTypes = MBeanUtil.getParamsAndTypes(params, types); 479 try { 481 Object returnValue = MBeanUtil.invoke(objectName, methodName, 482 (Object [])(paramsAndTypes[0]), (String [])(paramsAndTypes[1])); 483 if (returnValue == null) 484 return; 485 String [] choices = null; 486 if (returnValue instanceof ObjectName []) { 487 ObjectName [] objectNameList = (ObjectName [])returnValue; 488 choices = new String [objectNameList.length]; 489 if (attributeName == null) 490 attributeName = "name"; 491 for(int i =0; i < choices.length; i++) { 492 String dropDownChoice = (String ) 493 MBeanUtil.getAttribute(objectNameList[i], attributeName); 494 choices[i] = dropDownChoice; 495 } 496 } 497 else if (returnValue instanceof String []) { 498 choices = (String [])returnValue; 499 } 500 501 OptionList dropDownMenuOptions = new OptionList(choices,choices); dropDownChild.setOptions(dropDownMenuOptions); 503 } catch (Exception ex) { 504 throw new FrameworkException(ex, cvd, handlerCtx.getView()); 505 } 506 507 } 508 509 public void populateResourceAdapter(RequestContext ctx, HandlerContext handlerCtx) { 510 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 512 DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent(); 514 515 ViewDescriptor vd = parent.getViewDescriptor(); 517 ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName()); 518 519 dropDownChild.setLabelForNoneSelected(" "); 520 try { 521 ObjectName [] dropDownObjectName = (ObjectName []) MBeanUtil.invoke( 522 "com.sun.appserv:type=applications,category=config", 523 "getAllDeployedConnectors", null, null); 524 531 532 String [] systemConnectors = 533 (String []) MBeanUtil.invoke("com.sun.appserv:type=resources,category=config", 534 "getSystemConnectorsAllowingPoolCreation", null, null); 535 536 String [] embeddedConnectors = null; 538 try { 539 String [] types = new String []{"java.lang.String", "java.lang.String"}; 540 Object [] params = new Object []{null, "domain" }; 541 embeddedConnectors = (String []) MBeanUtil.invoke( 542 "com.sun.appserv:type=applications,category=config", 543 "getEmbeddedConnectorNames", params, types); 544 }catch(Exception ex){ 545 Util.logINFO("Exception when calling getEmbeddedConnectorNames"); 546 ex.printStackTrace(); 547 } 548 549 557 558 int numAdapters = 559 (dropDownObjectName==null?0:dropDownObjectName.length) + 560 (embeddedConnectors==null?0:embeddedConnectors.length) + 561 (systemConnectors==null?0:systemConnectors.length); 562 563 String [] choices = new String [numAdapters]; 564 int i = 0; 565 if(dropDownObjectName != null) { 566 for(;i < dropDownObjectName.length; i++) { 567 String dropDownChoice = (String ) 569 MBeanUtil.getAttribute(dropDownObjectName[i], "name"); 570 choices[i] = dropDownChoice; 571 } 573 } 574 if (embeddedConnectors != null) { 575 for(int j = 0; j < embeddedConnectors.length; j++, i++) { 576 choices[i] = embeddedConnectors[j]; 577 } 579 } 580 if (systemConnectors != null) { 581 for(int j = 0; j < systemConnectors.length; j++, i++) { 582 choices[i] = systemConnectors[j]; 583 } 585 } 586 OptionList dropDownMenuOptions = new OptionList(choices,choices); dropDownChild.setOptions(dropDownMenuOptions); 588 } catch (Exception ex) { 589 throw new FrameworkException(ex, cvd, handlerCtx.getView()); 590 } 591 } 592 593 public void populateServerInstances(RequestContext ctx, HandlerContext handlerCtx) { 596 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 598 DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent(); 600 601 ViewDescriptor vd = parent.getViewDescriptor(); 603 ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName()); 604 boolean isEE = ConfigProperties.getInstance().getTargetSupported().booleanValue(); 605 Boolean onlyRunningServer = (Boolean ) handlerCtx.getInputValue("onlyRunningServer"); 606 try { 607 ArrayList results = new ArrayList (); 608 if (isEE){ 609 results.add(""); 610 results.add("server"); 611 Object unclustered = MBeanUtil.invoke("com.sun.appserv:type=servers,category=config", 612 "listUnclusteredServerInstances", null, null); 613 addToString(results, unclustered, onlyRunningServer); 614 ObjectName [] clusters = 615 (ObjectName []) MBeanUtil.invoke("com.sun.appserv:type=clusters,category=config", 616 "getCluster", null, null); 617 if (clusters != null){ 618 for(int i=0; i< clusters.length; i++){ 619 String clusterName = (String )MBeanUtil.getAttribute(clusters[i], "name"); 620 String objectName= "com.sun.appserv:type=cluster,name=" + 621 clusterName + ",category=config"; 622 Object clustered = MBeanUtil.invoke(objectName, 623 "listServerInstances", null,null); 624 addToString(results, clustered, onlyRunningServer); 625 } 626 } 627 }else{ 628 results.add("server"); 629 } 630 631 String [] choices = new String [results.size()]; 632 for(int i=0; i< results.size(); i++){ 633 choices[i] = (String ) results.get(i); 634 } 635 636 OptionList dropDownMenuOptions = new OptionList(choices,choices); dropDownChild.setOptions(dropDownMenuOptions); 638 } catch (Exception ex) { 639 throw new FrameworkException(ex, cvd, handlerCtx.getView()); 640 } 641 } 642 643 644 public void setDropDownOptions(RequestContext ctx, HandlerContext handlerCtx) { 645 SelectableGroup dropDownChild = (SelectableGroup)handlerCtx.getInputValue(DISPLAY_FIELD); 647 Object names = handlerCtx.getInputValue("names"); 648 Object labels = handlerCtx.getInputValue("labels"); 649 if (names instanceof String []){ 650 OptionList dropDownMenuOptions = new OptionList((String []) labels,(String []) names); dropDownChild.setOptions(dropDownMenuOptions); 652 }else 653 if (names instanceof ArrayList ){ 654 ArrayList nm = (ArrayList )names; 655 ArrayList lb = (ArrayList )labels; 656 657 OptionList dropDownMenuOptions = new OptionList( 658 (String []) nm.toArray(new String [ nm.size()]), 659 (String []) lb.toArray(new String [lb.size()])); 660 661 dropDownChild.setOptions(dropDownMenuOptions); 662 }else{ 663 throw new FrameworkException("setDropDownOptions() expects String[] or ArrayList for parameter names and labels"); 664 } 665 } 666 667 668 673 public void populateList(RequestContext ctx, HandlerContext handlerCtx) { 674 675 SelectableGroup dropDownChild = (SelectableGroup) getSelectableGroup(handlerCtx); 677 populateDropDown(handlerCtx, dropDownChild); 678 String initialValue = (String )handlerCtx.getInputValue("initialValue"); 680 dropDownChild.setLabelForNoneSelected(" "); 681 if (initialValue == null){ 682 String attributeName = (String )handlerCtx.getInputValue("selectAttribute"); 683 String objectName = (String )handlerCtx.getInputValue("selectObjectName"); 684 initialValue = (String ) MBeanUtil.getAttribute(objectName, attributeName); 685 } 686 687 if (initialValue != null){ 688 String [] eachRow = initialValue.split(","); 689 if (eachRow != null & eachRow.length > 0){ 690 dropDownChild.setValues(eachRow); 691 } 692 } 693 } 694 695 public void setDropDownOptionsAndDefaultValue(RequestContext ctx, HandlerContext handlerCtx) { 696 SelectableGroup dropDownChild = (SelectableGroup)handlerCtx.getInputValue(DISPLAY_FIELD); 698 String [] names = (String []) handlerCtx.getInputValue("names"); 699 String [] labels = (String []) handlerCtx.getInputValue("labels"); 700 OptionList dropDownMenuOptions = new OptionList(labels,names); dropDownChild.setOptions(dropDownMenuOptions); 702 if( (names!=null) && names.length > 0) 703 dropDownChild.setValue(names[0]); 704 } 705 706 public void isInArray(RequestContext ctx, HandlerContext handlerCtx) { 707 String s = (String )handlerCtx.getInputValue("string"); 708 String [] array = (String []) handlerCtx.getInputValue("array"); 709 Boolean isInArray = Boolean.FALSE; 710 for (int i=0; i< array.length; i++) { 711 if (s.equals(array[i])) { 712 isInArray = Boolean.TRUE; 713 break; 714 } 715 } 716 handlerCtx.setOutputValue("isInArray", isInArray); 717 } 718 719 private void addToString(ArrayList result, Object obj, Boolean onlyRunningServer) 720 { 721 boolean includeAll = true; 722 if (obj == null) 723 return; 724 if ((onlyRunningServer != null) && onlyRunningServer.booleanValue()) 725 includeAll = false; 726 if (obj instanceof String []){ 727 String [] ss = (String []) obj; 728 for(int i=0; i< ss.length; i++){ 729 if (includeAll) 730 result.add(ss[i]); 731 else{ 732 if (LogViewerHandler.isServerRunning(ss[i])) 733 result.add(ss[i]); 734 } 735 } 736 }else 737 if (obj instanceof ObjectName []){ 738 ObjectName [] oo = (ObjectName [])obj; 739 for(int i =0; i < oo.length; i++) { 740 String nm = (String )MBeanUtil.getAttribute(oo[i], "name"); 741 if (includeAll) 742 result.add(nm); 743 else{ 744 if (LogViewerHandler.isServerRunning(nm)) 745 result.add(nm); 746 } 747 } 748 } 749 } 750 751 752 760 public void logout(RequestContext ctx, HandlerContext handlerCtx) { 761 ctx.getRequest().getSession().removeAttribute("AdminGUItimeOut"); 762 ctx.getRequest().getSession().invalidate(); 763 RequestContextImpl.markResponseStarted(ctx); 764 try { 765 ctx.getServletContext().getRequestDispatcher(ENTRY_URI). 766 forward(ctx.getRequest(), ctx.getResponse()); 767 } catch (ServletException ex) { 768 throw new FrameworkException(ex, null, handlerCtx.getView()); 769 } catch (IOException ex) { 770 throw new FrameworkException(ex, null, handlerCtx.getView()); 771 } 772 } 773 774 public void handleTabHrefRequest(RequestContext ctx, HandlerContext handlerCtx) { 775 View view = handlerCtx.getView(); 776 View tabset = view.getParent(); ViewBean vb = (ViewBean)tabset.getParent(); 778 779 try { 780 DescriptorCCTabs tabs = (DescriptorCCTabs)vb.getChild(tabset.getName()); 781 782 ViewCommandEvent ev = (ViewCommandEvent)handlerCtx.getEvent(); 784 RequestInvocationEvent reqEvent = 785 new ViewRequestInvocationEvent(ev.getSource(), ctx, 786 ev.getInvocation()); 787 tabs.handleTabHrefRequest(reqEvent); 788 } catch (Exception ex) { 789 throw new FrameworkException(ex, null, view); 790 } 791 } 792 793 794 public void beginDropDownDisplay(RequestContext ctx, HandlerContext handlerCtx) { 795 CCDropDownMenuTag tag = (CCDropDownMenuTag)handlerCtx.getEvent().getSource(); 796 tag.setOnChange("javascript: loadRightSide();"); 797 } 798 799 static public void setTimeOut(RequestContext rc) { 800 String timeOut = null; 802 try { 803 timeOut = (String )MBeanUtil.getAttribute( 804 "ias:type=das-config,config=server-config,category=config", 805 "admin-session-timeout-in-minutes"); 806 } catch (Exception ex) { 807 throw new FrameworkException( 808 "Exception throw in trying to get '"+ 809 "admin_session_timeout_in_minutes'", ex); 810 } 811 if ((timeOut != null) && !timeOut.equals("")) { 812 try { 813 int time = new Integer (timeOut).intValue(); 814 HttpServletRequest req = rc.getRequest(); 815 if (time == 0) { 816 req.getSession().setMaxInactiveInterval(-1); 817 } else { 818 req.getSession().setMaxInactiveInterval(time*60); 819 } 820 if (Util.isLoggableFINE()) { 821 Util.logFINE("Setting session time out to "+timeOut+" minutes."); 822 } 823 } catch (NumberFormatException ex) { 824 throw new FrameworkException( 825 "Unable to convert '"+timeOut+"'!", ex); 826 } 827 } 828 } 829 830 831 834 public void showTimeOut(RequestContext ctx, HandlerContext handlerCtx) throws Exception { 835 View view = handlerCtx.getView(); 836 String timeOut = (String )((CCTextField)view).getValue(); 837 if (timeOut == null || timeOut.equals("")) { 838 HttpServletRequest req = ctx.getRequest(); 839 int time = req.getSession().getMaxInactiveInterval(); 840 if (time <= 0) 841 ((CCTextField)view).setValue("0"); 842 else 843 ((CCTextField)view).setValue(""+(time/60)); 844 } 845 } 846 847 public void setFullTableName(RequestContext ctx, HandlerContext handlerCtx) { 848 View view = handlerCtx.getView(); 849 DescriptorContainerView descView = (DescriptorContainerView) 850 (((ViewBase)view).getParentViewBean()); 851 853 String childName = (String )handlerCtx.getInputValue("propertiesTableName"); 854 if (childName == null || childName.length() == 0) { 855 return; 856 } 857 childName = descView.getName() + "." + childName; 858 ((DisplayField)view).setValue(childName); 859 } 860 861 public void addValueToPropertiesList(RequestContext ctx, HandlerContext handlerCtx) { 862 Map props = (Map )handlerCtx.getInputValue("Properties"); 863 if (props == null || props.size() == 0) { 864 return; 865 } 866 String value = (String )handlerCtx.getInputValue("propertyValue"); 867 String key = (String )handlerCtx.getInputValue("propertyName"); 868 props.put(key, value); 869 handlerCtx.setOutputValue(VALUE, props); 870 handlerCtx.setOutputValue("props", new Properties ()); 871 } 872 873 public void getXMLFileFromClasspath(RequestContext ctx, HandlerContext handlerCtx) { 874 String fileName = (String )handlerCtx.getInputValue("fileName"); 875 if (fileName == null || fileName.length() == 0) { 876 return; 877 } 878 InputStream is = getClass().getClassLoader().getResourceAsStream(fileName); 879 handlerCtx.setOutputValue(VALUE, is); 880 } 881 882 885 public void deleteChildView(RequestContext ctx, HandlerContext handlerCtx) { 886 ServletRequest req = ctx.getRequest(); 888 889 ContainerViewBase base = (ContainerViewBase)handlerCtx.getInputValue("container"); 891 String childName = (String )handlerCtx.getInputValue("child"); 892 if ((base == null) || (childName == null)) { 893 throw new FrameworkException( 894 "'view' and/or 'child' attributes were null!", null, handlerCtx.getView()); 895 } 896 boolean clearModel = 897 new Boolean (""+handlerCtx.getInputValue("clearModel")).booleanValue(); 898 899 if (clearModel) { 901 Model model = (Model)handlerCtx.getInputValue("model"); 902 if (model == null) { 903 View child = base.getChild(childName); 904 if (child instanceof ContainerView) { 905 model = ((ContainerView)child).getDefaultModel(); 906 } else if (child instanceof DisplayFieldImpl) { 907 model = ((DisplayFieldImpl)child).getModel(); 908 } 909 } 910 if ((model != null) && (model instanceof DefaultModel)) { 911 ((DefaultModel)model).clear(); 912 } 913 } 914 915 base.removeChild(childName); 916 } 917 918 919 920 928 public void clearModels(RequestContext ctx, HandlerContext handlerCtx) { 929 Object obj = handlerCtx.getInputValue(MODEL_NAMES); 930 if (obj == null) { 931 throw new FrameworkException( 932 "You must specifiy 'models' to remove from Session."); 933 } 934 if (obj instanceof String ) { 935 ArrayList list = new ArrayList (); 936 list.add(obj); 937 obj = list; 938 } 939 if (!(obj instanceof List )) { 940 throw new FrameworkException( 941 "'"+MODEL_NAMES+"' must be a java.util.List!"); 942 } 943 String names[] = 944 (String [])((List )obj).toArray(new String [((List )obj).size()]); 945 946 HttpServletRequest req = ctx.getRequest(); 948 HttpSession session = req.getSession(); 949 ModelManager modelMgr = ctx.getModelManager(); 950 Model model = null; 951 for (int count=0; count<names.length; count++) { 952 obj = session.getAttribute(names[count]); 953 if (obj != null) { 954 model = (Model)obj; 955 if (model instanceof DefaultModel) { 956 ((DefaultModel)model).clear(); 959 } 960 modelMgr.removeFromSession(model); 961 } 962 } 963 } 964 965 966 969 public void dumpMBeanNames(RequestContext ctx, HandlerContext handlerCtx) { 970 try { 971 javax.management.MBeanServerConnection server = MBeanUtil.getMBeanServer(); 972 java.util.Iterator it = server.queryNames(null, null).iterator(); 973 StringBuffer buf = new StringBuffer (); 974 buf.append(" MBean Object Names:\n"); 975 buf.append("======================\n"); 976 while (it.hasNext()) { 977 buf.append(" * "+it.next().toString()); 978 } 979 { 980 Util.logCONFIG(buf.toString()); 981 } 982 } catch (Exception ex) { 983 } 985 } 986 987 public void parseFilterOptions(RequestContext ctx, HandlerContext handlerCtx) { 988 View view = handlerCtx.getView(); 989 990 String value = (String )handlerCtx.getInputValue("value"); 991 if (value != null) { 992 String [] values = value.split(";"); 993 handlerCtx.setOutputValue("methodName", values[0]); 994 if (values.length > 1) { 995 handlerCtx.setOutputValue("editPage", values[1]); 996 } 997 } 999 } 1000 1001 1005 public void clearCache(RequestContext ctx, HandlerContext handlerCtx) { 1006 ViewDescriptorManager.getInstance().clearCache(); 1007 } 1008 1009 public void dumpStack(RequestContext ctx, HandlerContext handlerCtx) { 1010 Thread.currentThread().dumpStack(); 1011 } 1012 1013 1016 public void dumpMBeanInfo(RequestContext ctx, HandlerContext handlerCtx) { 1017 String output = null; 1018 try { 1019 javax.management.MBeanServerConnection server = MBeanUtil.getMBeanServer(); 1020 java.util.Iterator it = server.queryNames(null, null).iterator(); 1021 StringBuffer buf = new StringBuffer (); 1022 buf.append("\n MBean Object Info:"); 1023 buf.append("================================"); 1024 ObjectName name; 1025 javax.management.MBeanInfo info; 1026 javax.management.MBeanOperationInfo opInfo[]; 1027 javax.management.MBeanParameterInfo paramInfo[]; 1028 javax.management.MBeanAttributeInfo attInfo[]; 1029 javax.management.MBeanNotificationInfo noteInfo[]; 1030 while (it.hasNext()) { 1031 buf.append("----------------------------\n"); 1032 name = (ObjectName )it.next(); 1033 buf.append(" OBJECT NAME: "+name.toString()+"\n"); 1034 try { 1035 info = server.getMBeanInfo(name); 1036 } catch (Exception ex) { 1037 throw new FrameworkException( 1038 "Can't get the MBeanInfo!", ex, null, handlerCtx.getView()); 1039 } 1040 buf.append(" CLASS NAME: "+info.getClassName()+"\n"); 1041 buf.append(" DESCRIPTION: "+info.getDescription()+"\n"); 1042 buf.append(" OPERATIONS:\n"); 1044 opInfo = info.getOperations(); 1045 for (int count=0; count<opInfo.length; count++) { 1046 if (opInfo[count] == null) { 1047 buf.append(" WARNING: opInfo["+count+"] is null!\n"); 1048 continue; 1049 } 1050 buf.append("\t* "+opInfo[count].getReturnType()+" "+opInfo[count].getName()+"("); 1051 paramInfo = opInfo[count].getSignature(); 1052 for (int idx=0; idx<paramInfo.length; idx++) { 1053 buf.append(paramInfo[idx].getType()) 1054 .append(" ") 1055 .append(paramInfo[idx].getName()) 1056 .append(" - ") 1057 .append(paramInfo[idx].getDescription()); 1058 if (idx<paramInfo.length-1) { 1059 buf.append(", "); 1060 } 1061 } 1062 buf.append(") - "+opInfo[count].getImpact()+"\n"); 1063 if (opInfo[count].getDescription() != null) 1064 buf.append("\t Desc: "+opInfo[count].getDescription()+"\n\n"); 1065 } 1066 buf.append(" Attributes:\n"); 1068 attInfo = info.getAttributes(); 1069 for (int count=0; count<attInfo.length; count++) { 1070 buf.append("\t* "+attInfo[count].getType()+" "+attInfo[count].getName()); 1071 if (attInfo[count].isIs()) { 1072 buf.append(" - HAS 'is' GETTER"); 1073 } 1074 if (!attInfo[count].isReadable()) { 1075 buf.append(" - NOT READABLE"); 1076 } 1077 if (!attInfo[count].isWritable()) { 1078 buf.append(" - NOT WRITABLE"); 1079 } 1080 if (attInfo[count].getDescription() != null) 1081 buf.append("\n\t Desc: "+attInfo[count].getDescription()+"\n"); 1082 } 1083 noteInfo = info.getNotifications(); 1085 if (noteInfo.length > 0) { 1086 buf.append(" Notifications:\n"); 1087 for (int count=0; count<noteInfo.length; count++) { 1088 buf.append("\t") 1089 .append(noteInfo[count].getName()) 1090 .append(" - ") 1091 .append(noteInfo[count].getDescription()+"\n"); 1092 String types[] = noteInfo[count].getNotifTypes(); 1093 buf.append("\t Notification Types: "); 1094 for (int idx=0; idx<types.length; idx++) { 1095 buf.append("\t\t"+types[idx]+"\n"); 1096 } 1097 buf.append("\n"); 1098 } 1099 } 1100 buf.append("\n"); 1101 } 1102 buf.append("======================\n"); 1103 output = buf.toString(); 1104 { 1105 Util.logCONFIG(output); 1106 } 1107 } catch (Exception ex) { 1108 } 1110 handlerCtx.setOutputValue(VALUE, output); 1111 } 1112 1113 1114 1123 public void mbeanExceptionCheck(RequestContext ctx, HandlerContext handlerCtx) { 1124 if (!(handlerCtx.getEvent() instanceof ErrorEvent)) { 1125 throw new FrameworkException( 1126 "This method is meant only for ErrorEvent types. This "+ 1127 "handler will attempt to find a message from the "+ 1128 "ErrorEvent's Exception", null, handlerCtx.getView()); 1129 } 1130 1131 Throwable ex = ((ErrorEvent)handlerCtx.getEvent()).getException(); 1133 if (ex == null) { 1134 throw new FrameworkException( 1135 "Exception is null, this is illegal!", null, handlerCtx.getView()); 1136 } 1137 Throwable last = ex; 1138 String message = null; 1139 String val = ex.getLocalizedMessage(); 1140 if (val == null) { 1141 val = ex.getMessage(); 1142 } 1143 if (val != null) { 1144 message = val; 1145 } 1146 boolean foundMBean = false; 1147 boolean foundAMX = false; 1148 while (ex != null) { 1149 if (ex instanceof RootCauseException) { 1151 ex = ((RootCauseException)ex).getRootCause(); 1152 } else { 1153 if (ex instanceof MBeanException ) { 1154 foundMBean = true; 1156 } else if (ex instanceof UndeclaredThrowableException ) { 1157 foundAMX = true; 1158 } 1159 if (foundAMX) { 1160 ex = ExceptionUtil.getRootCause(ex); 1161 } else { 1162 ex = ex.getCause(); 1163 } 1164 } 1165 1166 if (ex != null) { 1168 last = ex; 1169 val = ex.getLocalizedMessage(); 1170 if (val == null) { 1171 val = ex.getMessage(); 1172 } 1173 if (val != null) { 1174 message = val; 1175 if ((ex instanceof MBeanException ) || foundMBean || foundAMX) { 1176 break; 1177 } 1178 } 1179 } 1180 } 1181 1182 ServletRequest req = ctx.getRequest(); 1184 handlerCtx.setOutputValue(MBEAN_MESSAGE, 1185 (message == null) ? "error.NullMessage" : message); 1186 handlerCtx.setOutputValue(HAS_MBEAN_MESSAGE, TRUE); 1187 handlerCtx.setOutputValue(HAS_ERROR_MESSAGE, TRUE); 1188 handlerCtx.setOutputValue(ALERT_TYPE, "error"); 1189 handlerCtx.setOutputValue(ALERT_SUMMARY, "alert.Summary"); 1190 } 1191 1192 1193 1196 public void logException(RequestContext ctx, HandlerContext handlerCtx) { 1197 if (!Util.isLoggableINFO()) { 1198 return; 1199 } 1200 ServletRequest req = ctx.getRequest(); 1201 Throwable ex = (Throwable )handlerCtx.getInputValue(EXCEPTION_TO_LOG); 1202 String level = (String )handlerCtx.getInputValue(LEVEL); 1203 if (level == null) 1204 level = "FINE"; 1205 if (ex != null) { 1206 if (level.equalsIgnoreCase("FINEST")) 1207 Util.logFINEST(ex); 1208 else if (level.equalsIgnoreCase("FINER")) 1209 Util.logFINER(ex); 1210 else if (level.equalsIgnoreCase("FINE")) 1211 Util.logFINE(ex); 1212 else if (level.equalsIgnoreCase("CONFIG")) 1213 Util.logCONFIG(ex); 1214 else if (level.equalsIgnoreCase("INFO")) 1215 Util.logINFO(ex); 1216 else if (level.equalsIgnoreCase("WARNING")) 1217 Util.logWARNING(ex); 1218 else if (level.equalsIgnoreCase("SEVERE")) 1219 Util.logSEVERE(ex); 1220 } else { 1221 Util.logFINE(getClass().getName()+ 1222 ".logException() called without an exception to log."); 1223 } 1224 } 1225 1226 1243 public void isXGreaterThanY(RequestContext ctx, HandlerContext handlerCtx) { 1244 Long long1 = (Long )handlerCtx.getInputValue("X"); 1246 Long long2 = (Long )handlerCtx.getInputValue("Y"); 1247 if ((long1 == null) || (long2 == null)) { 1248 throw new FrameworkException(getClass().getName()+ 1249 ".isXGreaterThanY() requires both 'X' and 'Y' as request "+ 1250 "attributes.", null, handlerCtx.getView()); 1251 } 1252 1253 Boolean result = new Boolean (long1.longValue()>long2.longValue()); 1255 1256 handlerCtx.setOutputValue(VALUE, result); 1258 } 1259 1260 1264 public void longAdd(RequestContext ctx, HandlerContext handlerCtx) { 1265 Long long1 = (Long )handlerCtx.getInputValue(LONG_INTEGER_1); 1267 Long long2 = (Long )handlerCtx.getInputValue(LONG_INTEGER_2); 1268 if ((long1 == null) || (long2 == null)) { 1269 throw new FrameworkException(getClass().getName()+ 1270 ".longAdd() requires that both '"+LONG_INTEGER_1+"' and '"+ 1271 LONG_INTEGER_2+"' be supplied as request attributes.", 1272 null, handlerCtx.getView()); 1273 } 1274 1275 Long result = new Long (long1.longValue()+long2.longValue()); 1277 1278 handlerCtx.setOutputValue(LONG_ADD_RESULT, result); 1280 } 1281 1282 1283 1286 public void sleep(RequestContext ctx, HandlerContext handlerCtx) { 1287 try { 1288 Thread.currentThread().sleep(1*1000); 1289 } catch (Exception ex) { 1290 ex.printStackTrace(); 1291 } 1292 } 1293 1294 1299 public void throwException(RequestContext ctx, HandlerContext handlerCtx) { 1300 throw new RuntimeException ("Throwing an exception for testing "+ 1301 "purposes. The view name given to this handler is: '"+ 1302 handlerCtx.getView().getName()+"'. The EventObject is: '"+handlerCtx.getEvent()+ 1303 "'. The event.getSource() is: '"+handlerCtx.getEvent().getSource()+"'."); 1304 } 1305 1306 1309 public Boolean returnTrueIfEmpty(RequestContext ctx, HandlerContext handlerCtx) { 1310 Object value = handlerCtx.getInputValue("value"); 1311 if (value == null) 1312 return TRUE; 1313 if (value instanceof String ) 1314 return ( Util.isEmpty((String ) value)) ? TRUE: FALSE; 1315 if (value instanceof Object []) 1316 { int size = ((Object [])value).length; 1317 return (((Object [])value).length == 0) ? TRUE: FALSE; 1319 } 1320 return FALSE; 1321 } 1322 1323 1327 public Boolean returnFalse(RequestContext ctx, HandlerContext handlerCtx) { 1328 return FALSE; 1329 } 1330 1331 1332 1336 public Boolean returnTrue(RequestContext ctx, HandlerContext handlerCtx) { 1337 return TRUE; 1338 } 1339 1340 public void setExtraValuesMapInCommandField(RequestContext ctx, HandlerContext handlerCtx) { 1341 CommandFieldBase commandField = (CommandFieldBase)handlerCtx.getView(); 1342 HashMap m = new HashMap (); 1343 m.put((String )handlerCtx.getInputValue(NAME), 1344 handlerCtx.getInputValue("value")); 1345 commandField.setExtraValuesMap(m); 1346 } 1347 1348 1349 public void addExtraValueInCommandField(RequestContext ctx, HandlerContext handlerCtx) { 1350 CommandFieldBase commandField = (CommandFieldBase)handlerCtx.getView(); 1351 String name = ((String )handlerCtx.getInputValue(NAME)); 1352 String value = ((String )handlerCtx.getInputValue(VALUE)); 1353 commandField.addExtraValue(name, value); 1354 } 1355 1356 1359 public void isEqual(RequestContext ctx, HandlerContext handlerCtx) { 1360 Object key1 = handlerCtx.getInputValue("key1"); 1361 Object key2 = handlerCtx.getInputValue("key2"); 1362 Boolean result = FALSE; 1363 if (key1 != null && key2 != null) { 1364 result = new Boolean (key1.equals(key2)); 1365 } 1366 handlerCtx.setOutputValue("value", result); 1367 } 1368 1369 1372 public void isEqualsIgnoreCase(RequestContext ctx, HandlerContext handlerCtx) { 1373 String key1 = (String ) handlerCtx.getInputValue("key1"); 1374 String key2 = (String ) handlerCtx.getInputValue("key2"); 1375 Boolean result = FALSE; 1376 if (key1 != null && key2 != null) { 1377 result = new Boolean (key1.equalsIgnoreCase(key2)); 1378 } 1379 handlerCtx.setOutputValue("value", result); 1380 } 1381 1382 public void getNullIfEmpty(RequestContext ctx, HandlerContext handlerCtx) { 1385 Object obj = handlerCtx.getInputValue(VALUE); 1386 if (obj != null && obj instanceof String ) { 1387 String str = (String ) obj; 1388 if (str.trim().length() == 0) { 1389 obj = null; 1390 } 1391 } 1392 handlerCtx.setOutputValue(VALUE, obj); 1393 } 1394 1395 public void isValidMbean(RequestContext ctx, HandlerContext handlerCtx) { 1396 String objectName = (String )handlerCtx.getInputValue("mbeanName"); 1397 boolean valid = MBeanUtil.isValidMBean(objectName); 1398 handlerCtx.setOutputValue("isValid", new Boolean (valid)); 1399 } 1400 1401 public void convertStartEndDate(RequestContext ctx, HandlerContext handlerCtx) { 1402 String strStartDate = (String )handlerCtx.getInputValue("strStartDate"); 1403 String strEndDate = (String )handlerCtx.getInputValue("strEndDate"); 1404 DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); 1405 Date startDate = null; 1406 Date endDate = null; 1407 if (!Util.isEmpty(strStartDate)) { 1408 try { 1409 startDate = df.parse(strStartDate); 1410 } catch (java.text.ParseException pe) { 1411 throw new FrameworkException(Util.getMessage("msg.InvalidStartDateError", new Object []{strStartDate})); 1412 } 1413 } 1414 if(!Util.isEmpty(strEndDate)) { 1415 try { 1416 endDate = df.parse(strEndDate); 1417 } catch (java.text.ParseException pe) { 1418 throw new FrameworkException(Util.getMessage("msg.InvalidEndDateError", new Object []{strEndDate})); 1419 } 1420 } 1421 if (startDate != null && endDate != null) { 1422 if (startDate.after(endDate)) { 1423 throw new FrameworkException(Util.getMessage("msg.StartDateAfterEndDateError")); 1424 } 1425 } 1426 if (!Util.isEmpty(strStartDate) && Util.isEmpty(strEndDate)) { 1427 throw new FrameworkException(Util.getMessage("msg.MissingEndDateError")); 1428 } else if (Util.isEmpty(strStartDate) && !Util.isEmpty(strEndDate)) { 1429 throw new FrameworkException(Util.getMessage("msg.MissingStartDateError")); 1430 } 1431 1432 handlerCtx.setOutputValue("startDate", startDate); 1433 handlerCtx.setOutputValue("endDate", endDate); 1434 } 1435 1436 public void returnMap(RequestContext ctx, HandlerContext handlerCtx) { 1437 ArrayList keyList = (ArrayList )handlerCtx.getInputValue("keyList"); 1438 ArrayList valueList = (ArrayList )handlerCtx.getInputValue("valueList"); 1439 HashMap map = new HashMap (); 1440 for (int i=0; i < keyList.size(); i++) { 1441 map.put(keyList.get(i), valueList.get(i)); 1442 } 1443 handlerCtx.setOutputValue("map", map); 1444 } 1445 1446 private Object [] getNodeAgentsAsDropDown( String methodName, 1447 String objectName, ArrayList params, ArrayList types) 1448 { 1449 Object [] paramsAndTypes = MBeanUtil.getParamsAndTypes(params, types); 1450 try { 1451 Object objs = MBeanUtil.invoke(objectName, methodName, 1452 (Object [])(paramsAndTypes[0]), (String [])(paramsAndTypes[1])); 1453 if (objs != null && objs instanceof ObjectName []) { 1454 ObjectName [] naObjectNames = (ObjectName [])objs; 1455 1456 String [] naNames = new String [naObjectNames.length]; 1457 String [] labels = new String [naObjectNames.length]; 1458 for(int i =0; i < naObjectNames.length; i++) { 1459 String naName = (String )MBeanUtil.getAttribute(naObjectNames[i], "name"); 1460 String label = naName + 1461 " ("+getHostOfNodeAgent(naObjectNames[i].toString())+")"; 1462 naNames[i]= naName; 1463 labels[i] = label; 1464 } 1465 return new Object []{naNames, labels}; 1466 } 1467 return new Object []{new String []{""}, new String []{""}}; 1468 } catch (Exception ex) { 1469 throw new FrameworkException(ex); 1470 } 1471 } 1472 1473 private String getHostOfNodeAgent(String naObjectName) { 1474 1475 String hostName = Util.getMessage("nodeAgent.UnknownHost"); 1476 try { 1477 String [] types = new String []{"java.lang.String"}; 1478 Object [] params = new Object []{"rendezvousOccurred"}; 1479 String result = (String )MBeanUtil.invoke( 1480 naObjectName, 1481 "getPropertyValue", params, types); 1482 if (result.equalsIgnoreCase("false")) { 1483 return hostName; 1484 } 1485 } catch (Exception ex) { 1486 } 1489 try { 1490 ObjectName jmxConnector = (ObjectName )MBeanUtil.invoke( 1491 naObjectName, "getJmxConnector", null, null); 1492 if (jmxConnector != null ) { 1493 String [] types = new String []{"java.lang.String"}; 1494 Object [] params = new Object []{"client-hostname"}; 1495 hostName = (String )MBeanUtil.invoke( 1496 jmxConnector, 1497 "getPropertyValue", params, types); 1498 } 1499 }catch (Exception ex){ 1500 } 1503 return hostName; 1504 } 1505 1506 public String getHostOfNodeAgent(RequestContext ctx, HandlerContext handlerCtx) { 1507 String naObjectName = (String )handlerCtx.getInputValue("nodeAgentObjectName"); 1508 String hostName = getHostOfNodeAgent(naObjectName); 1509 handlerCtx.setOutputValue("hostName", hostName); 1510 return hostName; 1511 } 1512 1513 public void displayPropertyChild(RequestContext ctx, HandlerContext handlerCtx) { 1514 ViewDescriptor vd; 1515 vd = handlerCtx.getViewDescriptor(); 1516 1517 if (vd instanceof CCPropertySheetDescriptor) { 1518 CCPropertySheetModelInterface model = 1519 ((CCPropertySheetDescriptor)vd).getModel(); 1520 String propertyName = (String )handlerCtx.getInputValue("propertyName"); 1521 Boolean displayValue = (Boolean )handlerCtx.getInputValue("value"); 1522 if (propertyName != null) { 1523 model.setVisible(propertyName, displayValue.booleanValue()); 1524 } 1525 1526 } else { 1527 throw new RuntimeException ("ViewDesc should be of type property sheet."); 1528 } 1529 } 1530 1531 1537 public void PageTitleDisplay(RequestContext ctx, HandlerContext handlerCtx) { 1538 CCPageTitleTag tag = (CCPageTitleTag)handlerCtx.getEvent().getSource(); 1540 String titleKey = (String )handlerCtx.getInputValue("titleKey"); 1541 String helpKey = (String )handlerCtx.getInputValue("helpKey"); 1542 ArrayList argList = (ArrayList )handlerCtx.getInputValue("args"); 1543 Object [] args = null; 1544 if (argList != null && argList.size() > 0) { 1545 args = (Object [])argList.toArray(new Object [argList.size()]); 1546 } 1547 if(titleKey != null) { 1548 String titleText = null; 1549 if (args == null || args.length == 0) { 1550 titleText = Util.getMessage(titleKey); 1551 1552 } else { 1553 titleText = Util.getMessage(titleKey, args); 1554 } 1555 tag.setPageTitleText(titleText); 1556 } 1557 1558 if(helpKey != null) { 1559 String helpText = Util.getMessage(helpKey); 1560 tag.setPageTitleHelpMessage(helpText); 1561 } 1562 1563 } 1564 1565 public String temporaryFixHtmlError(RequestContext ctx, HandlerContext handlerCtx) { 1569 if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) { 1570 return null; 1572 } 1573 String content = (String ) ((ChildContentDisplayEvent)handlerCtx.getEvent()).getContent(); 1574 String result = content.replaceFirst("\"<", "\"> <") ; 1575 String result1 = result.replaceFirst("/> */>", "/> </input> ") ; 1576 return result1; 1577 } 1578 1579 1602 public void truncateMiddle(RequestContext ctx, HandlerContext handlerCtx) { 1603 int maxLength = ((Integer )handlerCtx.getInputValue(MAX_LENGTH)).intValue(); 1605 int headLength = ((Integer )handlerCtx.getInputValue(HEAD_LENGTH)).intValue(); 1606 int tailLength = ((Integer )handlerCtx.getInputValue(TAIL_LENGTH)).intValue(); 1607 String elipse = (String )handlerCtx.getInputValue(ELLIPSIS); 1608 String string = (String )handlerCtx.getInputValue(STRING); 1609 if (string == null) { 1610 string = ""; 1611 } 1612 1613 if (string.length() > maxLength) { 1615 string = string.substring(0, headLength) + 1617 elipse + 1618 string.substring(string.length()-tailLength); 1619 } 1620 1621 handlerCtx.setOutputValue(VALUE, string); 1623 } 1624 1635 1636 public String getDomainRoot(RequestContext ctx, HandlerContext handlerCtx) { 1637 String domainRoot = Util.getDomainRoot(); 1638 handlerCtx.setOutputValue("domainRoot", domainRoot); 1639 return domainRoot; 1640 } 1641 1642 1661 public String getEndDisplayString(RequestContext ctx, HandlerContext handlerCtx) { 1662 if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) { 1663 throw new FrameworkException(getClass().getName()+ 1664 ".getEndDisplayString is only valid for endDisplay events!", 1665 null, handlerCtx.getView()); 1666 } 1667 1668 String value = 1670 ((ChildContentDisplayEvent)handlerCtx.getEvent()).getContent(); 1671 1672 handlerCtx.setOutputValue(VALUE, value); 1674 1675 boolean returnEmptyString = false; 1677 Object input = handlerCtx.getInputValue(RETURN_EMPTY_STRING); 1678 if (input != null) { 1679 returnEmptyString = ((Boolean )input).booleanValue(); 1680 } 1681 1682 return returnEmptyString ? "" : value; 1684 } 1685 1686 1700 public void setBoundName(RequestContext ctx, HandlerContext handlerCtx) { 1701 DisplayFieldImpl dispField = 1703 (DisplayFieldImpl)handlerCtx.getInputValue(DISPLAY_FIELD); 1704 String name = (String )handlerCtx.getInputValue(NAME); 1705 if ((dispField == null) || (name == null) || name.equals("")) { 1706 throw new FrameworkException("'"+DISPLAY_FIELD+"' and '"+NAME+ 1707 "' are both required for setBoundName!", null, 1708 handlerCtx.getView()); 1709 } 1710 1711 dispField.setBoundName(name); 1713 } 1714 1715 1732 public void setDisplayLabel(RequestContext ctx, HandlerContext handlerCtx) { 1733 CCButton button = (CCButton)handlerCtx.getInputValue(CCBUTTON); 1735 String value = (String )handlerCtx.getInputValue(VALUE); 1736 if ((button == null) || (value == null)) { 1737 throw new FrameworkException("'"+CCBUTTON+"' and '"+VALUE+ 1738 "' are both required for setDisplayLabel!", null, 1739 handlerCtx.getView()); 1740 } 1741 1742 button.setDisplayLabel(value); 1744 } 1745 1746 1747 private static final String ENTRY_URI = "/admingui/TopFrameset"; 1748 1749 1750 public static final Boolean FALSE = new Boolean (false); 1751 public static final Boolean TRUE = new Boolean (true); 1752 1753 1754 1758 public static final String ALERT_TYPE = "ALERT_TYPE"; 1759 1760 1763 public static final String ALERT_SUMMARY = "ALERT_SUMMARY"; 1764 1765 1771 public static final String MBEAN_MESSAGE = "MBEAN_MESSAGE"; 1772 public static final String HAS_MBEAN_MESSAGE= "HAS_MBEAN_MESSAGE"; 1773 public static final String HAS_ERROR_MESSAGE= "HAS_ERROR_MESSAGE"; 1774 1775 public static final String NAME = "name"; 1776 public static final String VALUE = "value"; 1777 public static final String MODEL = "model"; 1778 public static final String MODEL_NAMES = "modelNames"; 1779 public static final String LONG_INTEGER_1 = "long1"; 1780 public static final String LONG_INTEGER_2 = "long2"; 1781 public static final String LONG_ADD_RESULT = "result"; 1782 public static final String EXCEPTION_TO_LOG = "exceptionToLog"; 1783 public static final String LEVEL = "level"; 1784 1785 public static final String DISPLAY_FIELD = "displayField"; 1786 public static final String CCBUTTON = "ccbutton"; 1787 1788 public static final String MAX_LENGTH = "maxLength"; 1789 public static final String HEAD_LENGTH = "headLength"; 1790 public static final String TAIL_LENGTH = "tailLength"; 1791 public static final String ELLIPSIS = "ellipsis"; 1792 public static final String STRING = "string"; 1793 1794 public static final String RETURN_EMPTY_STRING = "returnEmptyString"; 1795 1796} 1797 | Popular Tags |