1 23 24 28 29 package com.sun.enterprise.tools.admingui.handlers; 30 31 import java.io.IOException ; 32 import java.util.ArrayList ; 33 import java.util.EventObject ; 34 import java.util.StringTokenizer ; 35 import java.util.Enumeration ; 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 ; 58 import javax.management.ObjectName ; 59 import javax.management.AttributeList ; 60 import javax.management.Attribute ; 61 62 import javax.servlet.ServletException ; 63 import javax.servlet.ServletRequest ; 64 import javax.servlet.http.HttpServletRequest ; 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 94 public class AdvanceTabHandler { 95 96 97 public void displayAutoStart(RequestContext ctx, HandlerContext handlerCtx) throws Exception { 98 View view = handlerCtx.getView(); 99 DescriptorContainerView descView = (DescriptorContainerView)view; 100 String propertyName = (String )handlerCtx.getInputValue("propertyName"); 101 String methodName = (String )handlerCtx.getInputValue(METHOD_NAME); 102 String objectName = (String )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 objectName, String methodName) throws Exception { 123 Boolean value = (Boolean )MBeanUtil.invoke(new ObjectName (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 { 136 String objectName = (String )handlerCtx.getInputValue(OBJECT_NAME); 137 String value = (String )handlerCtx.getInputValue("displayFieldValue"); 138 String methodName = (String )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 []{new Boolean (value)}, 148 new String []{"boolean"}); 149 } 150 151 public void getAdvanceTabValuesFromMBean(RequestContext ctx, HandlerContext handlerCtx) throws Exception { 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 objectName = (String )handlerCtx.getInputValue(OBJECT_NAME); 166 String attributeName = (String )handlerCtx.getInputValue(ATTR_NAME); 167 String childName = (String )handlerCtx.getInputValue(CHILD_NAME); 168 String showTimeout = (String )handlerCtx.getInputValue("showTimeout"); 169 170 String value = null; 171 try { 172 value = (String )MBeanUtil.getAttribute(objectName, attributeName); 173 } catch (Exception 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 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 { 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 objectName = (String )handlerCtx.getInputValue(OBJECT_NAME); 209 String methodName = (String )handlerCtx.getInputValue(METHOD_NAME); 210 String childName = (String )handlerCtx.getInputValue(CHILD_NAME); 211 212 Boolean retValue = (Boolean )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 objectName = (String )handlerCtx.getInputValue(OBJECT_NAME); 223 String attributeName = (String )handlerCtx.getInputValue(ATTR_NAME); 224 String value = (String )handlerCtx.getInputValue("displayFieldValue"); 225 226 Attribute attr = new Attribute (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 childName = (String )handlerCtx.getInputValue(CHILD_NAME); 247 String objectName = (String )handlerCtx.getInputValue(OBJECT_NAME); 248 String [] params = {(String )handlerCtx.getInputValue(ATTR_NAME)}; 249 String [] types = {"java.lang.String"}; 250 descView.setDisplayFieldValue(childName, 251 MBeanUtil.invoke(objectName, "getDefaultAttributeValue", params, types)); 252 String value = (String )MBeanUtil.invoke(objectName, "getDefaultAttributeValue", params, types); 253 254 } 255 256 private String OBJECT_NAME = "objectName"; 257 private String CHILD_NAME = "childName"; 258 private String ATTR_NAME = "attributeName"; 259 private String METHOD_NAME = "methodName"; 260 private String VALUE = "value"; 261 262 } 263 | Popular Tags |