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 Server 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 APPLICATION_REF = "ApplicationRef"; 50 static public final String RESOURCE_REF = "ResourceRef"; 51 static public final String SYSTEM_PROPERTY = "SystemProperty"; 52 static public final String ELEMENT_PROPERTY = "ElementProperty"; 53 54 public Server() { 55 this(Common.USE_DEFAULT_VALUES); 56 } 57 58 public Server(int options) 59 { 60 super(comparators, runtimeVersion); 61 initPropertyTables(4); 63 this.createProperty("application-ref", APPLICATION_REF, 64 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 65 ApplicationRef.class); 66 this.createAttribute(APPLICATION_REF, "enabled", "Enabled", 67 AttrProp.CDATA, 68 null, "true"); 69 this.createAttribute(APPLICATION_REF, "virtual-servers", "VirtualServers", 70 AttrProp.CDATA | AttrProp.IMPLIED, 71 null, null); 72 this.createAttribute(APPLICATION_REF, "lb-enabled", "LbEnabled", 73 AttrProp.CDATA, 74 null, "false"); 75 this.createAttribute(APPLICATION_REF, "disable-timeout-in-minutes", "DisableTimeoutInMinutes", 76 AttrProp.CDATA, 77 null, "30"); 78 this.createAttribute(APPLICATION_REF, "ref", "Ref", 79 AttrProp.CDATA | AttrProp.REQUIRED, 80 null, null); 81 this.createProperty("resource-ref", RESOURCE_REF, 82 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 83 ResourceRef.class); 84 this.createAttribute(RESOURCE_REF, "enabled", "Enabled", 85 AttrProp.CDATA, 86 null, "true"); 87 this.createAttribute(RESOURCE_REF, "ref", "Ref", 88 AttrProp.CDATA | AttrProp.REQUIRED, 89 null, null); 90 this.createProperty("system-property", SYSTEM_PROPERTY, 91 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 92 SystemProperty.class); 93 this.createAttribute(SYSTEM_PROPERTY, "name", "Name", 94 AttrProp.CDATA | AttrProp.REQUIRED, 95 null, null); 96 this.createAttribute(SYSTEM_PROPERTY, "value", "Value", 97 AttrProp.CDATA | AttrProp.REQUIRED, 98 null, null); 99 this.createProperty("property", ELEMENT_PROPERTY, 100 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 101 ElementProperty.class); 102 this.createAttribute(ELEMENT_PROPERTY, "name", "Name", 103 AttrProp.CDATA | AttrProp.REQUIRED, 104 null, null); 105 this.createAttribute(ELEMENT_PROPERTY, "value", "Value", 106 AttrProp.CDATA | AttrProp.REQUIRED, 107 null, null); 108 this.initialize(options); 109 } 110 111 void initialize(int options) { 113 114 } 115 116 public void setApplicationRef(int index, ApplicationRef value) { 118 this.setValue(APPLICATION_REF, index, value); 119 } 120 121 public ApplicationRef getApplicationRef(int index) { 123 return (ApplicationRef)this.getValue(APPLICATION_REF, index); 124 } 125 126 public void setApplicationRef(ApplicationRef[] value) { 128 this.setValue(APPLICATION_REF, value); 129 } 130 131 public ApplicationRef[] getApplicationRef() { 133 return (ApplicationRef[])this.getValues(APPLICATION_REF); 134 } 135 136 public int sizeApplicationRef() { 138 return this.size(APPLICATION_REF); 139 } 140 141 public int addApplicationRef(ApplicationRef value) 143 throws ConfigException{ 144 return addApplicationRef(value, true); 145 } 146 147 public int addApplicationRef(ApplicationRef value, boolean overwrite) 149 throws ConfigException{ 150 ApplicationRef old = getApplicationRefByRef(value.getRef()); 151 if(old != null) { 152 throw new ConfigException(StringManager.getManager(Server.class).getString("cannotAddDuplicate", "ApplicationRef")); 153 } 154 return this.addValue(APPLICATION_REF, value, overwrite); 155 } 156 157 public int removeApplicationRef(ApplicationRef value){ 162 return this.removeValue(APPLICATION_REF, value); 163 } 164 165 public int removeApplicationRef(ApplicationRef value, boolean overwrite) 171 throws StaleWriteConfigException{ 172 return this.removeValue(APPLICATION_REF, value, overwrite); 173 } 174 175 public ApplicationRef getApplicationRefByRef(String id) { 176 if (null != id) { id = id.trim(); } 177 ApplicationRef[] o = getApplicationRef(); 178 if (o == null) return null; 179 180 for (int i=0; i < o.length; i++) { 181 if(o[i].getAttributeValue(Common.convertName(ServerTags.REF)).equals(id)) { 182 return o[i]; 183 } 184 } 185 186 return null; 187 188 } 189 public void setResourceRef(int index, ResourceRef value) { 191 this.setValue(RESOURCE_REF, index, value); 192 } 193 194 public ResourceRef getResourceRef(int index) { 196 return (ResourceRef)this.getValue(RESOURCE_REF, index); 197 } 198 199 public void setResourceRef(ResourceRef[] value) { 201 this.setValue(RESOURCE_REF, value); 202 } 203 204 public ResourceRef[] getResourceRef() { 206 return (ResourceRef[])this.getValues(RESOURCE_REF); 207 } 208 209 public int sizeResourceRef() { 211 return this.size(RESOURCE_REF); 212 } 213 214 public int addResourceRef(ResourceRef value) 216 throws ConfigException{ 217 return addResourceRef(value, true); 218 } 219 220 public int addResourceRef(ResourceRef value, boolean overwrite) 222 throws ConfigException{ 223 ResourceRef old = getResourceRefByRef(value.getRef()); 224 if(old != null) { 225 throw new ConfigException(StringManager.getManager(Server.class).getString("cannotAddDuplicate", "ResourceRef")); 226 } 227 return this.addValue(RESOURCE_REF, value, overwrite); 228 } 229 230 public int removeResourceRef(ResourceRef value){ 235 return this.removeValue(RESOURCE_REF, value); 236 } 237 238 public int removeResourceRef(ResourceRef value, boolean overwrite) 244 throws StaleWriteConfigException{ 245 return this.removeValue(RESOURCE_REF, value, overwrite); 246 } 247 248 public ResourceRef getResourceRefByRef(String id) { 249 if (null != id) { id = id.trim(); } 250 ResourceRef[] o = getResourceRef(); 251 if (o == null) return null; 252 253 for (int i=0; i < o.length; i++) { 254 if(o[i].getAttributeValue(Common.convertName(ServerTags.REF)).equals(id)) { 255 return o[i]; 256 } 257 } 258 259 return null; 260 261 } 262 public void setSystemProperty(int index, SystemProperty value) { 264 this.setValue(SYSTEM_PROPERTY, index, value); 265 } 266 267 public SystemProperty getSystemProperty(int index) { 269 return (SystemProperty)this.getValue(SYSTEM_PROPERTY, index); 270 } 271 272 public void setSystemProperty(SystemProperty[] value) { 274 this.setValue(SYSTEM_PROPERTY, value); 275 } 276 277 public SystemProperty[] getSystemProperty() { 279 return (SystemProperty[])this.getValues(SYSTEM_PROPERTY); 280 } 281 282 public int sizeSystemProperty() { 284 return this.size(SYSTEM_PROPERTY); 285 } 286 287 public int addSystemProperty(SystemProperty value) 289 throws ConfigException{ 290 return addSystemProperty(value, true); 291 } 292 293 public int addSystemProperty(SystemProperty value, boolean overwrite) 295 throws ConfigException{ 296 SystemProperty old = getSystemPropertyByName(value.getName()); 297 if(old != null) { 298 throw new ConfigException(StringManager.getManager(Server.class).getString("cannotAddDuplicate", "SystemProperty")); 299 } 300 return this.addValue(SYSTEM_PROPERTY, value, overwrite); 301 } 302 303 public int removeSystemProperty(SystemProperty value){ 308 return this.removeValue(SYSTEM_PROPERTY, value); 309 } 310 311 public int removeSystemProperty(SystemProperty value, boolean overwrite) 317 throws StaleWriteConfigException{ 318 return this.removeValue(SYSTEM_PROPERTY, value, overwrite); 319 } 320 321 public SystemProperty getSystemPropertyByName(String id) { 322 if (null != id) { id = id.trim(); } 323 SystemProperty[] o = getSystemProperty(); 324 if (o == null) return null; 325 326 for (int i=0; i < o.length; i++) { 327 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 328 return o[i]; 329 } 330 } 331 332 return null; 333 334 } 335 public void setElementProperty(int index, ElementProperty value) { 337 this.setValue(ELEMENT_PROPERTY, index, value); 338 } 339 340 public ElementProperty getElementProperty(int index) { 342 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 343 } 344 345 public void setElementProperty(ElementProperty[] value) { 347 this.setValue(ELEMENT_PROPERTY, value); 348 } 349 350 public ElementProperty[] getElementProperty() { 352 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 353 } 354 355 public int sizeElementProperty() { 357 return this.size(ELEMENT_PROPERTY); 358 } 359 360 public int addElementProperty(ElementProperty value) 362 throws ConfigException{ 363 return addElementProperty(value, true); 364 } 365 366 public int addElementProperty(ElementProperty value, boolean overwrite) 368 throws ConfigException{ 369 ElementProperty old = getElementPropertyByName(value.getName()); 370 if(old != null) { 371 throw new ConfigException(StringManager.getManager(Server.class).getString("cannotAddDuplicate", "ElementProperty")); 372 } 373 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 374 } 375 376 public int removeElementProperty(ElementProperty value){ 381 return this.removeValue(ELEMENT_PROPERTY, value); 382 } 383 384 public int removeElementProperty(ElementProperty value, boolean overwrite) 390 throws StaleWriteConfigException{ 391 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 392 } 393 394 public ElementProperty getElementPropertyByName(String id) { 395 if (null != id) { id = id.trim(); } 396 ElementProperty[] o = getElementProperty(); 397 if (o == null) return null; 398 399 for (int i=0; i < o.length; i++) { 400 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 401 return o[i]; 402 } 403 } 404 405 return null; 406 407 } 408 412 public String getName() { 413 return getAttributeValue(ServerTags.NAME); 414 } 415 420 public void setName(String v, boolean overwrite) throws StaleWriteConfigException { 421 setAttributeValue(ServerTags.NAME, v, overwrite); 422 } 423 427 public void setName(String v) { 428 setAttributeValue(ServerTags.NAME, v); 429 } 430 434 public String getConfigRef() { 435 return getAttributeValue(ServerTags.CONFIG_REF); 436 } 437 442 public void setConfigRef(String v, boolean overwrite) throws StaleWriteConfigException { 443 setAttributeValue(ServerTags.CONFIG_REF, v, overwrite); 444 } 445 449 public void setConfigRef(String v) { 450 setAttributeValue(ServerTags.CONFIG_REF, v); 451 } 452 456 public String getNodeAgentRef() { 457 return getAttributeValue(ServerTags.NODE_AGENT_REF); 458 } 459 464 public void setNodeAgentRef(String v, boolean overwrite) throws StaleWriteConfigException { 465 setAttributeValue(ServerTags.NODE_AGENT_REF, v, overwrite); 466 } 467 471 public void setNodeAgentRef(String v) { 472 setAttributeValue(ServerTags.NODE_AGENT_REF, v); 473 } 474 478 public String getLbWeight() { 479 return getAttributeValue(ServerTags.LB_WEIGHT); 480 } 481 486 public void setLbWeight(String v, boolean overwrite) throws StaleWriteConfigException { 487 setAttributeValue(ServerTags.LB_WEIGHT, v, overwrite); 488 } 489 493 public void setLbWeight(String v) { 494 setAttributeValue(ServerTags.LB_WEIGHT, v); 495 } 496 499 public static String getDefaultLbWeight() { 500 return "100".trim(); 501 } 502 506 public ApplicationRef newApplicationRef() { 507 return new ApplicationRef(); 508 } 509 510 514 public ResourceRef newResourceRef() { 515 return new ResourceRef(); 516 } 517 518 522 public SystemProperty newSystemProperty() { 523 return new SystemProperty(); 524 } 525 526 530 public ElementProperty newElementProperty() { 531 return new ElementProperty(); 532 } 533 534 539 protected String getRelativeXPath() { 540 String ret = null; 541 ret = "server" + (canHaveSiblings() ? "[@name='" + getAttributeValue("name") +"']" : "") ; 542 return (null != ret ? ret.trim() : null); 543 } 544 545 548 public static String getDefaultAttributeValue(String attr) { 549 if(attr == null) return null; 550 attr = attr.trim(); 551 if(attr.equals(ServerTags.LB_WEIGHT)) return "100".trim(); 552 return null; 553 } 554 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 556 comparators.add(c); 557 } 558 559 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 561 comparators.remove(c); 562 } 563 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 564 } 565 566 public void dump(StringBuffer str, String indent){ 568 String s; 569 Object o; 570 org.netbeans.modules.schema2beans.BaseBean n; 571 str.append(indent); 572 str.append("ApplicationRef["+this.sizeApplicationRef()+"]"); for(int i=0; i<this.sizeApplicationRef(); i++) 574 { 575 str.append(indent+"\t"); 576 str.append("#"+i+":"); 577 n = (org.netbeans.modules.schema2beans.BaseBean) this.getApplicationRef(i); 578 if (n != null) 579 n.dump(str, indent + "\t"); else 581 str.append(indent+"\tnull"); this.dumpAttributes(APPLICATION_REF, i, str, indent); 583 } 584 585 str.append(indent); 586 str.append("ResourceRef["+this.sizeResourceRef()+"]"); for(int i=0; i<this.sizeResourceRef(); i++) 588 { 589 str.append(indent+"\t"); 590 str.append("#"+i+":"); 591 n = (org.netbeans.modules.schema2beans.BaseBean) this.getResourceRef(i); 592 if (n != null) 593 n.dump(str, indent + "\t"); else 595 str.append(indent+"\tnull"); this.dumpAttributes(RESOURCE_REF, i, str, indent); 597 } 598 599 str.append(indent); 600 str.append("SystemProperty["+this.sizeSystemProperty()+"]"); for(int i=0; i<this.sizeSystemProperty(); i++) 602 { 603 str.append(indent+"\t"); 604 str.append("#"+i+":"); 605 n = (org.netbeans.modules.schema2beans.BaseBean) this.getSystemProperty(i); 606 if (n != null) 607 n.dump(str, indent + "\t"); else 609 str.append(indent+"\tnull"); this.dumpAttributes(SYSTEM_PROPERTY, i, str, indent); 611 } 612 613 str.append(indent); 614 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 616 { 617 str.append(indent+"\t"); 618 str.append("#"+i+":"); 619 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 620 if (n != null) 621 n.dump(str, indent + "\t"); else 623 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 625 } 626 627 } 628 public String dumpBeanNode(){ 629 StringBuffer str = new StringBuffer (); 630 str.append("Server\n"); this.dump(str, "\n "); return str.toString(); 633 }} 634 635 637 | Popular Tags |