KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CommonHandlers.java
26  *
27  */

28
29 package com.sun.enterprise.tools.admingui.handlers;
30
31 import java.io.IOException JavaDoc;
32 import java.io.InputStream JavaDoc;
33 import java.lang.reflect.UndeclaredThrowableException JavaDoc;
34 import java.text.DateFormat JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.Date JavaDoc;
37 import java.util.List JavaDoc;
38 import java.util.Stack JavaDoc;
39 import java.util.EventObject JavaDoc;
40 import java.util.StringTokenizer JavaDoc;
41 import java.util.Enumeration JavaDoc;
42 import java.util.HashMap JavaDoc;
43 import java.util.Map JavaDoc;
44 import java.util.Properties JavaDoc;
45
46 import com.iplanet.jato.RequestContext;
47 import com.iplanet.jato.RequestContextImpl;
48 import com.iplanet.jato.RequestManager;
49 import com.iplanet.jato.ViewBeanManager;
50 import com.iplanet.jato.model.DefaultModel;
51 import com.iplanet.jato.model.Model;
52 import com.iplanet.jato.ModelManager;
53 import com.iplanet.jato.util.RootCauseException;
54 import com.iplanet.jato.view.ContainerView;
55 import com.iplanet.jato.view.ContainerViewBase;
56 import com.iplanet.jato.view.View;
57 import com.iplanet.jato.view.DisplayFieldImpl;
58 import com.iplanet.jato.view.DisplayField;
59 import com.iplanet.jato.view.ViewBase;
60 import com.iplanet.jato.view.ViewBean;
61 import com.iplanet.jato.view.html.SelectableGroup;
62 import com.iplanet.jato.view.html.OptionList;
63 import com.iplanet.jato.view.html.HREF;
64 import com.iplanet.jato.view.event.RequestInvocationEvent;
65 import com.iplanet.jato.view.event.ViewRequestInvocationEvent;
66 import com.iplanet.jato.view.event.ViewCommandEvent;
67 import com.iplanet.jato.view.event.ChildContentDisplayEvent;
68
69 import javax.management.MBeanException JavaDoc;
70 import javax.management.ObjectName JavaDoc;
71 import javax.management.AttributeList JavaDoc;
72 import javax.management.Attribute JavaDoc;
73
74 import javax.servlet.ServletException JavaDoc;
75 import javax.servlet.ServletRequest JavaDoc;
76 import javax.servlet.http.HttpServletRequest JavaDoc;
77 import javax.servlet.http.HttpSession JavaDoc;
78
79 import com.sun.appserv.management.util.misc.ExceptionUtil;
80
81 import com.sun.enterprise.tools.guiframework.view.descriptors.CCPropertySheetDescriptor;
82 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
83 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle;
84 import com.sun.enterprise.tools.guiframework.view.DescriptorCCTabs;
85 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
86 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
87 import com.sun.enterprise.tools.guiframework.view.ViewDescriptorManager;
88 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
89 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent;
90 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent;
91
92 import com.sun.web.ui.model.CCActionTableModelInterface;
93 import com.sun.web.ui.model.CCPropertySheetModelInterface;
94 import com.sun.web.ui.taglib.html.CCDropDownMenuTag;
95 import com.sun.web.ui.taglib.pagetitle.CCPageTitleTag;
96 import com.sun.web.ui.view.html.CCButton;
97 import com.sun.web.ui.view.html.CCCheckBox;
98 import com.sun.web.ui.view.html.CCTextField;
99 import com.sun.web.ui.view.html.CCOption;
100 import com.sun.web.ui.view.html.CCOptionGroup;
101 import com.sun.web.ui.view.html.CCOptionSeparator;
102 import com.sun.web.ui.view.propertysheet.CCPropertySheet;
103 import com.sun.web.ui.view.tabs.CCTabs;
104
105 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
106 import com.sun.enterprise.tools.admingui.util.Util;
107 import com.sun.enterprise.tools.admingui.ConfigProperties;
108 import com.iplanet.jato.view.CommandFieldBase;
109
110 /**
111  *
112  */

113 public class CommonHandlers {
114
115     public void invokeMBean(RequestContext ctx, HandlerContext handlerCtx) {
116     View view = handlerCtx.getView();
117         
118         Object JavaDoc objectName = handlerCtx.getInputValue("objectName");
119         if (objectName == null) {
120             throw new FrameworkException("'objectName' is null in CommonHandlers.invokeMBean");
121     }
122         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
123         if (methodName == null) {
124             throw new FrameworkException("'methodName' is null in CommonHandlers.invokeMBean");
125     }
126         ArrayList JavaDoc types = (ArrayList JavaDoc)handlerCtx.getInputValue("types");
127         ArrayList JavaDoc params = (ArrayList JavaDoc)handlerCtx.getInputValue("params");
128         
129         
130         Object JavaDoc[] paramsAndTypes = MBeanUtil.getParamsAndTypes(params, types);
131
132         Object JavaDoc returnValue = null;
133         try {
134 // System.out.println("=====MBeanUtil.invoked.=====");
135
// System.out.println("objectName="+objectName.toString());
136
// System.out.println("methodName="+ methodName);
137
// if (params != null){
138
// System.out.println("params :: " + params.size() );
139
// for(int i=0; i< params.size(); i++){
140
// System.out.println( params.get(i));
141
// }
142
// }
143
// if (types != null){
144
// System.out.println("types :: " + types.size());
145
// for(int i=0; i< types.size(); i++){
146
// System.out.println( types.get(i));
147
// }
148
// }
149
returnValue = MBeanUtil.invoke(objectName.toString(), methodName,
150                     (Object JavaDoc[])(paramsAndTypes[0]), (String JavaDoc[])(paramsAndTypes[1]));
151             
152         } catch (Exception JavaDoc ex) {
153              if (ex.getCause().getCause() instanceof javax.management.InstanceNotFoundException JavaDoc) {
154                 // ignore, just return null;
155
// important for the monitoring code; don't know if monitor MBean is there or not
156
if (Util.isLoggableFINE()) {
157                     Util.logFINE("caught: InstanceNotFoundException");
158                 }
159             } else {
160                 while (!(view instanceof DescriptorContainerView) &&
161             (view != null)) {
162                     view = view.getParent();
163                 }
164                 ViewDescriptor vd = (view != null) ?
165                     ((DescriptorContainerView)view).getViewDescriptor(): null;
166                 //System.out.println("=====MBeanUtil.invoke failed.=====");
167
//System.out.println("objectName="+objectName.toString());
168
//System.out.println("methodName="+ methodName);
169
throw new FrameworkException(ex, vd, view);
170             }
171         }
172         handlerCtx.setOutputValue(VALUE, returnValue);
173         handlerCtx.setOutputValue("hasValue", new Boolean JavaDoc(returnValue != null).toString());
174         //System.out.println("hasValue="+ new Boolean(returnValue != null).toString() );
175
}
176     
177     public void getMBeanAttribute(RequestContext ctx, HandlerContext handlerCtx) {
178         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
179         if (objectName == null) {
180             throw new FrameworkException("'objectName' is null in CommonHandlers.getMBeanAttribute");
181     }
182         String JavaDoc attributeName = (String JavaDoc)handlerCtx.getInputValue("attributeName");
183         if (attributeName == null) {
184             throw new FrameworkException("'attributeName' is null in CommonHandlers.getMBeanAttribute");
185     }
186         Object JavaDoc value = null;
187         try {
188             value = MBeanUtil.getAttribute(objectName, attributeName);
189         } catch (Exception JavaDoc ex) {
190             throw new FrameworkException("Error in CommonHandlers.getMBeanAttribute: ", ex);
191         }
192         handlerCtx.setOutputValue(VALUE, value);
193     }
194     
195     // called to set the hidden variable in the tree view.
196
public void getCurrentPageName(RequestContext ctx, HandlerContext handlerCtx) {
197         handlerCtx.setOutputValue(VALUE, Util.getCurrentViewURL(ctx));
198     }
199     
200     private boolean firstObjectSet = false;
201     
202     private boolean addOption(String JavaDoc objectName, OptionList optionList,
203             CCOptionGroup optionGroup, HandlerContext ctx) {
204         boolean itemsAdded = false;
205         try {
206             // check to see if there will be anything to display...
207
//System.out.println("calling........ "+objectName+":getStatistics");
208
Object JavaDoc [] stats = (Object JavaDoc []) MBeanUtil.invoke(
209                 objectName, "getStatistics", null, null);
210             //System.out.println("called ........ "+objectName+":getStatistics "+stats.length);
211
if (stats == null || stats.length == 0)
212                 return itemsAdded; //nothing to add
213
} catch (Exception JavaDoc ex) {
214             //System.out.println("exception: "+ex.getMessage());
215
return itemsAdded;
216         }
217         // return the first object in the drop-down menu list.
218
if (firstObjectSet == false) {
219             firstObjectSet = true;
220             ctx.setOutputValue("objectName", objectName);
221         }
222
223         // add name and objectName to the drop-down menu list.
224
//System.out.println("calling..... "+objectName+":getName");
225
String JavaDoc name = (String JavaDoc) MBeanUtil.invoke(
226             objectName, "getName", null, null);
227         //System.out.println("called ..... "+objectName+":getName: "+name);
228
if (optionGroup != null) {
229             optionGroup.add(new CCOption(name, objectName));
230             itemsAdded = true;
231             //System.out.println("...... adding to OptGr: "+name);
232
} else {
233             optionList.add(new CCOption(name, objectName));
234             //itemsAdded = true;
235
//System.out.println("...... adding to OptList: "+name);
236
}
237         return itemsAdded;
238     }
239     
240     private boolean fillMenuOptions(String JavaDoc objectName, OptionList optionList,
241             CCOptionGroup optionGroup, Stack JavaDoc ogStack, boolean doGrouping,
242             HandlerContext ctx) {
243         boolean itemsAdded = false;
244         
245         ObjectName JavaDoc[] childObjects = null;
246         try {
247             //System.out.println("calling..... "+objectName+":getChildren");
248
childObjects = (ObjectName JavaDoc[])MBeanUtil.invoke(
249                 objectName, "getChildren", null, null);
250             //System.out.println("called. .... "+objectName+":getChildren "+childObjects.length);
251
} catch (Exception JavaDoc ex) {
252             //System.out.println("exception: "+ex.getMessage());
253
//return false;
254
}
255         if (childObjects != null && childObjects.length > 0) {
256             CCOptionGroup og = optionGroup;
257             if (doGrouping) {
258                 String JavaDoc name = (String JavaDoc) MBeanUtil.invoke(
259                     objectName, "getName", null, null);
260                 og = new CCOptionGroup(name, name);
261                 //System.out.println(" starting new opt gr: "+name);
262
}
263             // add the options of this node
264
itemsAdded = addOption(objectName, optionList, og, ctx);
265             // add options for any child nodes
266
for (int i=0; i<childObjects.length; i++) {
267                 //System.out.println("ChildObject: "+i+" "+childObjects[i]);
268
if (childObjects[i] != null) {
269                     itemsAdded |= fillMenuOptions(childObjects[i].toString(),
270                         optionList, og, ogStack, doGrouping, ctx);
271                 }
272             }
273             if (itemsAdded && doGrouping) {
274                 // add the option group to the option list if anything was added
275
//System.out.println(" ... adding gr to list.");
276
ogStack.push(og); // add it after the parent.
277
//optionList.add(og);
278
return false;
279             }
280         } else {
281             // just add an option of this objectName, if it has statistics.
282
itemsAdded = addOption(objectName, optionList, optionGroup, ctx);
283         }
284         return itemsAdded;
285     }
286     
287     public void populateMonitorDropDown(RequestContext ctx, HandlerContext handlerCtx) {
288         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
289
SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
290         
291         ArrayList JavaDoc objs = (ArrayList JavaDoc) handlerCtx.getInputValue("monitorObjects");
292         Boolean JavaDoc doGrouping = (Boolean JavaDoc) handlerCtx.getInputValue("doGrouping");
293         OptionList optionList = new OptionList();
294         Stack JavaDoc optGroupStack = new Stack JavaDoc();
295         firstObjectSet = false;
296         boolean itemsAdded = false;
297
298         for ( int i=0; i<objs.size(); i++) {
299             String JavaDoc objectName = (String JavaDoc)objs.get(i);
300             if (objectName == null)
301                 continue;
302             if (itemsAdded)
303                 optionList.add(new CCOptionSeparator());
304             itemsAdded = fillMenuOptions(objectName, optionList, null,
305                 optGroupStack, doGrouping.booleanValue(), handlerCtx);
306             while (optGroupStack.empty() == false) {
307                 optionList.add((CCOptionGroup)optGroupStack.pop());
308             }
309         }
310         dropDownChild.setOptions(optionList);
311     }
312     
313     public void populateMonitorAppsDropDown(RequestContext ctx, HandlerContext handlerCtx) {
314         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
315
SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
316         
317         String JavaDoc appsObject = (String JavaDoc) handlerCtx.getInputValue("appsObjectName");
318         ObjectName JavaDoc[] objs = null;
319         try {
320             objs = (ObjectName JavaDoc[])MBeanUtil.invoke(
321                 appsObject, "getChildren", null, null);
322         } catch (Exception JavaDoc ex) {
323             // ignore
324
}
325         OptionList optionList = new OptionList();
326         optionList.add(new CCOption("",""));
327         if (objs != null) {
328             for ( int i=0; i<objs.length; i++) {
329                 String JavaDoc name = null;
330                 try {
331                     //System.out.println("calling........... "+objs[i]+":getName");
332
name = (String JavaDoc) MBeanUtil.invoke(objs[i], "getName", null, null);
333                 } catch (Exception JavaDoc ex) {
334                     continue; // if can't get the name, skip it.
335
}
336                 optionList.add(new CCOption(name, objs[i].toString()));
337             }
338         }
339         dropDownChild.setOptions(optionList);
340     }
341     
342     public void populateNodeAgentsDropDown(RequestContext ctx, HandlerContext handlerCtx) {
343         SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
344         // get the parent container of the dropdown
345
DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent();
346         
347         // need the child descriptor to get a parameter, retrieve from the parent descriptor.
348
ViewDescriptor vd = parent.getViewDescriptor();
349         ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName());
350         
351     String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("dropDownMethodName");
352     String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("dropDownObjectName");
353     ArrayList JavaDoc params = (ArrayList JavaDoc)handlerCtx.getInputValue("params");
354     ArrayList JavaDoc types = (ArrayList JavaDoc)handlerCtx.getInputValue("types");
355         
356     if (objectName == null || methodName == null) {
357         throw new FrameworkException("objectName or methodName is null",
358                 cvd, handlerCtx.getView());
359     }
360     try {
361             Object JavaDoc[] objs = getNodeAgentsAsDropDown(methodName,objectName, params, types);
362             String JavaDoc[]naNames = (String JavaDoc[]) objs[0];
363             String JavaDoc[]naNamesWithHosts = (String JavaDoc[]) objs[1];
364             OptionList optionList = new OptionList(naNamesWithHosts, naNames);
365             dropDownChild.setOptions(optionList);
366         } catch (Exception JavaDoc ex) {
367         throw new FrameworkException(ex, cvd, handlerCtx.getView());
368     }
369         
370    }
371     
372     public void getNodeAgentsWithHosts(RequestContext ctx, HandlerContext handlerCtx) {
373         
374     String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
375     String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
376     ArrayList JavaDoc params = (ArrayList JavaDoc)handlerCtx.getInputValue("params");
377     ArrayList JavaDoc types = (ArrayList JavaDoc)handlerCtx.getInputValue("types");
378         
379     if (objectName == null || methodName == null) {
380         throw new FrameworkException("objectName or methodName is null", null, handlerCtx.getView());
381     }
382     try {
383             Object JavaDoc[] objs = getNodeAgentsAsDropDown(methodName,objectName, params, types);
384             handlerCtx.setOutputValue("naNames", objs[0]);
385             handlerCtx.setOutputValue("naNamesWithHosts", objs[1]);
386         }catch (Exception JavaDoc ex){
387         throw new FrameworkException(ex, null, handlerCtx.getView());
388     }
389    }
390     
391     public void addWebAppsFromEntApps(RequestContext ctx, HandlerContext handlerCtx) {
392         // Extract the web modules from the enterprise apps and add them to the
393
// menu options.
394
SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
395         OptionList options = dropDownChild.getOptions();
396         
397     try {
398             ObjectName JavaDoc[] objectNames = (ObjectName JavaDoc[])MBeanUtil.invoke(
399                 "com.sun.appserv:type=applications,category=config",
400                 "getAllDeployedJ2EEApplications",
401                 null, null);
402             
403             for (int i = 0; i < objectNames.length; i++) {
404                 //System.out.print(">>> objectNames[i]: " + objectNames[i]);
405
String JavaDoc appName = objectNames[i].getKeyProperty("name");
406                 
407                 String JavaDoc[] modules = (String JavaDoc[])MBeanUtil.invoke(
408                     "com.sun.appserv:type=applications,category=config",
409                     "getModuleComponents",
410                     new Object JavaDoc[]{appName},
411                     new String JavaDoc[]{"java.lang.String"});
412                     
413         for (int j = 0; j < modules.length; j++) {
414                     //System.out.println(">>> modules[j]: " + modules[j]);
415
ObjectName JavaDoc moduleName = new ObjectName JavaDoc(modules[j]);
416             
417             String JavaDoc type = moduleName.getKeyProperty("j2eeType");
418                     if (type != null && type.equalsIgnoreCase("WebModule")) {
419                         String JavaDoc name = moduleName.getKeyProperty("name");
420                         String JavaDoc entry = appName+"#"+name;
421                         options.add(entry, entry);
422                     }
423         }
424             }
425     } catch (Exception JavaDoc ex) {
426             if (Util.isLoggableFINE()) {
427                 Util.logFINE(ex);
428             }
429         }
430     }
431     
432     // Framework callback method to dynamically fill in choices of a dropdown menu.
433
public void populateDropDown(RequestContext ctx, HandlerContext handlerCtx) {
434          
435         SelectableGroup dropDownChild = (SelectableGroup) getSelectableGroup(handlerCtx);
436         populateDropDown(handlerCtx, dropDownChild);
437         String JavaDoc initialValue = (String JavaDoc)handlerCtx.getInputValue("initialValue");
438         if (initialValue == null || initialValue.length() == 0) {
439             dropDownChild.setLabelForNoneSelected(" ");
440     } else {
441         // Don't override what the user has already chosen -- CR#:6174991
442
if (dropDownChild.getValue() == null) {
443         dropDownChild.setValue(initialValue);
444         }
445     }
446     }
447     
448     private SelectableGroup getSelectableGroup(HandlerContext handlerCtx){
449         Object JavaDoc displayField = handlerCtx.getInputValue("displayField");
450         if (displayField == null)
451             displayField = handlerCtx.getView();
452         
453         if (! (displayField instanceof SelectableGroup)){
454              throw new FrameworkException("No displayField specified and current view is NOT a dropdown in populateDropDown");
455         }
456         return (SelectableGroup) displayField;
457     }
458     
459     private void populateDropDown(HandlerContext handlerCtx, SelectableGroup dropDownChild){
460         
461         // get the parent container of the dropdown
462
DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent();
463         // need the child descriptor to get a parameter, retrieve from the parent descriptor.
464
ViewDescriptor vd = parent.getViewDescriptor();
465         ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName());
466         
467         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("dropDownMethodName");
468     String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("dropDownObjectName");
469     String JavaDoc attributeName = (String JavaDoc)handlerCtx.getInputValue("dropDownAttributeName");
470     ArrayList JavaDoc params = (ArrayList JavaDoc)handlerCtx.getInputValue("params");
471     ArrayList JavaDoc types = (ArrayList JavaDoc)handlerCtx.getInputValue("types");
472     
473         
474     if (objectName == null || methodName == null) {
475         throw new FrameworkException("dropDownObjectName or dropDownMethodName is null in populateDropDown");
476     }
477
478         Object JavaDoc[] paramsAndTypes = MBeanUtil.getParamsAndTypes(params, types);
479         // and finally fill in the menu choices.
480
try {
481             Object JavaDoc returnValue = MBeanUtil.invoke(objectName, methodName,
482                 (Object JavaDoc[])(paramsAndTypes[0]), (String JavaDoc[])(paramsAndTypes[1]));
483             if (returnValue == null)
484                 return;
485             String JavaDoc [] choices = null;
486             if (returnValue instanceof ObjectName JavaDoc[]) {
487                 ObjectName JavaDoc[] objectNameList = (ObjectName JavaDoc[])returnValue;
488                 choices = new String JavaDoc[objectNameList.length];
489                 if (attributeName == null)
490                     attributeName = "name";
491                 for(int i =0; i < choices.length; i++) {
492                     String JavaDoc dropDownChoice = (String JavaDoc)
493                         MBeanUtil.getAttribute(objectNameList[i], attributeName);
494                     choices[i] = dropDownChoice;
495                 }
496             }
497             else if (returnValue instanceof String JavaDoc[]) {
498                 choices = (String JavaDoc[])returnValue;
499             }
500         
501         OptionList dropDownMenuOptions = new OptionList(choices,choices); // label and values
502
dropDownChild.setOptions(dropDownMenuOptions);
503     } catch (Exception JavaDoc ex) {
504         throw new FrameworkException(ex, cvd, handlerCtx.getView());
505     }
506         
507     }
508     
509     public void populateResourceAdapter(RequestContext ctx, HandlerContext handlerCtx) {
510         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
511
SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
512         // get the parent container of the dropdown
513
DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent();
514         
515         // need the child descriptor to get a parameter, retrieve from the parent descriptor.
516
ViewDescriptor vd = parent.getViewDescriptor();
517         ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName());
518         
519         dropDownChild.setLabelForNoneSelected(" ");
520     try {
521             ObjectName JavaDoc[] dropDownObjectName = (ObjectName JavaDoc[]) MBeanUtil.invoke(
522                 "com.sun.appserv:type=applications,category=config",
523                 "getAllDeployedConnectors", null, null);
524             /*
525              * we use getSystemConnectorsAllowingPoolCreation() as it doesn't expose __ds, __cp, __xa.
526              *
527             String[] systemConnectors =
528                 (String[]) MBeanUtil.invoke("com.sun.appserv:type=applications,category=config",
529                 "getAllSystemConnectors", null, null);
530              */

531             
532             String JavaDoc[] systemConnectors =
533                 (String JavaDoc[]) MBeanUtil.invoke("com.sun.appserv:type=resources,category=config",
534                 "getSystemConnectorsAllowingPoolCreation", null, null);
535             
536             //We can remove the catch after backend implemented the method.
537
String JavaDoc[] embeddedConnectors = null;
538             try {
539                 String JavaDoc[] types = new String JavaDoc[]{"java.lang.String", "java.lang.String"};
540                 Object JavaDoc[] params = new Object JavaDoc[]{null, "domain" };
541                 embeddedConnectors = (String JavaDoc[]) MBeanUtil.invoke(
542                     "com.sun.appserv:type=applications,category=config",
543                     "getEmbeddedConnectorNames", params, types);
544             }catch(Exception JavaDoc ex){
545                 Util.logINFO("Exception when calling getEmbeddedConnectorNames");
546                 ex.printStackTrace();
547             }
548
549             /* API used in 7.0
550             ObjectName[] dropDownObjectName = (ObjectName[]) MBeanUtil.invoke("com.sun.appserv:type=applications,category=config",
551                "getAllDeployedConnectors", null, null);
552             
553              String[] systemConnectors =
554                 (String[]) MBeanUtil.invoke("com.sun.appserv:type=resources,category=config",
555                 "getSystemConnectorsAllowingPoolCreation", null, null);
556              */

557             
558             int numAdapters =
559                 (dropDownObjectName==null?0:dropDownObjectName.length) +
560                 (embeddedConnectors==null?0:embeddedConnectors.length) +
561                 (systemConnectors==null?0:systemConnectors.length);
562                 
563         String JavaDoc [] choices = new String JavaDoc[numAdapters];
564             int i = 0;
565         if(dropDownObjectName != null) {
566         for(;i < dropDownObjectName.length; i++) {
567             //hardcoding the name for now, may be we should get this from the xml file.
568
String JavaDoc dropDownChoice = (String JavaDoc)
569                         MBeanUtil.getAttribute(dropDownObjectName[i], "name");
570             choices[i] = dropDownChoice;
571                     //System.out.println("dropDownObjectName=" +dropDownObjectName[i].toString() + " name=" + dropDownChoice);
572
}
573         }
574         if (embeddedConnectors != null) {
575         for(int j = 0; j < embeddedConnectors.length; j++, i++) {
576             choices[i] = embeddedConnectors[j];
577                     //System.out.println("embeddedConnectors= "+ embeddedConnectors[j]);
578
}
579             }
580             if (systemConnectors != null) {
581         for(int j = 0; j < systemConnectors.length; j++, i++) {
582             choices[i] = systemConnectors[j];
583                     //System.out.println("systemConnectors= "+ systemConnectors[j]);
584
}
585             }
586         OptionList dropDownMenuOptions = new OptionList(choices,choices); // label and values
587
dropDownChild.setOptions(dropDownMenuOptions);
588     } catch (Exception JavaDoc ex) {
589         throw new FrameworkException(ex, cvd, handlerCtx.getView());
590     }
591     }
592     
593     //This method will populate with the ALL (started,stopped) server instance, including those in cluster.
594
//unless onlyRunningServer is set to true;
595
public void populateServerInstances(RequestContext ctx, HandlerContext handlerCtx) {
596         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
597
SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
598         // get the parent container of the dropdown
599
DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent();
600         
601         // need the child descriptor to get a parameter, retrieve from the parent descriptor.
602
ViewDescriptor vd = parent.getViewDescriptor();
603         ViewDescriptor cvd = vd.getChildDescriptor(dropDownChild.getName());
604         boolean isEE = ConfigProperties.getInstance().getTargetSupported().booleanValue();
605         Boolean JavaDoc onlyRunningServer = (Boolean JavaDoc) handlerCtx.getInputValue("onlyRunningServer");
606     try {
607             ArrayList JavaDoc results = new ArrayList JavaDoc();
608             if (isEE){
609                 results.add("");
610                 results.add("server");
611                 Object JavaDoc unclustered = MBeanUtil.invoke("com.sun.appserv:type=servers,category=config",
612                 "listUnclusteredServerInstances", null, null);
613                 addToString(results, unclustered, onlyRunningServer);
614                 ObjectName JavaDoc[] clusters =
615                 (ObjectName JavaDoc[]) MBeanUtil.invoke("com.sun.appserv:type=clusters,category=config",
616                 "getCluster", null, null);
617                 if (clusters != null){
618                     for(int i=0; i< clusters.length; i++){
619                         String JavaDoc clusterName = (String JavaDoc)MBeanUtil.getAttribute(clusters[i], "name");
620                         String JavaDoc objectName= "com.sun.appserv:type=cluster,name=" +
621                             clusterName + ",category=config";
622                         Object JavaDoc clustered = MBeanUtil.invoke(objectName,
623                             "listServerInstances", null,null);
624                         addToString(results, clustered, onlyRunningServer);
625                     }
626                 }
627             }else{
628                 results.add("server");
629             }
630         
631             String JavaDoc[] choices = new String JavaDoc[results.size()];
632             for(int i=0; i< results.size(); i++){
633                 choices[i] = (String JavaDoc) results.get(i);
634             }
635             
636         OptionList dropDownMenuOptions = new OptionList(choices,choices); // label and values
637
dropDownChild.setOptions(dropDownMenuOptions);
638     } catch (Exception JavaDoc ex) {
639         throw new FrameworkException(ex, cvd, handlerCtx.getView());
640     }
641     }
642     
643     
644      public void setDropDownOptions(RequestContext ctx, HandlerContext handlerCtx) {
645         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
646
SelectableGroup dropDownChild = (SelectableGroup)handlerCtx.getInputValue(DISPLAY_FIELD);
647         Object JavaDoc names = handlerCtx.getInputValue("names");
648         Object JavaDoc labels = handlerCtx.getInputValue("labels");
649         if (names instanceof String JavaDoc[]){
650             OptionList dropDownMenuOptions = new OptionList((String JavaDoc[]) labels,(String JavaDoc[]) names); // label and values
651
dropDownChild.setOptions(dropDownMenuOptions);
652         }else
653         if (names instanceof ArrayList JavaDoc){
654             ArrayList JavaDoc nm = (ArrayList JavaDoc)names;
655             ArrayList JavaDoc lb = (ArrayList JavaDoc)labels;
656             
657             OptionList dropDownMenuOptions = new OptionList(
658                     (String JavaDoc[]) nm.toArray(new String JavaDoc[ nm.size()]),
659                     (String JavaDoc[]) lb.toArray(new String JavaDoc[lb.size()]));
660             
661             dropDownChild.setOptions(dropDownMenuOptions);
662         }else{
663             throw new FrameworkException("setDropDownOptions() expects String[] or ArrayList for parameter names and labels");
664         }
665      }
666      
667      
668      /*
669       * Populate a selectable list, with multiple selections, the selected value
670       * will either be the initialValue or obtained by getting the attribute of the
671       * object.
672       */

673      public void populateList(RequestContext ctx, HandlerContext handlerCtx) {
674          
675          //Fill the selected list first
676
SelectableGroup dropDownChild = (SelectableGroup) getSelectableGroup(handlerCtx);
677          populateDropDown(handlerCtx, dropDownChild);
678          //initialValue should be a comma seperated list
679
String JavaDoc initialValue = (String JavaDoc)handlerCtx.getInputValue("initialValue");
680          dropDownChild.setLabelForNoneSelected(" ");
681          if (initialValue == null){
682             String JavaDoc attributeName = (String JavaDoc)handlerCtx.getInputValue("selectAttribute");
683             String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("selectObjectName");
684             initialValue = (String JavaDoc) MBeanUtil.getAttribute(objectName, attributeName);
685          }
686          
687          if (initialValue != null){
688              String JavaDoc[] eachRow = initialValue.split(",");
689              if (eachRow != null & eachRow.length > 0){
690                  dropDownChild.setValues(eachRow);
691              }
692     }
693      }
694      
695      public void setDropDownOptionsAndDefaultValue(RequestContext ctx, HandlerContext handlerCtx) {
696         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
697
SelectableGroup dropDownChild = (SelectableGroup)handlerCtx.getInputValue(DISPLAY_FIELD);
698         String JavaDoc[] names = (String JavaDoc[]) handlerCtx.getInputValue("names");
699         String JavaDoc[] labels = (String JavaDoc[]) handlerCtx.getInputValue("labels");
700         OptionList dropDownMenuOptions = new OptionList(labels,names); // label and values
701
dropDownChild.setOptions(dropDownMenuOptions);
702         if( (names!=null) && names.length > 0)
703             dropDownChild.setValue(names[0]);
704      }
705      
706      public void isInArray(RequestContext ctx, HandlerContext handlerCtx) {
707         String JavaDoc s = (String JavaDoc)handlerCtx.getInputValue("string");
708         String JavaDoc[] array = (String JavaDoc[]) handlerCtx.getInputValue("array");
709         Boolean JavaDoc isInArray = Boolean.FALSE;
710             for (int i=0; i< array.length; i++) {
711                 if (s.equals(array[i])) {
712                     isInArray = Boolean.TRUE;
713                     break;
714                 }
715             }
716         handlerCtx.setOutputValue("isInArray", isInArray);
717      }
718     
719     private void addToString(ArrayList JavaDoc result, Object JavaDoc obj, Boolean JavaDoc onlyRunningServer)
720     {
721         boolean includeAll = true;
722         if (obj == null)
723             return;
724         if ((onlyRunningServer != null) && onlyRunningServer.booleanValue())
725             includeAll = false;
726         if (obj instanceof String JavaDoc[]){
727             String JavaDoc[] ss = (String JavaDoc[]) obj;
728             for(int i=0; i< ss.length; i++){
729                 if (includeAll)
730                     result.add(ss[i]);
731                 else{
732                     if (LogViewerHandler.isServerRunning(ss[i]))
733                         result.add(ss[i]);
734                 }
735             }
736         }else
737         if (obj instanceof ObjectName JavaDoc[]){
738             ObjectName JavaDoc[] oo = (ObjectName JavaDoc[])obj;
739             for(int i =0; i < oo.length; i++) {
740                 String JavaDoc nm = (String JavaDoc)MBeanUtil.getAttribute(oo[i], "name");
741                 if (includeAll)
742                     result.add(nm);
743                 else{
744                     if (LogViewerHandler.isServerRunning(nm))
745                         result.add(nm);
746                 }
747             }
748         }
749     }
750         
751
752     /**
753      * This method logs the user out of the admingui. This is accomplished
754      * by invalidating the user's session, marking the response started, and
755      * forwarding (via the RequestDispatcher) to the next page. The
756      * RequestDispatcher is used b/c, we cannot forward the standard way
757      * after invalidating the session. The markResponseStarted() method is
758      * necessary because we can't foward the standard way.
759      */

760     public void logout(RequestContext ctx, HandlerContext handlerCtx) {
761         ctx.getRequest().getSession().removeAttribute("AdminGUItimeOut");
762     ctx.getRequest().getSession().invalidate();
763     RequestContextImpl.markResponseStarted(ctx);
764     try {
765         ctx.getServletContext().getRequestDispatcher(ENTRY_URI).
766         forward(ctx.getRequest(), ctx.getResponse());
767     } catch (ServletException JavaDoc ex) {
768         throw new FrameworkException(ex, null, handlerCtx.getView());
769     } catch (IOException JavaDoc ex) {
770         throw new FrameworkException(ex, null, handlerCtx.getView());
771     }
772     }
773
774     public void handleTabHrefRequest(RequestContext ctx, HandlerContext handlerCtx) {
775     View view = handlerCtx.getView();
776         View tabset = view.getParent(); // the view is the href
777
ViewBean vb = (ViewBean)tabset.getParent();
778         
779         try {
780             DescriptorCCTabs tabs = (DescriptorCCTabs)vb.getChild(tabset.getName());
781             
782             // make a new event type
783
ViewCommandEvent ev = (ViewCommandEvent)handlerCtx.getEvent();
784             RequestInvocationEvent reqEvent =
785                 new ViewRequestInvocationEvent(ev.getSource(), ctx,
786            ev.getInvocation());
787             tabs.handleTabHrefRequest(reqEvent);
788         } catch (Exception JavaDoc ex) {
789         throw new FrameworkException(ex, null, view);
790         }
791     }
792     
793     
794     public void beginDropDownDisplay(RequestContext ctx, HandlerContext handlerCtx) {
795         CCDropDownMenuTag tag = (CCDropDownMenuTag)handlerCtx.getEvent().getSource();
796         tag.setOnChange("javascript: loadRightSide();");
797     }
798     
799     static public void setTimeOut(RequestContext rc) {
800         // called by the AdminGUIServlet
801
String JavaDoc timeOut = null;
802         try {
803             timeOut = (String JavaDoc)MBeanUtil.getAttribute(
804                 "ias:type=das-config,config=server-config,category=config",
805                 "admin-session-timeout-in-minutes");
806         } catch (Exception JavaDoc ex) {
807         throw new FrameworkException(
808         "Exception throw in trying to get '"+
809         "admin_session_timeout_in_minutes'", ex);
810         }
811         if ((timeOut != null) && !timeOut.equals("")) {
812             try {
813                 int time = new Integer JavaDoc(timeOut).intValue();
814                 HttpServletRequest JavaDoc req = rc.getRequest();
815                 if (time == 0) {
816                     req.getSession().setMaxInactiveInterval(-1);
817         } else {
818                     req.getSession().setMaxInactiveInterval(time*60);
819         }
820         if (Util.isLoggableFINE()) {
821             Util.logFINE("Setting session time out to "+timeOut+" minutes.");
822         }
823             } catch (NumberFormatException JavaDoc ex) {
824         throw new FrameworkException(
825             "Unable to convert '"+timeOut+"'!", ex);
826             }
827         }
828     }
829
830
831     /**
832      *
833      */

834     public void showTimeOut(RequestContext ctx, HandlerContext handlerCtx) throws Exception JavaDoc {
835     View view = handlerCtx.getView();
836         String JavaDoc timeOut = (String JavaDoc)((CCTextField)view).getValue();
837         if (timeOut == null || timeOut.equals("")) {
838             HttpServletRequest JavaDoc req = ctx.getRequest();
839             int time = req.getSession().getMaxInactiveInterval();
840             if (time <= 0)
841                 ((CCTextField)view).setValue("0");
842             else
843                 ((CCTextField)view).setValue(""+(time/60));
844         }
845     }
846
847     public void setFullTableName(RequestContext ctx, HandlerContext handlerCtx) {
848     View view = handlerCtx.getView();
849     DescriptorContainerView descView = (DescriptorContainerView)
850         (((ViewBase)view).getParentViewBean());
851     //ViewDescriptor vd = descView.getViewDescriptor();
852

853     String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue("propertiesTableName");
854         if (childName == null || childName.length() == 0) {
855         return;
856     }
857         childName = descView.getName() + "." + childName;
858         ((DisplayField)view).setValue(childName);
859     }
860
861     public void addValueToPropertiesList(RequestContext ctx, HandlerContext handlerCtx) {
862     Map JavaDoc props = (Map JavaDoc)handlerCtx.getInputValue("Properties");
863         if (props == null || props.size() == 0) {
864         return;
865     }
866     String JavaDoc value = (String JavaDoc)handlerCtx.getInputValue("propertyValue");
867     String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("propertyName");
868     props.put(key, value);
869     handlerCtx.setOutputValue(VALUE, props);
870     handlerCtx.setOutputValue("props", new Properties JavaDoc());
871     }
872
873     public void getXMLFileFromClasspath(RequestContext ctx, HandlerContext handlerCtx) {
874     String JavaDoc fileName = (String JavaDoc)handlerCtx.getInputValue("fileName");
875         if (fileName == null || fileName.length() == 0) {
876         return;
877     }
878     InputStream JavaDoc is = getClass().getClassLoader().getResourceAsStream(fileName);
879     handlerCtx.setOutputValue(VALUE, is);
880     }
881     
882     /**
883      *
884      */

885     public void deleteChildView(RequestContext ctx, HandlerContext handlerCtx) {
886         // Get the ServletRequest
887
ServletRequest JavaDoc req = ctx.getRequest();
888
889     // Get the parameters
890
ContainerViewBase base = (ContainerViewBase)handlerCtx.getInputValue("container");
891     String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue("child");
892     if ((base == null) || (childName == null)) {
893         throw new FrameworkException(
894         "'view' and/or 'child' attributes were null!", null, handlerCtx.getView());
895     }
896     boolean clearModel =
897         new Boolean JavaDoc(""+handlerCtx.getInputValue("clearModel")).booleanValue();
898
899     // Optionally clear the Model
900
if (clearModel) {
901         Model model = (Model)handlerCtx.getInputValue("model");
902         if (model == null) {
903         View child = base.getChild(childName);
904         if (child instanceof ContainerView) {
905             model = ((ContainerView)child).getDefaultModel();
906         } else if (child instanceof DisplayFieldImpl) {
907             model = ((DisplayFieldImpl)child).getModel();
908         }
909         }
910         if ((model != null) && (model instanceof DefaultModel)) {
911         ((DefaultModel)model).clear();
912         }
913     }
914
915     base.removeChild(childName);
916     }
917
918
919
920     /**
921      * This method iterates over an array of Model names. For each model
922      * name, it clears the Model (in the case of DefaultModels) and checks
923      * to see if the model exists in Session. If it does exist in Session,
924      * it will be removed from session. This method expects MODEL_NAMES
925      * ("modelNames") to be a request Attribute specifying the Model names
926      * to remove.
927      */

928     public void clearModels(RequestContext ctx, HandlerContext handlerCtx) {
929     Object JavaDoc obj = handlerCtx.getInputValue(MODEL_NAMES);
930     if (obj == null) {
931         throw new FrameworkException(
932         "You must specifiy 'models' to remove from Session.");
933     }
934     if (obj instanceof String JavaDoc) {
935         ArrayList JavaDoc list = new ArrayList JavaDoc();
936         list.add(obj);
937         obj = list;
938     }
939     if (!(obj instanceof List JavaDoc)) {
940         throw new FrameworkException(
941         "'"+MODEL_NAMES+"' must be a java.util.List!");
942     }
943     String JavaDoc names[] =
944         (String JavaDoc [])((List JavaDoc)obj).toArray(new String JavaDoc[((List JavaDoc)obj).size()]);
945
946     // Check and remove each model as necessary.
947
HttpServletRequest JavaDoc req = ctx.getRequest();
948     HttpSession JavaDoc session = req.getSession();
949     ModelManager modelMgr = ctx.getModelManager();
950     Model model = null;
951     for (int count=0; count<names.length; count++) {
952         obj = session.getAttribute(names[count]);
953         if (obj != null) {
954         model = (Model)obj;
955         if (model instanceof DefaultModel) {
956             // First clear() the model b/c the model on the next
957
// page will still be in memory and needs to be reset.
958
((DefaultModel)model).clear();
959         }
960         modelMgr.removeFromSession(model);
961         }
962     }
963     }
964
965     
966     /**
967      *
968      */

969     public void dumpMBeanNames(RequestContext ctx, HandlerContext handlerCtx) {
970         try {
971             javax.management.MBeanServerConnection JavaDoc server = MBeanUtil.getMBeanServer();
972             java.util.Iterator JavaDoc it = server.queryNames(null, null).iterator();
973             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
974             buf.append(" MBean Object Names:\n");
975             buf.append("======================\n");
976             while (it.hasNext()) {
977                 buf.append(" * "+it.next().toString());
978             }
979             {
980                 Util.logCONFIG(buf.toString());
981             }
982         } catch (Exception JavaDoc ex) {
983             // ignore.
984
}
985     }
986
987     public void parseFilterOptions(RequestContext ctx, HandlerContext handlerCtx) {
988     View view = handlerCtx.getView();
989         
990         String JavaDoc value = (String JavaDoc)handlerCtx.getInputValue("value");
991         if (value != null) {
992             String JavaDoc[] values = value.split(";");
993             handlerCtx.setOutputValue("methodName", values[0]);
994             if (values.length > 1) {
995                 handlerCtx.setOutputValue("editPage", values[1]);
996             }
997             //System.out.println("values : " + values[0] + "," + values[1]);
998
}
999     }
1000
1001    /**
1002     * This method clears the ViewDescriptor cache so that changes in that
1003     * file can be re-read.
1004     */

1005    public void clearCache(RequestContext ctx, HandlerContext handlerCtx) {
1006    ViewDescriptorManager.getInstance().clearCache();
1007    }
1008
1009    public void dumpStack(RequestContext ctx, HandlerContext handlerCtx) {
1010        Thread.currentThread().dumpStack();
1011    }
1012     
1013    /**
1014     * This method dumps very detailed MBeanInfo about ALL Mbeans.
1015     */

1016    public void dumpMBeanInfo(RequestContext ctx, HandlerContext handlerCtx) {
1017    String JavaDoc output = null;
1018        try {
1019            javax.management.MBeanServerConnection JavaDoc server = MBeanUtil.getMBeanServer();
1020            java.util.Iterator JavaDoc it = server.queryNames(null, null).iterator();
1021            StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
1022            buf.append("\n MBean Object Info:");
1023            buf.append("================================");
1024            ObjectName JavaDoc name;
1025            javax.management.MBeanInfo JavaDoc info;
1026            javax.management.MBeanOperationInfo JavaDoc opInfo[];
1027            javax.management.MBeanParameterInfo JavaDoc paramInfo[];
1028            javax.management.MBeanAttributeInfo JavaDoc attInfo[];
1029            javax.management.MBeanNotificationInfo JavaDoc noteInfo[];
1030            while (it.hasNext()) {
1031                buf.append("----------------------------\n");
1032                name = (ObjectName JavaDoc)it.next();
1033                buf.append(" OBJECT NAME: "+name.toString()+"\n");
1034                try {
1035                    info = server.getMBeanInfo(name);
1036                } catch (Exception JavaDoc ex) {
1037                    throw new FrameworkException(
1038                        "Can't get the MBeanInfo!", ex, null, handlerCtx.getView());
1039                }
1040                buf.append(" CLASS NAME: "+info.getClassName()+"\n");
1041                buf.append(" DESCRIPTION: "+info.getDescription()+"\n");
1042                // Operations
1043
buf.append(" OPERATIONS:\n");
1044                opInfo = info.getOperations();
1045                for (int count=0; count<opInfo.length; count++) {
1046                    if (opInfo[count] == null) {
1047                        buf.append(" WARNING: opInfo["+count+"] is null!\n");
1048                        continue;
1049                    }
1050                    buf.append("\t* "+opInfo[count].getReturnType()+" "+opInfo[count].getName()+"(");
1051                    paramInfo = opInfo[count].getSignature();
1052                    for (int idx=0; idx<paramInfo.length; idx++) {
1053                        buf.append(paramInfo[idx].getType())
1054                            .append(" ")
1055                            .append(paramInfo[idx].getName())
1056                            .append(" - ")
1057                            .append(paramInfo[idx].getDescription());
1058                        if (idx<paramInfo.length-1) {
1059                            buf.append(", ");
1060                        }
1061                    }
1062                    buf.append(") - "+opInfo[count].getImpact()+"\n");
1063                    if (opInfo[count].getDescription() != null)
1064                        buf.append("\t Desc: "+opInfo[count].getDescription()+"\n\n");
1065                }
1066                // Attributes
1067
buf.append(" Attributes:\n");
1068                attInfo = info.getAttributes();
1069                for (int count=0; count<attInfo.length; count++) {
1070                    buf.append("\t* "+attInfo[count].getType()+" "+attInfo[count].getName());
1071                    if (attInfo[count].isIs()) {
1072                        buf.append(" - HAS 'is' GETTER");
1073                    }
1074                    if (!attInfo[count].isReadable()) {
1075                        buf.append(" - NOT READABLE");
1076                    }
1077                    if (!attInfo[count].isWritable()) {
1078                        buf.append(" - NOT WRITABLE");
1079                    }
1080                    if (attInfo[count].getDescription() != null)
1081                        buf.append("\n\t Desc: "+attInfo[count].getDescription()+"\n");
1082                }
1083                // Notifications
1084
noteInfo = info.getNotifications();
1085                if (noteInfo.length > 0) {
1086                    buf.append(" Notifications:\n");
1087                    for (int count=0; count<noteInfo.length; count++) {
1088                        buf.append("\t")
1089                            .append(noteInfo[count].getName())
1090                            .append(" - ")
1091                            .append(noteInfo[count].getDescription()+"\n");
1092                        String JavaDoc types[] = noteInfo[count].getNotifTypes();
1093                        buf.append("\t Notification Types: ");
1094                        for (int idx=0; idx<types.length; idx++) {
1095                            buf.append("\t\t"+types[idx]+"\n");
1096                        }
1097                        buf.append("\n");
1098                    }
1099                }
1100                buf.append("\n");
1101            }
1102            buf.append("======================\n");
1103        output = buf.toString();
1104            {
1105                Util.logCONFIG(output);
1106            }
1107        } catch (Exception JavaDoc ex) {
1108            // ignore
1109
}
1110    handlerCtx.setOutputValue(VALUE, output);
1111    }
1112
1113
1114    /**
1115     * This handler is designed for Error Handlers only. It checks the given
1116     * exception to see if any MBean exceptions are present. If one is, then
1117     * the message is pulled off and stored in request attribute
1118     * "MBEAN_MESSAGE". If one is not found, the lowest non-null message is
1119     * set in the "MBEAN_MESSAGE" attribute. "HAS_MBEAN_MESSAGE" is always
1120     * set to true, "ALERT_TYPE" is always set to "error", and "ALERT_SUMMARY"
1121     * is set to "alert.Summary".
1122     */

1123    public void mbeanExceptionCheck(RequestContext ctx, HandlerContext handlerCtx) {
1124    if (!(handlerCtx.getEvent() instanceof ErrorEvent)) {
1125        throw new FrameworkException(
1126        "This method is meant only for ErrorEvent types. This "+
1127        "handler will attempt to find a message from the "+
1128        "ErrorEvent's Exception", null, handlerCtx.getView());
1129    }
1130
1131    // Look for an MBeanException
1132
Throwable JavaDoc ex = ((ErrorEvent)handlerCtx.getEvent()).getException();
1133    if (ex == null) {
1134        throw new FrameworkException(
1135        "Exception is null, this is illegal!", null, handlerCtx.getView());
1136    }
1137    Throwable JavaDoc last = ex;
1138    String JavaDoc message = null;
1139    String JavaDoc val = ex.getLocalizedMessage();
1140    if (val == null) {
1141        val = ex.getMessage();
1142    }
1143    if (val != null) {
1144        message = val;
1145    }
1146    boolean foundMBean = false;
1147        boolean foundAMX = false;
1148    while (ex != null) {
1149        // Get the next exception
1150
if (ex instanceof RootCauseException) {
1151        ex = ((RootCauseException)ex).getRootCause();
1152        } else {
1153        if (ex instanceof MBeanException JavaDoc) {
1154            // Flag to stop as soon as we have a message
1155
foundMBean = true;
1156        } else if (ex instanceof UndeclaredThrowableException JavaDoc) {
1157                    foundAMX = true;
1158                }
1159                if (foundAMX) {
1160                    ex = ExceptionUtil.getRootCause(ex);
1161                } else {
1162                    ex = ex.getCause();
1163                }
1164        }
1165
1166        // Try to get the message
1167
if (ex != null) {
1168        last = ex;
1169        val = ex.getLocalizedMessage();
1170        if (val == null) {
1171            val = ex.getMessage();
1172        }
1173        if (val != null) {
1174            message = val;
1175            if ((ex instanceof MBeanException JavaDoc) || foundMBean || foundAMX) {
1176            break;
1177            }
1178        }
1179        }
1180    }
1181
1182    // Pull off the message as best we can
1183
ServletRequest JavaDoc req = ctx.getRequest();
1184    handlerCtx.setOutputValue(MBEAN_MESSAGE,
1185        (message == null) ? "error.NullMessage" : message);
1186    handlerCtx.setOutputValue(HAS_MBEAN_MESSAGE, TRUE);
1187    handlerCtx.setOutputValue(HAS_ERROR_MESSAGE, TRUE);
1188    handlerCtx.setOutputValue(ALERT_TYPE, "error");
1189    handlerCtx.setOutputValue(ALERT_SUMMARY, "alert.Summary");
1190    }
1191
1192
1193    /**
1194     * Exception Log Handler -- This handler logs an exception to the LogFile.
1195     */

1196    public void logException(RequestContext ctx, HandlerContext handlerCtx) {
1197    if (!Util.isLoggableINFO()) {
1198        return;
1199    }
1200    ServletRequest JavaDoc req = ctx.getRequest();
1201    Throwable JavaDoc ex = (Throwable JavaDoc)handlerCtx.getInputValue(EXCEPTION_TO_LOG);
1202    String JavaDoc level = (String JavaDoc)handlerCtx.getInputValue(LEVEL);
1203        if (level == null)
1204            level = "FINE";
1205    if (ex != null) {
1206            if (level.equalsIgnoreCase("FINEST"))
1207                Util.logFINEST(ex);
1208            else if (level.equalsIgnoreCase("FINER"))
1209                Util.logFINER(ex);
1210            else if (level.equalsIgnoreCase("FINE"))
1211                Util.logFINE(ex);
1212            else if (level.equalsIgnoreCase("CONFIG"))
1213                Util.logCONFIG(ex);
1214            else if (level.equalsIgnoreCase("INFO"))
1215                Util.logINFO(ex);
1216            else if (level.equalsIgnoreCase("WARNING"))
1217                Util.logWARNING(ex);
1218            else if (level.equalsIgnoreCase("SEVERE"))
1219                Util.logSEVERE(ex);
1220    } else {
1221        Util.logFINE(getClass().getName()+
1222        ".logException() called without an exception to log.");
1223    }
1224    }
1225
1226    /**
1227     * <P> This method determines if the input value X is greater than the
1228     * input value Y. Both input values are expected to be Integers,
1229     * the result will be stored in "result" and will be a Boolean.</P>
1230     *
1231     * <P> This method expects the following input parameters:</P>
1232     *
1233     * <UL><LI>X -- Long -- The integer X to evaluate
1234     * <LI>Y -- Long -- The integer Y to evaluate</LI></UL>
1235     *
1236     * <P> It returns the following output parameters:</P>
1237     *
1238     * <UL><LI>value -- Boolean -- Result of: X&gt;Y</LI></UL>
1239     *
1240     * @param ctx The RequestContext
1241     * @param handlerCtx The HandlerContext
1242     */

1243    public void isXGreaterThanY(RequestContext ctx, HandlerContext handlerCtx) {
1244    // Get the input values
1245
Long JavaDoc long1 = (Long JavaDoc)handlerCtx.getInputValue("X");
1246    Long JavaDoc long2 = (Long JavaDoc)handlerCtx.getInputValue("Y");
1247    if ((long1 == null) || (long2 == null)) {
1248        throw new FrameworkException(getClass().getName()+
1249        ".isXGreaterThanY() requires both 'X' and 'Y' as request "+
1250        "attributes.", null, handlerCtx.getView());
1251    }
1252
1253    // Perform the check...
1254
Boolean JavaDoc result = new Boolean JavaDoc(long1.longValue()>long2.longValue());
1255
1256    // Set the result
1257
handlerCtx.setOutputValue(VALUE, result);
1258    }
1259
1260    /**
1261     * This method adds two long integers together. The 2 longs should be
1262     * stored in "long1" and "long2". The result will be stored as "result".
1263     */

1264    public void longAdd(RequestContext ctx, HandlerContext handlerCtx) {
1265        // Get the inputs
1266
Long JavaDoc long1 = (Long JavaDoc)handlerCtx.getInputValue(LONG_INTEGER_1);
1267    Long JavaDoc long2 = (Long JavaDoc)handlerCtx.getInputValue(LONG_INTEGER_2);
1268    if ((long1 == null) || (long2 == null)) {
1269        throw new FrameworkException(getClass().getName()+
1270        ".longAdd() requires that both '"+LONG_INTEGER_1+"' and '"+
1271        LONG_INTEGER_2+"' be supplied as request attributes.",
1272        null, handlerCtx.getView());
1273    }
1274
1275    // Add the 2 numbers together
1276
Long JavaDoc result = new Long JavaDoc(long1.longValue()+long2.longValue());
1277
1278    // Set the result
1279
handlerCtx.setOutputValue(LONG_ADD_RESULT, result);
1280    }
1281
1282
1283    /**
1284     * <p> This method sleeps for a second.</p>
1285     */

1286    public void sleep(RequestContext ctx, HandlerContext handlerCtx) {
1287    try {
1288        Thread.currentThread().sleep(1*1000);
1289    } catch (Exception JavaDoc ex) {
1290        ex.printStackTrace();
1291    }
1292    }
1293
1294    /**
1295     * This handler throws a RuntimeException for testing purposes. This
1296     * allows you to put this handler anywhere to test how an exception will
1297     * be handled.
1298     */

1299    public void throwException(RequestContext ctx, HandlerContext handlerCtx) {
1300    throw new RuntimeException JavaDoc("Throwing an exception for testing "+
1301        "purposes. The view name given to this handler is: '"+
1302        handlerCtx.getView().getName()+"'. The EventObject is: '"+handlerCtx.getEvent()+
1303        "'. The event.getSource() is: '"+handlerCtx.getEvent().getSource()+"'.");
1304    }
1305
1306    /**
1307     * This handler returns TRUE if the test object is null or have no element.
1308     */

1309    public Boolean JavaDoc returnTrueIfEmpty(RequestContext ctx, HandlerContext handlerCtx) {
1310        Object JavaDoc value = handlerCtx.getInputValue("value");
1311        if (value == null)
1312            return TRUE;
1313        if (value instanceof String JavaDoc)
1314            return ( Util.isEmpty((String JavaDoc) value)) ? TRUE: FALSE;
1315        if (value instanceof Object JavaDoc[])
1316        { int size = ((Object JavaDoc[])value).length;
1317            //System.out.println("returnFalseIfEmpty: is instanceof Object[] " + size);
1318
return (((Object JavaDoc[])value).length == 0) ? TRUE: FALSE;
1319        }
1320        return FALSE;
1321    }
1322
1323    /**
1324     * This handler returns false. If you want a beginDisplay event to
1325     * return false.
1326     */

1327    public Boolean JavaDoc returnFalse(RequestContext ctx, HandlerContext handlerCtx) {
1328    return FALSE;
1329    }
1330
1331
1332    /**
1333     * This handler returns true. This is useful if you want a beginDisplay
1334     * event to return true.
1335     */

1336    public Boolean JavaDoc returnTrue(RequestContext ctx, HandlerContext handlerCtx) {
1337    return TRUE;
1338    }
1339    
1340    public void setExtraValuesMapInCommandField(RequestContext ctx, HandlerContext handlerCtx) {
1341        CommandFieldBase commandField = (CommandFieldBase)handlerCtx.getView();
1342        HashMap JavaDoc m = new HashMap JavaDoc();
1343        m.put((String JavaDoc)handlerCtx.getInputValue(NAME),
1344            handlerCtx.getInputValue("value"));
1345        commandField.setExtraValuesMap(m);
1346    }
1347    
1348    
1349    public void addExtraValueInCommandField(RequestContext ctx, HandlerContext handlerCtx) {
1350        CommandFieldBase commandField = (CommandFieldBase)handlerCtx.getView();
1351    String JavaDoc name = ((String JavaDoc)handlerCtx.getInputValue(NAME));
1352    String JavaDoc value = ((String JavaDoc)handlerCtx.getInputValue(VALUE));
1353        commandField.addExtraValue(name, value);
1354    }
1355    
1356    /**
1357     * This handler returns true if key1 = key2.
1358     */

1359    public void isEqual(RequestContext ctx, HandlerContext handlerCtx) {
1360        Object JavaDoc key1 = handlerCtx.getInputValue("key1");
1361        Object JavaDoc key2 = handlerCtx.getInputValue("key2");
1362        Boolean JavaDoc result = FALSE;
1363        if (key1 != null && key2 != null) {
1364            result = new Boolean JavaDoc(key1.equals(key2));
1365        }
1366        handlerCtx.setOutputValue("value", result);
1367    }
1368    
1369    /**
1370     * This handler returns true if key1 = key2 (ignore case).
1371     */

1372    public void isEqualsIgnoreCase(RequestContext ctx, HandlerContext handlerCtx) {
1373        String JavaDoc key1 = (String JavaDoc) handlerCtx.getInputValue("key1");
1374        String JavaDoc key2 = (String JavaDoc) handlerCtx.getInputValue("key2");
1375        Boolean JavaDoc result = FALSE;
1376        if (key1 != null && key2 != null) {
1377            result = new Boolean JavaDoc(key1.equalsIgnoreCase(key2));
1378        }
1379        handlerCtx.setOutputValue("value", result);
1380    }
1381
1382    // returns null if object is 'empty' - for Strings this means, strings with wghite
1383
// spaces only
1384
public void getNullIfEmpty(RequestContext ctx, HandlerContext handlerCtx) {
1385        Object JavaDoc obj = handlerCtx.getInputValue(VALUE);
1386        if (obj != null && obj instanceof String JavaDoc) {
1387            String JavaDoc str = (String JavaDoc) obj;
1388            if (str.trim().length() == 0) {
1389                obj = null;
1390            }
1391        }
1392    handlerCtx.setOutputValue(VALUE, obj);
1393    }
1394    
1395    public void isValidMbean(RequestContext ctx, HandlerContext handlerCtx) {
1396        String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("mbeanName");
1397        boolean valid = MBeanUtil.isValidMBean(objectName);
1398    handlerCtx.setOutputValue("isValid", new Boolean JavaDoc(valid));
1399    }
1400    
1401    public void convertStartEndDate(RequestContext ctx, HandlerContext handlerCtx) {
1402        String JavaDoc strStartDate = (String JavaDoc)handlerCtx.getInputValue("strStartDate");
1403        String JavaDoc strEndDate = (String JavaDoc)handlerCtx.getInputValue("strEndDate");
1404        DateFormat JavaDoc df = DateFormat.getDateInstance(DateFormat.SHORT);
1405        Date JavaDoc startDate = null;
1406        Date JavaDoc endDate = null;
1407        if (!Util.isEmpty(strStartDate)) {
1408            try {
1409                startDate = df.parse(strStartDate);
1410            } catch (java.text.ParseException JavaDoc pe) {
1411                throw new FrameworkException(Util.getMessage("msg.InvalidStartDateError", new Object JavaDoc[]{strStartDate}));
1412            }
1413        }
1414        if(!Util.isEmpty(strEndDate)) {
1415            try {
1416                endDate = df.parse(strEndDate);
1417            } catch (java.text.ParseException JavaDoc pe) {
1418                throw new FrameworkException(Util.getMessage("msg.InvalidEndDateError", new Object JavaDoc[]{strEndDate}));
1419            }
1420        }
1421        if (startDate != null && endDate != null) {
1422            if (startDate.after(endDate)) {
1423                throw new FrameworkException(Util.getMessage("msg.StartDateAfterEndDateError"));
1424            }
1425        }
1426        if (!Util.isEmpty(strStartDate) && Util.isEmpty(strEndDate)) {
1427            throw new FrameworkException(Util.getMessage("msg.MissingEndDateError"));
1428        } else if (Util.isEmpty(strStartDate) && !Util.isEmpty(strEndDate)) {
1429            throw new FrameworkException(Util.getMessage("msg.MissingStartDateError"));
1430        }
1431        
1432        handlerCtx.setOutputValue("startDate", startDate);
1433        handlerCtx.setOutputValue("endDate", endDate);
1434    }
1435    
1436    public void returnMap(RequestContext ctx, HandlerContext handlerCtx) {
1437        ArrayList JavaDoc keyList = (ArrayList JavaDoc)handlerCtx.getInputValue("keyList");
1438        ArrayList JavaDoc valueList = (ArrayList JavaDoc)handlerCtx.getInputValue("valueList");
1439        HashMap JavaDoc map = new HashMap JavaDoc();
1440        for (int i=0; i < keyList.size(); i++) {
1441            map.put(keyList.get(i), valueList.get(i));
1442        }
1443        handlerCtx.setOutputValue("map", map);
1444    }
1445    
1446    private Object JavaDoc[] getNodeAgentsAsDropDown( String JavaDoc methodName,
1447        String JavaDoc objectName, ArrayList JavaDoc params, ArrayList JavaDoc types)
1448    {
1449        Object JavaDoc[] paramsAndTypes = MBeanUtil.getParamsAndTypes(params, types);
1450    try {
1451            Object JavaDoc objs = MBeanUtil.invoke(objectName, methodName,
1452                (Object JavaDoc[])(paramsAndTypes[0]), (String JavaDoc[])(paramsAndTypes[1]));
1453            if (objs != null && objs instanceof ObjectName JavaDoc[]) {
1454                ObjectName JavaDoc[] naObjectNames = (ObjectName JavaDoc[])objs;
1455
1456                String JavaDoc[] naNames = new String JavaDoc[naObjectNames.length];
1457                String JavaDoc[] labels = new String JavaDoc[naObjectNames.length];
1458                for(int i =0; i < naObjectNames.length; i++) {
1459                    String JavaDoc naName = (String JavaDoc)MBeanUtil.getAttribute(naObjectNames[i], "name");
1460                    String JavaDoc label = naName +
1461                        " ("+getHostOfNodeAgent(naObjectNames[i].toString())+")";
1462                    naNames[i]= naName;
1463                    labels[i] = label;
1464                }
1465                return new Object JavaDoc[]{naNames, labels};
1466            }
1467            return new Object JavaDoc[]{new String JavaDoc[]{""}, new String JavaDoc[]{""}};
1468        } catch (Exception JavaDoc ex) {
1469        throw new FrameworkException(ex);
1470    }
1471    }
1472    
1473    private String JavaDoc getHostOfNodeAgent(String JavaDoc naObjectName) {
1474        
1475        String JavaDoc hostName = Util.getMessage("nodeAgent.UnknownHost");
1476        try {
1477            String JavaDoc[] types = new String JavaDoc[]{"java.lang.String"};
1478            Object JavaDoc[] params = new Object JavaDoc[]{"rendezvousOccurred"};
1479            String JavaDoc result = (String JavaDoc)MBeanUtil.invoke(
1480                naObjectName,
1481                "getPropertyValue", params, types);
1482            if (result.equalsIgnoreCase("false")) {
1483                return hostName;
1484            }
1485        } catch (Exception JavaDoc ex) {
1486            //System.out.println("=============== Exception in getHostOfNodeAgent ============= \n" + ex);
1487
//ex.printStackTrace(System.out);
1488
}
1489        try {
1490            ObjectName JavaDoc jmxConnector = (ObjectName JavaDoc)MBeanUtil.invoke(
1491                naObjectName, "getJmxConnector", null, null);
1492            if (jmxConnector != null ) {
1493                String JavaDoc[] types = new String JavaDoc[]{"java.lang.String"};
1494                Object JavaDoc[] params = new Object JavaDoc[]{"client-hostname"};
1495                hostName = (String JavaDoc)MBeanUtil.invoke(
1496                    jmxConnector,
1497                    "getPropertyValue", params, types);
1498            }
1499        }catch (Exception JavaDoc ex){
1500            //System.out.println("=============== Exception in getHostOfNodeAgent ============= \n" + ex);
1501
//ex.printStackTrace(System.out);
1502
}
1503        return hostName;
1504    }
1505    
1506    public String JavaDoc getHostOfNodeAgent(RequestContext ctx, HandlerContext handlerCtx) {
1507        String JavaDoc naObjectName = (String JavaDoc)handlerCtx.getInputValue("nodeAgentObjectName");
1508        String JavaDoc hostName = getHostOfNodeAgent(naObjectName);
1509    handlerCtx.setOutputValue("hostName", hostName);
1510        return hostName;
1511    }
1512    
1513    public void displayPropertyChild(RequestContext ctx, HandlerContext handlerCtx) {
1514    ViewDescriptor vd;
1515        vd = handlerCtx.getViewDescriptor();
1516        
1517        if (vd instanceof CCPropertySheetDescriptor) {
1518            CCPropertySheetModelInterface model =
1519                ((CCPropertySheetDescriptor)vd).getModel();
1520            String JavaDoc propertyName = (String JavaDoc)handlerCtx.getInputValue("propertyName");
1521        Boolean JavaDoc displayValue = (Boolean JavaDoc)handlerCtx.getInputValue("value");
1522            if (propertyName != null) {
1523                model.setVisible(propertyName, displayValue.booleanValue());
1524            }
1525   
1526        } else {
1527            throw new RuntimeException JavaDoc("ViewDesc should be of type property sheet.");
1528        }
1529    }
1530    
1531    /**
1532     * Displays the tile, and help messages for PageTitle.
1533     * Inputs should be the localized keys for title, and help messages.
1534     * @param ctx
1535     * @param handlerCtx
1536     */

1537    public void PageTitleDisplay(RequestContext ctx, HandlerContext handlerCtx) {
1538// the child should be something like: com.sun.web.ui.view.html.CCPageTitleTag
1539
CCPageTitleTag tag = (CCPageTitleTag)handlerCtx.getEvent().getSource();
1540        String JavaDoc titleKey = (String JavaDoc)handlerCtx.getInputValue("titleKey");
1541        String JavaDoc helpKey = (String JavaDoc)handlerCtx.getInputValue("helpKey");
1542        ArrayList JavaDoc argList = (ArrayList JavaDoc)handlerCtx.getInputValue("args");
1543        Object JavaDoc[] args = null;
1544        if (argList != null && argList.size() > 0) {
1545            args = (Object JavaDoc[])argList.toArray(new Object JavaDoc[argList.size()]);
1546        }
1547        if(titleKey != null) {
1548            String JavaDoc titleText = null;
1549            if (args == null || args.length == 0) {
1550            titleText = Util.getMessage(titleKey);
1551            
1552            } else {
1553                titleText = Util.getMessage(titleKey, args);
1554            }
1555            tag.setPageTitleText(titleText);
1556        }
1557        
1558        if(helpKey != null) {
1559            String JavaDoc helpText = Util.getMessage(helpKey);
1560            tag.setPageTitleHelpMessage(helpText);
1561        }
1562        
1563    }
1564
1565    //This fix is temporary to work around a bug in Jato/Lockhard which generate invalid html
1566
//when the function setExtraValuesMapInCommandField() is called inside the beginDisplay event
1567
//of a button.
1568
public String JavaDoc temporaryFixHtmlError(RequestContext ctx, HandlerContext handlerCtx) {
1569    if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
1570        //System.out.println(" !!!! temporaryFixHtmlError returns NULL");
1571
return null;
1572    }
1573    String JavaDoc content = (String JavaDoc) ((ChildContentDisplayEvent)handlerCtx.getEvent()).getContent();
1574        String JavaDoc result = content.replaceFirst("\"<", "\"> <") ;
1575        String JavaDoc result1 = result.replaceFirst("/> */>", "/> </input> ") ;
1576        return result1;
1577    }
1578
1579    /**
1580     * <P> This method shortens the middle of the given string if it is longer
1581     * than the specified maxLength.</P>
1582     *
1583     * <P> This method expects the following input parameters:</P>
1584     *
1585     * <UL><LI>maxLength -- Integer -- Max String length before
1586     * truncating</LI>
1587     * <LI>headLength -- Integer -- Number of characters to leave at
1588     * the beginning of the string</LI>
1589     * <LI>tailLength -- Integer -- Number of characters to lave at
1590     * the end of the string</LI>
1591     * <LI>elipse -- String -- The replacement string for the
1592     * truncated portion</LI>
1593     * <LI>string -- String -- The String to shorten</LI></UL>
1594     *
1595     * <P> It returns the following output parameters:</P>
1596     *
1597     * <UL><LI>value -- String -- The shortened string</LI></UL>
1598     *
1599     * @param ctx The RequestContext
1600     * @param handlerCtx The HandlerContext
1601     */

1602    public void truncateMiddle(RequestContext ctx, HandlerContext handlerCtx) {
1603    // Get input values
1604
int maxLength = ((Integer JavaDoc)handlerCtx.getInputValue(MAX_LENGTH)).intValue();
1605        int headLength = ((Integer JavaDoc)handlerCtx.getInputValue(HEAD_LENGTH)).intValue();
1606        int tailLength = ((Integer JavaDoc)handlerCtx.getInputValue(TAIL_LENGTH)).intValue();
1607        String JavaDoc elipse = (String JavaDoc)handlerCtx.getInputValue(ELLIPSIS);
1608        String JavaDoc string = (String JavaDoc)handlerCtx.getInputValue(STRING);
1609    if (string == null) {
1610        string = "";
1611    }
1612
1613    // Check to see if we should do anything
1614
if (string.length() > maxLength) {
1615        // Shorten string
1616
string = string.substring(0, headLength) +
1617             elipse +
1618             string.substring(string.length()-tailLength);
1619    }
1620
1621    // Set the output value
1622
handlerCtx.setOutputValue(VALUE, string);
1623    }
1624     /**
1625     * <P> This method returns the domain root. </P>
1626     *
1627     *
1628     * <P> It returns the following output parameters:</P>
1629     *
1630     * <UL><LI>value -- String -- DomainRoot directory for this Install.</LI></UL>
1631     *
1632     * @param ctx The RequestContext
1633     * @param handlerCtx The HandlerContext
1634     */

1635    
1636    public String JavaDoc getDomainRoot(RequestContext ctx, HandlerContext handlerCtx) {
1637        String JavaDoc domainRoot = Util.getDomainRoot();
1638        handlerCtx.setOutputValue("domainRoot", domainRoot);
1639        return domainRoot;
1640    }
1641    
1642    /**
1643     * <P> This method returns the endDisplay String as an output value. It
1644     * optionally returns "" from the method (thereby skipping all output
1645     * to the actual stream).</P>
1646     *
1647     * <P> This method expects the following input parameters:</P>
1648     *
1649     * <UL><LI>returnEmptyString -- Boolean -- true to return "", false
1650     * to return the original HTML string</LI></UL>
1651     *
1652     * <P> It returns the following output parameters:</P>
1653     *
1654     * <UL><LI>value -- String -- The html string</LI></UL>
1655     *
1656     * @param ctx The RequestContext
1657     * @param handlerCtx The HandlerContext
1658     *
1659     * @return The original string or "" depending on "returnEmptyString"
1660     */

1661    public String JavaDoc getEndDisplayString(RequestContext ctx, HandlerContext handlerCtx) {
1662    if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
1663        throw new FrameworkException(getClass().getName()+
1664        ".getEndDisplayString is only valid for endDisplay events!",
1665        null, handlerCtx.getView());
1666    }
1667
1668    // Get the HTML String
1669
String JavaDoc value =
1670        ((ChildContentDisplayEvent)handlerCtx.getEvent()).getContent();
1671
1672    // Set the output value
1673
handlerCtx.setOutputValue(VALUE, value);
1674
1675    // Get the input parameter
1676
boolean returnEmptyString = false;
1677    Object JavaDoc input = handlerCtx.getInputValue(RETURN_EMPTY_STRING);
1678    if (input != null) {
1679        returnEmptyString = ((Boolean JavaDoc)input).booleanValue();
1680    }
1681
1682    // Return the value
1683
return returnEmptyString ? "" : value;
1684    }
1685
1686    /**
1687     * <P> This method sets the "bound name" for the given DisplayField.
1688     * This method does not alter the associated Model. This is useful
1689     * if the DisplayField name does not match the Model name.</P>
1690     *
1691     * <P> This method expects the following input parameters:</P>
1692     *
1693     * <UL><LI>displayField -- DisplayField -- The DisplayField</LI>
1694     * <LI>name -- String -- The bound name</LI>
1695     * </UL>
1696     *
1697     * @param ctx The RequestContext
1698     * @param handlerCtx The HandlerContext
1699     */

1700    public void setBoundName(RequestContext ctx, HandlerContext handlerCtx) {
1701    // Get input values
1702
DisplayFieldImpl dispField =
1703        (DisplayFieldImpl)handlerCtx.getInputValue(DISPLAY_FIELD);
1704    String JavaDoc name = (String JavaDoc)handlerCtx.getInputValue(NAME);
1705    if ((dispField == null) || (name == null) || name.equals("")) {
1706        throw new FrameworkException("'"+DISPLAY_FIELD+"' and '"+NAME+
1707        "' are both required for setBoundName!", null,
1708        handlerCtx.getView());
1709    }
1710
1711    // Set the bound name
1712
dispField.setBoundName(name);
1713    }
1714
1715    /**
1716     * <P> This method sets the "display label" for the given CCHref.
1717     * Setting the value of the CCHref has no (or little) effect
1718     * currently in LH. The value is ignored when the JSP tag sets its
1719     * own "default value". Futher since they set the value tag's
1720     * default value, containers that re-use Tags ALWAYS have the default
1721     * value set. Using the "display label" is the only way to change
1722     * the value of a button on the fly.</P>
1723     *
1724     * <P> This method expects the following input parameters:</P>
1725     *
1726     * <UL><LI>cchref -- DisplayField -- The DisplayField</LI>
1727     * <LI>value -- String -- The bound name</LI></UL>
1728     *
1729     * @param ctx The RequestContext
1730     * @param handlerCtx The HandlerContext
1731     */

1732    public void setDisplayLabel(RequestContext ctx, HandlerContext handlerCtx) {
1733    // Get input values
1734
CCButton button = (CCButton)handlerCtx.getInputValue(CCBUTTON);
1735    String JavaDoc value = (String JavaDoc)handlerCtx.getInputValue(VALUE);
1736    if ((button == null) || (value == null)) {
1737        throw new FrameworkException("'"+CCBUTTON+"' and '"+VALUE+
1738        "' are both required for setDisplayLabel!", null,
1739        handlerCtx.getView());
1740    }
1741
1742    // Set the display label
1743
button.setDisplayLabel(value);
1744    }
1745
1746
1747    private static final String JavaDoc ENTRY_URI = "/admingui/TopFrameset";
1748    
1749
1750    public static final Boolean JavaDoc FALSE = new Boolean JavaDoc(false);
1751    public static final Boolean JavaDoc TRUE = new Boolean JavaDoc(true);
1752
1753
1754    /**
1755     * This attribute key should be set to one of the following: "error",
1756     * "help", "info", "warning".
1757     */

1758    public static final String JavaDoc ALERT_TYPE = "ALERT_TYPE";
1759
1760    /**
1761     *
1762     */

1763    public static final String JavaDoc ALERT_SUMMARY = "ALERT_SUMMARY";
1764
1765    /**
1766     * This attribute key is used to store a message from an MBeanException as
1767     * a request attribute. If an exception is thrown, but it is not an MBean
1768     * Exception, then a the last message in the trace is used.
1769     *
1770     */

1771    public static final String JavaDoc MBEAN_MESSAGE = "MBEAN_MESSAGE";
1772    public static final String JavaDoc HAS_MBEAN_MESSAGE= "HAS_MBEAN_MESSAGE";
1773    public static final String JavaDoc HAS_ERROR_MESSAGE= "HAS_ERROR_MESSAGE";
1774
1775    public static final String JavaDoc NAME = "name";
1776    public static final String JavaDoc VALUE = "value";
1777    public static final String JavaDoc MODEL = "model";
1778    public static final String JavaDoc MODEL_NAMES = "modelNames";
1779    public static final String JavaDoc LONG_INTEGER_1 = "long1";
1780    public static final String JavaDoc LONG_INTEGER_2 = "long2";
1781    public static final String JavaDoc LONG_ADD_RESULT = "result";
1782    public static final String JavaDoc EXCEPTION_TO_LOG = "exceptionToLog";
1783    public static final String JavaDoc LEVEL = "level";
1784
1785    public static final String JavaDoc DISPLAY_FIELD = "displayField";
1786    public static final String JavaDoc CCBUTTON = "ccbutton";
1787
1788    public static final String JavaDoc MAX_LENGTH = "maxLength";
1789    public static final String JavaDoc HEAD_LENGTH = "headLength";
1790    public static final String JavaDoc TAIL_LENGTH = "tailLength";
1791    public static final String JavaDoc ELLIPSIS = "ellipsis";
1792    public static final String JavaDoc STRING = "string";
1793
1794    public static final String JavaDoc RETURN_EMPTY_STRING = "returnEmptyString";
1795    
1796}
1797
Popular Tags