1 23 24 28 29 package com.sun.enterprise.tools.admingui.handlers; 30 31 import java.net.InetAddress ; 32 import java.net.UnknownHostException ; 33 import java.io.*; 34 import java.util.List ; 35 import java.util.ArrayList ; 36 import java.util.Enumeration ; 37 import java.util.HashMap ; 38 import java.util.Iterator ; 39 import java.util.Map ; 40 import java.util.Properties ; 41 import java.util.Set ; 42 import java.util.Vector ; 43 44 import com.iplanet.jato.RequestContext; 45 import com.iplanet.jato.RequestManager; 46 import com.iplanet.jato.model.DefaultModel; 47 import com.iplanet.jato.model.Model; 48 import com.iplanet.jato.model.ModelControlException; 49 import com.iplanet.jato.view.*; 50 import com.iplanet.jato.view.html.SelectableGroup; 51 import com.iplanet.jato.view.html.TextField; 52 import com.iplanet.jato.view.html.OptionList; 53 import com.iplanet.jato.view.event.*; 54 55 import com.sun.web.ui.model.CCActionTableModelInterface; 56 import com.sun.web.ui.taglib.pagetitle.CCPageTitleTag; 57 import com.sun.web.ui.model.CCPropertySheetModelInterface; 58 import com.sun.web.ui.model.CCPropertySheetModel; 59 import com.sun.web.ui.common.CCI18N; 60 61 62 import javax.management.MBeanException ; 63 import javax.management.ObjectName ; 64 import javax.management.Attribute ; 65 import javax.management.AttributeList ; 66 import javax.management.MBeanInfo ; 67 import javax.management.MBeanAttributeInfo ; 68 69 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 70 import com.sun.enterprise.tools.guiframework.view.descriptors.CCPropertySheetDescriptor; 71 import com.sun.enterprise.tools.guiframework.model.ModelManager; 72 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle; 73 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 74 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 75 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 76 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor; 77 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent; 78 import com.sun.enterprise.tools.guiframework.view.DescriptorCCActionTable; 79 80 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 81 import com.sun.enterprise.tools.admingui.util.Util; 82 import com.sun.enterprise.tools.admingui.util.JarExtract; 83 import com.sun.enterprise.tools.admingui.tree.IndexTreeNode; 84 import com.sun.enterprise.tools.admingui.tree.IndexTreeModelImpl; 85 import com.sun.enterprise.tools.admingui.tree.IndexTreeModel; 86 import com.sun.enterprise.tools.admingui.ConfigProperties; 87 88 import com.sun.enterprise.connectors.ConnectorRuntime; 89 90 import com.sun.enterprise.deployment.backend.DeploymentStatus; 91 import com.sun.enterprise.deployment.client.DeploymentFacility; 92 import com.sun.enterprise.deployment.client.DeploymentFacilityFactory; 93 import com.sun.enterprise.deployment.client.JESProgressObject; 94 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 95 import com.sun.enterprise.deployment.deploy.shared.ArchiveFactory; 96 import com.sun.enterprise.deployment.util.DeploymentProperties; 97 98 import com.sun.enterprise.appclient.jws.NamingConventions; 100 101 import com.sun.enterprise.tools.admingui.util.FileUtil; 102 103 106 public class DeploymentHandler { 107 108 public void deploy(RequestContext ctx, HandlerContext handlerCtx) throws Exception { 110 View view = handlerCtx.getView(); 111 if (!(view instanceof DescriptorContainerView)) { 112 View parent = view.getParent(); 113 if (!(parent instanceof DescriptorContainerView)) { 114 throw new FrameworkException( 115 "view is not DescriptorContainerView", null, view); 116 } else { 117 view = parent; 118 } 119 } 120 if (view instanceof DescriptorCCPageTitle) { 121 view = view.getParent(); 122 } 123 DescriptorContainerView descView = (DescriptorContainerView)view; 124 125 Properties dProps = new Properties (); 126 ViewDescriptor vd = descView.getViewDescriptor(); 127 128 ArrayList displayNames = (ArrayList )handlerCtx.getInputValue("displayNames"); 129 ArrayList modelNames = (ArrayList )handlerCtx.getInputValue("attributeNames"); 130 131 for (int i = 0; i < displayNames.size(); i++) { 132 String displayValue = 133 (String )descView.getDisplayFieldValue((String )displayNames.get(i)); 134 if (displayValue==null) continue; 136 dProps.setProperty((String )modelNames.get(i), displayValue); 137 } 138 139 String jws = dProps.getProperty("java-web-start-enabled"); 140 if (jws != null){ 141 dProps.setProperty(DeploymentProperties.DEPLOY_OPTION_JAVA_WEB_START_ENABLED_KEY, jws); 142 dProps.remove("java-web-start-enabled"); 143 } 144 145 String libraries = dProps.getProperty("libraries"); 146 if (libraries != null){ 147 dProps.setProperty(DeploymentProperties.DEPLOY_OPTION_LIBRARIES_KEY, libraries); 148 dProps.remove("libraries"); 149 } 150 151 152 dProps.setProperty("force", "false"); 153 Boolean isTargetSupported = 155 ConfigProperties.getInstance().getTargetSupported(); 156 String type = (String )handlerCtx.getInputValue("appType"); 157 if(isTargetSupported != null && !isTargetSupported.booleanValue() && (type.equals("war")||type.equals("ear"))){ 158 String displayValue = 159 (String )descView.getDisplayFieldValue("virtualservers"); 160 dProps.setProperty(DeploymentProperties.VIRTUAL_SERVERS, displayValue); 161 } 162 if((type.equals("war")||type.equals("ear")||type.equals("jar")) && 163 (isTargetSupported != null && isTargetSupported.booleanValue())) { 164 String displayValue = 165 (String )descView.getDisplayFieldValue("availabilityEnabled"); 166 dProps.setProperty(DeploymentProperties.AVAILABILITY_ENABLED, displayValue); 167 } 168 169 String objectName = (String )handlerCtx.getInputValue("objectName"); 170 String methodName = (String )handlerCtx.getInputValue("methodName"); 171 String [] targets = (String [])handlerCtx.getInputValue("targets"); 172 173 String location = (String )descView.getDisplayFieldValue("location"); 175 Object raConfig = null; 178 if (type.equals("rar")){ 179 ArrayList params = (ArrayList )handlerCtx.getInputValue("resourceAdapterParams"); 180 ArrayList types = (ArrayList )handlerCtx.getInputValue("resourceAdapterTypes"); 181 try { 182 raConfig = createResourceAdapter("com.sun.appserv:type=resources,category=config", 183 "createResourceAdapterConfig", params, types); 184 } catch (Exception ex) { 185 Util.logINFO("Deployment Handler createResourceConfig failed. "+ex.getMessage()); 188 } 189 } 190 try{ 191 invokeDeploymentFacility(targets, dProps, location); 192 }catch (Exception ex){ 193 if (raConfig != null){ 194 String key = (String )MBeanUtil.getAttribute(raConfig.toString(), "resource-adapter-name"); 196 String [] types = new String []{"java.lang.String"}; 197 Object [] params = new Object []{key}; 198 try{ 199 MBeanUtil.invoke("com.sun.appserv:type=resources,category=config", "removeResourceAdapterConfigByResourceAdapterName", params, types); 200 }catch(Exception ex1){ 201 Util.logINFO("Deployment Handler removeResourceAdapterConfig failed. "+ex1.getMessage()); 202 } 203 } 204 throw ex; 205 } 206 207 if (raConfig != null) { 208 String registryType = (String )handlerCtx.getInputValue("registryType"); 209 String propName = null; 210 if (registryType.equals("uddi")) { 211 propName = "com.sun.appserv.registry.uddi"; 212 } else if (registryType.equals("ebxml")) { 213 propName = "com.sun.appserv.registry.ebxml"; 214 } 215 if (propName != null) { 216 Attribute attr = new Attribute (propName, "true"); 217 String [] types = new String []{"javax.management.Attribute"}; 218 Object [] params = new Object []{attr}; 219 MBeanUtil.invoke((ObjectName )raConfig, "setProperty", params, types); 220 } 221 } 222 } 223 224 public static boolean invokeDeploymentFacility(String [] targets, Properties props, String archivePath) 225 throws Exception { 226 if(archivePath == null) { 227 throw new FrameworkException("archivePath is null"); 229 } 230 if("true".equals(props.getProperty("force"))) { 231 boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue(); 232 if (isTargetSupported){ 233 targets = new String []{"domain"}; 235 }else{ 236 targets = new String []{"server"}; 237 } 238 } 239 if(targets == null || targets.length == 0) { 240 targets = new String []{"server"}; 242 } 243 archivePath = archivePath.replace('\\', '/' ); 244 AbstractArchive archive = (new ArchiveFactory()).openArchive(archivePath); 245 DeploymentFacility df= DeploymentFacilityFactory.getLocalDeploymentFacility(); 246 JESProgressObject progressObject = null; 247 248 progressObject = df.deploy(df.createTargets(targets), archive, null , props); DeploymentStatus status = null; 250 do { 251 status = progressObject.getCompletedStatus(); 252 if(status == null) { 253 try { 254 Thread.currentThread().sleep(1000); 255 } catch(InterruptedException ie) { 256 } 257 } 258 } while (status == null); 259 boolean ret = checkDeployStatus(status, "deployment.warning"); 260 return ret; 261 } 262 263 private static boolean checkDeployStatus(DeploymentStatus status, String warningIndex )throws FrameworkException 264 { 265 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 267 PrintWriter pw = new PrintWriter(bos); 268 DeploymentStatus.parseDeploymentStatus(status, pw); 269 byte[] statusBytes = bos.toByteArray(); 270 String statusString = new String (statusBytes); 271 String bundle = "com.sun.enterprise.tools.admingui.resources.Resources"; 272 273 if (status!=null && status.getStatus() == DeploymentStatus.FAILURE){ 274 throw new FrameworkException(statusString); 275 } 276 if (status!=null && status.getStatus() == DeploymentStatus.WARNING){ 278 if (warningIndex != null) 279 Util.logINFO( Util.getMessage(bundle, warningIndex, null)); 280 } 281 return true; 282 } 283 284 285 public void descriptorDisplay(RequestContext ctx, HandlerContext handlerCtx) { 286 String fileName = (String )ctx.getRequest().getAttribute("fileName"); 287 String objectName = (String )ctx.getRequest().getAttribute("objectName"); 288 289 View view = handlerCtx.getView(); 290 DisplayField descriptorField = (DisplayField)view; 291 292 String descriptors = (String )MBeanUtil.invoke(objectName, "getDeploymentDescriptor", 293 new Object []{fileName}, new String []{"java.lang.String"}); 294 295 descriptorField.setValue(descriptors); 296 } 297 298 public void beginDescriptorTitleDisplay(RequestContext ctx, HandlerContext handlerCtx) { 299 CCPageTitleTag tag = (CCPageTitleTag)handlerCtx.getEvent().getSource(); 300 String fileName = (String )handlerCtx.getInputValue("filename"); 301 302 if (fileName != null) { 304 File f = new File(fileName); 305 fileName = f.getName(); 306 } 307 tag.setPageTitleText(fileName); 308 } 309 310 public void beginUploadPageTitleDisplay(RequestContext ctx, HandlerContext handlerCtx) { 311 CCPageTitleTag tag = (CCPageTitleTag)handlerCtx.getEvent().getSource(); 312 String appType = (String )handlerCtx.getInputValue("applicationType"); 313 Boolean redeploy = (Boolean )handlerCtx.getInputValue("redeploy"); 314 String key = null; 315 if (redeploy.booleanValue()) { 316 key = "redeploy.PageTitle"; 317 } else { 318 key = "upload.PageTitle"; 319 } 320 HashMap map = new HashMap (); 321 map.put("war", Util.getMessage("upload.WebModule")); 322 map.put("ear", Util.getMessage("upload.EnterpriseApplication")); 323 map.put("jar", Util.getMessage("upload.EJBModule")); 324 map.put("rar", Util.getMessage("upload.ConnectorModule")); 325 map.put("all", Util.getMessage("upload.AppclientModule")); 326 map.put("mbean", Util.getMessage("upload.CustomMBean")); 327 String mappedValue = (String )map.get(appType); 328 String titleText = Util.getMessage(key, new Object []{mappedValue}); 329 330 tag.setPageTitleText(titleText); 331 if (appType.equals("all")) { 332 appType = "jar"; 334 } 335 String helpText = ""; 336 if (appType.equals("mbean")){ 337 helpText = Util.getMessage("createCustomMBean.pageHelp"); 338 }else 339 helpText = Util.getMessage("uploadPageHelp", new Object []{appType, mappedValue}); 340 341 tag.setPageTitleHelpMessage(helpText); 342 } 343 344 public void extractJarFile(RequestContext ctx, HandlerContext handlerCtx) { 345 String fileName = (String )handlerCtx.getInputValue("fileName"); 346 String domainRoot = (String )handlerCtx.getInputValue("domainRoot"); 347 348 if(fileName == null || domainRoot == null) { 349 throw new FrameworkException("fileName, or domainRoot is null DeploymentHandlers.extractJarFile"); 350 } 351 352 try { 353 FileUtil.extractMbeanJarFile(domainRoot, fileName ); 354 }catch (IOException ex){ 355 throw new FrameworkException(ex); 356 } 357 358 } 359 360 361 362 363 365 public void saveThreadPool(RequestContext ctx, HandlerContext handlerCtx) { 366 String name = (String )handlerCtx.getInputValue("name"); 367 String objectName = (String )handlerCtx.getInputValue("objectName"); 368 String threadPool = (String )handlerCtx.getInputValue("threadPoolId"); 369 if (objectName == null) { 370 throw new FrameworkException("'objectName' is null in DeploymentHandler.saveThreadPool"); 371 } 372 373 try { 374 Attribute attr = new Attribute ("thread-pool-ids", threadPool); 375 MBeanUtil.setAttribute(objectName, attr); 376 } catch (Exception ex) { 377 } 382 } 383 384 public void getVirtualservers(RequestContext ctx, HandlerContext handlerCtx) { 385 View view = handlerCtx.getView(); 386 if (!(view instanceof DescriptorContainerView)) { 387 View parent = view.getParent(); 388 if (!(parent instanceof DescriptorContainerView)) { 389 throw new FrameworkException("View is not a DescriptorContainerView!", null, view); 390 } else { 391 view = parent; 392 } 393 } 394 if (view instanceof DescriptorCCPageTitle) { 395 view = view.getParent(); 396 } 397 DescriptorContainerView descView = (DescriptorContainerView)view; 398 String childName = (String )handlerCtx.getInputValue("childName"); 399 TextField textFieldChild = (TextField)descView.getChild(childName); 400 401 String objectName = (String )handlerCtx.getInputValue("vsObjectName"); 402 String vsMethodName = (String )handlerCtx.getInputValue("vsMethodName"); 403 String vsList = ""; 404 405 Object [] vsObjectName = (Object []) 406 MBeanUtil.invoke(objectName, vsMethodName, null, null); 407 String attributeName = "id"; 409 if(vsObjectName != null) { 410 for(int i =0; i < vsObjectName.length; i++) { 411 String virtualservers = (String ) 412 MBeanUtil.getAttribute(vsObjectName[i].toString(), attributeName); 413 if(virtualservers != null && !(virtualservers.equals("__asadmin"))) { 414 vsList += virtualservers + ","; 415 } 416 } 417 } 418 if (vsList.length() > 0) { 419 vsList = vsList.substring(0, vsList.length()-1); 421 textFieldChild.setValue(vsList); 422 } 423 } 424 425 public void setThreadPoolID(RequestContext ctx, HandlerContext handlerCtx) { 426 View view = handlerCtx.getView(); 427 DescriptorContainerView descView = (DescriptorContainerView)view.getParent(); 428 String editKey = (String )descView.getDisplayFieldValue("editKey"); 429 String adapterObjectName = "com.sun.appserv:type=resource-adapter-config,category=config,resource-adapter-name="+editKey; 430 try { 431 String threadPool = (String )MBeanUtil.getAttribute(adapterObjectName, "thread-pool-ids"); 432 ((TextField)view).setValue(threadPool); 433 } catch (Exception ex) { 434 } 436 } 437 438 441 public void loadResourceAdapterProperties(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException { 442 View view = handlerCtx.getView(); 443 ViewDescriptor desc = null; 444 if (handlerCtx.getEvent() instanceof BeforeCreateEvent) 445 desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 446 else { 447 DescriptorContainerView descView = (DescriptorContainerView)((ViewBase)view); 448 desc = descView.getViewDescriptor(); 449 } 450 451 CCActionTableModelInterface model = 452 (CCActionTableModelInterface)handlerCtx.getInputValue("propertiesModel"); 453 ((DefaultModel)model).clear(); 454 Object properties = handlerCtx.getInputValue("properties"); 455 456 if (properties == null) { 457 if (Util.isLoggableFINER()) { 458 Util.logFINER("NO ATTRS FOUND!!"); 459 } 460 return; 462 } 463 464 else if(properties instanceof AttributeList ) { 465 loadResourceAdapterProperties((AttributeList )properties, model); 466 } 467 else if(properties instanceof Map ) { 468 loadResourceAdapterProperties((Map )properties, model); 469 } 470 else { 471 throw new FrameworkException("Unknown instance properties", desc, view); 472 } 473 474 } 475 476 private void loadResourceAdapterProperties (AttributeList attrs, CCActionTableModelInterface model) throws ModelControlException { 477 StringBuffer buf = new StringBuffer (); 479 for(int rowNo = 0; rowNo < attrs.size(); rowNo++) { 480 Attribute attr = (Attribute )attrs.get(rowNo); 481 buf.append("!!! name = " + attr.getName() + " , value = " + attr.getValue()+"\n"); 482 } 483 if (Util.isLoggableFINER()) { 484 Util.logFINER(buf.toString()); 485 } 486 487 model.setRowSelectionType("none"); 488 model.beforeFirst(); 489 for (int rowNo = 0; rowNo < attrs.size(); rowNo++) { 490 model.appendRow(); 491 Attribute attr = (Attribute )attrs.get(rowNo); 492 model.setValue(PROPERTY_NAME, attr.getName()); 493 model.setValue(PROPERTY_VALUE, attr.getValue()); 494 } 495 } 496 497 private void loadResourceAdapterProperties (Map properties, CCActionTableModelInterface model) throws ModelControlException { 498 Set s = properties.keySet(); 499 Iterator iter = s.iterator(); 500 501 model.setRowSelectionType("none"); 502 model.beforeFirst(); 503 while (iter.hasNext()) { 504 Object key = iter.next(); 505 model.appendRow(); 506 model.setValue(PROPERTY_NAME, key); 507 model.setValue(PROPERTY_VALUE, properties.get(key)); 508 } 509 510 } 511 512 515 public void getResourceAdapterProperties(RequestContext ctx, HandlerContext handlerCtx) { 516 517 String location = (String )handlerCtx.getInputValue("location"); 518 if (location == null) { 519 handlerCtx.setOutputValue("properties", null); 523 return; 524 } 525 try{ 526 527 Map props = ConnectorRuntime.getRuntime().getResourceAdapterBeanProperties(location); 528 Set s = props.keySet(); 532 Map newMap = new HashMap (); 533 for (Iterator iter = s.iterator(); iter.hasNext(); ) { 534 newMap.put(iter.next(), ""); 535 } 536 handlerCtx.setOutputValue("properties", newMap); 537 }catch (Exception ex){ 538 Util.logSEVERE("Error in getting ResourceAdapter Properties ", ex); 540 handlerCtx.setOutputValue("properties", null); 541 return; 542 } 543 } 544 545 549 550 public void getResourceAdapterPropertiesForEdit(RequestContext ctx, HandlerContext handlerCtx) { 551 View view = handlerCtx.getView(); 552 553 Object objectName = handlerCtx.getInputValue("objectName"); 554 if (objectName == null) { 555 throw new FrameworkException("'objectName' is null in DeploymentHandler.getResourceAdpaterPropertiesForEdit"); 556 } 557 String methodName = (String )handlerCtx.getInputValue("methodName"); 558 if (methodName == null) { 559 throw new FrameworkException("'methodName' is null in DeploymentHandler.getResourceAdpaterPropertiesForEdit"); 560 } 561 Object returnValue = null; 562 try { 563 564 returnValue = MBeanUtil.invoke(objectName.toString(), methodName, 565 null, null); 566 567 } catch (Exception ex) { 568 } 570 handlerCtx.setOutputValue("value", returnValue); 571 } 572 573 public void createResourceAdapter(RequestContext ctx, HandlerContext handlerCtx) { 574 View view = handlerCtx.getView(); 575 576 Object objectName = handlerCtx.getInputValue("objectName"); 577 if (objectName == null) { 578 throw new FrameworkException("'objectName' is null in CommonHandlers.invokeMBean"); 579 } 580 String methodName = (String )handlerCtx.getInputValue("methodName"); 581 if (methodName == null) { 582 throw new FrameworkException("'methodName' is null in CommonHandlers.invokeMBean"); 583 } 584 ArrayList types = (ArrayList )handlerCtx.getInputValue("types"); 585 ArrayList params = (ArrayList )handlerCtx.getInputValue("params"); 586 587 createResourceAdapter(objectName, methodName, params, types); 588 } 589 590 private Object createResourceAdapter(Object objectName, String methodName, ArrayList params, ArrayList types) { 591 Object [] paramsAndTypes = MBeanUtil.getParamsAndTypes(params, types); 592 try { 593 return MBeanUtil.invoke(objectName.toString(), methodName, 594 (Object [])(paramsAndTypes[0]), (String [])(paramsAndTypes[1])); 595 596 } catch (Exception ex) { 597 } 599 return null; 600 } 601 602 private void setResourceAdapterProperties(String name) { 603 String objectName = "com.sun.appserv:type=resource-adapter-config,category=config,resource-adapter-name="+ name; 604 Properties props = null; 605 try { 606 props = ConnectorRuntime.getRuntime().getResourceAdapterConfigProps(name); 608 } 609 catch (Exception e) { 610 Util.logINFO("Deployment Handler setResourceAdapterProperties:"+e.getMessage()); 612 return; 613 } 614 Enumeration ee = props.propertyNames(); 615 616 while(ee.hasMoreElements()) { 617 Object key = ee.nextElement(); 618 String [] type = new String []{"javax.management.Attribute"}; 619 Attribute attr = new Attribute (key.toString(), props.getProperty(key.toString()).toString()); 620 Object [] params = new Object []{attr}; 621 MBeanUtil.invoke(objectName, "setProperty", params, type); 622 } 623 624 } 625 626 public void applicationRefAction(RequestContext ctx, HandlerContext handlerCtx) { 627 View view = handlerCtx.getView(); 628 DescriptorContainerView descView = (DescriptorContainerView) 629 (((ViewBase)view).getParentViewBean()); 630 ViewDescriptor vd = descView.getViewDescriptor(); 631 632 String tableChildName = (String )handlerCtx.getInputValue("tableChildName"); 634 ViewDescriptor tableDescriptor = vd.getChildDescriptor(tableChildName); 635 if (tableDescriptor == null) { 636 throw new FrameworkException("tableDescriptor is null", vd, view); 637 } 638 if (!(tableDescriptor instanceof CCActionTableDescriptor)) { 639 throw new FrameworkException("tableDescriptor is of wrong type", 640 tableDescriptor, view); 641 } 642 CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("propertiesModel"); 643 if (model == null) { 644 throw new FrameworkException("PropertiesHandler.getModel: Parameter 'propertiesModel' not specified"); 645 } 646 String editKeyValue = (String )handlerCtx.getInputValue("editKeyValue"); 647 String action = (String )handlerCtx.getInputValue("action"); 648 String methodName = (String )handlerCtx.getInputValue("methodName"); 649 model.setRowSelectionType("multiple"); 650 try { 651 model.beforeFirst(); 652 while(model.next()) { 653 if (model.isRowSelected()) { 654 String objectName = (String )model.getValue("objectName"); 655 String target = (String )MBeanUtil.getAttribute(objectName, "name"); 656 changeEnableStatus(editKeyValue, new String [] { target }, action); 657 model.setRowSelected(false); 658 } 659 } 660 } catch (Exception ex) { 661 Util.logFINER("Error while enabling: " + vd.getName()); 662 throw new FrameworkException(ex); 663 } 664 ContainerViewBase containerView = 665 (ContainerViewBase)(tableDescriptor.getView(ctx).getParent()); 666 containerView.removeChild(tableDescriptor.getName()); 667 ((DefaultModel)model).clear(); 668 } 669 670 671 672 public void actionClicked(RequestContext ctx, HandlerContext handlerCtx) { 673 View view = handlerCtx.getView(); 674 DescriptorContainerView descView = (DescriptorContainerView) 675 (((ViewBase)view).getParentViewBean()); 676 ViewDescriptor vd = descView.getViewDescriptor(); 677 String childName = (String )vd.getParameter("tableChildName"); 678 679 if (childName == null) { 680 throw new FrameworkException("childName not specified", vd, view); 681 } 682 ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName); 683 if (tableDescriptor == null) { 684 throw new FrameworkException("tableDescriptor is null", vd, view); 685 } 686 if (!(tableDescriptor instanceof CCActionTableDescriptor)) { 687 throw new FrameworkException("tableDescriptor is of wrong type", 688 tableDescriptor, view); 689 } 690 String buttonClicked = (String )handlerCtx.getInputValue("ClickedAction"); 691 try { 692 693 if (buttonClicked.equalsIgnoreCase("undeploy")) { 694 String type = (String )handlerCtx.getInputValue("AppType"); 695 undeploy(((CCActionTableDescriptor)tableDescriptor).getModel(), 696 tableDescriptor, type); 697 } 698 else { 699 doAction(((CCActionTableDescriptor)tableDescriptor).getModel(), 700 tableDescriptor, buttonClicked); 701 } 702 } catch (FrameworkException ex) { 703 throw new FrameworkException("Error while deleting from: '"+ 704 tableDescriptor.getName()+"'", ex, tableDescriptor, descView); 705 } 706 } 707 708 private void doAction(CCActionTableModelInterface model, ViewDescriptor vd, String buttonClicked) { 709 RequestContext ctx = RequestManager.getRequestContext(); 710 DeploymentFacility df= DeploymentFacilityFactory.getLocalDeploymentFacility(); 711 String defaultTarget = ConfigProperties.getInstance().getDefaultTarget(); 712 JESProgressObject progressObject = null; 713 model.setRowSelectionType("multiple"); 714 try { 715 model.beforeFirst(); 716 while(model.next()) { 718 if (model.isRowSelected()) { 719 enableDisableAll((String ) model.getValue(NAME), buttonClicked); 720 model.setRowSelected(false); 721 } 722 } 723 }catch (Exception ex) { 724 throw new FrameworkException("Error while " + buttonClicked + " : '"+ 725 vd.getName()+"'", ex, vd, null); 726 } 727 View view = vd.getView(ctx).getParent(); 728 ContainerViewBase descView = (ContainerViewBase)view; 729 descView.removeChild(vd.getName()); 730 ((DefaultModel)model).clear(); 731 } 732 733 private void enableDisableAll(String appsName, String action) 734 { 735 RequestContext ctx = RequestManager.getRequestContext(); 736 Boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported(); 737 boolean targetSupported = (isTargetSupported == null) ? false : isTargetSupported.booleanValue(); 738 String defaultTarget = ConfigProperties.getInstance().getDefaultTarget(); 739 if (targetSupported){ 740 String [] params = new String [] {appsName}; 741 String [] types = new String [] {"java.lang.String"}; 742 ObjectName [] refs = (ObjectName []) MBeanUtil.invoke("com.sun.appserv:type=applications,category=config" , "listReferencees", params, types); 743 int size = (refs==null ) ? 0 : refs.length; 744 String [] targetList = new String [size]; 745 for(int i=0; i<size; i++){ 746 targetList[i] = (String )MBeanUtil.getAttribute(refs[i], "name"); 747 } 748 changeEnableStatus(appsName, targetList, action); 749 }else{ 750 changeEnableStatus(appsName, new String [] { defaultTarget }, action); 751 } 752 } 753 754 static public void changeEnableStatus(String appsName, String [] targetList, String action ){ 755 if (targetList == null) return; 756 Object [] params = new String []{appsName}; 759 760 Integer type = (Integer ) MBeanUtil.invoke("com.sun.appserv:type=applications,category=config", "getModuleType", params, new String []{"java.lang.String"}); 761 if((type != null) && (type.intValue() == DisplayItemMapper.MODULE_MBEAN)){ 762 changeEnableStatusForMbean(appsName,targetList,action); 763 return; 764 } 765 766 boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue(); 767 DeploymentFacility df= DeploymentFacilityFactory.getLocalDeploymentFacility(); 768 JESProgressObject progressObject = null; 769 if (action.equals("enable") || action.equals("true")){ 770 if (isTargetSupported){ 772 if (getAppStatus(appsName, "domain").equals("false")){ 773 String [] newTargetList = new String [targetList.length+1]; 774 for(int i=0; i< targetList.length; i++){ 775 newTargetList[i]=targetList[i]; 776 } 777 newTargetList[targetList.length] = "domain"; 778 targetList = newTargetList; 779 } 780 } 781 progressObject = df.enable(df.createTargets(targetList), appsName); 782 }else{ 783 progressObject = df.disable(df.createTargets(targetList), appsName); 784 } 785 DeploymentStatus status = df.waitFor(progressObject); 786 checkDeployStatus(status, null); 787 } 788 789 static private void changeEnableStatusForMbean(String appsName, String [] targetList, String action){ 790 791 boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue(); 792 if (action.equals("enable") || action.equals("true")){ 793 if (getAppStatus(appsName, "domain").equals("false")){ 795 MBeanUtil.setAttribute("com.sun.appserv:type=mbean,category=config,name="+appsName, new Attribute ("enabled", "true")); 796 } 797 } 798 String status = (action.equals("true") || action.equals("enable")) ? "true" : "false"; 799 Attribute attr = new Attribute ("enabled", status); 800 for(int i=0; i<targetList.length; i++){ 801 String objname = "com.sun.appserv:type=application-ref,category=config,ref="+appsName+",server="+targetList[i]; 802 MBeanUtil.setAttribute(objname, attr); 803 } 804 } 805 806 807 private void undeploy(CCActionTableModelInterface model, ViewDescriptor vd, String type) { 808 RequestContext ctx = RequestManager.getRequestContext(); 809 String deleteKey = (String )vd.getParameter("deleteKey"); 810 String objectName = (String )vd.getParameter("rowObjectName"); 811 Boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported(); 813 boolean targetSupported = isTargetSupported == null ? false:isTargetSupported.booleanValue(); 814 815 if (deleteKey == null) { 816 throw new FrameworkException("No delete key specified"); 817 } 818 if (objectName == null) { 819 throw new FrameworkException("No ObjectName specified"); 820 } 821 822 model.setRowSelectionType("multiple"); 823 DeploymentFacility df= DeploymentFacilityFactory.getLocalDeploymentFacility(); 824 try { 825 model.beforeFirst(); 826 while(model.next()) { 828 if (model.isRowSelected()) { 829 String componentName = model.getValue(deleteKey).toString(); 830 if(type.equals("rar")) { 831 try { 832 String defaultTarget = ConfigProperties.getInstance().getDefaultTarget(); 833 String key = model.getValue(deleteKey).toString(); 834 Object [] params = new Object []{key, defaultTarget}; 835 String [] types = new String []{"java.lang.String", "java.lang.String"}; 836 String resourceMethodName = "deleteResourceAdapterConfig"; 837 String resourceObjectName = "com.sun.appserv:type=resources,category=config"; 838 MBeanUtil.invoke(resourceObjectName, resourceMethodName, params, 839 types); 840 } 841 catch(Exception ex) { 842 Util.logINFO("Deployment Handler deleteResourceAdapter Failed:"+ex.getMessage()); 844 } 845 } 848 849 JESProgressObject progressObject = null; 850 String [] targetNames = null; 851 if(targetSupported){ 852 targetNames = getApplicationTargets(model.getValue(deleteKey).toString(), objectName); 853 }else { 854 targetNames = new String [] {ConfigProperties.getInstance().getDefaultTarget()}; 855 } 856 progressObject = df.undeploy(df.createTargets(targetNames), componentName, null); 857 model.setRowSelected(false); 858 DeploymentStatus status = df.waitFor(progressObject); 859 checkDeployStatus(status, null); 860 } 861 } 862 } catch (Exception ex) { 863 throw new FrameworkException("Error while undeploying: '"+ 864 vd.getName()+"'", ex, vd, null); 865 } 866 View view = vd.getView(ctx).getParent(); 867 ContainerViewBase descView = (ContainerViewBase)view; 868 descView.removeChild(vd.getName()); 869 ((DefaultModel)model).clear(); 870 } 871 872 private String [] getApplicationTargets(String name, String objectName) throws Exception { 873 ObjectName [] returnValue = null; 874 Vector targets = new Vector (); 875 try { 876 returnValue = (ObjectName [])MBeanUtil.invoke(objectName, "listReferencees", new Object []{name}, 877 new String []{"java.lang.String"}); 878 for(int i = 0; returnValue!=null && i < returnValue.length; i++) { 879 targets.add(MBeanUtil.getAttribute(returnValue[i], "name")); 880 } 881 } catch (Exception ex) { 882 throw ex; 883 } 884 if(targets.size() == 0) { 885 String defaultTarget = ConfigProperties.getInstance().getDefaultTarget(); 886 targets.add(defaultTarget); 887 } 888 return (String [])(targets.toArray(new String [targets.size()])); 889 } 890 891 public void createAppReferences(RequestContext ctx, HandlerContext handlerCtx) { 893 String [] targetNames = (String [])handlerCtx.getInputValue("targets"); 894 if (targetNames != null && targetNames.length > 0){ 895 String key = (String )handlerCtx.getInputValue("key"); 896 DeploymentFacility df= DeploymentFacilityFactory.getLocalDeploymentFacility(); 897 JESProgressObject progressObject = null; 898 Properties dProps = new Properties (); 899 progressObject = df.createAppRef(df.createTargets(targetNames), key, dProps); 901 DeploymentStatus status = df.waitFor(progressObject); 902 checkDeployStatus(status, null); 903 } 904 } 905 906 public void deleteAppReferences(RequestContext ctx, HandlerContext handlerCtx) { 907 String [] targetNames = (String [])handlerCtx.getInputValue("targets"); 908 if (targetNames != null && targetNames.length > 0){ 909 String key = (String )handlerCtx.getInputValue("key"); 910 DeploymentFacility df= DeploymentFacilityFactory.getLocalDeploymentFacility(); 911 JESProgressObject progressObject = null; 912 progressObject = df.deleteAppRef(df.createTargets(targetNames), key, null); 913 DeploymentStatus status = df.waitFor(progressObject); 914 checkDeployStatus(status, null); 915 } 916 } 917 918 920 public void loadDescriptorTableModel(RequestContext ctx, HandlerContext handlerCtx) { 921 View view = handlerCtx.getView(); 922 ArrayList displayNamesList = (ArrayList )handlerCtx.getInputValue("displayNames"); 923 String appName = (String )ctx.getRequest().getAttribute("editKeyValue"); 924 if (!(handlerCtx.getEvent() instanceof BeforeCreateEvent)) { 925 ViewDescriptor desc = (view instanceof DescriptorContainerView) ? 926 ((DescriptorContainerView)view).getViewDescriptor() : 927 (ViewDescriptor)null; 928 throw new FrameworkException("This handler is for 'beforeCreate'" + 929 " handlers only!", desc, view); 930 } 931 932 ViewDescriptor desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 933 if (!(desc instanceof CCActionTableDescriptor)) { 934 throw new FrameworkException("Table model expected here", desc, view); 935 } 936 CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)desc; 937 CCActionTableModelInterface model = ccDesc.getModel(); 938 939 String type = (String )handlerCtx.getInputValue("value"); 940 if (type == null) { 941 throw new FrameworkException("'type' is null in DeploymentHandlers.loadDescriptorTableModel"); 942 } 943 String standardDescriptor = null; 944 String sunSpecificDescriptor = null; 945 946 String [] descriptors = null; 947 if(appName != null) { 948 descriptors = getDescriptors(appName, null); 949 for(int j=0; descriptors != null && j < descriptors.length; j++) { 950 model.appendRow(); 951 model.setValue((String )displayNamesList.get(0), appName); 952 int index = descriptors[j].lastIndexOf(File.separator) +1; 953 model.setValue((String )displayNamesList.get(1), descriptors[j].substring(index)); 954 model.setValue("location", descriptors[j]); 955 } 956 957 if(type.equals("j2ee-application")) { 959 String [] modules = (String [])MBeanUtil.invoke("com.sun.appserv:type=applications,category=config", "getModuleComponents", 960 new Object []{appName}, new String []{"java.lang.String"}); 961 if(modules != null) { 962 for (int i=0; i < modules.length; i++) { 963 try { 964 String subComponentName = new ObjectName (modules[i]).getKeyProperty("name"); 965 descriptors = getDescriptors(appName, subComponentName); 966 967 for(int j=0; descriptors != null && j < descriptors.length; j++) { 968 model.appendRow(); 969 model.setValue((String )displayNamesList.get(0), subComponentName); 970 int index = descriptors[j].lastIndexOf(File.separator) +1; 971 model.setValue((String )displayNamesList.get(1), descriptors[j].substring(index)); 972 model.setValue("location", descriptors[j]); 973 } 974 975 } catch (Exception e){ 976 } 978 } 979 } 980 } 981 } 982 } 983 984 private String [] getDescriptors(String appName, String subComponent) { 985 String [] descriptors = (String [])MBeanUtil.invoke("com.sun.appserv:type=applications,category=config", "getDeploymentDescriptorLocations", 986 new Object []{appName, subComponent}, new String []{"java.lang.String", "java.lang.String"}); 987 return descriptors; 988 } 989 990 static private String getAppStatus(String appName, String target){ 991 Object status = MBeanUtil.invoke( 992 "com.sun.appserv:type=applications,category=config", 993 "getStatus", 994 new String [] {appName, target}, 995 new String [] {"java.lang.String", "java.lang.String"} 996 ); 997 return status.toString(); 998 } 999 1000 public void getAppStatus2(RequestContext ctx, HandlerContext handlerCtx) { 1001 handlerCtx.setOutputValue( 1002 "status", 1003 getAppStatus( 1004 (String )handlerCtx.getInputValue("appName"), 1005 (String )handlerCtx.getInputValue("target"))); 1006 } 1007 1008 public void loadDeploymentTableModel(RequestContext ctx, HandlerContext handlerCtx) { 1009 View view = handlerCtx.getView(); 1010 if (!(handlerCtx.getEvent() instanceof BeforeCreateEvent)) { 1011 ViewDescriptor desc = (view instanceof DescriptorContainerView) ? 1012 ((DescriptorContainerView)view).getViewDescriptor() : 1013 (ViewDescriptor)null; 1014 throw new FrameworkException("This handler is for 'beforeCreate'" + 1015 " handlers only!", desc, view); 1016 } 1017 1018 ViewDescriptor desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 1019 if (!(desc instanceof CCActionTableDescriptor)) { 1020 throw new FrameworkException("Table model expected here", desc, view); 1021 } 1022 CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)desc; 1023 CCActionTableModelInterface model = ccDesc.getModel(); 1024 ((DefaultModel)model).clear(); 1025 1026 ArrayList modelNamesList = (ArrayList )handlerCtx.getInputValue("attributeNames"); 1027 ArrayList displayNamesList = (ArrayList )handlerCtx.getInputValue("displayNames"); 1028 String [] modelNames = (String []) 1029 modelNamesList.toArray(new String [modelNamesList.size()]); 1030 Object [] keys = (Object [])handlerCtx.getInputValue("keys"); 1031 1032 if (keys == null) { 1033 return; } 1035 for (int rowNo = 0; rowNo < keys.length; rowNo++) { 1036 1037 String objectType = null; 1038 String type = null; 1039 ObjectName currentObjName = null; 1040 try { 1041 currentObjName = new ObjectName (keys[rowNo].toString()); 1042 type = currentObjName.getKeyProperty("type"); 1043 } catch (Exception ex) { 1044 throw new FrameworkException(ex, ccDesc, view); 1045 } 1046 boolean isApp = false; 1047 boolean isAppRef = false; 1048 boolean isResource = false; 1049 boolean isResourceRef = false; 1050 if (type != null){ 1051 if (type.equals("application-ref")){ 1052 isAppRef = true; 1053 }else 1054 if (type.equals("resource-ref")){ 1055 isResourceRef = true; 1056 }else 1057 if (type.equals("j2ee-application") || type.equals("ejb-module") 1058 || type.equals("web-module") || type.equals("connector-module")){ 1059 isApp = true; 1060 objectType = (String )MBeanUtil.getAttribute(currentObjName, "object-type"); 1061 if( objectType != null && !objectType.equalsIgnoreCase("user")) { 1062 continue; 1063 } 1064 }else 1065 if (type.equals("appclient-module")|| type.equals("lifecycle-module") || type.equals("mbean")){ 1066 isApp = true; 1067 }else 1068 isResource = true; 1069 } 1070 boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue(); 1071 AttributeList attrList = new AttributeList (); 1072 for(int i=0; i < modelNames.length; i++){ 1073 1074 String attrValue = (String ) MBeanUtil.getAttribute(keys[rowNo].toString(),modelNames[i]); 1075 if( ! "enabled".equals(modelNames[i])){ 1076 attrList.add(new Attribute (modelNames[i], attrValue)); 1077 continue; 1078 } 1079 String realStatus = ""; 1081 if (isApp){ 1082 int statusSummary = getAppStatusSummary( keys[rowNo].toString()); 1083 realStatus = convertStatusSummary(statusSummary); 1084 } 1085 if (isAppRef){ 1086 String appsName = currentObjName.getKeyProperty("ref"); 1087 realStatus = getRealTargetStatus(appsName, currentObjName); 1088 } 1089 if(isResourceRef){ 1090 realStatus = getRealResourceTargetStatus(currentObjName); 1091 } 1092 if(isResource){ 1093 int statusSummary = getResourceStatusSummary(currentObjName); 1094 realStatus = convertStatusSummary(statusSummary); 1095 } 1096 attrList.add(new Attribute (modelNames[i], realStatus)); 1097 } 1098 model.appendRow(); 1099 1100 for (int i = 0, colNo = 0; i < attrList.size(); i++) { 1101 Attribute attr = (Attribute )attrList.get(i); 1102 1103 while ((colNo < modelNames.length) && 1104 !attr.getName().equals(modelNames[colNo])) { 1105 colNo++; 1106 } 1107 if (colNo < modelNames.length) { 1108 if (attr.getName().equals("java-web-start-enabled")){ 1109 String attrValue = ("false".equals(attr.getValue())) ? Util.getMessage("common.Disabled") : Util.getMessage("common.Enabled"); 1110 model.setValue((String )displayNamesList.get(colNo), attrValue); 1111 }else 1112 model.setValue((String )displayNamesList.get(colNo), attr.getValue()); 1113 } 1114 } 1115 String objn = currentObjName.toString(); 1116 model.setValue("objectName", objn); 1117 model.setValue("objectType", type); 1118 } 1119 } 1120 1121 public void loadSubcomponents(RequestContext ctx, HandlerContext handlerCtx) { 1122 View view = handlerCtx.getView(); 1123 ViewDescriptor desc = ((DescriptorCCActionTable)view).getViewDescriptor(); 1124 String moduleName = (String )handlerCtx.getInputValue("moduleName"); 1125 CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)desc; 1126 CCActionTableModelInterface model = ccDesc.getModel(); 1127 String objectName = (String )handlerCtx.getInputValue("objectName"); 1129 String methodName = (String )handlerCtx.getInputValue("methodName"); 1130 try { 1131 String [] modules = (String [])MBeanUtil.invoke(objectName, methodName, 1132 new Object []{moduleName}, new String []{"java.lang.String"}); 1133 for(int i = 0; i < modules.length; i++) { 1134 ObjectName on = new ObjectName (modules[i]); 1135 model.appendRow(); 1136 model.setValue("componentName", on.getKeyProperty("name")); 1138 model.setValue("componentType", on.getKeyProperty("j2eeType")); 1139 } 1140 } catch (Exception ex) { 1141 throw new FrameworkException( 1142 "Exception thrown while attempting to get Modules List.", 1143 ex, ccDesc, view); 1144 } 1145 } 1146 public void displayDeployPageChild(RequestContext ctx, HandlerContext handlerCtx) throws Exception { 1149 View view = handlerCtx.getView(); 1150 if (!(view instanceof DescriptorContainerView)) { 1151 View parent = view.getParent(); 1152 if (!(parent instanceof DescriptorContainerView)) { 1153 throw new FrameworkException("View is not a DescriptorContainerView!", null, view); 1154 } else { 1155 view = parent; 1156 } 1157 } 1158 if (view instanceof DescriptorCCPageTitle) { 1159 view = view.getParent(); 1160 } 1161 DescriptorContainerView descView = (DescriptorContainerView)view; 1162 Boolean isTargetSupported = 1163 ConfigProperties.getInstance().getTargetSupported(); 1164 String propertyName = (String )handlerCtx.getInputValue("propertyName"); 1165 ViewDescriptor propertySheetDescriptor = descView.getViewDescriptor(); 1166 1167 if (propertyName == null) { 1168 throw new FrameworkException("displayVirtualserver: propertySheetName is null", propertySheetDescriptor, view); 1169 } 1170 1171 if (propertySheetDescriptor == null) { 1172 throw new FrameworkException("displaVirtualServer: propertySheetDescriptor is null", propertySheetDescriptor, view); 1173 } 1174 if(!(propertySheetDescriptor instanceof CCPropertySheetDescriptor)) { 1175 throw new FrameworkException("displayVirtualServer: propertySheetDescriptor is of wrong type", propertySheetDescriptor, view); 1176 } 1177 CCPropertySheetModelInterface model = ((CCPropertySheetDescriptor)propertySheetDescriptor).getModel(); 1178 1179 if (isTargetSupported != null && isTargetSupported.booleanValue()) { 1180 model.setVisible(propertyName, false); 1181 handlerCtx.setOutputValue("value", "true"); 1182 } else { 1183 model.setVisible(propertyName, true); 1184 handlerCtx.setOutputValue("value", "false"); 1185 } 1186 } 1187 1188 public String endExecuteLinkDisplay(RequestContext ctx, HandlerContext handlerCtx) { 1189 View bean = handlerCtx.getView(); 1190 ChildContentDisplayEvent ev = (ChildContentDisplayEvent)handlerCtx.getEvent(); 1191 String content = ev.getContent(); 1192 String isWebService = (String )handlerCtx.getInputValue("isWebService"); 1193 String appName = (String )handlerCtx.getInputValue("appName"); 1194 String port = null; 1195 try { 1196 port = getPortForApplication(appName); 1197 } catch (Exception ex) { 1198 ex.printStackTrace(); } 1200 1201 String serverName = ctx.getRequest().getServerName(); 1202 String ctxtRoot= (String )handlerCtx.getInputValue("ctxtRoot"); 1203 if (ctxtRoot == null || ctxtRoot.length() == 0) { 1204 ctxtRoot = "/"; 1205 } 1206 if (ctxtRoot.indexOf("/") != 0) { 1207 ctxtRoot = "/" + ctxtRoot; 1208 } 1209 String text = removeProp(content, "onclick"); 1210 if (port != null) { 1211 if (isWebService == null) { 1212 content = addProp(removeProp(text, "href"), 1213 "href=\"http://" + serverName + ":" + port + ctxtRoot + "\" target=\"_blank\""); 1214 } else { 1215 content = addProp(text, 1216 "onClick=\"window.open('http://" + serverName + ":" + port + ctxtRoot + "');document.Form.target='_self'\""); } 1218 } 1219 else { 1220 if (isWebService == null) { 1221 content = addProp(removeProp(text, "href"), 1222 "href=\""+ ctxtRoot +"\" target=\"_blank\""); 1223 } else { 1224 content = addProp(text, 1225 "onClick=\"window.open('"+ ctxtRoot + "');document.Form.target='_self'\""); } 1227 } 1228 return content; 1229 } 1230 1231 1232 public void getLaunchURLPath(RequestContext ctx, HandlerContext handlerCtx) { 1233 View bean = handlerCtx.getView(); 1234 String appclientName = (String )handlerCtx.getInputValue("appclientName"); 1235 String applicationName = (String )handlerCtx.getInputValue("applicationName"); 1236 if (Util.isEmpty(appclientName)) 1237 throw new FrameworkException("Deployment.getLaunchURLPath(), appclientName is NULL"); 1238 try { 1239 String jwsEnabled ; 1240 if (Util.isEmpty(applicationName)) 1241 jwsEnabled = (String ) MBeanUtil.getAttribute("com.sun.appserv:type=appclient-module,category=config,name="+appclientName, "java-web-start-enabled"); 1242 else 1243 jwsEnabled = (String ) MBeanUtil.getAttribute("com.sun.appserv:type=j2ee-application,category=config,name="+applicationName, "java-web-start-enabled"); 1244 if ( "false".equals(jwsEnabled)){ 1245 handlerCtx.setOutputValue("isEnabled", Boolean.FALSE); 1246 return; 1247 } 1248 1249 NamingConventions nc = new NamingConventions(); 1250 String path = (Util.isEmpty(applicationName)) ? nc.getLaunchURLPath(appclientName) : 1251 nc.getLaunchURLPath(applicationName, appclientName); 1252 if (!Util.isEmpty(path)){ 1253 handlerCtx.setOutputValue("path", path); 1254 handlerCtx.setOutputValue("isEnabled", Boolean.TRUE); 1255 }else 1256 handlerCtx.setOutputValue("isEnabled", Boolean.FALSE); 1257 1258 }catch (Exception ex){ 1259 Util.logFINE(ex); 1261 ex.printStackTrace(); 1262 handlerCtx.setOutputValue("isEnabled", Boolean.FALSE); 1263 } 1264 } 1265 1266 public void getAppClientLinkPE(RequestContext ctx, HandlerContext handlerCtx) { 1267 String appName = (String )handlerCtx.getInputValue("appId"); 1268 String port = null; 1269 try { 1270 port = getPortForApplication(appName); 1271 } catch (Exception ex) { 1272 ex.printStackTrace(); } 1274 String serverName = ctx.getRequest().getServerName(); 1275 String appendUrl = (String )handlerCtx.getInputValue("appendUrl"); 1276 if (port != null) 1277 appendUrl = "http://" + serverName + ":" + port + appendUrl; 1278 handlerCtx.setOutputValue("appClientLink", appendUrl); 1279 } 1280 1281 1282 public void getAppClientLinks(RequestContext ctx, HandlerContext handlerCtx) { 1283 String id = (String )handlerCtx.getInputValue("appId"); 1285 String appendUrl = (String )handlerCtx.getInputValue("appendUrl"); 1286 if (appendUrl != null) { 1287 appendUrl = ((appendUrl.startsWith("/") ? appendUrl.substring(1) : appendUrl)); 1288 } 1289 List urls = getURLs(id, getWebAppReferencees(id)); 1291 String [] values = new String [urls.size()]; 1292 for(int i=0; i< urls.size(); i++){ 1293 values[i] = (String ) urls.get(i)+appendUrl; 1294 } 1295 handlerCtx.setOutputValue("appClientLinks", values); 1296 } 1297 1298 1299 public void populateRadioButtons(RequestContext ctx, HandlerContext handlerCtx) { 1301 SelectableGroup radioButtonChild = (SelectableGroup) handlerCtx.getView(); 1303 DescriptorContainerView parent = (DescriptorContainerView) radioButtonChild.getParent(); 1305 1306 ViewDescriptor vd = parent.getViewDescriptor(); 1308 ViewDescriptor cvd = vd.getChildDescriptor(radioButtonChild.getName()); 1309 1310 String [] appClientLinks = (String []) handlerCtx.getInputValue("appClientLinks"); 1311 OptionList options = new OptionList( appClientLinks, appClientLinks); radioButtonChild.setOptions(options); 1313 radioButtonChild.setValue(appClientLinks[0]); 1314 } 1315 1316 private String getNonAdminVirtualServer() { 1318 String vsId = null; 1319 ObjectName [] vsObjectNames = (ObjectName []) 1320 MBeanUtil.invoke("ias:type=configs,category=config", 1321 "listVirtualServers", 1322 new Object []{null}, 1323 new String []{"java.lang.String"}); 1324 if (vsObjectNames != null) { 1325 for (int i = 0; i < vsObjectNames.length; i++) { 1326 String id = (String )MBeanUtil.getAttribute(vsObjectNames[i], "id"); 1327 if (!(id.equals("__asadmin"))) { 1328 vsId = id; 1329 break; 1330 } 1331 } 1332 } 1333 return vsId; 1334 } 1335 1336 1337 private String getPortForApplication(String appName) { 1338 ObjectName appRef = (ObjectName )MBeanUtil.invoke 1339 ("ias:type=server,name=server,category=config", 1340 "getApplicationRefByRef", 1341 new Object []{appName}, 1342 new String []{"java.lang.String"}); 1343 1344 String vsId = null; 1345 if (appRef == null) { vsId = getNonAdminVirtualServer(); 1347 } 1348 else { 1349 vsId = (String )MBeanUtil.getAttribute(appRef, "virtual-servers"); 1350 if (vsId == null || vsId.length() ==0) { vsId = getNonAdminVirtualServer(); 1352 } else { 1353 if (vsId.indexOf(",") > 0) { 1354 vsId = vsId.substring(0, vsId.indexOf(",")); 1355 } 1356 } 1357 } 1358 if (vsId == null) 1359 return null; 1361 String port = null; 1362 ObjectName vsObjectName = (ObjectName ) 1363 MBeanUtil.invoke("ias:type=configs,category=config", 1364 "getVirtualServer", 1365 new Object []{vsId, null}, 1366 new String []{"java.lang.String", "java.lang.String"}); 1367 if (vsObjectName != null) { 1368 String listener = (String )MBeanUtil.getAttribute(vsObjectName, "http-listeners"); 1369 if (listener != null) { 1370 if (listener.indexOf(",") > 0) { 1371 listener = listener.substring(0, listener.indexOf(",")); 1372 } 1373 ObjectName listenerObjectName = (ObjectName ) 1374 MBeanUtil.invoke("ias:type=configs,category=config", 1375 "getHttpListener", 1376 new Object []{listener, null}, 1377 new String []{"java.lang.String", "java.lang.String"}); 1378 port = (String )MBeanUtil.getAttribute(listenerObjectName, "port"); 1379 } 1380 } 1381 return port; 1382 } 1383 1384 1385 private String addProp(String tag, String addText) { 1386 int i = tag.indexOf(' '); 1387 if (i<0) { 1388 return tag; 1389 } 1390 String text = tag.substring(0,i) + " " + addText + tag.substring(i,tag.length()); 1391 return text; 1392 } 1393 1394 private String removeProp(String tag, String prop) { 1395 int i = tag.indexOf(prop); 1396 if (i<0) return tag; 1397 int j = tag.indexOf('\"', i+2+prop.length()); 1398 if (j<0) return tag; 1399 String text = ""; 1400 if(prop.equals("onclick")) { 1401 text = tag.substring(0,i) + tag.substring(j+1, tag.length()); 1402 } else { 1403 text = tag.substring(0,i) + tag.substring(j+2, tag.length()); 1404 } 1405 return text; 1406 } 1407 1408 1409 1412 public static String getDefaultHostName() { 1413 String defaultHostName = "localhost"; 1414 try { 1415 InetAddress host = InetAddress.getLocalHost(); 1416 defaultHostName = host.getCanonicalHostName(); 1417 } catch(UnknownHostException uhe) { 1418 } 1421 return defaultHostName; 1422 } 1423 1424 1425 1431 protected String getHost(ObjectName serverInstance) { 1432 String nodeAgentRef = (String )MBeanUtil.getAttribute(serverInstance, "node-agent-ref"); 1434 if ((nodeAgentRef == null) || nodeAgentRef.equals("")) { 1435 return getDefaultHostName(); 1436 } 1437 1438 ObjectName jmxConnector = (ObjectName )MBeanUtil.invoke( 1440 "com.sun.appserv:type=node-agent,name="+nodeAgentRef+ 1441 ",category=config", 1442 "getJmxConnector", null, null); 1443 if (jmxConnector == null) { 1444 return getDefaultHostName(); 1445 } 1446 1447 AttributeList properties = (AttributeList )MBeanUtil.invoke( 1451 jmxConnector, "getProperties", null, null); 1452 Attribute att; 1453 String hostName = null; 1454 Iterator it = properties.iterator(); 1455 while (it.hasNext()) { 1456 att = (Attribute )it.next(); 1457 if (att.getName().equals("client-hostname")) { 1458 hostName = (String )att.getValue(); 1459 break; 1460 } 1461 } 1462 1463 if ((hostName == null) || hostName.equals("") || hostName.equals("0.0.0.0")) { 1465 return getDefaultHostName(); 1466 } 1467 1468 return hostName; 1470 } 1471 1472 1473 1481 protected String replaceTokens(ObjectName serverInstance, String src) { 1482 int idx = src.lastIndexOf("${"); 1483 if (idx < 0) { 1484 return src; 1486 } 1487 1488 Properties sysProp = (Properties ) 1490 MBeanUtil.invoke(serverInstance, "listSystemProperties", 1491 new Object []{ new Boolean ("true")}, new String []{"boolean"}); 1492 int endIdx; 1493 String newString; 1494 while (idx > -1) { 1495 endIdx = src.indexOf("}", idx+2); 1496 newString = 1497 src.substring(0, idx)+ 1498 sysProp.getProperty(src.substring(idx+2, endIdx)) + 1499 src.substring(endIdx+1); 1500 src = newString; 1501 idx = src.lastIndexOf("${"); 1502 } 1503 1504 return src; 1506 } 1507 1508 1509 1514 protected List getURLs(String appId, ObjectName serverInstance) { 1515 String configRef = (String )MBeanUtil.getAttribute(serverInstance, "config-ref"); 1517 1518 String name = (String )MBeanUtil.getAttribute(serverInstance, "name"); 1520 String appObj = "com.sun.appserv:type=application-ref,ref="+appId+",server="+name+",category=config"; 1521 1522 String strVirServers = (String )MBeanUtil.getAttribute(appObj, "virtual-servers"); 1524 if ((strVirServers == null) || strVirServers.equals("")) { 1525 1530 ObjectName listeners[] = (ObjectName [])MBeanUtil.invoke( 1532 "com.sun.appserv:type=http-service,config="+configRef+ 1533 ",category=config", "getHttpListener", null, null); 1534 1535 int count=0; 1537 while (count<listeners.length) { 1538 if (((String )MBeanUtil.getAttribute(listeners[count], 1539 "enabled")).equals("true")) { 1540 break; 1541 } 1542 count++; 1543 } 1544 if (count == listeners.length) { 1545 return new ArrayList (0); 1547 } 1548 1549 strVirServers = (String )MBeanUtil.getAttribute(listeners[count], 1551 "default-virtual-server"); 1552 } 1553 1554 String virServer; 1556 String listeners; 1557 Iterator listIt; 1558 String listener; 1559 List listenerList = new ArrayList (); 1560 Iterator it = Util.parseStringList(strVirServers, " ,").iterator(); 1561 while (it.hasNext()) { 1562 virServer = (String )it.next(); 1564 listeners = (String )MBeanUtil.getAttribute( 1565 "com.sun.appserv:type=virtual-server,id="+virServer+ 1566 ",config="+configRef+",category=config", 1567 "http-listeners"); 1568 listIt = Util.parseStringList(listeners, " ,").iterator(); 1569 1570 while (listIt.hasNext()) { 1572 listener = (String )listIt.next(); 1573 if (!listenerList.contains(listener)) { 1574 listenerList.add(listener); 1576 } 1577 } 1578 } 1579 1580 List urls = new ArrayList (listenerList.size()); 1582 StringBuffer url = null; 1583 String listenerObj; 1584 it = listenerList.iterator(); 1585 while (it.hasNext()) { 1586 listenerObj = "com.sun.appserv:type=http-listener,id="+it.next() 1588 +",config="+configRef+",category=config"; 1589 1590 url = new StringBuffer ("http"); 1592 if (MBeanUtil.getAttribute(listenerObj, "security-enabled").toString().equals("true")) { 1593 url.append("s"); 1595 } 1596 url.append("://"); 1597 1598 url.append(getHost(serverInstance)); 1600 url.append(":"); 1601 1602 url.append(replaceTokens(serverInstance, (String )MBeanUtil.getAttribute(listenerObj, "port"))); 1604 url.append("/"); 1605 1606 urls.add(url.toString()); 1608 } 1609 1610 return urls; 1611 } 1612 1613 1614 1623 protected List getURLs(String appId, ObjectName serverInstances[]) { 1624 List urls = new ArrayList (); 1626 for (int count=0; count<serverInstances.length; count++) { 1627 if (serverInstances[count].getKeyProperty("type").equals("cluster")) { 1628 urls.addAll(getURLs(appId, (ObjectName [])MBeanUtil.invoke( 1631 serverInstances[count], 1632 "listServerInstances", null, null))); 1633 } else { 1634 urls.addAll(getURLs(appId, serverInstances[count])); 1636 } 1637 } 1638 1639 return urls; 1641 } 1642 1643 1644 1651 protected ObjectName [] getWebAppReferencees(String appId) { 1652 return (ObjectName [])MBeanUtil.invoke( 1653 "com.sun.appserv:type=applications,category=config", 1654 "listReferencees", 1655 new Object [] { appId }, 1656 new String [] { "java.lang.String" }); 1657 } 1658 1659 1660 1666 public String getWebAppHrefs(RequestContext ctx, HandlerContext handlerCtx) { 1667 String id = (String )handlerCtx.getInputValue("appId"); 1669 String appendUrl = (String )handlerCtx.getInputValue("appendUrl"); 1670 1671 if (appendUrl != null) { 1672 appendUrl = ((appendUrl.startsWith("/") ? appendUrl.substring(1) : appendUrl)); 1673 } 1674 1675 1678 List urls = getURLs(id, getWebAppReferencees(id)); 1680 1681 DefaultModel model = (DefaultModel)handlerCtx.getInputValue("model"); 1683 if (model != null) { 1684 model.clear(); 1686 } 1687 1688 StringBuffer output = new StringBuffer (""); 1690 Iterator it = urls.iterator(); 1691 String url = null; 1692 while (it.hasNext()) { 1693 url = (String )it.next(); 1694 url = url + appendUrl; 1695 1696 output.append("<A HREF=\""+url+"\" target=\"_blank\">"+url+"</A><BR>"); 1698 1699 model.appendRow(); 1701 model.setValue("link", url); 1702 } 1703 1704 return output.toString(); 1706 } 1707 1708 public void getApplicationStatusSummary(RequestContext ctx, HandlerContext handlerCtx) { 1709 String appsName = (String )handlerCtx.getInputValue("appsName"); 1711 int status = getAppStatusSummary(appsName); 1712 String result = convertStatusSummary(status); 1713 if (result == null) { 1714 result = "false" ; 1716 Util.logWARNING("======= Error in getting enabled status for '" + appsName + "'" ); 1717 } 1718 handlerCtx.setOutputValue("value", result); 1719 } 1720 1721 public void getResourceStatusSummary(RequestContext ctx, HandlerContext handlerCtx) { 1722 String resObj = (String )handlerCtx.getInputValue("resObjectName"); 1723 try{ 1724 int status = getResourceStatusSummary(new ObjectName (resObj)); 1725 String result = convertStatusSummary(status); 1726 handlerCtx.setOutputValue("value", result); 1727 }catch (Exception ex){ 1728 throw new FrameworkException("error in getResourceStatusSummary ", ex); 1729 } 1730 } 1731 1732 public void getRealTargetStatus(RequestContext ctx, HandlerContext handlerCtx) { 1733 String appsName = (String )handlerCtx.getInputValue("appsName"); 1735 String target = (String )handlerCtx.getInputValue("target"); 1736 String status = getRealTargetStatus(appsName, target); 1737 handlerCtx.setOutputValue("value", status); 1738 } 1739 1740 private String getRealTargetStatus(String appsName, Object target){ 1741 try{ 1742 String enabled = getAppStatus(appsName, "domain"); 1743 if ("false".equals(enabled)){ 1744 return "false"; 1745 }else{ 1746 if(target instanceof ObjectName ) 1747 return (String ) MBeanUtil.getAttribute((ObjectName )target, "enabled"); 1748 else 1749 return getAppStatus(appsName, (String )target); 1750 } 1751 }catch(Exception ex){ 1752 return ""; 1754 } 1755 } 1756 1757 public void getRealResourceTargetStatus(RequestContext ctx, HandlerContext handlerCtx) { 1758 try { 1760 String refsObjectName = (String )handlerCtx.getInputValue("refsObjectName"); 1761 ObjectName refsObject = new ObjectName (refsObjectName); 1762 String status = getRealResourceTargetStatus(refsObject); 1763 handlerCtx.setOutputValue("value", status); 1764 }catch(Exception ex){ 1765 throw new FrameworkException("Error in getRealResourceTargetStatus ", ex); 1766 } 1767 } 1768 1769 public void saveStatusPE(RequestContext ctx, HandlerContext handlerCtx) { 1770 try { 1771 ObjectName objectName = new ObjectName ((String )handlerCtx.getInputValue("objectName")); 1772 ObjectName refObjectName = new ObjectName ((String )handlerCtx.getInputValue("refObjectName")); 1773 String value = (String )handlerCtx.getInputValue("value"); 1774 1775 1778 if(refObjectName.getKeyProperty("type").equals("application-ref") && 1779 !(objectName.getKeyProperty("type").equals("mbean"))){ 1780 changeEnableStatus(objectName.getKeyProperty("name"), new String [] { "server" }, value); 1781 }else{ 1782 MBeanUtil.setAttribute(objectName, new Attribute ("enabled", "true")); 1783 MBeanUtil.setAttribute(refObjectName, new Attribute ("enabled", value)); 1784 } 1785 }catch(Exception ex){ 1786 throw new FrameworkException(ex); 1787 } 1788 } 1789 1790 private String getRealResourceTargetStatus(ObjectName refsObject){ 1791 String resName = refsObject.getKeyProperty("ref"); 1792 String resType = (String ) MBeanUtil.invoke( 1793 "com.sun.com.sun.appserv:type=resources,category=config", 1794 "getResourceType", 1795 new String [] {resName}, 1796 new String [] {"java.lang.String"}); 1797 try{ 1798 ObjectName obj = new ObjectName ("com.sun.appserv:category=config,type="+resType+",jndi-name="+resName); 1799 String status = (String ) MBeanUtil.getAttribute(obj, "enabled"); 1800 if ("true".equals(status)){ 1801 status = (String ) MBeanUtil.getAttribute(refsObject, "enabled"); 1802 } 1803 return status; 1804 }catch(Exception ex){ 1805 throw new FrameworkException("Error in getRealResourceTargetStatus", ex); 1806 } 1807 } 1808 1809 1814 private int getAppStatusSummary(String appsObjName) 1815 { 1816 ObjectName []refs = null; 1817 int count =0; 1818 try{ 1819 String appsName=(String ) MBeanUtil.getAttribute(appsObjName, "name"); 1820 boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue(); 1821 if (!isTargetSupported){ 1822 ObjectName server = new ObjectName ("com.sun.appserv:type=server,name=server,category=config"); 1823 refs = new ObjectName []{server}; 1824 }else{ 1825 String [] params = new String [] {appsName}; 1826 String [] types = new String [] {"java.lang.String"}; 1827 refs = (ObjectName []) MBeanUtil.invoke("com.sun.appserv:type=applications,category=config" , "listReferencees", params, types); 1828 if (refs.length ==0) 1829 return APP_NO_TARGET; 1830 } 1831 String status = getAppStatus(appsName, ConfigProperties.getInstance().getDefaultTarget()); 1832 if ("false".equals(status)) 1833 return APP_ALL_DISABLED; 1834 for(int i=0; i < refs.length; i++){ 1835 String [] params = new String [] {appsName}; 1836 String [] types = new String [] {"java.lang.String"}; 1837 ObjectName appRefsObj = (ObjectName )MBeanUtil.invoke( refs[i], "getApplicationRefByRef", params, types ); 1838 String refStatus = (String )MBeanUtil.getAttribute(appRefsObj, "enabled"); 1839 if ("true".equals(refStatus)){ 1840 count++; 1841 } 1842 } 1843 if (count == refs.length) return APP_ALL_ENABLED; 1844 return count; 1845 }catch(Exception ex){ 1846 Util.logSEVERE(ex); 1847 return APP_UNKNOWN; 1848 } 1849 } 1850 1851 1856 private int getResourceStatusSummary(ObjectName resObject) 1857 { 1858 String resName = resObject.getKeyProperty("jndi-name"); 1859 int count = 0; 1860 String [] params = new String [] {resName}; 1861 String [] types = new String [] {"java.lang.String"}; 1862 ObjectName [] refs = null; 1863 boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue(); 1864 try { 1865 if (!isTargetSupported){ 1866 ObjectName server = new ObjectName ("com.sun.appserv:type=server,name=server,category=config"); 1867 refs = new ObjectName []{server}; 1868 }else{ 1869 refs = (ObjectName []) MBeanUtil.invoke("com.sun.appserv:type=resources,category=config" , "listReferencees", params, types); 1870 if (refs.length ==0) 1871 return APP_NO_TARGET; 1872 } 1873 String status = (String )MBeanUtil.getAttribute(resObject, "enabled"); 1874 if ("false".equals(status)) 1875 return APP_ALL_DISABLED; 1876 for(int i=0; i < refs.length; i++){ 1877 ObjectName resRefsObj = (ObjectName )MBeanUtil.invoke( refs[i], "getResourceRefByRef", params, types ); 1878 String refStatus = (String )MBeanUtil.getAttribute(resRefsObj, "enabled"); 1879 if ("true".equals(refStatus)){ 1880 count++; 1881 } 1882 } 1883 if (count == refs.length) return APP_ALL_ENABLED; 1884 return count; 1885 }catch(Exception ex){ 1886 Util.logWARNING(ex); 1887 return APP_UNKNOWN; 1888 } 1889 } 1890 1891 private String convertStatusSummary(int statusSummary){ 1892 String disp = null; 1893 boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue(); 1894 if (statusSummary == APP_UNKNOWN){ 1895 disp = (isTargetSupported)?Util.getMessage("deploy.unknown") : "false" ; }else 1897 if (statusSummary == APP_ALL_ENABLED){ 1898 disp = (isTargetSupported)?Util.getMessage("deploy.allEnabled") : "true"; 1899 }else 1900 if (statusSummary == APP_ALL_DISABLED){ 1901 disp = (isTargetSupported)?Util.getMessage("deploy.allDisabled") : "false"; 1902 }else 1903 if (statusSummary == APP_NO_TARGET){ 1904 disp = (isTargetSupported)? Util.getMessage("deploy.noTarget") : "true"; 1905 }else{ 1906 disp = (isTargetSupported)? Util.getMessage("deploy.someEnabled", new String []{""+statusSummary}) : "true"; 1908 } 1909 return disp; 1910 1911 } 1912 1913 public void loadMbeanAttrTable(RequestContext ctx, HandlerContext handlerCtx) { 1914 View view = handlerCtx.getView(); 1915 ViewDescriptor desc = null; 1916 if (handlerCtx.getEvent() instanceof BeforeCreateEvent) { 1917 desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 1918 } else { 1919 DescriptorContainerView descView = (DescriptorContainerView) 1920 (((ViewBase)view).getParentViewBean()); 1921 desc = descView.getViewDescriptor(); 1922 } 1923 CCActionTableModelInterface model =(CCActionTableModelInterface)handlerCtx.getInputValue("model"); 1924 if (model == null) { 1925 throw new FrameworkException("loadCallFlowDataTable: No Model Specified.", 1926 desc, handlerCtx.getView()); 1927 } 1928 String implClass = (String )handlerCtx.getInputValue("implClass"); 1929 Boolean create = (Boolean )handlerCtx.getInputValue("create"); 1930 1931 Object [] params = {implClass}; 1932 String [] types = {"java.lang.String"}; 1933 MBeanInfo mbinfo = (MBeanInfo ) MBeanUtil.invoke("com.sun.appserv:type=applications,category=config", "getMBeanInfo", params, types); 1934 MBeanAttributeInfo [] attrArray = mbinfo.getAttributes(); 1935 if (attrArray == null || attrArray.length < 0){ 1936 return; 1937 } 1938 AttributeList attrList = null; 1939 if(!create){ 1940 String objName = (String )handlerCtx.getInputValue("mbeanObjectName"); 1941 attrList = (AttributeList ) MBeanUtil.invoke(objName, "getProperties", null, null); 1942 } 1943 1944 ((DefaultModel)model).clear(); 1945 try { 1946 model.beforeFirst(); 1947 for(int i=0; i<attrArray.length; i++){ 1948 model.appendRow(); 1949 String name = attrArray[i].getName(); 1950 model.setValue("propertyName", name); 1951 model.setValue("type", attrArray[i].getType()); 1952 if(!create){ 1953 String val = getMbeanPropertyValue(attrList, name); 1954 if (val != null) 1955 model.setValue("propertyValue", val); 1956 } 1957 } 1958 1961 }catch (Exception ex) { 1962 throw new FrameworkException(ex); 1963 } 1964 } 1965 1966 private String getMbeanPropertyValue(AttributeList attrList, String name){ 1967 if( attrList == null) 1968 return null; 1969 Iterator it = attrList.iterator(); 1970 while (it.hasNext()) { 1971 Attribute att = (Attribute )it.next(); 1972 if (att.getName().equals(name)) { 1973 return (String ) att.getValue(); 1974 } 1975 } 1976 return null; 1977 } 1978 1979 public void getMbeanAttrFromTable(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException { 1980 Boolean ignoreEmptyValues = (Boolean )handlerCtx.getInputValue("ignoreEmptyValues"); 1981 CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("propertiesModel"); 1982 model.beforeFirst(); 1985 Properties properties = new Properties (); 1986 while (model.next()) { 1987 String name = (String ) model.getValue("propertyName"); 1988 String value = (String ) model.getValue("propertyValue"); 1989 if (!Util.isEmpty(name)) { 1990 if (Util.isEmpty(value)) { 1991 if (ignoreEmptyValues!=null && ignoreEmptyValues.booleanValue()==true) 1992 continue; 1993 } 1994 properties.setProperty(name, value); 1995 } 1996 } 1997 handlerCtx.setOutputValue("properties", properties); 1998 } 1999 2000 2001 public static final String FORCE = "force"; 2003 public static final String DEFAULT_FORCE = "true"; 2004 public static final String CASCADE = "cascade"; 2005 public static final String DEFAULT_CASCADE = "false"; 2006 public static final String VERIFY = "verify"; 2007 public static final String DEFAULT_VERIFY = "false"; 2008 public static final String PRECOMPILE_JSP = "precompilejsp"; 2009 public static final String ENABLE = "enable"; 2010 public static final String CONTEXT_ROOT = "contextRoot"; 2011 public static final String ARCHIVE_NAME = "archiveName"; 2012 public static final String NAME = "name"; 2013 public static final String TYPE = "type"; 2014 public static final String TARGET = "target"; 2015 2016 public static final String LOCATION = "location"; 2018 public static final String REDEPLOY = "redeploy"; 2019 2020 public static final String PROPERTY_NAME = "propertyName"; 2021 public static final String PROPERTY_VALUE = "propertyValue"; 2022 2023 public static final int APP_UNKNOWN = -3; 2024 public static final int APP_NO_TARGET = -2; 2025 public static final int APP_ALL_ENABLED = -1; 2026 public static final int APP_ALL_DISABLED = 0; 2027 2028 2029 2030 2031} 2032 | Popular Tags |