1 23 24 28 29 package com.sun.enterprise.config.serverbeans; 30 31 import org.w3c.dom.*; 32 import org.netbeans.modules.schema2beans.*; 33 import java.beans.*; 34 import java.util.*; 35 import java.io.Serializable ; 36 import com.sun.enterprise.config.ConfigBean; 37 import com.sun.enterprise.config.ConfigException; 38 import com.sun.enterprise.config.StaleWriteConfigException; 39 import com.sun.enterprise.util.i18n.StringManager; 40 41 43 public class JavaConfig extends ConfigBean implements Serializable 44 { 45 46 static Vector comparators = new Vector(); 47 private static final org.netbeans.modules.schema2beans.Version runtimeVersion = new org.netbeans.modules.schema2beans.Version(4, 2, 0); 48 49 static public final String PROFILER = "Profiler"; 50 static public final String JVM_OPTIONS = "JvmOptions"; 51 static public final String ELEMENT_PROPERTY = "ElementProperty"; 52 53 public JavaConfig() { 54 this(Common.USE_DEFAULT_VALUES); 55 } 56 57 public JavaConfig(int options) 58 { 59 super(comparators, runtimeVersion); 60 initPropertyTables(3); 62 this.createProperty("profiler", PROFILER, 63 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 64 Profiler.class); 65 this.createAttribute(PROFILER, "name", "Name", 66 AttrProp.CDATA | AttrProp.REQUIRED, 67 null, null); 68 this.createAttribute(PROFILER, "classpath", "Classpath", 69 AttrProp.CDATA | AttrProp.IMPLIED, 70 null, null); 71 this.createAttribute(PROFILER, "native-library-path", "NativeLibraryPath", 72 AttrProp.CDATA | AttrProp.IMPLIED, 73 null, null); 74 this.createAttribute(PROFILER, "enabled", "Enabled", 75 AttrProp.CDATA, 76 null, "true"); 77 this.createProperty("jvm-options", JVM_OPTIONS, Common.SEQUENCE_OR | 78 Common.TYPE_0_N | Common.TYPE_STRING | Common.TYPE_KEY, 79 String .class); 80 this.createProperty("property", ELEMENT_PROPERTY, Common.SEQUENCE_OR | 81 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 82 ElementProperty.class); 83 this.createAttribute(ELEMENT_PROPERTY, "name", "Name", 84 AttrProp.CDATA | AttrProp.REQUIRED, 85 null, null); 86 this.createAttribute(ELEMENT_PROPERTY, "value", "Value", 87 AttrProp.CDATA | AttrProp.REQUIRED, 88 null, null); 89 this.initialize(options); 90 } 91 92 void initialize(int options) { 94 95 } 96 97 public void setProfiler(Profiler value) { 99 this.setValue(PROFILER, value); 100 } 101 102 public Profiler getProfiler() { 104 return (Profiler)this.getValue(PROFILER); 105 } 106 107 public void setJvmOptions(String [] value) { 109 this.setValue(JVM_OPTIONS, value); 110 } 111 112 public String [] getJvmOptions() { 114 return (String [])this.getValues(JVM_OPTIONS); 115 } 116 117 public int sizeJvmOptions() { 119 return this.size(JVM_OPTIONS); 120 } 121 122 public int addJvmOptions(String value) 124 throws ConfigException{ 125 return addJvmOptions(value, true); 126 } 127 128 public int addJvmOptions(String value, boolean overwrite) 130 throws ConfigException{ 131 return this.addValue(JVM_OPTIONS, value, overwrite); 132 } 133 134 public int removeJvmOptions(String value){ 139 return this.removeValue(JVM_OPTIONS, value); 140 } 141 142 public int removeJvmOptions(String value, boolean overwrite) 148 throws StaleWriteConfigException{ 149 return this.removeValue(JVM_OPTIONS, value, overwrite); 150 } 151 152 public void setElementProperty(int index, ElementProperty value) { 154 this.setValue(ELEMENT_PROPERTY, index, value); 155 } 156 157 public ElementProperty getElementProperty(int index) { 159 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 160 } 161 162 public void setElementProperty(ElementProperty[] value) { 164 this.setValue(ELEMENT_PROPERTY, value); 165 } 166 167 public ElementProperty[] getElementProperty() { 169 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 170 } 171 172 public int sizeElementProperty() { 174 return this.size(ELEMENT_PROPERTY); 175 } 176 177 public int addElementProperty(ElementProperty value) 179 throws ConfigException{ 180 return addElementProperty(value, true); 181 } 182 183 public int addElementProperty(ElementProperty value, boolean overwrite) 185 throws ConfigException{ 186 ElementProperty old = getElementPropertyByName(value.getName()); 187 if(old != null) { 188 throw new ConfigException(StringManager.getManager(JavaConfig.class).getString("cannotAddDuplicate", "ElementProperty")); 189 } 190 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 191 } 192 193 public int removeElementProperty(ElementProperty value){ 198 return this.removeValue(ELEMENT_PROPERTY, value); 199 } 200 201 public int removeElementProperty(ElementProperty value, boolean overwrite) 207 throws StaleWriteConfigException{ 208 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 209 } 210 211 public ElementProperty getElementPropertyByName(String id) { 212 if (null != id) { id = id.trim(); } 213 ElementProperty[] o = getElementProperty(); 214 if (o == null) return null; 215 216 for (int i=0; i < o.length; i++) { 217 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 218 return o[i]; 219 } 220 } 221 222 return null; 223 224 } 225 229 public String getJavaHome() { 230 return getAttributeValue(ServerTags.JAVA_HOME); 231 } 232 237 public void setJavaHome(String v, boolean overwrite) throws StaleWriteConfigException { 238 setAttributeValue(ServerTags.JAVA_HOME, v, overwrite); 239 } 240 244 public void setJavaHome(String v) { 245 setAttributeValue(ServerTags.JAVA_HOME, v); 246 } 247 250 public static String getDefaultJavaHome() { 251 return "${com.sun.aas.javaRoot}".trim(); 252 } 253 257 public boolean isDebugEnabled() { 258 return toBoolean(getAttributeValue(ServerTags.DEBUG_ENABLED)); 259 } 260 265 public void setDebugEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException { 266 setAttributeValue(ServerTags.DEBUG_ENABLED, ""+(v==true), overwrite); 267 } 268 272 public void setDebugEnabled(boolean v) { 273 setAttributeValue(ServerTags.DEBUG_ENABLED, ""+(v==true)); 274 } 275 278 public static String getDefaultDebugEnabled() { 279 return "false".trim(); 280 } 281 285 public String getDebugOptions() { 286 return getAttributeValue(ServerTags.DEBUG_OPTIONS); 287 } 288 293 public void setDebugOptions(String v, boolean overwrite) throws StaleWriteConfigException { 294 setAttributeValue(ServerTags.DEBUG_OPTIONS, v, overwrite); 295 } 296 300 public void setDebugOptions(String v) { 301 setAttributeValue(ServerTags.DEBUG_OPTIONS, v); 302 } 303 306 public static String getDefaultDebugOptions() { 307 return "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n".trim(); 308 } 309 313 public String getRmicOptions() { 314 return getAttributeValue(ServerTags.RMIC_OPTIONS); 315 } 316 321 public void setRmicOptions(String v, boolean overwrite) throws StaleWriteConfigException { 322 setAttributeValue(ServerTags.RMIC_OPTIONS, v, overwrite); 323 } 324 328 public void setRmicOptions(String v) { 329 setAttributeValue(ServerTags.RMIC_OPTIONS, v); 330 } 331 334 public static String getDefaultRmicOptions() { 335 return "-iiop -poa -alwaysgenerate -keepgenerated -g".trim(); 336 } 337 341 public String getJavacOptions() { 342 return getAttributeValue(ServerTags.JAVAC_OPTIONS); 343 } 344 349 public void setJavacOptions(String v, boolean overwrite) throws StaleWriteConfigException { 350 setAttributeValue(ServerTags.JAVAC_OPTIONS, v, overwrite); 351 } 352 356 public void setJavacOptions(String v) { 357 setAttributeValue(ServerTags.JAVAC_OPTIONS, v); 358 } 359 362 public static String getDefaultJavacOptions() { 363 return "-g".trim(); 364 } 365 369 public String getClasspathPrefix() { 370 return getAttributeValue(ServerTags.CLASSPATH_PREFIX); 371 } 372 377 public void setClasspathPrefix(String v, boolean overwrite) throws StaleWriteConfigException { 378 setAttributeValue(ServerTags.CLASSPATH_PREFIX, v, overwrite); 379 } 380 384 public void setClasspathPrefix(String v) { 385 setAttributeValue(ServerTags.CLASSPATH_PREFIX, v); 386 } 387 391 public String getClasspathSuffix() { 392 return getAttributeValue(ServerTags.CLASSPATH_SUFFIX); 393 } 394 399 public void setClasspathSuffix(String v, boolean overwrite) throws StaleWriteConfigException { 400 setAttributeValue(ServerTags.CLASSPATH_SUFFIX, v, overwrite); 401 } 402 406 public void setClasspathSuffix(String v) { 407 setAttributeValue(ServerTags.CLASSPATH_SUFFIX, v); 408 } 409 413 public String getServerClasspath() { 414 return getAttributeValue(ServerTags.SERVER_CLASSPATH); 415 } 416 421 public void setServerClasspath(String v, boolean overwrite) throws StaleWriteConfigException { 422 setAttributeValue(ServerTags.SERVER_CLASSPATH, v, overwrite); 423 } 424 428 public void setServerClasspath(String v) { 429 setAttributeValue(ServerTags.SERVER_CLASSPATH, v); 430 } 431 435 public String getSystemClasspath() { 436 return getAttributeValue(ServerTags.SYSTEM_CLASSPATH); 437 } 438 443 public void setSystemClasspath(String v, boolean overwrite) throws StaleWriteConfigException { 444 setAttributeValue(ServerTags.SYSTEM_CLASSPATH, v, overwrite); 445 } 446 450 public void setSystemClasspath(String v) { 451 setAttributeValue(ServerTags.SYSTEM_CLASSPATH, v); 452 } 453 457 public String getNativeLibraryPathPrefix() { 458 return getAttributeValue(ServerTags.NATIVE_LIBRARY_PATH_PREFIX); 459 } 460 465 public void setNativeLibraryPathPrefix(String v, boolean overwrite) throws StaleWriteConfigException { 466 setAttributeValue(ServerTags.NATIVE_LIBRARY_PATH_PREFIX, v, overwrite); 467 } 468 472 public void setNativeLibraryPathPrefix(String v) { 473 setAttributeValue(ServerTags.NATIVE_LIBRARY_PATH_PREFIX, v); 474 } 475 479 public String getNativeLibraryPathSuffix() { 480 return getAttributeValue(ServerTags.NATIVE_LIBRARY_PATH_SUFFIX); 481 } 482 487 public void setNativeLibraryPathSuffix(String v, boolean overwrite) throws StaleWriteConfigException { 488 setAttributeValue(ServerTags.NATIVE_LIBRARY_PATH_SUFFIX, v, overwrite); 489 } 490 494 public void setNativeLibraryPathSuffix(String v) { 495 setAttributeValue(ServerTags.NATIVE_LIBRARY_PATH_SUFFIX, v); 496 } 497 501 public String getBytecodePreprocessors() { 502 return getAttributeValue(ServerTags.BYTECODE_PREPROCESSORS); 503 } 504 509 public void setBytecodePreprocessors(String v, boolean overwrite) throws StaleWriteConfigException { 510 setAttributeValue(ServerTags.BYTECODE_PREPROCESSORS, v, overwrite); 511 } 512 516 public void setBytecodePreprocessors(String v) { 517 setAttributeValue(ServerTags.BYTECODE_PREPROCESSORS, v); 518 } 519 523 public boolean isEnvClasspathIgnored() { 524 return toBoolean(getAttributeValue(ServerTags.ENV_CLASSPATH_IGNORED)); 525 } 526 531 public void setEnvClasspathIgnored(boolean v, boolean overwrite) throws StaleWriteConfigException { 532 setAttributeValue(ServerTags.ENV_CLASSPATH_IGNORED, ""+(v==true), overwrite); 533 } 534 538 public void setEnvClasspathIgnored(boolean v) { 539 setAttributeValue(ServerTags.ENV_CLASSPATH_IGNORED, ""+(v==true)); 540 } 541 544 public static String getDefaultEnvClasspathIgnored() { 545 return "true".trim(); 546 } 547 551 public Profiler newProfiler() { 552 return new Profiler(); 553 } 554 555 559 public ElementProperty newElementProperty() { 560 return new ElementProperty(); 561 } 562 563 568 protected String getRelativeXPath() { 569 String ret = null; 570 ret = "java-config"; 571 return (null != ret ? ret.trim() : null); 572 } 573 574 577 public static String getDefaultAttributeValue(String attr) { 578 if(attr == null) return null; 579 attr = attr.trim(); 580 if(attr.equals(ServerTags.JAVA_HOME)) return "${com.sun.aas.javaRoot}".trim(); 581 if(attr.equals(ServerTags.DEBUG_ENABLED)) return "false".trim(); 582 if(attr.equals(ServerTags.DEBUG_OPTIONS)) return "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n".trim(); 583 if(attr.equals(ServerTags.RMIC_OPTIONS)) return "-iiop -poa -alwaysgenerate -keepgenerated -g".trim(); 584 if(attr.equals(ServerTags.JAVAC_OPTIONS)) return "-g".trim(); 585 if(attr.equals(ServerTags.ENV_CLASSPATH_IGNORED)) return "true".trim(); 586 return null; 587 } 588 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 590 comparators.add(c); 591 } 592 593 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 595 comparators.remove(c); 596 } 597 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 598 } 599 600 public void dump(StringBuffer str, String indent){ 602 String s; 603 Object o; 604 org.netbeans.modules.schema2beans.BaseBean n; 605 str.append(indent); 606 str.append("Profiler"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getProfiler(); 608 if (n != null) 609 n.dump(str, indent + "\t"); else 611 str.append(indent+"\tnull"); this.dumpAttributes(PROFILER, 0, str, indent); 613 614 str.append(indent); 615 str.append("JvmOptions["+this.sizeJvmOptions()+"]"); for(int i=0; i<this.sizeJvmOptions(); i++) 617 { 618 str.append(indent+"\t"); 619 str.append("#"+i+":"); 620 str.append(indent+"\t"); str.append("<"); o = this.getValue(JVM_OPTIONS, i); 623 str.append((o==null?"null":o.toString().trim())); str.append(">\n"); this.dumpAttributes(JVM_OPTIONS, i, str, indent); 626 } 627 628 str.append(indent); 629 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 631 { 632 str.append(indent+"\t"); 633 str.append("#"+i+":"); 634 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 635 if (n != null) 636 n.dump(str, indent + "\t"); else 638 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 640 } 641 642 } 643 public String dumpBeanNode(){ 644 StringBuffer str = new StringBuffer (); 645 str.append("JavaConfig\n"); this.dump(str, "\n "); return str.toString(); 648 }} 649 650 652 | Popular Tags |