1 23 24 package com.sun.enterprise.tools.admingui.handlers; 25 26 import java.util.ArrayList ; 27 import java.util.EventObject ; 28 29 import com.iplanet.jato.view.View; 30 import com.iplanet.jato.view.ViewBase; 31 import com.iplanet.jato.view.ViewBean; 32 import com.iplanet.jato.view.html.SelectableGroup; 33 import com.iplanet.jato.view.html.OptionList; 34 import com.iplanet.jato.view.ContainerViewBase; 35 import com.iplanet.jato.RequestContext; 36 import com.iplanet.jato.RequestManager; 37 import com.iplanet.jato.model.DefaultModel; 38 import com.iplanet.jato.model.Model; 39 import com.iplanet.jato.model.ModelControlException; 40 41 import javax.management.MBeanException ; 42 import javax.management.ObjectName ; 43 import javax.management.AttributeList ; 44 import javax.management.Attribute ; 45 46 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 47 import com.sun.enterprise.tools.guiframework.model.ModelManager; 48 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle; 49 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 50 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 51 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 52 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor; 53 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent; 54 55 import com.sun.web.ui.model.CCActionTableModelInterface; 56 57 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 58 59 60 public class JVMOptionsHandler { 61 62 private CCActionTableModelInterface getModel(HandlerContext handlerCtx, ViewDescriptor desc) { 63 CCActionTableModelInterface model = 64 (CCActionTableModelInterface)handlerCtx.getInputValue("model"); 65 model.setRowSelectionType("multiple"); 66 67 if (model == null) { 68 throw new FrameworkException("JVMOptionsHandler.getModel: No Model Specified.", 69 desc, handlerCtx.getView()); 70 } 71 return model; 72 } 73 74 private void loadModel(CCActionTableModelInterface model, String [] list) throws ModelControlException { 75 model.beforeFirst(); 76 for(int rowNo = 0; rowNo < list.length; rowNo++) { 77 model.appendRow(); 78 model.setValue(PROPERTY_VALUE, list[rowNo]); 79 model.setRowSelected(false); 80 } 81 } 82 83 public void populateModel(RequestContext ctx, HandlerContext handlerCtx) { 84 View view = handlerCtx.getView(); 85 ViewDescriptor desc = null; 86 if (handlerCtx.getEvent() instanceof BeforeCreateEvent) { 87 desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor(); 88 } else { 89 DescriptorContainerView descView = (DescriptorContainerView) 90 (((ViewBase)view).getParentViewBean()); 91 desc = descView.getViewDescriptor(); 92 } 93 94 String objectName = (String )handlerCtx.getInputValue(OBJECT_NAME); 95 String [] jvmOptions = null; 96 try { 97 jvmOptions = (String [])MBeanUtil.getAttribute(new ObjectName (objectName), ATTRIBUTE_NAME); 98 } catch (Exception ex) { 99 return; 101 } 104 105 try { 106 CCActionTableModelInterface model = getModel(handlerCtx, desc); 107 ((DefaultModel)model).clear(); 108 loadModel(model, jvmOptions); 109 } catch (Exception ex) { 110 throw new FrameworkException("populatePropsTableModel: Loading error. ", ex, 111 desc, view); 112 } 113 } 114 115 public void addProperty(RequestContext ctx, HandlerContext handlerCtx) { 116 View view = handlerCtx.getView(); 117 DescriptorContainerView descView = (DescriptorContainerView) 118 (((ViewBase)view).getParentViewBean()); 119 ViewDescriptor vd = descView.getViewDescriptor(); 120 121 try { 122 CCActionTableModelInterface model = getModel(handlerCtx, vd); 123 model.appendRow(); 124 model.setValue(PROPERTY_VALUE, ""); 125 model.beforeFirst(); 126 } catch (Exception ex) { 127 throw new FrameworkException("JVMOptionsHandler.addProperty: ", ex, 128 vd, view); 129 } 130 } 131 132 133 public void updateOptions(RequestContext ctx, HandlerContext handlerCtx) { 134 View view = handlerCtx.getView(); 135 DescriptorContainerView descView = (DescriptorContainerView) 136 (((ViewBase)view).getParentViewBean()); 137 ViewDescriptor vd = descView.getViewDescriptor(); 138 139 String objectName = (String )handlerCtx.getInputValue(OBJECT_NAME); 140 CCActionTableModelInterface model = getModel(handlerCtx, vd); 141 ArrayList options = new ArrayList (); 142 143 try { 144 model.beforeFirst(); 145 while(model.next()) { 146 String value = (String ) model.getValue(PROPERTY_VALUE); 147 if (value != null && (! value.trim().equals(""))) { 148 options.add(value); 149 model.setRowSelected(false); 150 } 151 } 152 String [] jvmOptions = (String [])options.toArray(new String [0]); 153 Attribute attr = new Attribute (ATTRIBUTE_NAME, jvmOptions); 155 MBeanUtil.setAttribute(objectName, attr); 156 157 ((DefaultModel)model).clear(); 158 } catch (Exception ex) { 160 throw new FrameworkException("JVMOptionsHandler.updateOptions: ", ex, 161 vd, view); 162 } 163 } 164 165 public void deleteOptions(RequestContext ctx, HandlerContext handlerCtx) { 166 View view = handlerCtx.getView(); 167 DescriptorContainerView descView = (DescriptorContainerView) 168 (((ViewBase)view).getParentViewBean()); 169 ViewDescriptor vd = descView.getViewDescriptor(); 170 171 String objectName = (String )ctx.getRequest().getAttribute(OBJECT_NAME); 172 174 CCActionTableModelInterface model = getModel(handlerCtx, vd); 175 ArrayList options = new ArrayList (); 176 177 try { 178 model.beforeFirst(); 179 while(model.next()) { 180 String value = (String ) model.getValue(PROPERTY_VALUE); 181 if (value != null && (! value.trim().equals(""))) { 182 if (model.isRowSelected() == false) { 183 options.add(value); 184 } 186 } 187 } 188 String [] jvmOptions = (String [])options.toArray(new String [0]); 189 ((DefaultModel)model).clear(); 190 loadModel(model, jvmOptions); 191 } catch (Exception ex) { 192 throw new FrameworkException("JVMOptionsHandler.deleteOptions: ", ex, 193 vd, view); 194 } 195 } 196 197 public void getSecurityManagerStatus(RequestContext ctx, HandlerContext handlerCtx) { 198 199 String objectName = (String )handlerCtx.getInputValue("objectName"); 200 if (objectName == null){ 201 throw new FrameworkException("JVMOptionsHandler.getSecurityManagerStatus requires INPUT objectName"); 202 } 203 204 Boolean status = isSecurityManagerEnabled(objectName); 205 handlerCtx.setOutputValue("securityManagerEnabled", status.toString()); 206 } 207 208 209 private Boolean isSecurityManagerEnabled(String objectName){ 210 String [] jvmOptions = null; 211 try { 212 jvmOptions = (String [])MBeanUtil.getAttribute(new ObjectName (objectName), ATTRIBUTE_NAME); 213 if (jvmOptions != null){ 214 for(int i=0; i< jvmOptions.length; i++){ 215 if (jvmOptions[i].trim().equals(JVM_OPTION_SECURITY_MANAGER) || 216 jvmOptions[i].trim().startsWith(JVM_OPTION_SECURITY_MANAGER_WITH_EQUAL)){ 217 return Boolean.TRUE; 218 } 219 } 220 } 221 } catch (Exception ex) { 222 } 224 return Boolean.FALSE; 225 } 226 227 228 public void setSecurityManager(RequestContext ctx, HandlerContext handlerCtx) { 229 230 String objectName = (String )handlerCtx.getInputValue("objectName"); 231 String value = (String )handlerCtx.getInputValue("value"); 232 if (objectName == null || value == null){ 233 throw new FrameworkException("JVMOptionsHandler.setSecurityManager requires INPUT objectName and value"); 234 } 235 Boolean status = isSecurityManagerEnabled(objectName); 236 Boolean userValue = new Boolean (value); 237 if (status.equals(userValue)){ 238 return; 240 } 241 ArrayList newOptions = new ArrayList (); 242 try { 243 String [] origOptions = (String [])MBeanUtil.getAttribute(new ObjectName (objectName), ATTRIBUTE_NAME); 244 if(userValue){ 245 for(int i=0; i<origOptions.length; i++){ 246 newOptions.add(origOptions[i]); 247 } 248 newOptions.add(JVM_OPTION_SECURITY_MANAGER); 249 }else{ 250 for(int i=0; i<origOptions.length; i++){ 251 if (! (origOptions[i].trim().equals(JVM_OPTION_SECURITY_MANAGER) || 252 origOptions[i].trim().startsWith(JVM_OPTION_SECURITY_MANAGER_WITH_EQUAL))){ 253 newOptions.add(origOptions[i]); 254 } 255 } 256 } 257 258 } catch (Exception ex) { 259 } 261 String [] jvmOptions = (String [])newOptions.toArray(new String [0]); 262 Attribute attr = new Attribute (ATTRIBUTE_NAME, jvmOptions); 264 MBeanUtil.setAttribute(objectName, attr); 265 } 266 267 public static final String OBJECT_NAME = "objectName"; 269 public static final String PROPERTY_VALUE = "propertyValue"; 271 private static final String ATTRIBUTE_NAME = "jvm-options"; 273 274 private static final String JVM_OPTION_SECURITY_MANAGER = "-Djava.security.manager"; 275 private static final String JVM_OPTION_SECURITY_MANAGER_WITH_EQUAL = "-Djava.security.manager="; 276 } 277 | Popular Tags |