KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
33 import java.util.EventObject JavaDoc;
34 import java.util.StringTokenizer JavaDoc;
35 import java.util.Enumeration JavaDoc;
36
37 import com.iplanet.jato.RequestContext;
38 import com.iplanet.jato.RequestContextImpl;
39 import com.iplanet.jato.RequestManager;
40 import com.iplanet.jato.ViewBeanManager;
41 import com.iplanet.jato.model.DefaultModel;
42 import com.iplanet.jato.model.Model;
43 import com.iplanet.jato.util.RootCauseException;
44 import com.iplanet.jato.view.ContainerView;
45 import com.iplanet.jato.view.ContainerViewBase;
46 import com.iplanet.jato.view.View;
47 import com.iplanet.jato.view.DisplayFieldImpl;
48 import com.iplanet.jato.view.DisplayField;
49 import com.iplanet.jato.view.ViewBase;
50 import com.iplanet.jato.view.ViewBean;
51 import com.iplanet.jato.view.html.SelectableGroup;
52 import com.iplanet.jato.view.html.OptionList;
53 import com.iplanet.jato.view.event.RequestInvocationEvent;
54 import com.iplanet.jato.view.event.ViewRequestInvocationEvent;
55 import com.iplanet.jato.view.event.ViewCommandEvent;
56
57 import javax.management.MBeanException JavaDoc;
58 import javax.management.ObjectName JavaDoc;
59 import javax.management.AttributeList JavaDoc;
60 import javax.management.Attribute JavaDoc;
61
62 import javax.servlet.ServletException JavaDoc;
63 import javax.servlet.ServletRequest JavaDoc;
64 import javax.servlet.http.HttpServletRequest JavaDoc;
65
66 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
67 import com.sun.enterprise.tools.guiframework.view.descriptors.CCPropertySheetDescriptor;
68 import com.sun.enterprise.tools.guiframework.model.ModelManager;
69 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle;
70 import com.sun.enterprise.tools.guiframework.view.DescriptorCCTabs;
71 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
72 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
73 import com.sun.enterprise.tools.guiframework.view.ViewDescriptorManager;
74 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
75 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent;
76 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent;
77
78 import com.sun.web.ui.model.CCActionTableModelInterface;
79 import com.sun.web.ui.model.CCPropertySheetModelInterface;
80 import com.sun.web.ui.model.CCPropertySheetModel;
81 import com.sun.web.ui.view.html.CCTextField;
82 import com.sun.web.ui.view.html.CCCheckBox;
83 import com.sun.web.ui.taglib.html.CCDropDownMenuTag;
84 import com.sun.web.ui.view.propertysheet.CCPropertySheet;
85 import com.sun.web.ui.view.tabs.CCTabs;
86
87 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
88 import com.sun.enterprise.tools.admingui.util.Util;
89
90
91 /**
92  *
93  */

94 public class AdvanceTabHandler {
95
96     
97     public void displayAutoStart(RequestContext ctx, HandlerContext handlerCtx) throws Exception JavaDoc {
98         View view = handlerCtx.getView();
99     DescriptorContainerView descView = (DescriptorContainerView)view;
100         String JavaDoc propertyName = (String JavaDoc)handlerCtx.getInputValue("propertyName");
101         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue(METHOD_NAME);
102         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue(OBJECT_NAME);
103     
104     ViewDescriptor propertySheetDescriptor = descView.getViewDescriptor();
105     if (propertySheetDescriptor == null) {
106         throw new FrameworkException("displayAutoStart: propertySheetDescriptor is null", propertySheetDescriptor, view);
107     }
108     if(!(propertySheetDescriptor instanceof CCPropertySheetDescriptor)) {
109         throw new FrameworkException("displayAutoStart: propertySheetDescriptor is of wrong type", propertySheetDescriptor, view);
110     }
111         CCPropertySheetModelInterface model = ((CCPropertySheetDescriptor)propertySheetDescriptor).getModel();
112     
113     if (isAutoStartSupported(objectName, methodName)) {
114         model.setVisible(propertyName, true);
115             handlerCtx.setOutputValue(VALUE, "true");
116     } else {
117         model.setVisible(propertyName, false);
118             handlerCtx.setOutputValue(VALUE, "false");
119         }
120     }
121     
122     private boolean isAutoStartSupported(String JavaDoc objectName, String JavaDoc methodName) throws Exception JavaDoc {
123     Boolean JavaDoc value = (Boolean JavaDoc)MBeanUtil.invoke(new ObjectName JavaDoc(objectName), methodName, null, null);
124     
125     boolean returnValue = false;
126     
127     if (value != null) {
128         returnValue = value.booleanValue();
129     }
130     
131     return returnValue;
132     
133     }
134     
135     public void saveAutoStart(RequestContext ctx, HandlerContext handlerCtx) throws Exception JavaDoc {
136         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue(OBJECT_NAME);
137         String JavaDoc value = (String JavaDoc)handlerCtx.getInputValue("displayFieldValue");
138         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue(METHOD_NAME);
139     
140         if(!isAutoStartSupported(objectName, "isAutoStartSupported")) {
141             return;
142         }
143         
144     if(objectName == null || methodName == null) {
145         return;
146     }
147     MBeanUtil.invoke(objectName, methodName, new Object JavaDoc[]{new Boolean JavaDoc(value)},
148                 new String JavaDoc[]{"boolean"});
149     }
150     
151     public void getAdvanceTabValuesFromMBean(RequestContext ctx, HandlerContext handlerCtx) throws Exception JavaDoc {
152         View view = handlerCtx.getView();
153         if (!(view instanceof DescriptorContainerView)) {
154             View parent = view.getParent();
155             if (!(parent instanceof DescriptorContainerView)) {
156         throw new FrameworkException("View is not a DescriptorContainerView!", null, view);
157             } else {
158                 view = parent;
159             }
160         }
161         if (view instanceof DescriptorCCPageTitle) {
162             view = view.getParent();
163         }
164         DescriptorContainerView descView = (DescriptorContainerView)view;
165         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue(OBJECT_NAME);
166         String JavaDoc attributeName = (String JavaDoc)handlerCtx.getInputValue(ATTR_NAME);
167         String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue(CHILD_NAME);
168         String JavaDoc showTimeout = (String JavaDoc)handlerCtx.getInputValue("showTimeout");
169         
170         String JavaDoc value = null;
171         try {
172             value = (String JavaDoc)MBeanUtil.getAttribute(objectName, attributeName);
173         } catch (Exception JavaDoc ex) {
174         throw new FrameworkException(
175         "Exception throw in trying to get "+childName +" :"+ex);
176         }
177         if(showTimeout != null && showTimeout.equals("true")) {
178             if (value == null || value.equals("")) {
179                 HttpServletRequest JavaDoc req = RequestManager.getRequestContext().getRequest();
180                 int time = req.getSession().getMaxInactiveInterval();
181                 if (time <= 0)
182                     descView.setDisplayFieldValue(childName, "0");
183                 else
184                     descView.setDisplayFieldValue(childName,""+(time/60));
185             } else {
186                 descView.setDisplayFieldValue(childName, value);
187             }
188         }
189         else {
190             descView.setDisplayFieldValue(childName, value);
191         }
192     }
193     
194     public void getAutoStart(RequestContext ctx, HandlerContext handlerCtx) throws Exception JavaDoc {
195         View view = handlerCtx.getView();
196         if (!(view instanceof DescriptorContainerView)) {
197             View parent = view.getParent();
198             if (!(parent instanceof DescriptorContainerView)) {
199         throw new FrameworkException("View is not a DescriptorContainerView!", null, view);
200             } else {
201                 view = parent;
202             }
203         }
204         if (view instanceof DescriptorCCPageTitle) {
205             view = view.getParent();
206         }
207         DescriptorContainerView descView = (DescriptorContainerView)view;
208         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue(OBJECT_NAME);
209         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue(METHOD_NAME);
210         String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue(CHILD_NAME);
211         
212         Boolean JavaDoc retValue = (Boolean JavaDoc)MBeanUtil.invoke(objectName, methodName, null, null);
213         
214         if(retValue != null) {
215             CCCheckBox cb = (CCCheckBox)descView.getChild(childName);
216             ((CCCheckBox)cb).setValue(retValue.toString());
217         }
218         
219     }
220     
221     public void saveAdvanceTabValues(RequestContext ctx, HandlerContext handlerCtx) {
222         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue(OBJECT_NAME);
223         String JavaDoc attributeName = (String JavaDoc)handlerCtx.getInputValue(ATTR_NAME);
224         String JavaDoc value = (String JavaDoc)handlerCtx.getInputValue("displayFieldValue");
225         
226         Attribute JavaDoc attr = new Attribute JavaDoc(attributeName, value);
227         
228         MBeanUtil.setAttribute(objectName, attr);
229         
230     }
231     
232     public void restoreDefaultValues(RequestContext reqCtx, HandlerContext handlerCtx) {
233     View view = handlerCtx.getView();
234         if (!(view instanceof DescriptorContainerView)) {
235             View parent = view.getParent();
236             if (!(parent instanceof DescriptorContainerView)) {
237         throw new FrameworkException("View is not a DescriptorContainerView!", null, view);
238             } else {
239                 view = parent;
240             }
241         }
242         if (view instanceof DescriptorCCPageTitle) {
243             view = view.getParent();
244         }
245         DescriptorContainerView descView = (DescriptorContainerView)view;
246         String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue(CHILD_NAME);
247         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue(OBJECT_NAME);
248         String JavaDoc[] params = {(String JavaDoc)handlerCtx.getInputValue(ATTR_NAME)};
249         String JavaDoc[] types = {"java.lang.String"};
250         descView.setDisplayFieldValue(childName,
251                     MBeanUtil.invoke(objectName, "getDefaultAttributeValue", params, types));
252         String JavaDoc value = (String JavaDoc)MBeanUtil.invoke(objectName, "getDefaultAttributeValue", params, types);
253         
254     }
255     
256     private String JavaDoc OBJECT_NAME = "objectName";
257     private String JavaDoc CHILD_NAME = "childName";
258     private String JavaDoc ATTR_NAME = "attributeName";
259     private String JavaDoc METHOD_NAME = "methodName";
260     private String JavaDoc VALUE = "value";
261     
262 }
263
Popular Tags