KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > handlers > DeploymentHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * DeploymentHandler.java
26  *
27  */

28
29 package com.sun.enterprise.tools.admingui.handlers;
30
31 import java.net.InetAddress JavaDoc;
32 import java.net.UnknownHostException JavaDoc;
33 import java.io.*;
34 import java.util.List JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.Enumeration JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.Map JavaDoc;
40 import java.util.Properties JavaDoc;
41 import java.util.Set JavaDoc;
42 import java.util.Vector JavaDoc;
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 JavaDoc;
63 import javax.management.ObjectName JavaDoc;
64 import javax.management.Attribute JavaDoc;
65 import javax.management.AttributeList JavaDoc;
66 import javax.management.MBeanInfo JavaDoc;
67 import javax.management.MBeanAttributeInfo JavaDoc;
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.tools.admingui.util.NamingConventions;
99
import com.sun.enterprise.appclient.jws.NamingConventions;
100
101 import com.sun.enterprise.tools.admingui.util.FileUtil;
102
103 /**
104  *
105  */

106 public class DeploymentHandler {
107
108     // using DeploymentFacility API
109
public void deploy(RequestContext ctx, HandlerContext handlerCtx) throws Exception JavaDoc {
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 JavaDoc dProps = new Properties JavaDoc();
126     ViewDescriptor vd = descView.getViewDescriptor();
127
128     ArrayList JavaDoc displayNames = (ArrayList JavaDoc)handlerCtx.getInputValue("displayNames");
129         ArrayList JavaDoc modelNames = (ArrayList JavaDoc)handlerCtx.getInputValue("attributeNames");
130
131     for (int i = 0; i < displayNames.size(); i++) {
132         String JavaDoc displayValue =
133                 (String JavaDoc)descView.getDisplayFieldValue((String JavaDoc)displayNames.get(i));
134             if (displayValue==null) //to take care enable for PE & EE
135
continue;
136         dProps.setProperty((String JavaDoc)modelNames.get(i), displayValue);
137     }
138         /* For java-web-start-enabled & libraries, need to convert the key first */
139         String JavaDoc 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 JavaDoc 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     //This is required only for PE.
154
Boolean JavaDoc isTargetSupported =
155             ConfigProperties.getInstance().getTargetSupported();
156     String JavaDoc type = (String JavaDoc)handlerCtx.getInputValue("appType");
157     if(isTargetSupported != null && !isTargetSupported.booleanValue() && (type.equals("war")||type.equals("ear"))){
158         String JavaDoc displayValue =
159                 (String JavaDoc)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 JavaDoc displayValue =
165             (String JavaDoc)descView.getDisplayFieldValue("availabilityEnabled");
166         dProps.setProperty(DeploymentProperties.AVAILABILITY_ENABLED, displayValue);
167     }
168         
169     String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
170     String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
171         String JavaDoc[] targets = (String JavaDoc [])handlerCtx.getInputValue("targets");
172             
173         // to work around the bug# 6171271 on PC
174
String JavaDoc location = (String JavaDoc)descView.getDisplayFieldValue("location");
175         //char x1 = '\\';
176
//char x2 = '/';
177
Object JavaDoc raConfig = null;
178         if (type.equals("rar")){
179             ArrayList JavaDoc params = (ArrayList JavaDoc)handlerCtx.getInputValue("resourceAdapterParams");
180             ArrayList JavaDoc types = (ArrayList JavaDoc)handlerCtx.getInputValue("resourceAdapterTypes");
181             try {
182                  raConfig = createResourceAdapter("com.sun.appserv:type=resources,category=config",
183                                 "createResourceAdapterConfig", params, types);
184             } catch (Exception JavaDoc ex) {
185                 //if config cannot be created, due to existence or other error, we just log it
186
// but still continue with deployment.
187
Util.logINFO("Deployment Handler createResourceConfig failed. "+ex.getMessage());
188             }
189         }
190         try{
191             invokeDeploymentFacility(targets, dProps, location);
192         }catch (Exception JavaDoc ex){
193             if (raConfig != null){
194                 //cleanup/remove Config if that is created here.
195
String JavaDoc key = (String JavaDoc)MBeanUtil.getAttribute(raConfig.toString(), "resource-adapter-name");
196                 String JavaDoc[] types = new String JavaDoc[]{"java.lang.String"};
197                 Object JavaDoc[] params = new Object JavaDoc[]{key};
198                 try{
199                     MBeanUtil.invoke("com.sun.appserv:type=resources,category=config", "removeResourceAdapterConfigByResourceAdapterName", params, types);
200                 }catch(Exception JavaDoc ex1){
201                     Util.logINFO("Deployment Handler removeResourceAdapterConfig failed. "+ex1.getMessage());
202                 }
203             }
204             throw ex;
205         }
206         /* Set property if this rar is used for connecting to web service registry */
207         if (raConfig != null) {
208             String JavaDoc registryType = (String JavaDoc)handlerCtx.getInputValue("registryType");
209             String JavaDoc 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 JavaDoc attr = new Attribute JavaDoc(propName, "true");
217                 String JavaDoc[] types = new String JavaDoc[]{"javax.management.Attribute"};
218                 Object JavaDoc[] params = new Object JavaDoc[]{attr};
219                 MBeanUtil.invoke((ObjectName JavaDoc)raConfig, "setProperty", params, types);
220             }
221         }
222     }
223      
224      public static boolean invokeDeploymentFacility(String JavaDoc[] targets, Properties JavaDoc props, String JavaDoc archivePath)
225         throws Exception JavaDoc{
226         if(archivePath == null) {
227             //Localize this message.
228
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             //For redeployment target is domain by default for EE.
234
targets = new String JavaDoc[]{"domain"};
235             }else{
236                 targets = new String JavaDoc[]{"server"};
237             }
238         }
239         if(targets == null || targets.length == 0) {
240             //By default deploying to DAS to be in sync. with CLI.
241
targets = new String JavaDoc[]{"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); //null for deployment plan
249
DeploymentStatus status = null;
250         do {
251             status = progressObject.getCompletedStatus();
252             if(status == null) {
253                 try {
254                     Thread.currentThread().sleep(1000);
255                 } catch(InterruptedException JavaDoc 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 JavaDoc warningIndex )throws FrameworkException
264      {
265         // parse the deployment status and retrieve failure/warning msg
266
ByteArrayOutputStream bos = new ByteArrayOutputStream();
267         PrintWriter pw = new PrintWriter(bos);
268         DeploymentStatus.parseDeploymentStatus(status, pw);
269         byte[] statusBytes = bos.toByteArray();
270         String JavaDoc statusString = new String JavaDoc(statusBytes);
271         String JavaDoc bundle = "com.sun.enterprise.tools.admingui.resources.Resources";
272         
273          if (status!=null && status.getStatus() == DeploymentStatus.FAILURE){
274              throw new FrameworkException(statusString);
275          }
276          //maybe we should also display this to the user, instead of just 'hidding' in the log file.
277
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 JavaDoc fileName = (String JavaDoc)ctx.getRequest().getAttribute("fileName");
287     String JavaDoc objectName = (String JavaDoc)ctx.getRequest().getAttribute("objectName");
288
289     View view = handlerCtx.getView();
290     DisplayField descriptorField = (DisplayField)view;
291     
292         String JavaDoc descriptors = (String JavaDoc)MBeanUtil.invoke(objectName, "getDeploymentDescriptor",
293                                 new Object JavaDoc[]{fileName}, new String JavaDoc[]{"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 JavaDoc fileName = (String JavaDoc)handlerCtx.getInputValue("filename");
301         
302         //If we want to display the full path file name, comment out the following if.
303
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 JavaDoc appType = (String JavaDoc)handlerCtx.getInputValue("applicationType");
313         Boolean JavaDoc redeploy = (Boolean JavaDoc)handlerCtx.getInputValue("redeploy");
314         String JavaDoc key = null;
315         if (redeploy.booleanValue()) {
316             key = "redeploy.PageTitle";
317         } else {
318             key = "upload.PageTitle";
319         }
320         HashMap JavaDoc map = new HashMap JavaDoc();
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 JavaDoc mappedValue = (String JavaDoc)map.get(appType);
328         String JavaDoc titleText = Util.getMessage(key, new Object JavaDoc[]{mappedValue});
329         
330         tag.setPageTitleText(titleText);
331         if (appType.equals("all")) {
332             //Setting it to jar for appclient module type.
333
appType = "jar";
334         }
335         String JavaDoc helpText = "";
336         if (appType.equals("mbean")){
337             helpText = Util.getMessage("createCustomMBean.pageHelp");
338         }else
339             helpText = Util.getMessage("uploadPageHelp", new Object JavaDoc[]{appType, mappedValue});
340             
341         tag.setPageTitleHelpMessage(helpText);
342     }
343
344     public void extractJarFile(RequestContext ctx, HandlerContext handlerCtx) {
345         String JavaDoc fileName = (String JavaDoc)handlerCtx.getInputValue("fileName");
346         String JavaDoc domainRoot = (String JavaDoc)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     /* This is needed only for connector (rar) deployment. We've to work with Qingqing/vijay to fix this
364      * in the new API. We've to discuss this with Binod/Siva in IEC also. */

365     public void saveThreadPool(RequestContext ctx, HandlerContext handlerCtx) {
366     String JavaDoc name = (String JavaDoc)handlerCtx.getInputValue("name");
367     String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
368     String JavaDoc threadPool = (String JavaDoc)handlerCtx.getInputValue("threadPoolId");
369     if (objectName == null) {
370         throw new FrameworkException("'objectName' is null in DeploymentHandler.saveThreadPool");
371     }
372
373     try {
374         Attribute JavaDoc attr = new Attribute JavaDoc("thread-pool-ids", threadPool);
375         MBeanUtil.setAttribute(objectName, attr);
376     } catch (Exception JavaDoc ex) {
377         //might have been deployed from CLI.
378
//FIXME LATER. Directory deploy is broken, so not creating anymore. Commented on 06/10.
379
// createResourceAdapter(name, "com.sun.appserv:type=resources,category=config",
380
// "createResourceAdapterConfig", threadPool);
381
}
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 JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue("childName");
399     TextField textFieldChild = (TextField)descView.getChild(childName);
400     
401     String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("vsObjectName");
402     String JavaDoc vsMethodName = (String JavaDoc)handlerCtx.getInputValue("vsMethodName");
403     String JavaDoc vsList = "";
404
405     Object JavaDoc[] vsObjectName = (Object JavaDoc[])
406             MBeanUtil.invoke(objectName, vsMethodName, null, null);
407     //hardcoding the name for now, may be we should get this from the xml file.
408
String JavaDoc attributeName = "id";
409     if(vsObjectName != null) {
410         for(int i =0; i < vsObjectName.length; i++) {
411         String JavaDoc virtualservers = (String JavaDoc)
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         //stripping the last char
420
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 JavaDoc editKey = (String JavaDoc)descView.getDisplayFieldValue("editKey");
429     String JavaDoc adapterObjectName = "com.sun.appserv:type=resource-adapter-config,category=config,resource-adapter-name="+editKey;
430     try {
431         String JavaDoc threadPool = (String JavaDoc)MBeanUtil.getAttribute(adapterObjectName, "thread-pool-ids");
432         ((TextField)view).setValue(threadPool);
433     } catch (Exception JavaDoc ex) {
434         //squelch, it's o.k if we don't get this attribute.
435
}
436     }
437     
438      /**
439      *
440      */

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 JavaDoc properties = handlerCtx.getInputValue("properties");
455     
456     if (properties == null) {
457         if (Util.isLoggableFINER()) {
458         Util.logFINER("NO ATTRS FOUND!!");
459         }
460         //nothing to load..
461
return;
462     }
463     
464     else if(properties instanceof AttributeList JavaDoc) {
465         loadResourceAdapterProperties((AttributeList JavaDoc)properties, model);
466     }
467     else if(properties instanceof Map JavaDoc) {
468         loadResourceAdapterProperties((Map JavaDoc)properties, model);
469     }
470     else {
471         throw new FrameworkException("Unknown instance properties", desc, view);
472     }
473            
474     }
475     
476     private void loadResourceAdapterProperties (AttributeList JavaDoc attrs, CCActionTableModelInterface model) throws ModelControlException {
477     // Log some info..
478
StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
479         for(int rowNo = 0; rowNo < attrs.size(); rowNo++) {
480             Attribute JavaDoc attr = (Attribute JavaDoc)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 JavaDoc attr = (Attribute JavaDoc)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 JavaDoc properties, CCActionTableModelInterface model) throws ModelControlException {
498     Set JavaDoc s = properties.keySet();
499     Iterator JavaDoc iter = s.iterator();
500     
501     model.setRowSelectionType("none");
502         model.beforeFirst();
503     while (iter.hasNext()) {
504         Object JavaDoc 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     /**
513      * This method invokes ConnectorRuntime, and outputs the properties in request attribute.
514      */

515     public void getResourceAdapterProperties(RequestContext ctx, HandlerContext handlerCtx) {
516     
517     String JavaDoc location = (String JavaDoc)handlerCtx.getInputValue("location");
518         if (location == null) {
519             //if deployment failed, the page still needs to be repainted, and at this time,
520
//location is gone and will be null.
521
//we ignore it here so that the previouse deployment error message will show up.
522
handlerCtx.setOutputValue("properties", null);
523             return;
524         }
525         try{
526            
527     Map JavaDoc props = ConnectorRuntime.getRuntime().getResourceAdapterBeanProperties(location);
528         //refer to bug#6212118.
529
//The value of the key thats returned is the type, eg.class.java.lang.String, int, boolean etc
530
//We don't want to display that to the user.
531
Set JavaDoc s = props.keySet();
532         Map JavaDoc newMap = new HashMap JavaDoc();
533         for (Iterator JavaDoc iter = s.iterator(); iter.hasNext(); ) {
534             newMap.put(iter.next(), "");
535         }
536             handlerCtx.setOutputValue("properties", newMap);
537         }catch (Exception JavaDoc ex){
538             //refer to bug#6278568.
539
Util.logSEVERE("Error in getting ResourceAdapter Properties ", ex);
540             handlerCtx.setOutputValue("properties", null);
541             return;
542         }
543     }
544     
545     /*
546      * Adding this method for now to take care of directoryDeployment. We're not creating
547      * RAConfig in directory deployment.
548      */

549     
550     public void getResourceAdapterPropertiesForEdit(RequestContext ctx, HandlerContext handlerCtx) {
551     View view = handlerCtx.getView();
552         
553         Object JavaDoc objectName = handlerCtx.getInputValue("objectName");
554         if (objectName == null) {
555             throw new FrameworkException("'objectName' is null in DeploymentHandler.getResourceAdpaterPropertiesForEdit");
556     }
557         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
558         if (methodName == null) {
559             throw new FrameworkException("'methodName' is null in DeploymentHandler.getResourceAdpaterPropertiesForEdit");
560     }
561         Object JavaDoc returnValue = null;
562         try {
563             
564             returnValue = MBeanUtil.invoke(objectName.toString(), methodName,
565                     null, null);
566             
567         } catch (Exception JavaDoc ex) {
568         //squelch the Exception here, o.k for RAConfig.
569
}
570         handlerCtx.setOutputValue("value", returnValue);
571     }
572
573     public void createResourceAdapter(RequestContext ctx, HandlerContext handlerCtx) {
574     View view = handlerCtx.getView();
575         
576         Object JavaDoc objectName = handlerCtx.getInputValue("objectName");
577         if (objectName == null) {
578             throw new FrameworkException("'objectName' is null in CommonHandlers.invokeMBean");
579     }
580         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
581         if (methodName == null) {
582             throw new FrameworkException("'methodName' is null in CommonHandlers.invokeMBean");
583     }
584         ArrayList JavaDoc types = (ArrayList JavaDoc)handlerCtx.getInputValue("types");
585         ArrayList JavaDoc params = (ArrayList JavaDoc)handlerCtx.getInputValue("params");
586         
587     createResourceAdapter(objectName, methodName, params, types);
588     }
589     
590     private Object JavaDoc createResourceAdapter(Object JavaDoc objectName, String JavaDoc methodName, ArrayList JavaDoc params, ArrayList JavaDoc types) {
591     Object JavaDoc[] paramsAndTypes = MBeanUtil.getParamsAndTypes(params, types);
592     try {
593             return MBeanUtil.invoke(objectName.toString(), methodName,
594                     (Object JavaDoc[])(paramsAndTypes[0]), (String JavaDoc[])(paramsAndTypes[1]));
595             
596         } catch (Exception JavaDoc ex) {
597         //squelch this here, due to cli inconsistency, and redeploy.
598
}
599         return null;
600     }
601     
602     private void setResourceAdapterProperties(String JavaDoc name) {
603     String JavaDoc objectName = "com.sun.appserv:type=resource-adapter-config,category=config,resource-adapter-name="+ name;
604     Properties JavaDoc props = null;
605     try {
606         //We've to make this call to an MBean. For now o.k.
607
props = ConnectorRuntime.getRuntime().getResourceAdapterConfigProps(name);
608     }
609     catch (Exception JavaDoc e) {
610         //O.K to squelch, due CLI issues.
611
Util.logINFO("Deployment Handler setResourceAdapterProperties:"+e.getMessage());
612         return;
613     }
614     Enumeration JavaDoc ee = props.propertyNames();
615     
616     while(ee.hasMoreElements()) {
617         Object JavaDoc key = ee.nextElement();
618         String JavaDoc[] type = new String JavaDoc[]{"javax.management.Attribute"};
619         Attribute JavaDoc attr = new Attribute JavaDoc(key.toString(), props.getProperty(key.toString()).toString());
620             Object JavaDoc[] params = new Object JavaDoc[]{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         //we may need to get the tabilChildName from the xml file.
633
String JavaDoc tableChildName = (String JavaDoc)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 JavaDoc editKeyValue = (String JavaDoc)handlerCtx.getInputValue("editKeyValue");
647         String JavaDoc action = (String JavaDoc)handlerCtx.getInputValue("action");
648         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
649         model.setRowSelectionType("multiple");
650         try {
651             model.beforeFirst();
652             while(model.next()) {
653             if (model.isRowSelected()) {
654                 String JavaDoc objectName = (String JavaDoc)model.getValue("objectName");
655                     String JavaDoc target = (String JavaDoc)MBeanUtil.getAttribute(objectName, "name");
656                     changeEnableStatus(editKeyValue, new String JavaDoc[] { target }, action);
657                 model.setRowSelected(false);
658             }
659             }
660         } catch (Exception JavaDoc 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     /* This method is invoked when user clicks enable/disable/undeploy in the table. */
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 JavaDoc childName = (String JavaDoc)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 JavaDoc buttonClicked = (String JavaDoc)handlerCtx.getInputValue("ClickedAction");
691     try {
692             
693         if (buttonClicked.equalsIgnoreCase("undeploy")) {
694                 String JavaDoc type = (String JavaDoc)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 JavaDoc buttonClicked) {
709     RequestContext ctx = RequestManager.getRequestContext();
710         DeploymentFacility df= DeploymentFacilityFactory.getLocalDeploymentFacility();
711         String JavaDoc defaultTarget = ConfigProperties.getInstance().getDefaultTarget();
712         JESProgressObject progressObject = null;
713         model.setRowSelectionType("multiple");
714         try {
715             model.beforeFirst();
716             // from the model, get the child that has the needed value...
717
while(model.next()) {
718                 if (model.isRowSelected()) {
719                     enableDisableAll((String JavaDoc) model.getValue(NAME), buttonClicked);
720                     model.setRowSelected(false);
721                 }
722             }
723         }catch (Exception JavaDoc 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 JavaDoc appsName, String JavaDoc action)
734     {
735         RequestContext ctx = RequestManager.getRequestContext();
736         Boolean JavaDoc isTargetSupported = ConfigProperties.getInstance().getTargetSupported();
737     boolean targetSupported = (isTargetSupported == null) ? false : isTargetSupported.booleanValue();
738         String JavaDoc defaultTarget = ConfigProperties.getInstance().getDefaultTarget();
739         if (targetSupported){
740             String JavaDoc[] params = new String JavaDoc[] {appsName};
741             String JavaDoc[] types = new String JavaDoc[] {"java.lang.String"};
742             ObjectName JavaDoc[] refs = (ObjectName JavaDoc[]) MBeanUtil.invoke("com.sun.appserv:type=applications,category=config" , "listReferencees", params, types);
743             int size = (refs==null ) ? 0 : refs.length;
744             String JavaDoc[] targetList = new String JavaDoc[size];
745             for(int i=0; i<size; i++){
746                 targetList[i] = (String JavaDoc)MBeanUtil.getAttribute(refs[i], "name");
747             }
748             changeEnableStatus(appsName, targetList, action);
749         }else{
750             changeEnableStatus(appsName, new String JavaDoc[] { defaultTarget }, action);
751         }
752     }
753     
754     static public void changeEnableStatus(String JavaDoc appsName, String JavaDoc[] targetList, String JavaDoc action ){
755         if (targetList == null) return;
756         //DeploymentFacility is not responsible for changing the enable/disable status of custom mbean
757
//We need to handle it differently.
758
Object JavaDoc[] params = new String JavaDoc[]{appsName};
759         
760         Integer JavaDoc type = (Integer JavaDoc) MBeanUtil.invoke("com.sun.appserv:type=applications,category=config", "getModuleType", params, new String JavaDoc[]{"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             //when enabling a target, we always ensure that the application is enabled.
771
if (isTargetSupported){
772                 if (getAppStatus(appsName, "domain").equals("false")){
773                     String JavaDoc[] newTargetList = new String JavaDoc[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 JavaDoc appsName, String JavaDoc[] targetList, String JavaDoc action){
790         
791         boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue();
792         if (action.equals("enable") || action.equals("true")){
793             //when enabling a target, we always ensure that the application is enabled.
794
if (getAppStatus(appsName, "domain").equals("false")){
795                     MBeanUtil.setAttribute("com.sun.appserv:type=mbean,category=config,name="+appsName, new Attribute JavaDoc("enabled", "true"));
796                 }
797         }
798         String JavaDoc status = (action.equals("true") || action.equals("enable")) ? "true" : "false";
799         Attribute JavaDoc attr = new Attribute JavaDoc("enabled", status);
800         for(int i=0; i<targetList.length; i++){
801             String JavaDoc 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 JavaDoc type) {
808     RequestContext ctx = RequestManager.getRequestContext();
809     String JavaDoc deleteKey = (String JavaDoc)vd.getParameter("deleteKey");
810     String JavaDoc objectName = (String JavaDoc)vd.getParameter("rowObjectName");
811     //String deleteMethodName = (String)vd.getParameter("deleteMethodName");
812
Boolean JavaDoc 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         // from the model, get the child that has the needed value...
827
while(model.next()) {
828         if (model.isRowSelected()) {
829             String JavaDoc componentName = model.getValue(deleteKey).toString();
830             if(type.equals("rar")) {
831             try {
832                 String JavaDoc defaultTarget = ConfigProperties.getInstance().getDefaultTarget();
833                 String JavaDoc key = model.getValue(deleteKey).toString();
834                 Object JavaDoc[] params = new Object JavaDoc[]{key, defaultTarget};
835                 String JavaDoc[] types = new String JavaDoc[]{"java.lang.String", "java.lang.String"};
836                 String JavaDoc resourceMethodName = "deleteResourceAdapterConfig";
837                 String JavaDoc resourceObjectName = "com.sun.appserv:type=resources,category=config";
838                 MBeanUtil.invoke(resourceObjectName, resourceMethodName, params,
839                     types);
840             }
841             catch(Exception JavaDoc ex) {
842                 //Squelching here is o.k. localize this mesg.
843
Util.logINFO("Deployment Handler deleteResourceAdapter Failed:"+ex.getMessage());
844             }
845             //commenting this out on 06/10, some reason it doesn't delete rar module.
846
//dProps.setProperty("cascade", "true");
847
}
848                     
849                     JESProgressObject progressObject = null;
850                     String JavaDoc[] targetNames = null;
851             if(targetSupported){
852             targetNames = getApplicationTargets(model.getValue(deleteKey).toString(), objectName);
853             }else {
854                         targetNames = new String JavaDoc[] {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 JavaDoc 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 JavaDoc[] getApplicationTargets(String JavaDoc name, String JavaDoc objectName) throws Exception JavaDoc {
873     ObjectName JavaDoc[] returnValue = null;
874     Vector JavaDoc targets = new Vector JavaDoc();
875     try {
876             returnValue = (ObjectName JavaDoc[])MBeanUtil.invoke(objectName, "listReferencees", new Object JavaDoc[]{name},
877                 new String JavaDoc[]{"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 JavaDoc ex) {
882         throw ex;
883         }
884     if(targets.size() == 0) {
885         String JavaDoc defaultTarget = ConfigProperties.getInstance().getDefaultTarget();
886         targets.add(defaultTarget);
887     }
888     return (String JavaDoc[])(targets.toArray(new String JavaDoc[targets.size()]));
889     }
890     
891     //Status of app-ref created will be the same as the app itself.
892
public void createAppReferences(RequestContext ctx, HandlerContext handlerCtx) {
893         String JavaDoc[] targetNames = (String JavaDoc[])handlerCtx.getInputValue("targets");
894         if (targetNames != null && targetNames.length > 0){
895             String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
896             DeploymentFacility df= DeploymentFacilityFactory.getLocalDeploymentFacility();
897             JESProgressObject progressObject = null;
898             Properties JavaDoc dProps = new Properties JavaDoc();
899             //dProps.setProperty(DeploymentProperties.ENABLE, getAppStatus(key, ConfigProperties.getInstance().getDefaultTarget()));
900
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 JavaDoc[] targetNames = (String JavaDoc[])handlerCtx.getInputValue("targets");
908         if (targetNames != null && targetNames.length > 0){
909             String JavaDoc key = (String JavaDoc)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     /**load
919      * */

920     public void loadDescriptorTableModel(RequestContext ctx, HandlerContext handlerCtx) {
921     View view = handlerCtx.getView();
922     ArrayList JavaDoc displayNamesList = (ArrayList JavaDoc)handlerCtx.getInputValue("displayNames");
923     String JavaDoc appName = (String JavaDoc)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 JavaDoc type = (String JavaDoc)handlerCtx.getInputValue("value");
940     if (type == null) {
941             throw new FrameworkException("'type' is null in DeploymentHandlers.loadDescriptorTableModel");
942     }
943     String JavaDoc standardDescriptor = null;
944     String JavaDoc sunSpecificDescriptor = null;
945     
946     String JavaDoc[] 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 JavaDoc)displayNamesList.get(0), appName);
952                 int index = descriptors[j].lastIndexOf(File.separator) +1;
953         model.setValue((String JavaDoc)displayNamesList.get(1), descriptors[j].substring(index));
954         model.setValue("location", descriptors[j]);
955         }
956     
957         //load subcomponent descriptors for ear file
958
if(type.equals("j2ee-application")) {
959         String JavaDoc[] modules = (String JavaDoc[])MBeanUtil.invoke("com.sun.appserv:type=applications,category=config", "getModuleComponents",
960                                 new Object JavaDoc[]{appName}, new String JavaDoc[]{"java.lang.String"});
961         if(modules != null) {
962             for (int i=0; i < modules.length; i++) {
963             try {
964                 String JavaDoc subComponentName = new ObjectName JavaDoc(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 JavaDoc)displayNamesList.get(0), subComponentName);
970                  int index = descriptors[j].lastIndexOf(File.separator) +1;
971                  model.setValue((String JavaDoc)displayNamesList.get(1), descriptors[j].substring(index));
972                  model.setValue("location", descriptors[j]);
973                 }
974             
975             } catch (Exception JavaDoc e){
976                 //we may not reach here.
977
}
978             }
979         }
980         }
981     }
982     }
983     
984     private String JavaDoc[] getDescriptors(String JavaDoc appName, String JavaDoc subComponent) {
985     String JavaDoc[] descriptors = (String JavaDoc[])MBeanUtil.invoke("com.sun.appserv:type=applications,category=config", "getDeploymentDescriptorLocations",
986                             new Object JavaDoc[]{appName, subComponent}, new String JavaDoc[]{"java.lang.String", "java.lang.String"});
987     return descriptors;
988     }
989     
990     static private String JavaDoc getAppStatus(String JavaDoc appName, String JavaDoc target){
991         Object JavaDoc status = MBeanUtil.invoke(
992                 "com.sun.appserv:type=applications,category=config",
993                 "getStatus",
994                 new String JavaDoc[] {appName, target},
995                 new String JavaDoc[] {"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 JavaDoc)handlerCtx.getInputValue("appName"),
1005                (String JavaDoc)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 JavaDoc modelNamesList = (ArrayList JavaDoc)handlerCtx.getInputValue("attributeNames");
1027        ArrayList JavaDoc displayNamesList = (ArrayList JavaDoc)handlerCtx.getInputValue("displayNames");
1028        String JavaDoc[] modelNames = (String JavaDoc[])
1029            modelNamesList.toArray(new String JavaDoc[modelNamesList.size()]);
1030        Object JavaDoc[] keys = (Object JavaDoc[])handlerCtx.getInputValue("keys");
1031
1032        if (keys == null) {
1033            return; //nothing to load..
1034
}
1035        for (int rowNo = 0; rowNo < keys.length; rowNo++) {
1036
1037        String JavaDoc objectType = null;
1038        String JavaDoc type = null;
1039            ObjectName JavaDoc currentObjName = null;
1040        try {
1041                currentObjName = new ObjectName JavaDoc(keys[rowNo].toString());
1042        type = currentObjName.getKeyProperty("type");
1043        } catch (Exception JavaDoc 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 JavaDoc)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 JavaDoc attrList = new AttributeList JavaDoc();
1072            for(int i=0; i < modelNames.length; i++){
1073                
1074                String JavaDoc attrValue = (String JavaDoc) MBeanUtil.getAttribute(keys[rowNo].toString(),modelNames[i]);
1075                if( ! "enabled".equals(modelNames[i])){
1076                    attrList.add(new Attribute JavaDoc(modelNames[i], attrValue));
1077                    continue;
1078                }
1079                //special handling for the status attribute
1080
String JavaDoc realStatus = "";
1081                if (isApp){
1082                    int statusSummary = getAppStatusSummary( keys[rowNo].toString());
1083                    realStatus = convertStatusSummary(statusSummary);
1084                }
1085                if (isAppRef){
1086                    String JavaDoc 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 JavaDoc(modelNames[i], realStatus));
1097            }
1098            model.appendRow();
1099
1100            for (int i = 0, colNo = 0; i < attrList.size(); i++) {
1101                Attribute JavaDoc attr = (Attribute JavaDoc)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 JavaDoc attrValue = ("false".equals(attr.getValue())) ? Util.getMessage("common.Disabled") : Util.getMessage("common.Enabled");
1110                        model.setValue((String JavaDoc)displayNamesList.get(colNo), attrValue);
1111                    }else
1112                        model.setValue((String JavaDoc)displayNamesList.get(colNo), attr.getValue());
1113                }
1114            }
1115            String JavaDoc 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 JavaDoc moduleName = (String JavaDoc)handlerCtx.getInputValue("moduleName");
1125        CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)desc;
1126        CCActionTableModelInterface model = ccDesc.getModel();
1127    //Make sure to throw error if the attributes are null
1128
String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
1129    String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
1130    try {
1131        String JavaDoc[] modules = (String JavaDoc[])MBeanUtil.invoke(objectName, methodName,
1132                            new Object JavaDoc[]{moduleName}, new String JavaDoc[]{"java.lang.String"});
1133        for(int i = 0; i < modules.length; i++) {
1134            ObjectName JavaDoc on = new ObjectName JavaDoc(modules[i]);
1135            model.appendRow();
1136            //Get the display field names from XML file
1137
model.setValue("componentName", on.getKeyProperty("name"));
1138            model.setValue("componentType", on.getKeyProperty("j2eeType"));
1139        }
1140    } catch (Exception JavaDoc ex) {
1141        throw new FrameworkException(
1142        "Exception thrown while attempting to get Modules List.",
1143        ex, ccDesc, view);
1144    }
1145    }
1146    //Method display the field from the propertysheet if Target is supported. We may move this to
1147
//TargetHandlers if necessary, i.e. if used in many places.
1148
public void displayDeployPageChild(RequestContext ctx, HandlerContext handlerCtx) throws Exception JavaDoc {
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 JavaDoc isTargetSupported =
1163            ConfigProperties.getInstance().getTargetSupported();
1164        String JavaDoc propertyName = (String JavaDoc)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 JavaDoc endExecuteLinkDisplay(RequestContext ctx, HandlerContext handlerCtx) {
1189    View bean = handlerCtx.getView();
1190        ChildContentDisplayEvent ev = (ChildContentDisplayEvent)handlerCtx.getEvent();
1191        String JavaDoc content = ev.getContent();
1192        String JavaDoc isWebService = (String JavaDoc)handlerCtx.getInputValue("isWebService");
1193        String JavaDoc appName = (String JavaDoc)handlerCtx.getInputValue("appName");
1194        String JavaDoc port = null;
1195        try {
1196            port = getPortForApplication(appName);
1197        } catch (Exception JavaDoc ex) {
1198            ex.printStackTrace(); // ignore this exception..
1199
}
1200
1201        String JavaDoc serverName = ctx.getRequest().getServerName();
1202        String JavaDoc ctxtRoot= (String JavaDoc)handlerCtx.getInputValue("ctxtRoot");
1203        if (ctxtRoot == null || ctxtRoot.length() == 0) {
1204            ctxtRoot = "/";
1205    }
1206        if (ctxtRoot.indexOf("/") != 0) {
1207            ctxtRoot = "/" + ctxtRoot;
1208    }
1209        String JavaDoc 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'\""); //Web Service Tester form
1217
}
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'\""); //Web Service Tester form
1226
}
1227        }
1228        return content;
1229    }
1230    
1231    
1232     public void getLaunchURLPath(RequestContext ctx, HandlerContext handlerCtx) {
1233    View bean = handlerCtx.getView();
1234        String JavaDoc appclientName = (String JavaDoc)handlerCtx.getInputValue("appclientName");
1235        String JavaDoc applicationName = (String JavaDoc)handlerCtx.getInputValue("applicationName");
1236        if (Util.isEmpty(appclientName))
1237            throw new FrameworkException("Deployment.getLaunchURLPath(), appclientName is NULL");
1238        try {
1239            String JavaDoc jwsEnabled ;
1240            if (Util.isEmpty(applicationName))
1241                jwsEnabled = (String JavaDoc) MBeanUtil.getAttribute("com.sun.appserv:type=appclient-module,category=config,name="+appclientName, "java-web-start-enabled");
1242            else
1243                jwsEnabled = (String JavaDoc) 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 JavaDoc 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 JavaDoc ex){
1259            //NamingConvention may throw ConfigException. log it and assume null.
1260
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 JavaDoc appName = (String JavaDoc)handlerCtx.getInputValue("appId");
1268            String JavaDoc port = null;
1269            try {
1270                port = getPortForApplication(appName);
1271            } catch (Exception JavaDoc ex) {
1272                ex.printStackTrace(); // ignore this exception..
1273
}
1274            String JavaDoc serverName = ctx.getRequest().getServerName();
1275            String JavaDoc appendUrl = (String JavaDoc)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    // First get the application id
1284
String JavaDoc id = (String JavaDoc)handlerCtx.getInputValue("appId");
1285        String JavaDoc appendUrl = (String JavaDoc)handlerCtx.getInputValue("appendUrl");
1286        if (appendUrl != null) {
1287            appendUrl = ((appendUrl.startsWith("/") ? appendUrl.substring(1) : appendUrl));
1288        }
1289    // Get all the URLs
1290
List JavaDoc urls = getURLs(id, getWebAppReferencees(id));
1291        String JavaDoc[] values = new String JavaDoc[urls.size()];
1292        for(int i=0; i< urls.size(); i++){
1293            values[i] = (String JavaDoc) urls.get(i)+appendUrl;
1294        }
1295        handlerCtx.setOutputValue("appClientLinks", values);
1296     }
1297     
1298     
1299     // Framework callback method to dynamically fill in choices of a dropdown menu.
1300
public void populateRadioButtons(RequestContext ctx, HandlerContext handlerCtx) {
1301        // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
1302
SelectableGroup radioButtonChild = (SelectableGroup) handlerCtx.getView();
1303        // get the parent container of the dropdown
1304
DescriptorContainerView parent = (DescriptorContainerView) radioButtonChild.getParent();
1305        
1306        // need the child descriptor to get a parameter, retrieve from the parent descriptor.
1307
ViewDescriptor vd = parent.getViewDescriptor();
1308        ViewDescriptor cvd = vd.getChildDescriptor(radioButtonChild.getName());
1309        
1310        String JavaDoc[] appClientLinks = (String JavaDoc[]) handlerCtx.getInputValue("appClientLinks");
1311        OptionList options = new OptionList( appClientLinks, appClientLinks); // label and values
1312
radioButtonChild.setOptions(options);
1313        radioButtonChild.setValue(appClientLinks[0]);
1314    }
1315
1316    // returns 'first' nonadmin virtual server -
1317
private String JavaDoc getNonAdminVirtualServer() {
1318        String JavaDoc vsId = null;
1319        ObjectName JavaDoc[] vsObjectNames = (ObjectName JavaDoc[])
1320            MBeanUtil.invoke("ias:type=configs,category=config",
1321            "listVirtualServers",
1322            new Object JavaDoc[]{null},
1323            new String JavaDoc[]{"java.lang.String"});
1324        if (vsObjectNames != null) {
1325            for (int i = 0; i < vsObjectNames.length; i++) {
1326                String JavaDoc id = (String JavaDoc)MBeanUtil.getAttribute(vsObjectNames[i], "id");
1327                if (!(id.equals("__asadmin"))) {
1328                    vsId = id;
1329                    break;
1330                }
1331            }
1332        }
1333        return vsId;
1334    }
1335
1336    /* returns the port number on which appName could be executed */
1337    private String JavaDoc getPortForApplication(String JavaDoc appName) {
1338        ObjectName JavaDoc appRef = (ObjectName JavaDoc)MBeanUtil.invoke
1339            ("ias:type=server,name=server,category=config",
1340            "getApplicationRefByRef",
1341            new Object JavaDoc[]{appName},
1342            new String JavaDoc[]{"java.lang.String"});
1343
1344        String JavaDoc vsId = null;
1345        if (appRef == null) { // no ref found for this application
1346
vsId = getNonAdminVirtualServer();
1347        }
1348        else {
1349            vsId = (String JavaDoc)MBeanUtil.getAttribute(appRef, "virtual-servers");
1350            if (vsId == null || vsId.length() ==0) { // no vs found for this application
1351
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; // no vs found for this app..
1360

1361        String JavaDoc port = null;
1362        ObjectName JavaDoc vsObjectName = (ObjectName JavaDoc)
1363            MBeanUtil.invoke("ias:type=configs,category=config",
1364            "getVirtualServer",
1365            new Object JavaDoc[]{vsId, null},
1366            new String JavaDoc[]{"java.lang.String", "java.lang.String"});
1367        if (vsObjectName != null) {
1368            String JavaDoc listener = (String JavaDoc)MBeanUtil.getAttribute(vsObjectName, "http-listeners");
1369            if (listener != null) {
1370                if (listener.indexOf(",") > 0) {
1371                    listener = listener.substring(0, listener.indexOf(","));
1372                }
1373                ObjectName JavaDoc listenerObjectName = (ObjectName JavaDoc)
1374                    MBeanUtil.invoke("ias:type=configs,category=config",
1375                    "getHttpListener",
1376                    new Object JavaDoc[]{listener, null},
1377                    new String JavaDoc[]{"java.lang.String", "java.lang.String"});
1378                port = (String JavaDoc)MBeanUtil.getAttribute(listenerObjectName, "port");
1379            }
1380        }
1381        return port;
1382    }
1383 
1384
1385    private String JavaDoc addProp(String JavaDoc tag, String JavaDoc addText) {
1386        int i = tag.indexOf(' ');
1387        if (i<0) {
1388            return tag;
1389    }
1390        String JavaDoc text = tag.substring(0,i) + " " + addText + tag.substring(i,tag.length());
1391        return text;
1392    }
1393
1394    private String JavaDoc removeProp(String JavaDoc tag, String JavaDoc 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 JavaDoc 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    /**
1410     * This method is used as a fallback when no Hostname is provided.
1411     */

1412    public static String JavaDoc getDefaultHostName() {
1413        String JavaDoc defaultHostName = "localhost";
1414    try {
1415        InetAddress JavaDoc host = InetAddress.getLocalHost();
1416        defaultHostName = host.getCanonicalHostName();
1417    } catch(UnknownHostException JavaDoc uhe) {
1418// sLogger.log(Level.FINEST, "mbean.get_local_host_error", uhe);
1419
// sLogger.log(Level.INFO, "mbean.use_default_host");
1420
}
1421    return defaultHostName;
1422    }
1423
1424
1425    /**
1426     * This method determines the hostname of the given serverInstance
1427     * ObjectName to the best of its ability. It will attempt to obtain the node-agent....
1428     *
1429     * @param serverInstance The ObjectName to use to determine the hostname
1430     */

1431    protected String JavaDoc getHost(ObjectName JavaDoc serverInstance) {
1432    // Find the node agent (if there is one)
1433
String JavaDoc nodeAgentRef = (String JavaDoc)MBeanUtil.getAttribute(serverInstance, "node-agent-ref");
1434    if ((nodeAgentRef == null) || nodeAgentRef.equals("")) {
1435        return getDefaultHostName();
1436    }
1437
1438    // Get the JMX connector for the node agent
1439
ObjectName JavaDoc jmxConnector = (ObjectName JavaDoc)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    // Try to get the hostname
1448
// Get "client-hostname" from the properties (use this way instead
1449
// of getProperty to avoid exception
1450
AttributeList JavaDoc properties = (AttributeList JavaDoc)MBeanUtil.invoke(
1451        jmxConnector, "getProperties", null, null);
1452    Attribute JavaDoc att;
1453    String JavaDoc hostName = null;
1454    Iterator JavaDoc it = properties.iterator();
1455    while (it.hasNext()) {
1456        att = (Attribute JavaDoc)it.next();
1457        if (att.getName().equals("client-hostname")) {
1458        hostName = (String JavaDoc)att.getValue();
1459        break;
1460        }
1461    }
1462
1463    // Get default host name
1464
if ((hostName == null) || hostName.equals("") || hostName.equals("0.0.0.0")) {
1465        return getDefaultHostName();
1466    }
1467
1468    // We found the hostname!!
1469
return hostName;
1470    }
1471
1472
1473    /**
1474     *
1475     * @param src The String which may contain tokens for
1476     * substitution.
1477     *
1478     * @param serverInstance The serverInstance which has the system
1479     * properties.
1480     */

1481    protected String JavaDoc replaceTokens(ObjectName JavaDoc serverInstance, String JavaDoc src) {
1482    int idx = src.lastIndexOf("${");
1483    if (idx < 0) {
1484        // Nothing to do
1485
return src;
1486    }
1487
1488    // Get the Properties
1489
Properties JavaDoc sysProp = (Properties JavaDoc)
1490        MBeanUtil.invoke(serverInstance, "listSystemProperties",
1491        new Object JavaDoc[]{ new Boolean JavaDoc("true")}, new String JavaDoc[]{"boolean"});
1492    int endIdx;
1493    String JavaDoc 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 the result after the substitution(s)
1505
return src;
1506    }
1507
1508
1509    /**
1510     * This method expects a ObjectName to a server instance (not a cluster).
1511     * It will obtain its configuration and determine its concrete port
1512     * number(s).
1513     */

1514    protected List JavaDoc getURLs(String JavaDoc appId, ObjectName JavaDoc serverInstance) {
1515    // Get the config ref name, this is used in a couple places below
1516
String JavaDoc configRef = (String JavaDoc)MBeanUtil.getAttribute(serverInstance, "config-ref");
1517
1518    // First get the application-ref ObjectName
1519
String JavaDoc name = (String JavaDoc)MBeanUtil.getAttribute(serverInstance, "name");
1520    String JavaDoc appObj = "com.sun.appserv:type=application-ref,ref="+appId+",server="+name+",category=config";
1521
1522    // Next get the virtual server(s)
1523
String JavaDoc strVirServers = (String JavaDoc)MBeanUtil.getAttribute(appObj, "virtual-servers");
1524    if ((strVirServers == null) || strVirServers.equals("")) {
1525        // No virtual server was specified, we must look at the listeners,
1526
// find the first *enabled* listener, then look at the listener's
1527
// *default* virtual server's listeners (backwards I know... but
1528
// this is how it is).
1529

1530        // First get all the listeners for this instance
1531
ObjectName JavaDoc listeners[] = (ObjectName JavaDoc[])MBeanUtil.invoke(
1532        "com.sun.appserv:type=http-service,config="+configRef+
1533        ",category=config", "getHttpListener", null, null);
1534
1535        // Find the first enabled listener
1536
int count=0;
1537        while (count<listeners.length) {
1538        if (((String JavaDoc)MBeanUtil.getAttribute(listeners[count],
1539            "enabled")).equals("true")) {
1540            break;
1541        }
1542        count++;
1543        }
1544        if (count == listeners.length) {
1545        // There are no enabled listeners, return an empty List
1546
return new ArrayList JavaDoc(0);
1547        }
1548
1549        // Now pull off the default-virutal-server
1550
strVirServers = (String JavaDoc)MBeanUtil.getAttribute(listeners[count],
1551        "default-virtual-server");
1552    }
1553
1554    // Next get the http listeners from the virtual servers
1555
String JavaDoc virServer;
1556    String JavaDoc listeners;
1557    Iterator JavaDoc listIt;
1558    String JavaDoc listener;
1559    List JavaDoc listenerList = new ArrayList JavaDoc();
1560    Iterator JavaDoc it = Util.parseStringList(strVirServers, " ,").iterator();
1561    while (it.hasNext()) {
1562        // Get each virtual server's list of listeners
1563
virServer = (String JavaDoc)it.next();
1564        listeners = (String JavaDoc)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        // Add each unique listener
1571
while (listIt.hasNext()) {
1572        listener = (String JavaDoc)listIt.next();
1573        if (!listenerList.contains(listener)) {
1574            // Only add unique listeners
1575
listenerList.add(listener);
1576        }
1577        }
1578    }
1579
1580    // There will be 1 URL per listener
1581
List JavaDoc urls = new ArrayList JavaDoc(listenerList.size());
1582    StringBuffer JavaDoc url = null;
1583    String JavaDoc listenerObj;
1584    it = listenerList.iterator();
1585    while (it.hasNext()) {
1586        // Get the next listener
1587
listenerObj = "com.sun.appserv:type=http-listener,id="+it.next()
1588        +",config="+configRef+",category=config";
1589
1590        // Start the URL
1591
url = new StringBuffer JavaDoc("http");
1592        if (MBeanUtil.getAttribute(listenerObj, "security-enabled").toString().equals("true")) {
1593        // Security is enabled on this port, add an 's'
1594
url.append("s");
1595        }
1596        url.append("://");
1597
1598        // Host
1599
url.append(getHost(serverInstance));
1600        url.append(":");
1601
1602        // Port
1603
url.append(replaceTokens(serverInstance, (String JavaDoc)MBeanUtil.getAttribute(listenerObj, "port")));
1604        url.append("/");
1605
1606        // Add the URL to the List
1607
urls.add(url.toString());
1608    }
1609
1610    return urls;
1611    }
1612
1613
1614    /**
1615     * This method takes an array of object name. These object names may
1616     * either be server instances or cluster instances. It will get the
1617     * cluster's instances and recurse. It will pass the server instances to
1618     * getURLs(ObjectName).
1619     *
1620     * @param serverInstance An array of ObjectName, server instances
1621     * and/or clusters
1622     */

1623    protected List JavaDoc getURLs(String JavaDoc appId, ObjectName JavaDoc serverInstances[]) {
1624    // Iterate over all the supplied server instance ObjectNames
1625
List JavaDoc urls = new ArrayList JavaDoc();
1626    for (int count=0; count<serverInstances.length; count++) {
1627        if (serverInstances[count].getKeyProperty("type").equals("cluster")) {
1628        // We found a cluster, get the server instances in the cluster
1629
// listServerInstances returns: com.sun.appserv:type=server,name=Instance1A,category=config
1630
urls.addAll(getURLs(appId, (ObjectName JavaDoc[])MBeanUtil.invoke(
1631            serverInstances[count],
1632            "listServerInstances", null, null)));
1633        } else {
1634        // We have a Server Instance, just get the urls
1635
urls.addAll(getURLs(appId, serverInstances[count]));
1636        }
1637    }
1638
1639    // Return the URLs
1640
return urls;
1641    }
1642
1643
1644    /**
1645     * This method finds all the webapps associated w/ appId
1646     *
1647     * @param appId The application
1648     *
1649     * @return The ObjectName[] of servers / clusters
1650     */

1651    protected ObjectName JavaDoc[] getWebAppReferencees(String JavaDoc appId) {
1652    return (ObjectName JavaDoc[])MBeanUtil.invoke(
1653        "com.sun.appserv:type=applications,category=config",
1654        "listReferencees",
1655        new Object JavaDoc[] { appId },
1656        new String JavaDoc[] { "java.lang.String" });
1657    }
1658
1659
1660    /**
1661     * This method uses the given appId to find all the possible
1662     * server/port combinations available for accessing the application. It
1663     * will create String representing the concatenation of all the URLs
1664     * seperated by <BR>'s.
1665     */

1666    public String JavaDoc getWebAppHrefs(RequestContext ctx, HandlerContext handlerCtx) {
1667    // First get the application id
1668
String JavaDoc id = (String JavaDoc)handlerCtx.getInputValue("appId");
1669        String JavaDoc appendUrl = (String JavaDoc)handlerCtx.getInputValue("appendUrl");
1670
1671        if (appendUrl != null) {
1672            appendUrl = ((appendUrl.startsWith("/") ? appendUrl.substring(1) : appendUrl));
1673        }
1674        
1675    // getWebAppReferencees = com.sun.appserv:type=cluster,name=Cluster1,category=config
1676
// getWebAppReferencees = com.sun.appserv:type=server,name=server,category=config
1677

1678    // Get all the URLs
1679
List JavaDoc urls = getURLs(id, getWebAppReferencees(id));
1680
1681    // Check to see if we have a Model to populate...
1682
DefaultModel model = (DefaultModel)handlerCtx.getInputValue("model");
1683    if (model != null) {
1684        // Initialize the model...
1685
model.clear();
1686    }
1687
1688    // Create a default output, plus popluate the supplied Model (if any)
1689
StringBuffer JavaDoc output = new StringBuffer JavaDoc("");
1690    Iterator JavaDoc it = urls.iterator();
1691    String JavaDoc url = null;
1692    while (it.hasNext()) {
1693        url = (String JavaDoc)it.next();
1694            url = url + appendUrl;
1695            
1696        // Add each URL to the output string
1697
output.append("<A HREF=\""+url+"\" target=\"_blank\">"+url+"</A><BR>");
1698
1699        // Add each URL to the Model
1700
model.appendRow();
1701        model.setValue("link", url);
1702    }
1703
1704    // Return a String containing all the URLs
1705
return output.toString();
1706    }
1707
1708    public void getApplicationStatusSummary(RequestContext ctx, HandlerContext handlerCtx) {
1709    // First get the application id
1710
String JavaDoc appsName = (String JavaDoc)handlerCtx.getInputValue("appsName");
1711        int status = getAppStatusSummary(appsName);
1712        String JavaDoc result = convertStatusSummary(status);
1713        if (result == null) {
1714            //error case, will only occur for PE.
1715
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 JavaDoc resObj = (String JavaDoc)handlerCtx.getInputValue("resObjectName");
1723        try{
1724            int status = getResourceStatusSummary(new ObjectName JavaDoc(resObj));
1725            String JavaDoc result = convertStatusSummary(status);
1726            handlerCtx.setOutputValue("value", result);
1727        }catch (Exception JavaDoc ex){
1728            throw new FrameworkException("error in getResourceStatusSummary ", ex);
1729        }
1730    }
1731    
1732    public void getRealTargetStatus(RequestContext ctx, HandlerContext handlerCtx) {
1733    // First get the application id
1734
String JavaDoc appsName = (String JavaDoc)handlerCtx.getInputValue("appsName");
1735        String JavaDoc target = (String JavaDoc)handlerCtx.getInputValue("target");
1736        String JavaDoc status = getRealTargetStatus(appsName, target);
1737        handlerCtx.setOutputValue("value", status);
1738    }
1739    
1740    private String JavaDoc getRealTargetStatus(String JavaDoc appsName, Object JavaDoc target){
1741        try{
1742            String JavaDoc enabled = getAppStatus(appsName, "domain");
1743            if ("false".equals(enabled)){
1744                return "false";
1745            }else{
1746                if(target instanceof ObjectName JavaDoc)
1747                    return (String JavaDoc) MBeanUtil.getAttribute((ObjectName JavaDoc)target, "enabled");
1748                else
1749                    return getAppStatus(appsName, (String JavaDoc)target);
1750            }
1751        }catch(Exception JavaDoc ex){
1752            //for the case of app client, it will failed. we just catch it here.
1753
return "";
1754        }
1755    }
1756    
1757    public void getRealResourceTargetStatus(RequestContext ctx, HandlerContext handlerCtx) {
1758    // First get the application id
1759
try {
1760            String JavaDoc refsObjectName = (String JavaDoc)handlerCtx.getInputValue("refsObjectName");
1761            ObjectName JavaDoc refsObject = new ObjectName JavaDoc(refsObjectName);
1762            String JavaDoc status = getRealResourceTargetStatus(refsObject);
1763            handlerCtx.setOutputValue("value", status);
1764        }catch(Exception JavaDoc ex){
1765            throw new FrameworkException("Error in getRealResourceTargetStatus ", ex);
1766        }
1767    }
1768   
1769    public void saveStatusPE(RequestContext ctx, HandlerContext handlerCtx) {
1770        try {
1771            ObjectName JavaDoc objectName = new ObjectName JavaDoc((String JavaDoc)handlerCtx.getInputValue("objectName"));
1772            ObjectName JavaDoc refObjectName = new ObjectName JavaDoc((String JavaDoc)handlerCtx.getInputValue("refObjectName"));
1773            String JavaDoc value = (String JavaDoc)handlerCtx.getInputValue("value");
1774            
1775            //type will either be application-ref or resource-ref
1776
//for applications, need to go through deployment facility to enable/disable.
1777

1778            if(refObjectName.getKeyProperty("type").equals("application-ref") &&
1779                !(objectName.getKeyProperty("type").equals("mbean"))){
1780                changeEnableStatus(objectName.getKeyProperty("name"), new String JavaDoc[] { "server" }, value);
1781            }else{
1782                MBeanUtil.setAttribute(objectName, new Attribute JavaDoc("enabled", "true"));
1783                MBeanUtil.setAttribute(refObjectName, new Attribute JavaDoc("enabled", value));
1784            }
1785        }catch(Exception JavaDoc ex){
1786            throw new FrameworkException(ex);
1787        }
1788    }
1789    
1790    private String JavaDoc getRealResourceTargetStatus(ObjectName JavaDoc refsObject){
1791        String JavaDoc resName = refsObject.getKeyProperty("ref");
1792        String JavaDoc resType = (String JavaDoc) MBeanUtil.invoke(
1793                "com.sun.com.sun.appserv:type=resources,category=config",
1794                "getResourceType",
1795                new String JavaDoc[] {resName},
1796                new String JavaDoc[] {"java.lang.String"});
1797        try{
1798            ObjectName JavaDoc obj = new ObjectName JavaDoc("com.sun.appserv:category=config,type="+resType+",jndi-name="+resName);
1799            String JavaDoc status = (String JavaDoc) MBeanUtil.getAttribute(obj, "enabled");
1800            if ("true".equals(status)){
1801                status = (String JavaDoc) MBeanUtil.getAttribute(refsObject, "enabled");
1802            }
1803            return status;
1804        }catch(Exception JavaDoc ex){
1805            throw new FrameworkException("Error in getRealResourceTargetStatus", ex);
1806        }
1807    }
1808    
1809   /* return -2: no target associated.
1810    * -1 : all targets enabled
1811    * 0 : all targets disabled
1812    * otherwise, the # of targets thats enabled.
1813    */

1814   private int getAppStatusSummary(String JavaDoc appsObjName)
1815   {
1816       ObjectName JavaDoc[]refs = null;
1817       int count =0;
1818       try{
1819           String JavaDoc appsName=(String JavaDoc) MBeanUtil.getAttribute(appsObjName, "name");
1820           boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue();
1821           if (!isTargetSupported){
1822                ObjectName JavaDoc server = new ObjectName JavaDoc("com.sun.appserv:type=server,name=server,category=config");
1823                refs = new ObjectName JavaDoc[]{server};
1824           }else{
1825               String JavaDoc[] params = new String JavaDoc[] {appsName};
1826               String JavaDoc[] types = new String JavaDoc[] {"java.lang.String"};
1827               refs = (ObjectName JavaDoc[]) 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 JavaDoc 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 JavaDoc[] params = new String JavaDoc[] {appsName};
1836               String JavaDoc[] types = new String JavaDoc[] {"java.lang.String"};
1837               ObjectName JavaDoc appRefsObj = (ObjectName JavaDoc)MBeanUtil.invoke( refs[i], "getApplicationRefByRef", params, types );
1838               String JavaDoc refStatus = (String JavaDoc)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 JavaDoc ex){
1846           Util.logSEVERE(ex);
1847           return APP_UNKNOWN;
1848       }
1849    }
1850   
1851   /* return -2: no target associated.
1852    * -1 : all targets enabled
1853    * 0 : all targets disabled
1854    * otherwise, the # of targets thats enabled.
1855    */

1856   private int getResourceStatusSummary(ObjectName JavaDoc resObject)
1857   {
1858       String JavaDoc resName = resObject.getKeyProperty("jndi-name");
1859       int count = 0;
1860       String JavaDoc[] params = new String JavaDoc[] {resName};
1861       String JavaDoc[] types = new String JavaDoc[] {"java.lang.String"};
1862       ObjectName JavaDoc[] refs = null;
1863       boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue();
1864       try {
1865            if (!isTargetSupported){
1866                   ObjectName JavaDoc server = new ObjectName JavaDoc("com.sun.appserv:type=server,name=server,category=config");
1867                   refs = new ObjectName JavaDoc[]{server};
1868           }else{
1869                refs = (ObjectName JavaDoc[]) 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 JavaDoc status = (String JavaDoc)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 JavaDoc resRefsObj = (ObjectName JavaDoc)MBeanUtil.invoke( refs[i], "getResourceRefByRef", params, types );
1878               String JavaDoc refStatus = (String JavaDoc)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 JavaDoc ex){
1886           Util.logWARNING(ex);
1887           return APP_UNKNOWN;
1888       }
1889    }
1890   
1891     private String JavaDoc convertStatusSummary(int statusSummary){
1892        String JavaDoc disp = null;
1893        boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue();
1894        if (statusSummary == APP_UNKNOWN){
1895            disp = (isTargetSupported)?Util.getMessage("deploy.unknown") : "false" ; //PE is checkbox that require true or false.
1896
}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            //should not get here for PE
1907
disp = (isTargetSupported)? Util.getMessage("deploy.someEnabled", new String JavaDoc[]{""+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 JavaDoc implClass = (String JavaDoc)handlerCtx.getInputValue("implClass");
1929        Boolean JavaDoc create = (Boolean JavaDoc)handlerCtx.getInputValue("create");
1930    
1931        Object JavaDoc[] params = {implClass};
1932        String JavaDoc[] types = {"java.lang.String"};
1933        MBeanInfo JavaDoc mbinfo = (MBeanInfo JavaDoc) MBeanUtil.invoke("com.sun.appserv:type=applications,category=config", "getMBeanInfo", params, types);
1934        MBeanAttributeInfo JavaDoc[] attrArray = mbinfo.getAttributes();
1935        if (attrArray == null || attrArray.length < 0){
1936            return;
1937        }
1938        AttributeList JavaDoc attrList = null;
1939        if(!create){
1940            String JavaDoc objName = (String JavaDoc)handlerCtx.getInputValue("mbeanObjectName");
1941            attrList = (AttributeList JavaDoc) 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 JavaDoc name = attrArray[i].getName();
1950                model.setValue("propertyName", name);
1951                model.setValue("type", attrArray[i].getType());
1952                if(!create){
1953                    String JavaDoc val = getMbeanPropertyValue(attrList, name);
1954                    if (val != null)
1955                        model.setValue("propertyValue", val);
1956                }
1957            }
1958// System.out.println("beginDisplay: After Loading Table =============== ");
1959
// ((DefaultModel)model).dumpValues(System.out);
1960

1961        }catch (Exception JavaDoc ex) {
1962            throw new FrameworkException(ex);
1963        }
1964    }
1965    
1966    private String JavaDoc getMbeanPropertyValue(AttributeList JavaDoc attrList, String JavaDoc name){
1967        if( attrList == null)
1968            return null;
1969        Iterator JavaDoc it = attrList.iterator();
1970        while (it.hasNext()) {
1971            Attribute JavaDoc att = (Attribute JavaDoc)it.next();
1972            if (att.getName().equals(name)) {
1973                return (String JavaDoc) att.getValue();
1974            }
1975        }
1976        return null;
1977    }
1978    
1979    public void getMbeanAttrFromTable(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException {
1980    Boolean JavaDoc ignoreEmptyValues = (Boolean JavaDoc)handlerCtx.getInputValue("ignoreEmptyValues");
1981        CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("propertiesModel");
1982// System.out.println("=== Just before getting Value from Table");
1983
// ((DefaultModel)model).dumpValues(System.out);
1984
model.beforeFirst();
1985        Properties JavaDoc properties = new Properties JavaDoc();
1986        while (model.next()) {
1987            String JavaDoc name = (String JavaDoc) model.getValue("propertyName");
1988            String JavaDoc value = (String JavaDoc) 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    //Deployment constants
2002
public static final String JavaDoc FORCE = "force";
2003    public static final String JavaDoc DEFAULT_FORCE = "true";
2004    public static final String JavaDoc CASCADE = "cascade";
2005    public static final String JavaDoc DEFAULT_CASCADE = "false";
2006    public static final String JavaDoc VERIFY = "verify";
2007    public static final String JavaDoc DEFAULT_VERIFY = "false";
2008    public static final String JavaDoc PRECOMPILE_JSP = "precompilejsp";
2009    public static final String JavaDoc ENABLE = "enable";
2010    public static final String JavaDoc CONTEXT_ROOT = "contextRoot";
2011    public static final String JavaDoc ARCHIVE_NAME = "archiveName";
2012    public static final String JavaDoc NAME = "name";
2013    public static final String JavaDoc TYPE = "type";
2014    public static final String JavaDoc TARGET = "target";
2015
2016    //DisplayField constants
2017
public static final String JavaDoc LOCATION = "location";
2018    public static final String JavaDoc REDEPLOY = "redeploy";
2019    
2020    public static final String JavaDoc PROPERTY_NAME = "propertyName";
2021    public static final String JavaDoc 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