KickJava   Java API By Example, From Geeks To Geeks.

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


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  * addRemoveHandlers.java
26  *
27  * Created on March 16, 2004, 12:34 PM
28  */

29
30 package com.sun.enterprise.tools.admingui.handlers;
31
32 import java.util.StringTokenizer JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Arrays JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.Vector JavaDoc;
38 import java.util.Properties JavaDoc;
39 import java.util.HashMap JavaDoc;
40 import java.util.Enumeration JavaDoc;
41
42 import javax.servlet.http.HttpServletRequest JavaDoc;
43
44 import javax.management.ObjectName JavaDoc;
45 import javax.management.Attribute JavaDoc;
46 import javax.management.AttributeList JavaDoc;
47
48 import com.iplanet.jato.RequestContext;
49 import com.iplanet.jato.RequestManager;
50 import com.iplanet.jato.model.DefaultModel;
51 import com.iplanet.jato.view.*;
52 import com.sun.web.ui.taglib.html.*;
53 import com.iplanet.jato.view.View;
54 import com.iplanet.jato.view.ViewBase;
55 import com.iplanet.jato.view.html.StaticTextField;
56 import com.iplanet.jato.view.html.HREF;
57 import com.iplanet.jato.RequestContext;
58 import com.iplanet.jato.view.html.OptionList;
59 import com.iplanet.jato.view.event.ChildContentDisplayEvent;
60
61 import com.sun.web.ui.model.CCAddRemoveModelInterface;
62 import com.sun.web.ui.view.addremove.CCAddRemove;
63 import com.sun.web.ui.model.CCPropertySheetModelInterface;
64 import com.sun.web.ui.model.CCActionTableModelInterface;
65
66 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
67 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
68 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
69 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent;
70 import com.sun.enterprise.tools.guiframework.view.descriptors.CCAddRemoveDescriptor;
71 import com.sun.enterprise.tools.guiframework.view.descriptors.CCPropertySheetDescriptor;
72 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor;
73 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
74 import com.sun.enterprise.tools.guiframework.event.handlers.AttributeHandlers;
75
76 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
77 import com.sun.enterprise.tools.admingui.util.Util;
78 import com.sun.enterprise.tools.admingui.ConfigProperties;
79
80
81 import com.sun.enterprise.admin.servermgmt.RuntimeStatusList;
82 import com.sun.enterprise.admin.servermgmt.RuntimeStatus;
83 import com.sun.enterprise.admin.common.Status;
84
85
86 public class TargetHandlers {
87
88     // Show or not to show the targets section of the property sheet.
89
// In PE we don't and in SE/EE we do.
90
public void setupTargetsSection(RequestContext ctx, HandlerContext handlerCtx) {
91         ViewDescriptor vd;
92         if (handlerCtx.getEvent() instanceof BeforeCreateEvent) {
93             vd = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
94         }
95         else {
96             vd = handlerCtx.getViewDescriptor();
97         }
98         
99         if (vd instanceof CCPropertySheetDescriptor) {
100             CCPropertySheetModelInterface model =
101                 ((CCPropertySheetDescriptor)vd).getModel();
102             String JavaDoc targetsSectionName = (String JavaDoc)handlerCtx.getInputValue("targetsSectionName");
103             Boolean JavaDoc hasTargets = ConfigProperties.getInstance().getTargetSupported();
104             if (targetsSectionName != null) {
105                 model.setVisible(targetsSectionName, hasTargets.booleanValue());
106                 handlerCtx.setOutputValue("hasTargets", hasTargets);
107             }
108             else {
109                 handlerCtx.setOutputValue("hasTargets", new Boolean JavaDoc(false));
110             }
111         } else {
112             throw new RuntimeException JavaDoc("ViewDesc should be of type property sheet.");
113         }
114     }
115
116     public void setAvailableList(RequestContext ctx, HandlerContext handlerCtx) {
117         ViewDescriptor vd;
118         if (handlerCtx.getEvent() instanceof BeforeCreateEvent) {
119             vd = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
120         }
121         else {
122             vd = handlerCtx.getViewDescriptor();
123         }
124         if (vd instanceof CCAddRemoveDescriptor) {
125             ObjectName JavaDoc[] clusters = (ObjectName JavaDoc[])handlerCtx.getInputValue("clusters");
126             ObjectName JavaDoc[] instances = (ObjectName JavaDoc[])handlerCtx.getInputValue("instances");
127             String JavaDoc[] names = getAllTargets(clusters, instances);
128             CCAddRemoveModelInterface model = ((CCAddRemoveDescriptor)vd).getModel();
129             CCAddRemoveDescriptor addRemoveDesc = (CCAddRemoveDescriptor)vd;
130             String JavaDoc defaultInstance = (String JavaDoc)handlerCtx.getInputValue("defaultInstance");
131             String JavaDoc defaultCluster = (String JavaDoc)handlerCtx.getInputValue("defaultCluster");
132             String JavaDoc defaultTarget = null;
133             Vector JavaDoc vv = new Vector JavaDoc(Arrays.asList(names));
134             if (!Util.isEmpty(defaultInstance)){
135                 vv.remove(defaultInstance);
136                 defaultTarget = defaultInstance;
137             }
138             if (!Util.isEmpty(defaultCluster)){
139                 vv.remove(defaultCluster);
140                 defaultTarget = defaultCluster;
141             }
142             if (defaultTarget != null){
143                 names = new String JavaDoc[vv.size()];
144                 for(int i=0; i<vv.size(); i++){
145                     names[i] = (String JavaDoc) vv.elementAt(i);
146                 }
147                 model.setSelectedOptionList(new OptionList(new String JavaDoc[]{defaultTarget}, new String JavaDoc[]{defaultTarget}));
148             }
149             model.setAvailableOptionList(new OptionList(names, names));
150         } else {
151             throw new RuntimeException JavaDoc("Not an AddRemoveComponent!");
152
153         }
154     }
155     public void setAllTargets(RequestContext ctx, HandlerContext handlerCtx) {
156     ObjectName JavaDoc[] clusters = (ObjectName JavaDoc[])handlerCtx.getInputValue("clusters");
157     ObjectName JavaDoc[] instances = (ObjectName JavaDoc[])handlerCtx.getInputValue("instances");
158     
159     String JavaDoc[] allTargets = getAllTargets(clusters, instances);
160     handlerCtx.setOutputValue("allTargets", allTargets);
161     }
162     
163     private String JavaDoc[] getAllTargets(ObjectName JavaDoc[] clusters, ObjectName JavaDoc[] instances) {
164     int clusterCount = (clusters == null)?(0):(clusters.length);
165     int instanceCount = (instances == null)?(0):(instances.length);
166     
167     String JavaDoc[] allTargets = new String JavaDoc[clusterCount + instanceCount];
168         int i;
169         for (i = 0; i < clusterCount; i++) {
170         allTargets[i] = (String JavaDoc)MBeanUtil.getAttribute(clusters[i], "name");
171         }
172         for (i = 0; i < instanceCount; i++) {
173         allTargets[i+clusterCount] = (String JavaDoc)MBeanUtil.getAttribute(instances[i], "name");
174         }
175     return allTargets;
176     }
177     
178      public void setSelectedTargets(RequestContext ctx, HandlerContext handlerCtx) {
179         ViewDescriptor vd;
180         if (handlerCtx.getEvent() instanceof BeforeCreateEvent) {
181             vd = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
182         }
183         else {
184             vd = handlerCtx.getViewDescriptor();
185         }
186         if (vd instanceof CCAddRemoveDescriptor) {
187             String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
188         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
189         Object JavaDoc refName = (Object JavaDoc)handlerCtx.getInputValue("referedTargets");
190             String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
191             if(key == null)
192                 key = "name";
193                         
194             if (targets == null) {
195         targets = new String JavaDoc[0];
196         }
197             String JavaDoc[] associatedTargets = null;
198             if(refName == null){
199                 refName = new String JavaDoc[0];
200             }
201             if (refName instanceof ObjectName JavaDoc[]) {
202                 associatedTargets = getAssociatedTargets((ObjectName JavaDoc[])refName, key);
203             } else if (refName instanceof String JavaDoc[]) {
204                 associatedTargets = (String JavaDoc[])refName;
205             }
206           
207         targets = getAvailableVirtualServers(targets, associatedTargets);
208             
209         CCAddRemoveDescriptor addRemoveDesc = (CCAddRemoveDescriptor)vd;
210             CCAddRemoveModelInterface model = addRemoveDesc.getModel();
211
212         model.setAvailableOptionList(new OptionList(targets, targets));
213         model.setSelectedOptionList(new OptionList(associatedTargets, associatedTargets));
214         } else {
215             throw new RuntimeException JavaDoc("Not an AddRemoveComponent!");
216
217         }
218     }
219      
220     
221     private String JavaDoc[] getAssociatedTargets(ObjectName JavaDoc[] refName, String JavaDoc key) {
222     String JavaDoc[] associatedTargets = (refName != null) ? new String JavaDoc[refName.length]:new String JavaDoc[0];
223     
224     for (int i=0; refName != null && i < refName.length; i++) {
225         associatedTargets[i] = refName[i].getKeyProperty(key);
226     }
227     return associatedTargets;
228     }
229     
230     public void setAvailableVirtualServers(RequestContext ctx, HandlerContext handlerCtx) {
231         ViewDescriptor vd;
232         if (handlerCtx.getEvent() instanceof BeforeCreateEvent) {
233             vd = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
234         }
235         else {
236             vd = handlerCtx.getViewDescriptor();
237         }
238         if (vd instanceof CCAddRemoveDescriptor) {
239             ObjectName JavaDoc[] virtualServers = (ObjectName JavaDoc[])handlerCtx.getInputValue("virtualServers");
240         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
241             int vsCount = (virtualServers == null)?(0):(virtualServers.length);
242             
243             String JavaDoc[] availableVS = new String JavaDoc[vsCount];
244             for (int i = 0; i < vsCount; i++) {
245                 availableVS[i] = (String JavaDoc)MBeanUtil.getAttribute(virtualServers[i], "id");
246             }
247             
248         CCAddRemoveDescriptor addRemoveDesc = (CCAddRemoveDescriptor)vd;
249             CCAddRemoveModelInterface model = addRemoveDesc.getModel();
250         String JavaDoc[] selectedVS = getAssociatedVirtualServers(objectName);
251     
252         if (selectedVS == null || selectedVS.length == 0) {
253         selectedVS = availableVS;
254         availableVS = new String JavaDoc[0];
255         }
256         else {
257         availableVS = getAvailableVirtualServers(availableVS, selectedVS);
258         }
259         model.setAvailableOptionList(new OptionList(availableVS, availableVS));
260         model.setSelectedOptionList(new OptionList(selectedVS, selectedVS));
261         } else {
262             throw new RuntimeException JavaDoc("Not an AddRemoveComponent!");
263
264         }
265     }
266     // we may need to move this to Util class.
267
private String JavaDoc[] getAvailableVirtualServers(String JavaDoc[] availableVS, String JavaDoc[] selectedVS) {
268         Vector JavaDoc availableVector = new Vector JavaDoc();
269         boolean selected = false;
270         
271         for(int i=0; i < availableVS.length; i++) {
272         for(int j=0; j < selectedVS.length; j++) {
273             if(availableVS[i].equals(selectedVS[j])) {
274             selected = true;
275             break;
276             }
277         }
278         if(!selected) {
279             availableVector.add(availableVS[i]);
280         }
281         selected = false;
282         }
283         availableVS = (String JavaDoc[])availableVector.toArray(new String JavaDoc[availableVector.size()]);
284         return availableVS;
285     }
286     
287     private String JavaDoc[] getAssociatedVirtualServers(String JavaDoc objectName) {
288     String JavaDoc str = (String JavaDoc)MBeanUtil.getAttribute(objectName, "virtual-servers");
289     String JavaDoc[] vs = Util.stringToArray(str, ",");
290     return vs;
291     }
292     
293     public void setVirtualServerAttribute(RequestContext ctx, HandlerContext handlerCtx) {
294     String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
295     String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
296     String JavaDoc virtualServers = Util.concatDelimiter(targets, ",");
297     Attribute JavaDoc attr = new Attribute JavaDoc("virtual-servers", virtualServers);
298     MBeanUtil.setAttribute(objectName, attr);
299     }
300
301     public void getSelectedTargets(RequestContext ctx, HandlerContext handlerCtx) {
302     String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue("targetsChildName");
303         if (childName == null || childName.length() == 0) {
304             return;
305         }
306         
307     View view = handlerCtx.getView();
308     DescriptorContainerView descView = (DescriptorContainerView)
309         (((ViewBase)view).getParentViewBean());
310     ViewDescriptor vd = descView.getViewDescriptor();
311     ViewDescriptor desc = vd.getChildDescriptor(childName);
312     if (!(desc instanceof CCAddRemoveDescriptor)) {
313         throw new FrameworkException("addRemoveDescriptor is of wrong type", desc, view);
314     }
315         CCAddRemoveDescriptor addRemoveDesc = ((CCAddRemoveDescriptor)desc);
316         CCAddRemoveModelInterface model = addRemoveDesc.getModel();
317         CCAddRemove addRemoveChild = (CCAddRemove)addRemoveDesc.getView(ctx);
318         
319         // DON'T DO THIS:
320
// CCAddRemove addRemoveChild = (CCAddRemove)(descView.getChild(childName));
321
// THIS CAUSES A NEW CCAddRemove CHILD TO BE CREATED, WITH A NEW MODEL
322
// AND THE MODEL HASN'T HAD THE REQUEST VALUES MAPPED TO IT!!!!!
323

324         OptionList selectedOptions = model.getSelectedOptionList(addRemoveChild);
325     OptionList availableOptions = model.getAvailableOptionList(addRemoveChild);
326         if (selectedOptions == null)
327             selectedOptions = model.getSelectedOptionList();
328     if (availableOptions == null)
329             availableOptions = model.getAvailableOptionList();
330         
331         String JavaDoc[] targets = null;
332         if (selectedOptions != null) {
333             targets = new String JavaDoc[selectedOptions.size()];
334             for (int i = 0; i < targets.length; i++) {
335                 targets[i] = selectedOptions.getValue(i);
336             }
337         }
338     //Using the above method to get the available lists also, to manage targets.
339
String JavaDoc[] availableTargets = null;
340         if (availableOptions != null) {
341             availableTargets = new String JavaDoc[availableOptions.size()];
342             for (int i = 0; i < availableTargets.length; i++) {
343                 availableTargets[i] = availableOptions.getValue(i);
344             }
345         }
346         handlerCtx.setOutputValue("targets", targets);
347     handlerCtx.setOutputValue("availableTargets", availableTargets);
348     }
349     
350     public void createReferences(RequestContext ctx, HandlerContext handlerCtx) {
351         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
352         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
353         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
354         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
355         String JavaDoc[] types= new String JavaDoc[]{"java.lang.String", "boolean", "java.lang.String"};
356         if (targets != null) {
357             for (int i = 0; i < targets.length; i++) {
358                 Object JavaDoc[] params = new Object JavaDoc[]{targets[i], new Boolean JavaDoc(true), key};
359                 MBeanUtil.invoke(objectName, methodName, params, types);
360             }
361         }
362     }
363     //Need to write a new method to create references, bcz the params are hard coded in the above createReferences method.
364
public void createMBeanWithReferences(RequestContext ctx, HandlerContext handlerCtx) {
365         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
366         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
367         ArrayList JavaDoc typesList= (ArrayList JavaDoc)handlerCtx.getInputValue("types");
368     ArrayList JavaDoc paramsList = (ArrayList JavaDoc)handlerCtx.getInputValue("params");
369         String JavaDoc[] targets = (String JavaDoc [])handlerCtx.getInputValue("targets");
370     String JavaDoc[] types = (String JavaDoc[])typesList.toArray(new String JavaDoc[typesList.size()]);
371         Boolean JavaDoc isTargetSupported = ConfigProperties.getInstance().getTargetSupported();
372         
373         if(targets == null || targets.length == 0) {
374             //By default deploying to DAS to be in sync. with CLI.
375
targets = new String JavaDoc[]{"server"};
376         }
377         
378         Map JavaDoc attrsMap = (Map JavaDoc) paramsList.get(0);
379         
380         if(isTargetSupported){
381             String JavaDoc enabled = (String JavaDoc)attrsMap.get("EEenabled");
382             if (Util.isEmpty(enabled)) enabled="true";
383             attrsMap.put("enabled", enabled);
384         }else{
385             String JavaDoc enabled = (String JavaDoc)attrsMap.get("PEenabled");
386             if (Util.isEmpty(enabled)) enabled="true";
387             attrsMap.put("enabled", enabled);
388         }
389         attrsMap.remove("PEenabled");
390         attrsMap.remove("EEenabled");
391         for (int i = 0; i < targets.length; i++) {
392         paramsList.add(0, targets[i]);
393         Object JavaDoc[] params = paramsList.toArray();
394                 MBeanUtil.invoke(objectName, methodName, params, types);
395                 paramsList.remove(0);
396                 String JavaDoc objName="com.sun.appserv:type=application-ref,category=config,ref=" + attrsMap.get("name")+ ",server="+ targets[i];
397                 //the following can be removed after bug#6342989 is fixed
398
Attribute JavaDoc attr = new Attribute JavaDoc("enabled", attrsMap.get("enabled"));
399                 MBeanUtil.setAttribute(objName, attr);
400         }
401         
402         // set Description
403
if(! Util.isEmpty( (String JavaDoc) attrsMap.get("description"))){
404             Attribute JavaDoc desc = new Attribute JavaDoc("description", attrsMap.get("description"));
405             MBeanUtil.setAttribute("com.sun.appserv:type=mbean,category=config,name="+attrsMap.get("name"), desc);
406         }
407         
408     }
409   
410     public void deleteReferences(RequestContext ctx, HandlerContext handlerCtx) {
411         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
412         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
413         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
414         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("availableTargets");
415         String JavaDoc[] types= new String JavaDoc[]{"java.lang.String", "java.lang.String"};
416         if (targets != null) {
417             for (int i = 0; i < targets.length; i++) {
418                 Object JavaDoc[] params = new Object JavaDoc[]{targets[i],key};
419                 MBeanUtil.invoke(objectName, methodName, params, types);
420             }
421         }
422     }
423
424     public void deleteLBReferences(RequestContext ctx, HandlerContext handlerCtx) {
425         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
426         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
427         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
428         String JavaDoc[] deleteTargets = (String JavaDoc[])handlerCtx.getInputValue("availableTargets");
429         String JavaDoc[] types= new String JavaDoc[]{"java.lang.String"};
430         
431         if(deleteTargets != null) {
432             for (int i = 0; i < deleteTargets.length; i++) {
433                 Object JavaDoc params[] = {deleteTargets[i]};
434                 MBeanUtil.invoke(objectName, methodName, params, types);
435             }
436         }
437     }
438         
439     public void createLBReferences(RequestContext ctx, HandlerContext handlerCtx) {
440         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
441         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
442         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
443         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
444         Object JavaDoc objName = null;
445         if (targets != null ) {
446             for (int i = 0; i < targets.length; i++) {
447                 String JavaDoc[] types2= new String JavaDoc[]{"java.lang.String"};
448                 Object JavaDoc params2[] = {targets[i]};
449                 try {
450                     objName = MBeanUtil.invoke(objectName, "getClusterRefByRef", params2, types2);
451                 } catch (Exception JavaDoc ex) {
452                     // ignore
453
}
454                 if(objName == null) {
455                     String JavaDoc[] types= new String JavaDoc[]{"javax.management.AttributeList"};
456                     AttributeList JavaDoc attrList = new AttributeList JavaDoc();
457                     attrList.add(new Attribute JavaDoc("ref", targets[i]));
458                     Object JavaDoc params[] = {attrList};
459                     MBeanUtil.invoke(objectName, methodName, params, types);
460                 }
461                 
462             }
463         }
464     }
465     
466     
467 // // FIXME: a cluster list should be passed in from XML calling MBean.invoke.
468
// // FIXME: Shouldn't have MBEan names in XML.
469
// private String[] getClusters() {
470
// ObjectName[] clusters =
471
// (ObjectName[]) MBeanUtil.invoke(
472
// "com.sun.appserv:type=clusters,category=config",
473
// "listClusters",
474
// new Object[]{null},
475
// new String[]{"java.lang.String"});
476
// String[] clusterNames= new String[clusters.length];
477
// for (int i = 0; i < clusters.length; i++) {
478
// clusterNames[i] = (String)MBeanUtil.getAttribute(clusters[i], "name");
479
// }
480
// return clusterNames;
481
// }
482
//
483
// private boolean isCluster(String name) {
484
// String[] clusters = getClusters();
485
// for (int i = 0; i < clusters.length; i++) {
486
// if (clusters[i].equals(name))
487
// return true;
488
// }
489
// return false;
490
// }
491
//
492
// // FIXME : work on getting a more efficient way to select the page to go to
493
// public void TargetHrefClicked(RequestContext ctx, HandlerContext handlerCtx) {
494
// HREF href = (HREF)handlerCtx.getView();
495
// String nextPage;
496
//
497
// if (isCluster(href.getValue().toString())) {
498
// nextPage = "cluster";
499
// }
500
// else {
501
// nextPage = "serverInstance";
502
// }
503
// handlerCtx.setOutputValue("nextPage", nextPage);
504
// }
505
public void getRequiredTargets(RequestContext ctx, HandlerContext handlerCtx) {
506        Object JavaDoc objectName = (Object JavaDoc)handlerCtx.getInputValue("ObjectName");
507         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("availableTargets"); //available targets from addremove comp.
508
String JavaDoc[] allTargets = (String JavaDoc[])handlerCtx.getInputValue("targetList");
509         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
510     HashMap JavaDoc availableTargetsList = Util.stringArrayToHashMap(targets);
511     Vector JavaDoc deleteTargets = new Vector JavaDoc();
512     Vector JavaDoc createTargets = new Vector JavaDoc();
513         if(key == null)
514             key = "name";
515         String JavaDoc[] instanceName = null;
516         if (objectName instanceof ObjectName JavaDoc[]) {
517             instanceName = getAssociatedTargets((ObjectName JavaDoc[])objectName, key);
518         } else if (objectName instanceof String JavaDoc[]) {
519             instanceName = (String JavaDoc[])objectName;
520         }
521         HashMap JavaDoc instancesList = Util.stringArrayToHashMap(instanceName);
522
523  //current associated instance list.
524

525     for (int i=0; allTargets != null && i < allTargets.length; i++) {
526         //Delete only if necessary
527
if(availableTargetsList.containsKey(allTargets[i]) && instancesList.containsKey(allTargets[i])) {
528         deleteTargets.add(allTargets[i]);
529         }
530         //Create only if necessary
531
if(!availableTargetsList.containsKey(allTargets[i]) && !instancesList.containsKey(allTargets[i])) {
532         createTargets.add(allTargets[i]);
533         }
534     }
535     handlerCtx.setOutputValue("deleteTargets", (String JavaDoc[])deleteTargets.toArray(new String JavaDoc[deleteTargets.size()]));
536     handlerCtx.setOutputValue("createTargets", (String JavaDoc[])createTargets.toArray(new String JavaDoc[createTargets.size()]));
537     }
538     
539     public void beginDisplayTargetPlaceHolder(RequestContext ctx, HandlerContext handlerCtx) {
540         StaticTextField field = (StaticTextField)handlerCtx.getView();
541         field.setValue(".TARGETVALUE.");
542     }
543     
544     public void beginDisplayTargetsInTable(RequestContext ctx, HandlerContext handlerCtx) {
545         HREF href = (HREF)handlerCtx.getView();
546         href.setValue(".TARGETVALUE.");
547     }
548     
549     public String JavaDoc endDisplayTargetsInTable(RequestContext ctx, HandlerContext handlerCtx) {
550     if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
551         return null;
552     }
553     ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent();
554     String JavaDoc content = dispEvent.getContent();
555         ObjectName JavaDoc[] targets = (ObjectName JavaDoc[])handlerCtx.getInputValue("targets");
556         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
557         if(key == null)
558             key = "name";
559         
560         String JavaDoc hrefs = "";
561         if (targets != null) {
562             for (int i = 0; i < targets.length; i++) {
563                 if (i > 0)
564                     hrefs += "<br />";
565                 
566                 String JavaDoc objectType = targets[i].getKeyProperty("type");
567                 String JavaDoc isCluster = (objectType.equalsIgnoreCase("cluster"))?"true":"false";
568                 String JavaDoc statusIcon = getStatusIconHtml(targets[i]);
569
570                 String JavaDoc tmp = content.replaceFirst(".TARGETVALUE.",
571                     (String JavaDoc)MBeanUtil.getAttribute(targets[i], key)+"&isCluster="+isCluster);
572                 hrefs += statusIcon + tmp.replaceAll(".TARGETVALUE.",
573                     (String JavaDoc)MBeanUtil.getAttribute(targets[i], key));
574             }
575         }
576         return hrefs;
577     }
578     
579     public String JavaDoc endDisplayLBsInTable(RequestContext ctx, HandlerContext handlerCtx) {
580     if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
581         return null;
582     }
583     ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent();
584     String JavaDoc content = dispEvent.getContent();
585         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
586         ObjectName JavaDoc[] lbs = (ObjectName JavaDoc[])handlerCtx.getInputValue("lbs");
587         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
588         if(key == null)
589             key = "name";
590         String JavaDoc hrefs = "";
591
592         if (targets != null && lbs != null) {
593             for (int i = 0; i < targets.length; i++) {
594                 String JavaDoc lbConfig = "";
595                 String JavaDoc name = "";
596                 if (i > 0)
597                     hrefs += "<br />";
598                 for(int j = 0; j < lbs.length; j++){
599                     lbConfig = (String JavaDoc)MBeanUtil.getAttribute(lbs[j].toString(), "lb-config-name");
600                     if(targets[i].equals(lbConfig)) {
601                         name = lbs[j].getKeyProperty("name");
602                     }
603                 }
604                 
605                 String JavaDoc tmp = content.replaceFirst(".TARGETVALUE.",
606                 name);
607                 hrefs += tmp.replaceAll(".TARGETVALUE.",
608                 name);
609             }
610         }
611         return hrefs;
612     }
613     
614      public void getStatusCounts(RequestContext ctx, HandlerContext handlerCtx) {
615         ObjectName JavaDoc[] instances = (ObjectName JavaDoc[])handlerCtx.getInputValue("instances");
616         int running = 0;
617         int restart = 0;
618         int stopped = 0;
619         
620         if (instances != null) {
621             for (int i = 0; i < instances.length; i++) {
622                 Object JavaDoc sts = null;
623                 try {
624                     sts = MBeanUtil.invoke(instances[i], "getRuntimeStatus", null, null);
625                 } catch (Exception JavaDoc ex) {
626                     // ignore
627
}
628                 if (sts != null && sts instanceof RuntimeStatus) {
629                     boolean restartNeeded = ((RuntimeStatus)sts).isRestartNeeded();
630                     Status s = ((RuntimeStatus)sts).getStatus();
631                     switch (s.getStatusCode()){
632                         case Status.kInstanceStartingCode:
633                         case Status.kInstanceRunningCode:
634                             running++;
635                             if (restartNeeded)
636                                 restart++;
637                             break;
638                         case Status.kInstanceStoppingCode:
639                         case Status.kInstanceNotRunningCode:
640                             stopped++;
641                             break;
642                     }
643                 }
644             }
645         }
646         handlerCtx.setOutputValue("running", new Integer JavaDoc(running));
647         handlerCtx.setOutputValue("restart", new Integer JavaDoc(restart));
648         handlerCtx.setOutputValue("stopped", new Integer JavaDoc(stopped));
649     }
650         
651     public static String JavaDoc getStatusIconHtml(ObjectName JavaDoc obj) {
652         if (obj == null)
653             return "";
654         Object JavaDoc sts = null;
655         try {
656             sts = MBeanUtil.invoke(obj, "getRuntimeStatus", null, null);
657         } catch (Exception JavaDoc ex) {
658             // ignore
659
}
660         return getStatusIconHtml(sts);
661     }
662     
663     public static String JavaDoc getStatusHtml(Object JavaDoc sts) {
664         if (sts == null) {
665             return getStatusIconHtml(-1, false, null) +
666                 Util.getMessage("serverinst.unknown");
667         }
668         else if (sts instanceof RuntimeStatus) {
669             boolean restartNeeded = ((RuntimeStatus)sts).isRestartNeeded();
670             Status s = ((RuntimeStatus)sts).getStatus();
671             int statusCode = s.getStatusCode();
672             String JavaDoc statusString = "";
673             switch (statusCode) {
674                 case Status.kInstanceStartingCode:
675                 case Status.kInstanceRunningCode: {
676                     if (restartNeeded) {
677                         statusString = Util.getMessage("serverinst.restart");
678                     } else {
679                         statusString = Util.getMessage("serverinst.running");
680                     }
681                     break;
682                 }
683                 case Status.kInstanceStoppingCode:
684                 case Status.kInstanceNotRunningCode: {
685                     statusString = Util.getMessage("serverinst.notRunning");
686                     break;
687                 }
688             }
689             return getStatusIconHtml(statusCode, restartNeeded, null) + statusString;
690         } else if (sts instanceof RuntimeStatusList) {
691             RuntimeStatusList stsList = (RuntimeStatusList) sts;
692             if (stsList.anyRunning())
693                 return getStatusIconHtml(Status.kInstanceRunningCode, false, stsList.toString()) + stsList.toString();
694             else
695                 return getStatusIconHtml(Status.kInstanceNotRunningCode, false, stsList.toString()) + stsList.toString();
696         }
697         return "";
698     }
699     
700     public static String JavaDoc getStatusIconHtml(Object JavaDoc sts) {
701         if (sts == null) {
702             return getStatusIconHtml(-1, false, null);
703         }
704         else if (sts instanceof RuntimeStatus) {
705             boolean restartNeeded = ((RuntimeStatus)sts).isRestartNeeded();
706             Status s = ((RuntimeStatus)sts).getStatus();
707             int statusCode = s.getStatusCode();
708             return getStatusIconHtml(statusCode, restartNeeded, null);
709         }
710         else if (sts instanceof RuntimeStatusList) {
711             RuntimeStatusList stsList = (RuntimeStatusList) sts;
712             if (stsList.anyRunning())
713                 return getStatusIconHtml(Status.kInstanceRunningCode, false, stsList.toString());
714             else
715                 return getStatusIconHtml(Status.kInstanceNotRunningCode, false, stsList.toString());
716         }
717         return "<img SRC=\"" + blankGif + "\" border=\"0\" alt=\"\"/>&nbsp;";
718         //return "<b>"+"?"+"</b>&nbsp;";
719
}
720
721     private static final String JavaDoc blankGif =
722         "/com_sun_web_ui/images/other/dot.gif\" width=\"11\" height=\"11";
723     
724     public static String JavaDoc getStatusIconHtml(int statusCode, boolean restartNeeded,
725             String JavaDoc altMessage) {
726         if (altMessage != null && altMessage.length() == 0)
727             altMessage = null;
728         switch (statusCode) {
729             case Status.kInstanceStartingCode:
730             case Status.kInstanceRunningCode: {
731                 if (restartNeeded) {
732             String JavaDoc restartGif = Util.getMessage("serverinst.restartGif");
733                     return "<img SRC=\"" +
734                         ((restartGif==null || restartGif.length()==0)?(blankGif):(restartGif)) +
735                         "\" border=\"0\" alt=\"" +
736                         ((altMessage==null)?(Util.getMessage("serverinst.restart")):altMessage) +
737                         "\" />&nbsp;";
738                 } else {
739             String JavaDoc runningGif = Util.getMessage("serverinst.runningGif");
740                     return "<img SRC=\"" +
741                         ((runningGif==null || runningGif.length()==0)?(blankGif):(runningGif)) +
742                         "\" border=\"0\" alt=\"" +
743                         ((altMessage==null)?Util.getMessage("serverinst.running"):altMessage) +
744                         "\" />&nbsp;";
745                 }
746             }
747             case Status.kInstanceStoppingCode:
748             case Status.kInstanceNotRunningCode: {
749         String JavaDoc stoppedGif = Util.getMessage("serverinst.stoppedGif");
750                 return "<img SRC=\"" +
751                     ((stoppedGif==null || stoppedGif.length()==0)?(blankGif):(stoppedGif)) +
752                     "\" border=\"0\" alt=\"" +
753                     ((altMessage==null)?Util.getMessage("serverinst.notRunning"):altMessage) +
754                     "\" />&nbsp;";
755             }
756             case -1: {
757         String JavaDoc unknownGif = Util.getMessage("serverinst.unknownGif");
758                 return "<img SRC=\"" +
759                     ((unknownGif==null || unknownGif.length()==0)?(blankGif):(unknownGif)) +
760                     "\" border=\"0\" alt=\"" +
761                     ((altMessage==null)?Util.getMessage("serverinst.unknown"):altMessage) +
762                     "\" />&nbsp;";
763                 
764             }
765             case Status.kEntityEnabledCode:
766             case Status.kEntityDisabledCode:
767             default:
768                 return "<img SRC=\"" + blankGif + "\" border=\"0\" alt=\"\"/>&nbsp;";
769                 //return "<b>"+"?"+"</b>&nbsp;";
770
}
771     }
772
773     public void disableButtons(RequestContext ctx, HandlerContext handlerCtx) {
774
775         Integer JavaDoc rCount = (Integer JavaDoc)handlerCtx.getInputValue("RunningCount");
776         Integer JavaDoc sCount = (Integer JavaDoc)handlerCtx.getInputValue("StoppedCount");
777     if (rCount == null || sCount == null)
778         throw new IllegalArgumentException JavaDoc(
779         "The parameter map did not contain 'StatusCount'!");
780         int r = ((Integer JavaDoc)rCount).intValue();
781         int s = ((Integer JavaDoc)sCount).intValue();
782         
783         if(r == 0) {
784             handlerCtx.setOutputValue("runngingStatus", "true");
785         } else {
786             handlerCtx.setOutputValue("runngingStatus", "false");
787         }
788         if(s == 0) {
789             handlerCtx.setOutputValue("stoppedStatus", "true");
790         } else {
791             handlerCtx.setOutputValue("stoppedStatus", "false");
792         }
793     }
794     
795
796     public String JavaDoc formatStatusCount(RequestContext ctx, HandlerContext handlerCtx) {
797         Object JavaDoc obj = handlerCtx.getInputValue("count");
798         if (obj == null)
799             throw new RuntimeException JavaDoc("null count in formatStatusCount!");
800         String JavaDoc count = obj.toString();
801         if (count.trim().equals("0")) {
802             if (blankGif == null || blankGif.length() == 0)
803                 return "&nbsp;&nbsp;--";
804             else
805                 return "<img SRC=\"" + blankGif + "\" border=\"0\" alt=\"\" />--";
806         }
807         
808         String JavaDoc icon = (String JavaDoc)handlerCtx.getInputValue("icon");
809         if (icon == null)
810             throw new RuntimeException JavaDoc("ICON is null in formatStatusCount!");
811         String JavaDoc s = "";
812         if (icon.equals("stopped"))
813             s = getStatusIconHtml(Status.kInstanceStoppingCode, false, null) + "&nbsp;" +count;
814         else if (icon.equals("restart"))
815             s = getStatusIconHtml(Status.kInstanceRunningCode, true, null) + "&nbsp;" + count;
816         else if (icon.equals("running"))
817             s = getStatusIconHtml(Status.kInstanceRunningCode, false, null) + "&nbsp;" + count;
818         return s;
819     }
820         
821     public String JavaDoc getObjectStatus(RequestContext ctx, HandlerContext handlerCtx) {
822         Object JavaDoc sts = null;
823         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
824
825         // If the object is a node agent and if the rendezvous hasn't occured
826
// yet, then need to give a better status than what the backend says.
827
try {
828             String JavaDoc objectType = new ObjectName JavaDoc(objectName).getKeyProperty("type");
829             if (objectType.equals("node-agent")) {
830                 String JavaDoc[] types = new String JavaDoc[]{"java.lang.String"};
831                 Object JavaDoc[] params = new Object JavaDoc[]{"rendezvousOccurred"};
832                 String JavaDoc result = (String JavaDoc)MBeanUtil.invoke(
833                     objectName, "getPropertyValue", params, types);
834                 if (result.equalsIgnoreCase("false")) {
835                     String JavaDoc status = Util.getMessage("nodeAgent.awaitingInitialSync");
836             String JavaDoc stoppedGif = Util.getMessage("serverinst.stoppedGif");
837                     if (stoppedGif != null && stoppedGif.length() != 0) {
838                         status = "<img SRC=\"" + stoppedGif +
839                             "\" border=\"0\" alt=\"" + status + "\" />&nbsp;" +
840                             status;
841                     }
842                     handlerCtx.setOutputValue("status", status);
843                     return status;
844                }
845             }
846         } catch (Exception JavaDoc ex) {
847             // ignore
848
}
849
850         try {
851             sts = MBeanUtil.invoke(objectName, "getRuntimeStatus", null, null);
852         } catch (Exception JavaDoc ex) {
853             // ignore
854
}
855         String JavaDoc status = getStatusHtml(sts);
856         // strip off the icon if it's a placeholder for spacing.
857
if (status.indexOf("dot.gif") > 0) {
858             int i = status.indexOf(";"); // from nbsp;
859
if (i > 0)
860                 status = status.substring(i+1);
861         }
862         handlerCtx.setOutputValue("status", status);
863         return status;
864     }
865     
866     public String JavaDoc isRunning(RequestContext ctx, HandlerContext handlerCtx) {
867         String JavaDoc status = "false";
868         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
869         try {
870             Object JavaDoc sts = MBeanUtil.invoke(objectName, "getRuntimeStatus", null, null);
871             if (sts != null && sts instanceof RuntimeStatus) {
872                 Status s = ((RuntimeStatus)sts).getStatus();
873                 int statusCode = s.getStatusCode();
874                 switch (statusCode) {
875                     case Status.kInstanceStartingCode:
876                     case Status.kInstanceRunningCode:
877                         status = "true";
878                         break;
879                     default:
880                         status = "false";
881                         break;
882                 }
883             }
884         } catch (Exception JavaDoc ex) {
885             // ignore
886
}
887         handlerCtx.setOutputValue("status", status);
888         return status;
889     }
890     
891     public String JavaDoc getClusterStatus(RequestContext ctx, HandlerContext handlerCtx) {
892         int restart = 0;
893         int running = 0;
894         int stopped = 0;
895         int unknown = 0;
896     
897         String JavaDoc status = Util.getMessage("serverinst.noInstances"); // "No Server Instances Defined";
898
String JavaDoc clusterObjectName = (String JavaDoc) handlerCtx.getInputValue("clusterObjectName");
899         Object JavaDoc objs = MBeanUtil.invoke(clusterObjectName, "listServerInstances", null, null);
900         if (objs != null && objs instanceof ObjectName JavaDoc[]) {
901             ObjectName JavaDoc [] instances = (ObjectName JavaDoc [])objs;
902             for (int i=0; i<instances.length; i++) {
903                 Object JavaDoc sts = null;
904                 try {
905                     sts = MBeanUtil.invoke(instances[i], "getRuntimeStatus", null, null);
906                 } catch (Exception JavaDoc ex) {
907                     // ignore
908
}
909                 if (sts != null && sts instanceof RuntimeStatus) {
910                     boolean restartNeeded = ((RuntimeStatus)sts).isRestartNeeded();
911                     Status s = ((RuntimeStatus)sts).getStatus();
912                     int statusCode = s.getStatusCode();
913                     switch (statusCode) {
914                         case Status.kInstanceStartingCode:
915                         case Status.kInstanceRunningCode:
916                             running++;
917                             if (restartNeeded)
918                                 restart++;
919                             break;
920                         case Status.kInstanceStoppingCode:
921                         case Status.kInstanceNotRunningCode:
922                             stopped++;
923                             break;
924                     }
925                 } else {
926                     unknown ++;
927                 }
928             }
929             if (instances.length > 0) {
930                 status = "" + running + Util.getMessage("serverinst.runningInstances");
931                 if (stopped > 0)
932                     status += "<br />" + stopped + Util.getMessage("serverinst.stoppedInstances");
933                 if (restart > 0)
934                     status += "<br />" + restart + Util.getMessage("serverinst.restartInstances");
935                 if (unknown > 0)
936                     status += "<br />" + unknown + Util.getMessage("serverinst.unknown");
937             }
938         }
939         handlerCtx.setOutputValue("status", status);
940         return status;
941     }
942
943     public boolean isTargetSupported(RequestContext ctx, HandlerContext handlerCtx) {
944         Boolean JavaDoc isTargetSupported =
945             ConfigProperties.getInstance().getTargetSupported();
946         handlerCtx.setOutputValue("isTargetSupported", isTargetSupported);
947         return isTargetSupported.booleanValue();
948     }
949     
950     public String JavaDoc endDisplayInstanceStatus(RequestContext ctx, HandlerContext handlerCtx) {
951         ObjectName JavaDoc[] instances = (ObjectName JavaDoc[])handlerCtx.getInputValue("instances");
952         String JavaDoc method = (String JavaDoc) handlerCtx.getInputValue("methodName");
953         
954         String JavaDoc result = "";
955         if (instances != null) {
956             for (int i = 0; i < instances.length; i++) {
957                 if (i > 0) {
958                     result = result + "<br />";
959                 }
960                 Object JavaDoc value = MBeanUtil.invoke(instances[i], method, null, null);
961                 if (value != null) {
962                     if (value instanceof RuntimeStatus)
963                         result += ((RuntimeStatus)value).toShortString().replaceAll(" ", "&nbsp;");
964                     else
965                         result += value.toString().replaceAll(" ", "&nbsp;");
966                 }
967             }
968         }
969         return result;
970     }
971     
972     public void resourceRefAction(RequestContext ctx, HandlerContext handlerCtx) {
973         View view = handlerCtx.getView();
974         DescriptorContainerView descView = (DescriptorContainerView)
975             (((ViewBase)view).getParentViewBean());
976         ViewDescriptor vd = descView.getViewDescriptor();
977         //we may need to get the tabilChildName from the xml file.
978
String JavaDoc tableChildName = (String JavaDoc)handlerCtx.getInputValue("tableChildName");
979         ViewDescriptor tableDescriptor = vd.getChildDescriptor(tableChildName);
980         if (tableDescriptor == null) {
981             throw new FrameworkException("tableDescriptor is null", vd, view);
982         }
983         if (!(tableDescriptor instanceof CCActionTableDescriptor)) {
984             throw new FrameworkException("tableDescriptor is of wrong type",
985             tableDescriptor, view);
986         }
987         CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("propertiesModel");
988         if (model == null) {
989                 throw new FrameworkException("PropertiesHandler.getModel: Parameter 'propertiesModel' not specified");
990             }
991         String JavaDoc editKeyValue = (String JavaDoc)handlerCtx.getInputValue("editKeyValue");
992         String JavaDoc action = (String JavaDoc)handlerCtx.getInputValue("action");
993         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
994         //CCActionTableModelInterface model = ((CCActionTableDescriptor)tableDescriptor).getModel();
995

996         model.setRowSelectionType("multiple");
997         try {
998             model.beforeFirst();
999             while(model.next()) {
1000            if (model.isRowSelected()) {
1001                String JavaDoc objectName = (String JavaDoc)model.getValue("objectName");
1002                ObjectName JavaDoc resRefObjectName = (ObjectName JavaDoc)MBeanUtil.invoke(objectName,
1003                    methodName, new Object JavaDoc[]{editKeyValue}, new String JavaDoc[]{"java.lang.String"});
1004                changeEnableStatus(resRefObjectName, action);
1005                model.setRowSelected(false);
1006            }
1007            }
1008        } catch (Exception JavaDoc ex) {
1009            throw new FrameworkException("Error while enabling: '"+
1010            vd.getName()+"'", ex, vd, null);
1011        }
1012        ContainerViewBase containerView =
1013                (ContainerViewBase)(tableDescriptor.getView(ctx).getParent());
1014        containerView.removeChild(tableDescriptor.getName());
1015        ((DefaultModel)model).clear();
1016    }
1017    
1018    public static void changeEnableStatus(ObjectName JavaDoc resRefObjectName, String JavaDoc action){
1019        Attribute JavaDoc attr = new Attribute JavaDoc("enabled", action);
1020        MBeanUtil.setAttribute(resRefObjectName, attr);
1021        if(action.equals("true")){
1022            //we need to ensure the resource itself is enabled.
1023
String JavaDoc editKeyValue = resRefObjectName.getKeyProperty("ref");
1024            changeResourceAttribute(editKeyValue, attr);
1025        }
1026    }
1027    
1028    static private void changeResourceAttribute(String JavaDoc resName, Attribute JavaDoc attr){
1029        try{
1030            String JavaDoc resType = (String JavaDoc) MBeanUtil.invoke(
1031                    "com.sun.com.sun.appserv:type=resources,category=config",
1032                    "getResourceType",
1033                    new String JavaDoc[] {resName},
1034                    new String JavaDoc[] {"java.lang.String"});
1035            ObjectName JavaDoc obj = new ObjectName JavaDoc("com.sun.com.sun.appserv:category=config,type="+resType+",jndi-name="+resName);
1036            MBeanUtil.setAttribute(obj, attr);
1037        }catch(javax.management.MalformedObjectNameException JavaDoc ex){
1038            throw new FrameworkException("error in TargetHandlers changeEnableStatus :", ex);
1039        }
1040    }
1041    
1042    public void changeResourceStatusAll(RequestContext ctx, HandlerContext handlerCtx) {
1043    View view = handlerCtx.getView();
1044    DescriptorContainerView descView = (DescriptorContainerView)
1045        (((ViewBase)view).getParentViewBean());
1046    ViewDescriptor vd = descView.getViewDescriptor();
1047    String JavaDoc childName = (String JavaDoc)vd.getParameter("tableChildName");
1048
1049    if (childName == null) {
1050        throw new FrameworkException("childName not specified", vd, view);
1051    }
1052    ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName);
1053    if (tableDescriptor == null) {
1054        throw new FrameworkException("tableDescriptor is null", vd, view);
1055    }
1056    if (!(tableDescriptor instanceof CCActionTableDescriptor)) {
1057        throw new FrameworkException("tableDescriptor is of wrong type",
1058        tableDescriptor, view);
1059    }
1060        String JavaDoc newStatus = (String JavaDoc)handlerCtx.getInputValue("new-status");
1061        String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
1062        doAction(((CCActionTableDescriptor)tableDescriptor).getModel(), tableDescriptor, key, newStatus);
1063    }
1064
1065    static private void doAction(CCActionTableModelInterface model, ViewDescriptor vd, String JavaDoc key, String JavaDoc newStatus) {
1066    RequestContext ctx = RequestManager.getRequestContext();
1067        Attribute JavaDoc attr = new Attribute JavaDoc("enabled", newStatus);
1068        try{
1069            model.setRowSelectionType("multiple");
1070            model.beforeFirst();
1071            // from the model, get the child that has the needed value...
1072
while(model.next()) {
1073                if (model.isRowSelected()) {
1074                    String JavaDoc resName = (String JavaDoc) model.getValue(key);
1075                    //we never disable the resource itself.
1076
if (newStatus.equals("true")){
1077                        MBeanUtil.setAttribute((String JavaDoc)model.getValue("objectName"), attr);
1078                        //changeResourceAttribute(resName, attr);
1079
}
1080                    String JavaDoc[] params = new String JavaDoc[] {resName};
1081                    String JavaDoc[] types = new String JavaDoc[] {"java.lang.String"};
1082                    boolean isTargetSupported = ConfigProperties.getInstance().getTargetSupported().booleanValue();
1083                    if (!isTargetSupported){
1084                        MBeanUtil.setAttribute("com.sun.appserv:type=resource-ref,server=server,category=config,ref="+resName, attr);
1085                    }else{
1086                        ObjectName JavaDoc[] targets = (ObjectName JavaDoc[]) MBeanUtil.invoke("com.sun.appserv:type=resources,category=config" , "listReferencees", params, types);
1087                        if (targets == null)
1088                            continue;
1089                        for(int i=0; i<targets.length; i++){
1090                            ObjectName JavaDoc resRef = (ObjectName JavaDoc)MBeanUtil.invoke(targets[i], "getResourceRefByRef", params, types);
1091                            MBeanUtil.setAttribute(resRef, attr);
1092                        }
1093                    }
1094                    model.setRowSelected(false);
1095                }
1096            }
1097        }catch (Exception JavaDoc ex){
1098            throw new FrameworkException("error in changeResourceStatus ", ex);
1099        }
1100    View view = vd.getView(ctx).getParent();
1101    ContainerViewBase descView = (ContainerViewBase)view;
1102    descView.removeChild(vd.getName());
1103    ((DefaultModel)model).clear();
1104    }
1105    
1106    //=======================
1107

1108    public void getDefaultTarget(RequestContext ctx, HandlerContext handlerCtx) {
1109        handlerCtx.setOutputValue("defaultTarget",
1110            ConfigProperties.getInstance().getDefaultTarget());
1111    }
1112    
1113    public void beginResourceEditTabsDisplay(RequestContext ctx, HandlerContext handlerCtx) {
1114        HREF href = (HREF)handlerCtx.getView();
1115        href.setValue(href.getValue() + ".RESOURCENAME.");
1116    }
1117    
1118    public String JavaDoc endResourceEditTabsDisplay(RequestContext ctx, HandlerContext handlerCtx) {
1119    if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
1120        return null;
1121    }
1122    ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent();
1123    String JavaDoc content = dispEvent.getContent();
1124        content = content.replaceAll(".RESOURCENAME.",
1125            "&name="+ctx.getRequest().getAttribute("editKeyValue"));
1126        return content;
1127    }
1128    
1129    public void beginEditTabsDisplay(RequestContext ctx, HandlerContext handlerCtx) {
1130        HREF href = (HREF)handlerCtx.getView();
1131        href.setValue(href.getValue() + ".PLACEHOLDER.");
1132    }
1133    
1134    public String JavaDoc endEditTabsDisplay(RequestContext ctx, HandlerContext handlerCtx) {
1135    if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
1136        return null;
1137    }
1138    ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent();
1139    String JavaDoc content = dispEvent.getContent();
1140        String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
1141        if (key==null)
1142            key="name";
1143        content = content.replaceAll(".PLACEHOLDER.",
1144            "&"+ key + "=" + ctx.getRequest().getAttribute(key));
1145        return content;
1146    }
1147    
1148    public String JavaDoc endClusteredInstanceTabsDisplay(RequestContext ctx, HandlerContext handlerCtx) {
1149    if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
1150        return null;
1151    }
1152    ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent();
1153    String JavaDoc content = dispEvent.getContent();
1154        String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
1155        if (key==null)
1156            key="name";
1157        content = content.replaceAll(".PLACEHOLDER.",
1158            "&"+ key + "=" + ctx.getRequest().getAttribute(key) + "&isCluster=true");
1159        return content;
1160    }
1161}
1162
Popular Tags