1 23 24 29 30 package com.sun.enterprise.tools.admingui.handlers; 31 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 36 import com.iplanet.jato.RequestContext; 37 import com.iplanet.jato.RequestContextImpl; 38 import com.iplanet.jato.RequestManager; 39 import com.iplanet.jato.ViewBeanManager; 40 import com.iplanet.jato.model.DefaultModel; 41 import com.iplanet.jato.model.Model; 42 import com.iplanet.jato.util.RootCauseException; 43 import com.iplanet.jato.view.ContainerView; 44 import com.iplanet.jato.view.ContainerViewBase; 45 import com.iplanet.jato.view.View; 46 import com.iplanet.jato.view.ViewBase; 47 import com.iplanet.jato.view.ViewBean; 48 import com.iplanet.jato.view.DisplayField; 49 50 import javax.management.MBeanException ; 51 import javax.management.ObjectName ; 52 import javax.management.AttributeList ; 53 import javax.management.Attribute ; 54 55 import javax.servlet.ServletRequest ; 56 57 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 58 import com.sun.enterprise.tools.guiframework.model.ModelManager; 59 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 60 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 61 import com.sun.enterprise.tools.guiframework.view.ViewDescriptorManager; 62 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 63 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor; 64 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent; 65 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent; 66 import com.sun.web.ui.model.CCActionTableModelInterface; 67 import com.sun.web.ui.view.table.CCActionTable; 68 import com.sun.web.ui.view.html.CCButton; 69 import com.sun.web.ui.taglib.pagetitle.CCPageTitleTag; 70 71 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 72 import com.sun.enterprise.tools.admingui.util.Util; 73 import com.sun.enterprise.tools.admingui.ConfigProperties; 74 75 import com.sun.enterprise.transaction.monitor.JTSMonitorMBean; 76 77 import com.sun.enterprise.admin.servermgmt.RuntimeStatus; 78 import com.sun.enterprise.admin.servermgmt.RuntimeStatusList; 79 80 81 85 public class TableHandlers { 86 87 88 89 public void executeMethod(RequestContext ctx, HandlerContext handlerCtx) { 90 View view = handlerCtx.getView(); DescriptorContainerView descView = 94 (DescriptorContainerView)(((ViewBase)view).getParentViewBean()); 95 ViewDescriptor vd = descView.getViewDescriptor(); 96 String childName = (String )handlerCtx.getInputValue("tableChildName"); 97 if(childName == null) { 98 throw new FrameworkException("executeMethod: childName not specified", vd, view); 99 } 100 101 ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName); 102 if (tableDescriptor == null) { 103 throw new FrameworkException("executeMethod: tableDescriptor is null", vd, view); 104 } 105 if(!(tableDescriptor instanceof CCActionTableDescriptor)) { 106 throw new FrameworkException( 107 "executeMethod: tableDescriptor is of wrong type", tableDescriptor, view); 108 } 109 CCActionTableModelInterface model = 110 ((CCActionTableDescriptor)tableDescriptor).getModel(); 111 String method = (String )handlerCtx.getInputValue("method"); 112 if (method == null) { 113 throw new FrameworkException("executeMethod: method name is null", vd, view); 114 } 115 116 model.setRowSelectionType("multiple"); 117 String objectName = null; 118 try { 119 model.beforeFirst(); 120 while(model.next()) { 121 if (model.isRowSelected()) { 122 objectName = (String )model.getValue("objectName"); 123 if (objectName == null) 124 continue; MBeanUtil.invoke(objectName, method, null, null); 126 model.setRowSelected(false); 127 } 128 } 129 } catch (Exception ex) { 130 throw new FrameworkException("Error while invoking '" + method + 131 "' on " + objectName, ex, tableDescriptor, view); 132 } 133 ContainerViewBase containerView = 134 (ContainerViewBase)(tableDescriptor.getView(ctx).getParent()); 135 containerView.removeChild(tableDescriptor.getName()); 136 ((DefaultModel)model).clear(); 137 } 138 139 public void deleteHandler(RequestContext ctx, HandlerContext handlerCtx) { 140 View view = handlerCtx.getView(); 141 DescriptorContainerView descView = (DescriptorContainerView)(((ViewBase)view).getParentViewBean()); 142 ViewDescriptor vd = descView.getViewDescriptor(); 143 String childName = (String )handlerCtx.getInputValue("tableChildName"); 144 if(childName == null) { 145 throw new FrameworkException("deleteHandler: childName not specified", vd, view); 146 } 147 148 ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName); 149 if (tableDescriptor == null) { 150 throw new FrameworkException("deleteHandler: tableDescriptor is null", vd, view); 151 } 152 if(!(tableDescriptor instanceof CCActionTableDescriptor)) { 153 throw new FrameworkException("deleteHandler: tableDescriptor is of wrong type", tableDescriptor, view); 154 } 155 CCActionTableModelInterface model = ((CCActionTableDescriptor)tableDescriptor).getModel(); 156 157 String deleteKey = (String )handlerCtx.getInputValue("deleteKey"); 158 String deleteMethodName = (String )handlerCtx.getInputValue("deleteMethodName"); 159 String objectName = (String )handlerCtx.getInputValue("rowObjectName"); 160 String cascade = (String )handlerCtx.getInputValue("deleteWithCascade"); 161 String deleteTarget = (String )handlerCtx.getInputValue("deleteTarget"); 162 Boolean isResource = (Boolean )handlerCtx.getInputValue("isResource"); 163 Boolean isLifecycleModule = (Boolean )handlerCtx.getInputValue("isLifecycleModule"); 164 165 if (objectName == null) { 166 throw new FrameworkException("No ObjectName specified", tableDescriptor, view); 167 } 168 if (deleteKey == null) { 169 throw new FrameworkException("No delete key specified", tableDescriptor, view); 170 } 171 if (deleteMethodName == null) { 172 throw new FrameworkException("deleteMethodName must be specified", tableDescriptor, view); 173 } 174 model.setRowSelectionType("multiple"); 175 try { 176 model.beforeFirst(); 177 while(model.next()) { 179 if (model.isRowSelected()) { 180 if (deleteMethodName != null) { 181 deleteTableRow(model.getValue(deleteKey), objectName, deleteMethodName, 182 cascade, deleteTarget, isResource, isLifecycleModule); 183 } 184 model.setRowSelected(false); 185 } 186 } 187 } catch (Exception ex) { 188 throw new FrameworkException("Error while deleting from: '"+ 189 tableDescriptor.getName()+"'", ex, tableDescriptor, view); 190 } 191 ContainerViewBase containerView = 192 (ContainerViewBase)(tableDescriptor.getView(ctx).getParent()); 193 containerView.removeChild(tableDescriptor.getName()); 194 ((DefaultModel)model).clear(); 195 } 196 197 public void deleteMBean(RequestContext ctx, HandlerContext handlerCtx) { 199 View view = handlerCtx.getView(); 200 DescriptorContainerView descView = (DescriptorContainerView)(((ViewBase)view).getParentViewBean()); 201 ViewDescriptor vd = descView.getViewDescriptor(); 202 String childName = (String )handlerCtx.getInputValue("tableChildName"); 203 if(childName == null) { 204 throw new FrameworkException("deleteHandler: childName not specified", vd, view); 205 } 206 207 ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName); 208 if (tableDescriptor == null) { 209 throw new FrameworkException("deleteHandler: tableDescriptor is null", vd, view); 210 } 211 if(!(tableDescriptor instanceof CCActionTableDescriptor)) { 212 throw new FrameworkException("deleteHandler: tableDescriptor is of wrong type", tableDescriptor, view); 213 } 214 CCActionTableModelInterface model = ((CCActionTableDescriptor)tableDescriptor).getModel(); 215 216 String deleteKey = (String )handlerCtx.getInputValue("deleteKey"); 217 String deleteMethodName = (String )handlerCtx.getInputValue("deleteMethodName"); 218 String objectName = (String )handlerCtx.getInputValue("rowObjectName"); 219 220 if (objectName == null) { 221 throw new FrameworkException("No ObjectName specified", tableDescriptor, view); 222 } 223 if (deleteKey == null) { 224 throw new FrameworkException("No delete key specified", tableDescriptor, view); 225 } 226 if (deleteMethodName == null) { 227 throw new FrameworkException("deleteMethodName must be specified", tableDescriptor, view); 228 } 229 model.setRowSelectionType("multiple"); 230 try { 231 model.beforeFirst(); 232 while(model.next()) { 234 if (model.isRowSelected()) { 235 String mbeanName = (String )model.getValue(deleteKey); 236 String [] targets = null; 238 boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue(); 239 if(isTargetSupported) { 240 targets = getReferences(objectName, "listReferencees", mbeanName); 241 } 242 if(targets == null || targets.length == 0) { 243 targets = new String []{ConfigProperties.getInstance().getDefaultTarget()}; 244 } 245 for(int i =0; i < targets.length; i++) { 246 MBeanUtil.invoke(objectName, deleteMethodName, new Object []{targets[i], mbeanName}, new String []{"java.lang.String", "java.lang.String"}); 247 } 248 249 model.setRowSelected(false); 250 } 251 } 252 } catch (Exception ex) { 253 throw new FrameworkException("Error while deleting from: '"+ 254 tableDescriptor.getName()+"'", ex, tableDescriptor, view); 255 } 256 ContainerViewBase containerView = 257 (ContainerViewBase)(tableDescriptor.getView(ctx).getParent()); 258 containerView.removeChild(tableDescriptor.getName()); 259 ((DefaultModel)model).clear(); 260 } 261 262 private String [] getReferences(String objectName, String methodName, String key) { 263 ObjectName [] refs = (ObjectName [])MBeanUtil.invoke(objectName, methodName, new Object []{key}, new String []{"java.lang.String"}); 264 String [] targets = null; 265 if(refs != null) { 266 targets = new String [refs.length]; 267 } 268 for (int i=0; refs != null && i < refs.length; i++) { 269 targets[i] = refs[i].getKeyProperty("name"); 270 } 271 return targets; 272 } 273 274 private void deleteTableRow(Object key, String objectName, String methodName, 275 String cascade, String target, Boolean isResource, Boolean isLifecycleModule) throws Exception { 276 Object [] params = null; 277 String [] types = null; 278 279 String defaultTarget = target; 280 if (isResource != null && isResource.booleanValue() == true) { 281 deleteResourceReferences(key.toString()); 282 defaultTarget = ConfigProperties.getInstance().getDefaultTarget(); 283 } 284 if (isLifecycleModule != null && isLifecycleModule.booleanValue() == true) { 285 deleteLifecycleReferences(key.toString()); 286 defaultTarget = ConfigProperties.getInstance().getDefaultTarget(); 287 } 288 289 if (cascade != null && cascade.equals("true")) { 290 if (defaultTarget == null) { 291 params = new Object []{key, new Boolean (true)}; 292 types = new String []{"java.lang.String", "java.lang.Boolean"}; 293 } 294 else { 295 params = new Object []{key, new Boolean (true), defaultTarget}; 296 types = new String []{"java.lang.String", "java.lang.Boolean", "java.lang.String"}; 297 } 298 } 299 else { if (defaultTarget == null) { 301 params = new Object []{key}; 302 types = new String []{"java.lang.String"}; 303 } 304 else { 305 params = new Object []{key, defaultTarget}; 306 types = new String []{"java.lang.String", "java.lang.String"}; 307 } 308 } 309 MBeanUtil.invoke(objectName, methodName, params, types); 314 } 315 316 private void deleteResourceReferences(String resourceName) 317 throws Exception { 318 if (ConfigProperties.getInstance().getTargetSupported().booleanValue() == false) { 319 return; 320 } 321 Object [] param = new Object []{resourceName}; 322 String [] type = new String []{"java.lang.String"}; 323 ObjectName [] references = 324 (ObjectName [])MBeanUtil.invoke("com.sun.appserv:type=resources,category=config", 325 "listReferencees", 326 param, type); 327 for(int i = 0; i < references.length; i++) { 328 String targetName = (String )MBeanUtil.getAttribute( 329 references[i], "name"); 330 MBeanUtil.invoke( 331 "com.sun.appserv:type=resources,category=config", 332 "deleteResourceReference", 333 new Object []{targetName, resourceName}, 334 new String []{"java.lang.String", "java.lang.String"}); 335 } 336 } 337 338 private void deleteLifecycleReferences(String lifecycleName) 339 throws Exception { 340 if (ConfigProperties.getInstance().getTargetSupported().booleanValue() == false) { 341 return; 342 } 343 Object [] param = new Object []{lifecycleName}; 344 String [] type = new String []{"java.lang.String"}; 345 ObjectName [] references = 346 (ObjectName [])MBeanUtil.invoke("com.sun.appserv:type=applications,category=config", 347 "listReferencees", 348 param, type); 349 for(int i = 0; i < references.length; i++) { 350 String targetName = (String )MBeanUtil.getAttribute( 351 references[i], "name"); 352 MBeanUtil.invoke( 353 "com.sun.appserv:type=applications,category=config", 354 "removeLifecycleModuleReference", 355 new Object []{lifecycleName, targetName}, 356 new String []{"java.lang.String", "java.lang.String"}); 357 } 358 } 359 360 361 362 private Object getName(Object obj) { 363 if (obj instanceof String ) { 366 String name = (String ) obj; 367 if (name.indexOf("category=monitor") >= 0) 368 return MBeanUtil.invoke(name, "getName", null, null); 369 } 370 return obj; 371 } 372 373 private CCActionTableDescriptor getTableDescriptor(HandlerContext handlerCtx) { 374 View view = handlerCtx.getView(); 375 ViewDescriptor desc = null; 377 View tableView = (View)handlerCtx.getInputValue("tableView"); 378 if (tableView != null) { 379 desc = ((DescriptorContainerView)tableView).getViewDescriptor(); 380 } 381 else if (handlerCtx.getEvent() instanceof BeforeCreateEvent) { 382 desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 383 } else if (view instanceof DescriptorContainerView) { 384 desc = ((DescriptorContainerView)view).getViewDescriptor(); 385 } 386 if ((desc == null) || !(desc instanceof CCActionTableDescriptor)) { 387 throw new FrameworkException("Unable to determine "+ 388 "CCActionTableDescriptor. This handler should be invoked "+ 389 "from a CCActionTable.", desc, view); 390 } 391 return (CCActionTableDescriptor)desc; 392 } 393 394 public void resetXMLinModel(RequestContext ctx, HandlerContext handlerCtx) { 395 CCActionTableDescriptor ccDesc = getTableDescriptor(handlerCtx); 396 ccDesc.resetXML(); 397 } 398 399 public void loadTableModel(RequestContext ctx, HandlerContext handlerCtx) { 400 CCActionTableDescriptor ccDesc = getTableDescriptor(handlerCtx); 402 CCActionTableModelInterface model = ccDesc.getModel(); 403 ((DefaultModel)model).clear(); 404 405 ArrayList displayNamesList = (ArrayList )handlerCtx.getInputValue("displayNames"); 406 Object keysObj = handlerCtx.getInputValue("keys"); Object [] keys = null; 408 if (keysObj instanceof Object []) { 409 keys = (Object [])keysObj; 410 } else if (keysObj instanceof List ) { 411 List keysList = (List )keysObj; 412 keys = new Object [keysList.size()]; 413 for (int i=0; i < keys.length; i++) { 414 keys[i] = keysList.get(i); 415 } 416 } 417 418 if (keys == null) { 419 return; } 421 422 ArrayList modelNamesList = (ArrayList )handlerCtx.getInputValue("attributeNames"); 423 String [] modelNames = null; 424 if (modelNamesList != null) 425 modelNames = (String [])modelNamesList.toArray(new String [modelNamesList.size()]); 426 if (keys instanceof String [] || modelNames == null) { 427 430 for (int rowNo = 0; rowNo < keys.length; rowNo++) { 431 model.appendRow(); 432 model.setValue((String )displayNamesList.get(0), getName(keys[rowNo].toString())); 433 model.setValue("objectName", keys[rowNo].toString()); 434 } 435 } 436 else if (keys instanceof ObjectName []) { 437 ObjectName [] objNames = (ObjectName [])keys; 438 if (isMixed(modelNames)) { 439 loadTable(objNames, modelNames, displayNamesList, model); 440 } else { 441 loadTableByGroup(objNames, modelNames, displayNamesList, model); 442 } 443 } 444 } 445 446 474 private boolean isMixed(String [] names) { 475 for (int i=0; i<names.length; i++) { 477 if (names[i] != null && names[i].indexOf('@') == 0) 478 return true; 479 } 480 return false; 481 } 482 483 private void loadTableByGroup(ObjectName [] objNames, String [] modelNames, 484 ArrayList displayNamesList, CCActionTableModelInterface model) { 485 for (int rowNo = 0; rowNo < objNames.length; rowNo++) { 486 AttributeList attrList = 488 MBeanUtil.getAttributes(objNames[rowNo].toString(), modelNames); 489 model.appendRow(); 490 491 for (int i = 0, colNo = 0; i < attrList.size(); i++) { 492 Attribute attr = (Attribute )attrList.get(i); 493 494 while (colNo < modelNames.length && 495 ! attr.getName().equals(modelNames[colNo])) { 496 colNo++; 497 } 498 if (colNo < modelNames.length) { 499 Object attrValue = attr.getValue(); 500 if (attrValue != null) { 501 attrValue = attrValue.toString(); 502 } 503 model.setValue((String )displayNamesList.get(colNo), 504 getName(attr.getValue())); 505 } 506 } 507 model.setValue("objectName", objNames[rowNo].toString()); 508 model.setValue("objectType", objNames[rowNo].getKeyProperty("type")); 509 } 510 } 511 512 513 private void loadTable(ObjectName [] objNames, String [] modelNames, 514 ArrayList displayNamesList, CCActionTableModelInterface model) { 515 for (int rowNo = 0; rowNo < objNames.length; rowNo++) { 518 model.appendRow(); 520 521 for (int colNo = 0; colNo < modelNames.length; colNo++) { 522 model.setValue((String )displayNamesList.get(colNo), 523 getValue(objNames[rowNo], modelNames[colNo])); 524 model.setValue("objectName", objNames[rowNo].toString()); 525 model.setValue("objectType", objNames[rowNo].getKeyProperty("type")); 526 } 527 } 528 } 529 530 private String getValue(ObjectName objName, String attrName) { 531 Object value = null; 532 if (attrName.indexOf('@') == 0 && attrName.length() > 3) { 533 String method = attrName.substring(2, attrName.length()-1); 534 try { 535 value = MBeanUtil.invoke(objName, method, null, null); 536 } catch (Exception ex) { 537 if (method.equals("getRuntimeStatus")) 538 return TargetHandlers.getStatusHtml(value); 540 else 541 value = ex.getMessage(); 542 } 543 } else { 544 value = MBeanUtil.getAttribute(objName, attrName); 545 } 546 String result = ""; 547 if (value != null) { 548 if (value instanceof RuntimeStatus || value instanceof RuntimeStatusList) { 549 result = TargetHandlers.getStatusHtml(value); 550 } else { 551 result = value.toString(); 552 } 553 } 554 return result; 555 } 556 557 563 public void ensureModelRows(RequestContext ctx, HandlerContext handlerCtx) { 564 ViewDescriptor desc = null; 565 if (handlerCtx.getEvent() instanceof BeforeCreateEvent) 566 desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 567 else { 568 throw new FrameworkException("ensureModelRows can only be called in BeforeCreate event handler!", desc, handlerCtx.getView()); 569 } 570 String dummyArrayName = ""; 571 while (desc != null) { 572 if (dummyArrayName.equals("") == false) 573 dummyArrayName = "." + dummyArrayName; 574 dummyArrayName = desc.getName() + dummyArrayName; 575 desc = desc.getParent(); 576 } 577 dummyArrayName += "." + "rowCounter"; 578 579 ServletRequest req = ctx.getRequest(); 580 Object arr[] = (Object [])req.getParameterValues(dummyArrayName); 581 582 if (arr == null) { 585 return; 587 } 588 589 DefaultModel model = (DefaultModel)handlerCtx.getInputValue(MODEL); 594 if (model == null) { 595 throw new FrameworkException("Model cannot be null!", desc, handlerCtx.getView()); 596 } 597 598 int rowsToAdd = arr.length; 600 rowsToAdd -= model.getNumRows(); 601 for (int count=0; count<rowsToAdd; count++) { 602 model.appendRow(); 603 } 604 } 605 606 607 public void handleTableMenuAction(RequestContext ctx, HandlerContext handlerCtx) { 609 String action = (String )handlerCtx.getInputValue("action"); 610 611 ViewDescriptor desc = null; 612 View tableView = (View)handlerCtx.getInputValue("tableView"); 613 if (tableView != null) { 614 desc = ((DescriptorContainerView)tableView).getViewDescriptor(); 615 } 616 CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)desc; 617 618 CCActionTableModelInterface model = ccDesc.getModel(); 619 try { 620 model.beforeFirst(); 621 while(model.next()) { 623 if (Util.isLoggableFINER()) 624 Util.logFINER("isRowSelected = " + model.isRowSelected()); 625 } 626 }catch (Exception ex){ 627 ex.printStackTrace(); 628 } 629 } 630 631 public void getTableFilterValue(RequestContext ctx, HandlerContext handlerCtx) { 632 String filterValue = (String )handlerCtx.getInputValue("displayFieldValue"); 633 if (filterValue != null && 634 filterValue.equals(CCActionTable.FILTER_ALL_ITEMS_OPTION)) { 635 filterValue = null; 636 } 637 handlerCtx.setOutputValue("filterValue", filterValue); 638 } 639 640 public void loadTransactionIds(RequestContext ctx, HandlerContext handlerCtx) { 641 View view = handlerCtx.getView(); 642 ViewDescriptor desc = null; 644 if (handlerCtx.getEvent() instanceof BeforeCreateEvent) { 645 desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 646 } else if (view instanceof DescriptorContainerView) { 647 desc = ((DescriptorContainerView)view).getViewDescriptor(); 648 } 649 if ((desc == null) || !(desc instanceof CCActionTableDescriptor)) { 650 throw new FrameworkException("Unable to determine "+ 651 "CCActionTableDescriptor. This handler should be invoked "+ 652 "from a CCActionTable.", desc, view); 653 } 654 CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)desc; 656 CCActionTableModelInterface model = ccDesc.getModel(); 657 658 ArrayList displayName = (ArrayList )handlerCtx.getInputValue("displayNames"); 659 List maps = (List )handlerCtx.getInputValue("maps"); 660 661 if (maps == null) { 662 return; } 664 665 for (Iterator iter = maps.iterator(); iter.hasNext();) { 666 java.util.Map m = (java.util.Map )iter.next(); 667 model.appendRow(); 668 model.setValue((String )displayName.get(0), (String )m.get(JTSMonitorMBean.TRANSACTION_ID)); 669 model.setValue((String )displayName.get(1), (String )m.get(JTSMonitorMBean.STATE)); 670 model.setValue((String )displayName.get(2), (String )m.get(JTSMonitorMBean.ELAPSED_TIME)); 671 model.setValue((String )displayName.get(3), (String )m.get(JTSMonitorMBean.COMPONENT_NAME)); 672 model.setValue((String )displayName.get(4), (String )m.get(JTSMonitorMBean.RESOURCE_NAMES)); 673 } 674 } 675 676 public void setTransactionPageTitle(RequestContext ctx, HandlerContext handlerCtx) { 677 Object obj = handlerCtx.getEvent().getSource(); 678 CCPageTitleTag tag = (CCPageTitleTag)handlerCtx.getEvent().getSource(); 680 AttributeList state = (AttributeList )handlerCtx.getInputValue("state"); 681 String status = Util.getMessage("common.unknown"); 682 if (state != null && state.get(0) != null) { 683 String value = (String )((Attribute )state.get(0)).getValue(); 684 status = value.equals("False")?Util.getMessage("transactionId.UnFreeze"):Util.getMessage("transactionId.Freeze"); 685 } 686 String bundle = "com.sun.enterprise.tools.admingui.resources.Resources"; 687 String pageTitle = tag.getPageTitleText(); 688 String localizedString = Util.getMessage(bundle, pageTitle, new Object []{status}); 689 tag.setPageTitleText(localizedString); 690 } 691 692 public void setTransactionDisplayFieldValues(RequestContext ctx, HandlerContext handlerCtx) { 693 View childView = handlerCtx.getView(); 694 DescriptorContainerView view = (DescriptorContainerView)(((ViewBase)childView).getParentViewBean()); 695 AttributeList state = (AttributeList )handlerCtx.getInputValue("state"); 696 String value = (String )((Attribute )state.get(0)).getValue(); 697 String status = value.equals("False")?Util.getMessage("transactionId.Freeze"):Util.getMessage("transactionId.UnFreeze"); 698 DisplayField stateField = (DisplayField)view.getDisplayField("Status"); 699 stateField.setValue(value); 700 CCButton button = (CCButton)childView; 701 button.setDisplayLabel(status); 702 } 703 704 public void setTransactionState(RequestContext ctx, HandlerContext handlerCtx) { 705 String objectName = (String )handlerCtx.getInputValue("objectName"); 706 View childView = handlerCtx.getView(); 707 DescriptorContainerView view = (DescriptorContainerView)(((ViewBase)childView).getParentViewBean()); 708 String state = (String )view.getDisplayFieldValue("Status"); 709 String methodName = state.equals("False")?"freeze":"unfreeze"; 710 MBeanUtil.invoke(objectName, methodName, null, null); 711 } 712 713 private void deleteCluster(String clusterName) { 714 removeLbRefs(clusterName); boolean running = true; 716 try { 718 RuntimeStatusList status = (RuntimeStatusList)MBeanUtil.invoke( 719 "com.sun.appserv:type=clusters,category=config", 720 "getRuntimeStatus", 721 new Object []{clusterName}, 722 new String []{"java.lang.String"}); 723 running = status.anyRunning(); 724 } catch (Exception ex) { 725 if (Util.isLoggableFINE()) 727 Util.logFINE(ex); 728 } 729 if (running) { 730 try { 732 MBeanUtil.invoke( 733 "com.sun.appserv:type=clusters,category=config", 734 "stopCluster", 735 new Object []{clusterName}, 736 new String []{"java.lang.String"}); 737 } catch (Exception ex) { 738 throw new FrameworkException(ex); 740 } 741 } 742 try { 743 ObjectName [] objectNames = (ObjectName [])MBeanUtil.invoke( 745 "com.sun.appserv:type=servers,category=config", 746 "listServerInstances", 747 new Object []{clusterName}, 748 new String []{"java.lang.String"}); 749 for (int i = 0; i < objectNames.length; i++) { 751 String instanceName = objectNames[i].getKeyProperty("name"); 753 754 String [] modules = (String [])MBeanUtil.invoke( 755 "com.sun.appserv:type=servers,category=config", 756 "deleteServerInstance", 757 new Object []{instanceName}, 758 new String []{"java.lang.String"}); 759 } 760 MBeanUtil.invoke( 762 "com.sun.appserv:type=clusters,category=config", 763 "deleteCluster", 764 new Object []{clusterName}, 765 new String []{"java.lang.String"}); 766 } catch (Exception ex) { 767 if (Util.isLoggableFINE()) { 768 Util.logFINE(ex); 769 } 770 throw new FrameworkException(ex); 771 } 772 } 773 774 private void removeLbRefs(String clusterName) { 775 Object params[] = {clusterName}; 776 String [] types= new String []{"java.lang.String"}; 777 String [] lbs = null; 778 try { 780 lbs = (String [])MBeanUtil.invoke("com.sun.appserv:type=olbadmin,category=config", "getLBConfigsForCluster", params, types); 781 782 } catch (Exception ex) { 783 if (Util.isLoggableFINE()) 785 Util.logFINE(ex); 786 } 787 if (lbs != null) { 789 try { 790 for (int i = 0; i < lbs.length; i++) { 791 MBeanUtil.invoke("com.sun.appserv:type=lb-config,name="+lbs[i]+",category=config", "removeClusterRefByRef", params, types); 792 } 793 } catch (Exception ex) { 794 throw new FrameworkException(ex); 795 } 796 } 797 } 798 799 public void deleteClusterAndInstances(RequestContext ctx, HandlerContext handlerCtx) { 800 View view = handlerCtx.getView(); DescriptorContainerView descView = 804 (DescriptorContainerView)(((ViewBase)view).getParentViewBean()); 805 ViewDescriptor vd = descView.getViewDescriptor(); 806 String childName = (String )handlerCtx.getInputValue("tableChildName"); 807 if(childName == null) { 808 throw new FrameworkException( 809 "deleteClusterAndInstances: childName not specified", vd, view); 810 } 811 812 ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName); 813 if (tableDescriptor == null) { 814 throw new FrameworkException( 815 "deleteClusterAndInstances: tableDescriptor is null", vd, view); 816 } 817 if(!(tableDescriptor instanceof CCActionTableDescriptor)) { 818 throw new FrameworkException( 819 "deleteClusterAndInstances: tableDescriptor is of wrong type", tableDescriptor, view); 820 } 821 CCActionTableModelInterface model = 822 ((CCActionTableDescriptor)tableDescriptor).getModel(); 823 824 model.setRowSelectionType("multiple"); 825 String objectName = null; 826 try { 827 model.beforeFirst(); 828 while(model.next()) { 829 if (model.isRowSelected()) { 830 objectName = (String )model.getValue("objectName"); 831 if (objectName == null) 832 continue; deleteCluster(new ObjectName (objectName).getKeyProperty("name")); 834 model.setRowSelected(false); 835 } 836 } 837 } catch (Exception ex) { 838 if (Util.isLoggableFINE()) 839 Util.logFINE(ex); 840 throw new FrameworkException(ex); 841 } 842 ContainerViewBase containerView = 843 (ContainerViewBase)(tableDescriptor.getView(ctx).getParent()); 844 containerView.removeChild(tableDescriptor.getName()); 845 ((DefaultModel)model).clear(); 846 } 847 848 public static final String MODEL = "model"; 849 } 850 | Popular Tags |