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 Cluster 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 SERVER_REF = "ServerRef"; 50 static public final String RESOURCE_REF = "ResourceRef"; 51 static public final String APPLICATION_REF = "ApplicationRef"; 52 static public final String SYSTEM_PROPERTY = "SystemProperty"; 53 static public final String ELEMENT_PROPERTY = "ElementProperty"; 54 55 public Cluster() { 56 this(Common.USE_DEFAULT_VALUES); 57 } 58 59 public Cluster(int options) 60 { 61 super(comparators, runtimeVersion); 62 initPropertyTables(5); 64 this.createProperty("server-ref", SERVER_REF, 65 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 66 ServerRef.class); 67 this.createAttribute(SERVER_REF, "ref", "Ref", 68 AttrProp.CDATA | AttrProp.REQUIRED, 69 null, null); 70 this.createAttribute(SERVER_REF, "disable-timeout-in-minutes", "DisableTimeoutInMinutes", 71 AttrProp.CDATA, 72 null, "30"); 73 this.createAttribute(SERVER_REF, "lb-enabled", "LbEnabled", 74 AttrProp.CDATA, 75 null, "false"); 76 this.createAttribute(SERVER_REF, "enabled", "Enabled", 77 AttrProp.CDATA, 78 null, "true"); 79 this.createProperty("resource-ref", RESOURCE_REF, 80 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 81 ResourceRef.class); 82 this.createAttribute(RESOURCE_REF, "enabled", "Enabled", 83 AttrProp.CDATA, 84 null, "true"); 85 this.createAttribute(RESOURCE_REF, "ref", "Ref", 86 AttrProp.CDATA | AttrProp.REQUIRED, 87 null, null); 88 this.createProperty("application-ref", APPLICATION_REF, 89 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 90 ApplicationRef.class); 91 this.createAttribute(APPLICATION_REF, "enabled", "Enabled", 92 AttrProp.CDATA, 93 null, "true"); 94 this.createAttribute(APPLICATION_REF, "virtual-servers", "VirtualServers", 95 AttrProp.CDATA | AttrProp.IMPLIED, 96 null, null); 97 this.createAttribute(APPLICATION_REF, "lb-enabled", "LbEnabled", 98 AttrProp.CDATA, 99 null, "false"); 100 this.createAttribute(APPLICATION_REF, "disable-timeout-in-minutes", "DisableTimeoutInMinutes", 101 AttrProp.CDATA, 102 null, "30"); 103 this.createAttribute(APPLICATION_REF, "ref", "Ref", 104 AttrProp.CDATA | AttrProp.REQUIRED, 105 null, null); 106 this.createProperty("system-property", SYSTEM_PROPERTY, 107 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 108 SystemProperty.class); 109 this.createAttribute(SYSTEM_PROPERTY, "name", "Name", 110 AttrProp.CDATA | AttrProp.REQUIRED, 111 null, null); 112 this.createAttribute(SYSTEM_PROPERTY, "value", "Value", 113 AttrProp.CDATA | AttrProp.REQUIRED, 114 null, null); 115 this.createProperty("property", ELEMENT_PROPERTY, 116 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 117 ElementProperty.class); 118 this.createAttribute(ELEMENT_PROPERTY, "name", "Name", 119 AttrProp.CDATA | AttrProp.REQUIRED, 120 null, null); 121 this.createAttribute(ELEMENT_PROPERTY, "value", "Value", 122 AttrProp.CDATA | AttrProp.REQUIRED, 123 null, null); 124 this.initialize(options); 125 } 126 127 void initialize(int options) { 129 130 } 131 132 public void setServerRef(int index, ServerRef value) { 134 this.setValue(SERVER_REF, index, value); 135 } 136 137 public ServerRef getServerRef(int index) { 139 return (ServerRef)this.getValue(SERVER_REF, index); 140 } 141 142 public void setServerRef(ServerRef[] value) { 144 this.setValue(SERVER_REF, value); 145 } 146 147 public ServerRef[] getServerRef() { 149 return (ServerRef[])this.getValues(SERVER_REF); 150 } 151 152 public int sizeServerRef() { 154 return this.size(SERVER_REF); 155 } 156 157 public int addServerRef(ServerRef value) 159 throws ConfigException{ 160 return addServerRef(value, true); 161 } 162 163 public int addServerRef(ServerRef value, boolean overwrite) 165 throws ConfigException{ 166 ServerRef old = getServerRefByRef(value.getRef()); 167 if(old != null) { 168 throw new ConfigException(StringManager.getManager(Cluster.class).getString("cannotAddDuplicate", "ServerRef")); 169 } 170 return this.addValue(SERVER_REF, value, overwrite); 171 } 172 173 public int removeServerRef(ServerRef value){ 178 return this.removeValue(SERVER_REF, value); 179 } 180 181 public int removeServerRef(ServerRef value, boolean overwrite) 187 throws StaleWriteConfigException{ 188 return this.removeValue(SERVER_REF, value, overwrite); 189 } 190 191 public ServerRef getServerRefByRef(String id) { 192 if (null != id) { id = id.trim(); } 193 ServerRef[] o = getServerRef(); 194 if (o == null) return null; 195 196 for (int i=0; i < o.length; i++) { 197 if(o[i].getAttributeValue(Common.convertName(ServerTags.REF)).equals(id)) { 198 return o[i]; 199 } 200 } 201 202 return null; 203 204 } 205 public void setResourceRef(int index, ResourceRef value) { 207 this.setValue(RESOURCE_REF, index, value); 208 } 209 210 public ResourceRef getResourceRef(int index) { 212 return (ResourceRef)this.getValue(RESOURCE_REF, index); 213 } 214 215 public void setResourceRef(ResourceRef[] value) { 217 this.setValue(RESOURCE_REF, value); 218 } 219 220 public ResourceRef[] getResourceRef() { 222 return (ResourceRef[])this.getValues(RESOURCE_REF); 223 } 224 225 public int sizeResourceRef() { 227 return this.size(RESOURCE_REF); 228 } 229 230 public int addResourceRef(ResourceRef value) 232 throws ConfigException{ 233 return addResourceRef(value, true); 234 } 235 236 public int addResourceRef(ResourceRef value, boolean overwrite) 238 throws ConfigException{ 239 ResourceRef old = getResourceRefByRef(value.getRef()); 240 if(old != null) { 241 throw new ConfigException(StringManager.getManager(Cluster.class).getString("cannotAddDuplicate", "ResourceRef")); 242 } 243 return this.addValue(RESOURCE_REF, value, overwrite); 244 } 245 246 public int removeResourceRef(ResourceRef value){ 251 return this.removeValue(RESOURCE_REF, value); 252 } 253 254 public int removeResourceRef(ResourceRef value, boolean overwrite) 260 throws StaleWriteConfigException{ 261 return this.removeValue(RESOURCE_REF, value, overwrite); 262 } 263 264 public ResourceRef getResourceRefByRef(String id) { 265 if (null != id) { id = id.trim(); } 266 ResourceRef[] o = getResourceRef(); 267 if (o == null) return null; 268 269 for (int i=0; i < o.length; i++) { 270 if(o[i].getAttributeValue(Common.convertName(ServerTags.REF)).equals(id)) { 271 return o[i]; 272 } 273 } 274 275 return null; 276 277 } 278 public void setApplicationRef(int index, ApplicationRef value) { 280 this.setValue(APPLICATION_REF, index, value); 281 } 282 283 public ApplicationRef getApplicationRef(int index) { 285 return (ApplicationRef)this.getValue(APPLICATION_REF, index); 286 } 287 288 public void setApplicationRef(ApplicationRef[] value) { 290 this.setValue(APPLICATION_REF, value); 291 } 292 293 public ApplicationRef[] getApplicationRef() { 295 return (ApplicationRef[])this.getValues(APPLICATION_REF); 296 } 297 298 public int sizeApplicationRef() { 300 return this.size(APPLICATION_REF); 301 } 302 303 public int addApplicationRef(ApplicationRef value) 305 throws ConfigException{ 306 return addApplicationRef(value, true); 307 } 308 309 public int addApplicationRef(ApplicationRef value, boolean overwrite) 311 throws ConfigException{ 312 ApplicationRef old = getApplicationRefByRef(value.getRef()); 313 if(old != null) { 314 throw new ConfigException(StringManager.getManager(Cluster.class).getString("cannotAddDuplicate", "ApplicationRef")); 315 } 316 return this.addValue(APPLICATION_REF, value, overwrite); 317 } 318 319 public int removeApplicationRef(ApplicationRef value){ 324 return this.removeValue(APPLICATION_REF, value); 325 } 326 327 public int removeApplicationRef(ApplicationRef value, boolean overwrite) 333 throws StaleWriteConfigException{ 334 return this.removeValue(APPLICATION_REF, value, overwrite); 335 } 336 337 public ApplicationRef getApplicationRefByRef(String id) { 338 if (null != id) { id = id.trim(); } 339 ApplicationRef[] o = getApplicationRef(); 340 if (o == null) return null; 341 342 for (int i=0; i < o.length; i++) { 343 if(o[i].getAttributeValue(Common.convertName(ServerTags.REF)).equals(id)) { 344 return o[i]; 345 } 346 } 347 348 return null; 349 350 } 351 public void setSystemProperty(int index, SystemProperty value) { 353 this.setValue(SYSTEM_PROPERTY, index, value); 354 } 355 356 public SystemProperty getSystemProperty(int index) { 358 return (SystemProperty)this.getValue(SYSTEM_PROPERTY, index); 359 } 360 361 public void setSystemProperty(SystemProperty[] value) { 363 this.setValue(SYSTEM_PROPERTY, value); 364 } 365 366 public SystemProperty[] getSystemProperty() { 368 return (SystemProperty[])this.getValues(SYSTEM_PROPERTY); 369 } 370 371 public int sizeSystemProperty() { 373 return this.size(SYSTEM_PROPERTY); 374 } 375 376 public int addSystemProperty(SystemProperty value) 378 throws ConfigException{ 379 return addSystemProperty(value, true); 380 } 381 382 public int addSystemProperty(SystemProperty value, boolean overwrite) 384 throws ConfigException{ 385 SystemProperty old = getSystemPropertyByName(value.getName()); 386 if(old != null) { 387 throw new ConfigException(StringManager.getManager(Cluster.class).getString("cannotAddDuplicate", "SystemProperty")); 388 } 389 return this.addValue(SYSTEM_PROPERTY, value, overwrite); 390 } 391 392 public int removeSystemProperty(SystemProperty value){ 397 return this.removeValue(SYSTEM_PROPERTY, value); 398 } 399 400 public int removeSystemProperty(SystemProperty value, boolean overwrite) 406 throws StaleWriteConfigException{ 407 return this.removeValue(SYSTEM_PROPERTY, value, overwrite); 408 } 409 410 public SystemProperty getSystemPropertyByName(String id) { 411 if (null != id) { id = id.trim(); } 412 SystemProperty[] o = getSystemProperty(); 413 if (o == null) return null; 414 415 for (int i=0; i < o.length; i++) { 416 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 417 return o[i]; 418 } 419 } 420 421 return null; 422 423 } 424 public void setElementProperty(int index, ElementProperty value) { 426 this.setValue(ELEMENT_PROPERTY, index, value); 427 } 428 429 public ElementProperty getElementProperty(int index) { 431 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 432 } 433 434 public void setElementProperty(ElementProperty[] value) { 436 this.setValue(ELEMENT_PROPERTY, value); 437 } 438 439 public ElementProperty[] getElementProperty() { 441 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 442 } 443 444 public int sizeElementProperty() { 446 return this.size(ELEMENT_PROPERTY); 447 } 448 449 public int addElementProperty(ElementProperty value) 451 throws ConfigException{ 452 return addElementProperty(value, true); 453 } 454 455 public int addElementProperty(ElementProperty value, boolean overwrite) 457 throws ConfigException{ 458 ElementProperty old = getElementPropertyByName(value.getName()); 459 if(old != null) { 460 throw new ConfigException(StringManager.getManager(Cluster.class).getString("cannotAddDuplicate", "ElementProperty")); 461 } 462 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 463 } 464 465 public int removeElementProperty(ElementProperty value){ 470 return this.removeValue(ELEMENT_PROPERTY, value); 471 } 472 473 public int removeElementProperty(ElementProperty value, boolean overwrite) 479 throws StaleWriteConfigException{ 480 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 481 } 482 483 public ElementProperty getElementPropertyByName(String id) { 484 if (null != id) { id = id.trim(); } 485 ElementProperty[] o = getElementProperty(); 486 if (o == null) return null; 487 488 for (int i=0; i < o.length; i++) { 489 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 490 return o[i]; 491 } 492 } 493 494 return null; 495 496 } 497 501 public String getName() { 502 return getAttributeValue(ServerTags.NAME); 503 } 504 509 public void setName(String v, boolean overwrite) throws StaleWriteConfigException { 510 setAttributeValue(ServerTags.NAME, v, overwrite); 511 } 512 516 public void setName(String v) { 517 setAttributeValue(ServerTags.NAME, v); 518 } 519 523 public String getConfigRef() { 524 return getAttributeValue(ServerTags.CONFIG_REF); 525 } 526 531 public void setConfigRef(String v, boolean overwrite) throws StaleWriteConfigException { 532 setAttributeValue(ServerTags.CONFIG_REF, v, overwrite); 533 } 534 538 public void setConfigRef(String v) { 539 setAttributeValue(ServerTags.CONFIG_REF, v); 540 } 541 545 public String getHeartbeatPort() { 546 return getAttributeValue(ServerTags.HEARTBEAT_PORT); 547 } 548 553 public void setHeartbeatPort(String v, boolean overwrite) throws StaleWriteConfigException { 554 setAttributeValue(ServerTags.HEARTBEAT_PORT, v, overwrite); 555 } 556 560 public void setHeartbeatPort(String v) { 561 setAttributeValue(ServerTags.HEARTBEAT_PORT, v); 562 } 563 567 public String getHeartbeatAddress() { 568 return getAttributeValue(ServerTags.HEARTBEAT_ADDRESS); 569 } 570 575 public void setHeartbeatAddress(String v, boolean overwrite) throws StaleWriteConfigException { 576 setAttributeValue(ServerTags.HEARTBEAT_ADDRESS, v, overwrite); 577 } 578 582 public void setHeartbeatAddress(String v) { 583 setAttributeValue(ServerTags.HEARTBEAT_ADDRESS, v); 584 } 585 589 public boolean isHeartbeatEnabled() { 590 return toBoolean(getAttributeValue(ServerTags.HEARTBEAT_ENABLED)); 591 } 592 597 public void setHeartbeatEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException { 598 setAttributeValue(ServerTags.HEARTBEAT_ENABLED, ""+(v==true), overwrite); 599 } 600 604 public void setHeartbeatEnabled(boolean v) { 605 setAttributeValue(ServerTags.HEARTBEAT_ENABLED, ""+(v==true)); 606 } 607 610 public static String getDefaultHeartbeatEnabled() { 611 return "true".trim(); 612 } 613 617 public ServerRef newServerRef() { 618 return new ServerRef(); 619 } 620 621 625 public ResourceRef newResourceRef() { 626 return new ResourceRef(); 627 } 628 629 633 public ApplicationRef newApplicationRef() { 634 return new ApplicationRef(); 635 } 636 637 641 public SystemProperty newSystemProperty() { 642 return new SystemProperty(); 643 } 644 645 649 public ElementProperty newElementProperty() { 650 return new ElementProperty(); 651 } 652 653 658 protected String getRelativeXPath() { 659 String ret = null; 660 ret = "cluster" + (canHaveSiblings() ? "[@name='" + getAttributeValue("name") +"']" : "") ; 661 return (null != ret ? ret.trim() : null); 662 } 663 664 667 public static String getDefaultAttributeValue(String attr) { 668 if(attr == null) return null; 669 attr = attr.trim(); 670 if(attr.equals(ServerTags.HEARTBEAT_ENABLED)) return "true".trim(); 671 return null; 672 } 673 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 675 comparators.add(c); 676 } 677 678 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 680 comparators.remove(c); 681 } 682 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 683 } 684 685 public void dump(StringBuffer str, String indent){ 687 String s; 688 Object o; 689 org.netbeans.modules.schema2beans.BaseBean n; 690 str.append(indent); 691 str.append("ServerRef["+this.sizeServerRef()+"]"); for(int i=0; i<this.sizeServerRef(); i++) 693 { 694 str.append(indent+"\t"); 695 str.append("#"+i+":"); 696 n = (org.netbeans.modules.schema2beans.BaseBean) this.getServerRef(i); 697 if (n != null) 698 n.dump(str, indent + "\t"); else 700 str.append(indent+"\tnull"); this.dumpAttributes(SERVER_REF, i, str, indent); 702 } 703 704 str.append(indent); 705 str.append("ResourceRef["+this.sizeResourceRef()+"]"); for(int i=0; i<this.sizeResourceRef(); i++) 707 { 708 str.append(indent+"\t"); 709 str.append("#"+i+":"); 710 n = (org.netbeans.modules.schema2beans.BaseBean) this.getResourceRef(i); 711 if (n != null) 712 n.dump(str, indent + "\t"); else 714 str.append(indent+"\tnull"); this.dumpAttributes(RESOURCE_REF, i, str, indent); 716 } 717 718 str.append(indent); 719 str.append("ApplicationRef["+this.sizeApplicationRef()+"]"); for(int i=0; i<this.sizeApplicationRef(); i++) 721 { 722 str.append(indent+"\t"); 723 str.append("#"+i+":"); 724 n = (org.netbeans.modules.schema2beans.BaseBean) this.getApplicationRef(i); 725 if (n != null) 726 n.dump(str, indent + "\t"); else 728 str.append(indent+"\tnull"); this.dumpAttributes(APPLICATION_REF, i, str, indent); 730 } 731 732 str.append(indent); 733 str.append("SystemProperty["+this.sizeSystemProperty()+"]"); for(int i=0; i<this.sizeSystemProperty(); i++) 735 { 736 str.append(indent+"\t"); 737 str.append("#"+i+":"); 738 n = (org.netbeans.modules.schema2beans.BaseBean) this.getSystemProperty(i); 739 if (n != null) 740 n.dump(str, indent + "\t"); else 742 str.append(indent+"\tnull"); this.dumpAttributes(SYSTEM_PROPERTY, i, str, indent); 744 } 745 746 str.append(indent); 747 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 749 { 750 str.append(indent+"\t"); 751 str.append("#"+i+":"); 752 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 753 if (n != null) 754 n.dump(str, indent + "\t"); else 756 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 758 } 759 760 } 761 public String dumpBeanNode(){ 762 StringBuffer str = new StringBuffer (); 763 str.append("Cluster\n"); this.dump(str, "\n "); return str.toString(); 766 }} 767 768 770 | Popular Tags |