1 19 20 24 25 package org.netbeans.modules.j2ee.sun.ws7.nodes; 26 27 import java.util.HashMap ; 28 import java.util.Map ; 29 import java.util.Set ; 30 import java.util.List ; 31 import java.util.HashSet ; 32 import java.util.Arrays ; 33 import java.util.Iterator ; 34 import java.util.Vector ; 35 import org.openide.nodes.Sheet; 36 import org.openide.nodes.PropertySupport; 37 import org.openide.util.NbBundle; 38 import org.openide.execution.NbClassPath; 39 40 import org.netbeans.modules.j2ee.sun.ws7.ide.editors.TaggedValue; 41 import org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentManager; 42 import org.netbeans.modules.j2ee.sun.ws7.ui.Util; 43 44 import javax.enterprise.deploy.spi.DeploymentManager ; 45 49 public class WS70JVMManagedObject extends WS70ManagedObjectBase{ 50 private WS70SunDeploymentManager manager; 51 private String configName; 52 private HashMap attributes; 53 private List jvmOptions; 54 55 public WS70JVMManagedObject(DeploymentManager manager, String config, HashMap attrs, 56 List jvmOptions) { 57 this.manager = ((WS70SunDeploymentManager)manager); 58 this.configName = config; 59 this.attributes = this.constructJVMAttributes(attrs); 60 this.jvmOptions = jvmOptions; 61 Iterator it = attributes.keySet().iterator(); 62 while(it.hasNext()){ 63 Attribute a = (Attribute)it.next(); 64 if(a.getName().equals(JVM_DEBUG_OPTION)){ 65 String debugString = a.getValue().toString(); 66 this.manager.setDebugOptions(debugString); 67 } 68 if(a.getName().equals(JVM_DEBUG)){ 69 boolean isDebug = ((Boolean )a.getValue()).booleanValue(); 70 this.manager.setDebugModeEnabled(isDebug); 71 } 72 } 73 74 } 75 public String getDisplayName(){ 76 return NbBundle.getMessage(WS70JVMManagedObject.class, "LBL_JVM_NODE_NAME"); } 78 79 public Attribute setAttribute(String attribute, Object value) throws Exception { 80 HashMap map = new HashMap (); 81 map.put(attribute, value.toString()); 82 try{ 83 manager.setJVMProps(configName, map); 84 if(attributes.containsKey(attribute)){ 85 attributes.put(attribute, value); 86 } 87 Util.showInformation( 88 NbBundle.getMessage(WS70JVMManagedObject.class, "MSG_RESTART_SERVER")); }catch(Exception ex){ 90 throw ex; 91 } 92 if(attribute.equals(JVM_DEBUG_OPTION)){ 93 this.manager.setDebugOptions(value.toString()); 95 } 96 if(attribute.equals(JVM_DEBUG)){ 97 this.manager.setDebugModeEnabled(((Boolean )value).booleanValue()); 99 } 100 return new Attribute(attribute, value); 101 } 102 private String setJVMOptions(List options) throws Exception { 103 try{ 104 manager.setJVMOptions(configName, options, 105 java.lang.Boolean.FALSE, null); 106 return NbBundle.getMessage(WS70JVMManagedObject.class, "MSG_RESTART_SERVER"); }catch(Exception ex){ 108 throw ex; 109 } 110 111 } 112 public Sheet updateSheet(Sheet sheet) { 113 Sheet.Set ps = sheet.get(Sheet.PROPERTIES); 114 try { 115 for(Iterator itr = attributes.keySet().iterator(); itr.hasNext(); ) { 116 Attribute a = (Attribute) itr.next(); 117 AttributeInfo attr = (AttributeInfo)attributes.get(a); 118 String shortDescription = getShortDescription(attr); 119 if (attr == null || ! attr.isReadable()) { 120 continue; 121 } 122 123 Class type = getSupportedType(attr.getType()); 124 if (attr.isWritable()) { 125 Set classpathAttrs = new HashSet (Arrays.asList(JVM_STR_TO_ARR)); 126 if(classpathAttrs.contains(a.getName())){ 127 if (a.getValue()!= null) { 128 ps.put(createNetBeansClassPathProperty(a, attr, 129 shortDescription)); 130 } else { 131 ps.put(createReadOnlyProperty(a, attr, 132 shortDescription)); 133 } 134 } else if (type != null) { 135 if (a.getValue() instanceof TaggedValue) { 136 ps.put(createTaggedProperty(a, attr, shortDescription, type)); 137 }else { 138 ps.put(createWritableProperty(a, attr, shortDescription, type)); 139 } 141 } else { 142 ps.put(createReadOnlyProperty(a, attr, shortDescription)); 143 } 144 }else { 145 Set classpathAttrs = new HashSet (Arrays.asList(JVM_STR_TO_ARR)); 146 if(classpathAttrs.contains(a.getName())){ 147 if (a.getValue()!= null) { 148 ps.put(createNetBeansClassPathProperty(a, attr, 149 shortDescription)); 150 } else { 151 ps.put(createReadOnlyProperty(a, attr, 152 shortDescription)); 153 } 154 } else { 155 ps.put(createReadOnlyProperty(a, attr, 156 shortDescription)); 157 } 158 } } Object [] opts = jvmOptions.toArray(); 162 String [] values = new String [opts.length]; 163 for(int i = 0;i<opts.length;i++){ 164 values[i] = (String )opts[i]; 165 } 166 String jvmOptionsName = NbBundle.getMessage(WS70JVMManagedObject.class, "LBL_JVM_OPTIONS"); Attribute attr = new Attribute(jvmOptionsName, values); 168 AttributeInfo attrInfo = new AttributeInfo(jvmOptionsName, "java.lang.String[]", 169 null, true, true, false); 170 171 ps.put(createModifiedStringArrayWritableProperty(attr, attrInfo, "")); 172 173 } catch (Exception t) { 174 t.printStackTrace(); 175 } 176 177 return sheet; 178 } 179 180 private HashMap constructJVMAttributes(HashMap attrMap){ 181 HashMap attributes = new HashMap (); 182 for(Iterator itr = attrMap.keySet().iterator(); itr.hasNext(); ) { 183 String attrName = (String ) itr.next(); 184 Object attrValue = attrMap.get(attrName); 185 Attribute attr = null; 186 AttributeInfo attrInfo = null; 187 Set classpathAttrs = new HashSet (Arrays.asList(JVM_STR_TO_ARR)); 188 Set booleans = new HashSet (Arrays.asList(JVM_BOOLEAN_VALS)); 189 if(booleans.contains(attrName)){ 195 Object obj = Boolean.getValue((java.lang.Boolean )attrValue); 196 attr = new Attribute(attrName, obj); 197 attrInfo = new AttributeInfo(attrName, obj.getClass().getName(), 198 null, true, true, true); 199 }else{ 200 attr = new Attribute(attrName, attrValue); 201 attrInfo = new AttributeInfo(attrName, "java.lang.String", 202 null, true, true, false); 203 204 } 205 206 attributes.put(attr, attrInfo); 207 208 } 209 return attributes; 210 } 211 PropertySupport createModifiedStringArrayWritableProperty(final Attribute a, 212 final AttributeInfo attr, 213 final String shortDescription) { 214 return new PropertySupport.ReadWrite(attr.getName(), 215 String [].class, 216 attr.getName(), 217 shortDescription) { 218 Attribute attribute = a; 219 public Object getValue() { 220 return attribute.getValue(); 221 } 222 public void setValue(Object value) { 223 try { 224 String [] values = (String [])value; 225 java.util.ArrayList list = new java.util.ArrayList (); 226 if (values.length >= 1) { 227 for (int i = 0; i < values.length; i++) { 228 list.add(values[i]); 229 } 230 try{ 231 String retval = setJVMOptions(list); 232 attribute.setValue(values); 233 Util.showInformation(retval, "JVM Options setting"); }catch(Exception ex){ 235 Util.showError(ex.getMessage()); 236 } 237 } 238 } catch (Exception e) { 239 Util.showError(e.getLocalizedMessage()); 240 } 241 } 242 243 }; 244 } 245 246 PropertySupport createNetBeansClassPathProperty(final Attribute a, 247 final AttributeInfo attr, 248 final String shortDescription) { 249 return new PropertySupport.ReadWrite(attr.getName(), 250 NbClassPath.class, 251 attr.getName(), 252 shortDescription) { 253 Attribute attribute = a; 254 255 public Object getValue() { 256 try { 257 if (attribute.getValue() != null) { 258 String x = attribute.getValue().toString(); 259 return new NbClassPath(attribute.getValue().toString()); 260 } 261 else { 262 return null; 263 } } catch (Exception ex) { 265 return null; 266 } 267 } 268 269 public void setValue(Object val) { 270 try { 271 String value = ((NbClassPath)val).getClassPath(); 272 attribute = setAttribute(getName(), value); 273 } catch (Exception e) { 274 Util.showError(e.getLocalizedMessage()); 275 } 276 } 277 }; 278 } 279 280 static String [] createClasspathArray(Object cpath) { 281 Vector path = new Vector (); 282 283 if (cpath != null) { 284 String classPath = cpath.toString(); 285 char sepChar = getSeperationChar(classPath); 286 287 while (classPath.indexOf(sepChar) != -1) { 288 int index = classPath.indexOf(sepChar); 289 String val = classPath.substring(0, index); 290 path.add(val); 291 classPath = classPath.substring(index + 1, 292 classPath.length()); 293 } 294 295 path.add(classPath); 296 } 297 298 if (path != null) { 299 Object [] finalPath = (Object [])path.toArray(); 300 String [] value = new String [finalPath.length]; 301 302 for (int i = 0; i < finalPath.length; i++) { 303 value[i] = finalPath[i].toString(); 304 } 305 306 return value; 307 } 308 else { 309 return null; 310 } } 312 313 private static char getSeperationChar(String classPath){ 314 if((classPath.indexOf(":") != -1) && (classPath.indexOf(";") != -1)) { return ';'; } 318 else { 319 return ':'; } } 322 323 } | Popular Tags |