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 LbConfig 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 CLUSTER_REF = "ClusterRef"; 50 static public final String SERVER_REF = "ServerRef"; 51 static public final String ELEMENT_PROPERTY = "ElementProperty"; 52 53 public LbConfig() { 54 this(Common.USE_DEFAULT_VALUES); 55 } 56 57 public LbConfig(int options) 58 { 59 super(comparators, runtimeVersion); 60 initPropertyTables(3); 62 this.createProperty("cluster-ref", CLUSTER_REF, Common.SEQUENCE_OR | 63 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 64 ClusterRef.class); 65 this.createAttribute(CLUSTER_REF, "ref", "Ref", 66 AttrProp.CDATA | AttrProp.REQUIRED, 67 null, null); 68 this.createAttribute(CLUSTER_REF, "lb-policy", "LbPolicy", 69 AttrProp.CDATA, 70 null, "round-robin"); 71 this.createAttribute(CLUSTER_REF, "lb-policy-module", "LbPolicyModule", 72 AttrProp.CDATA | AttrProp.IMPLIED, 73 null, null); 74 this.createProperty("server-ref", SERVER_REF, Common.SEQUENCE_OR | 75 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 76 ServerRef.class); 77 this.createAttribute(SERVER_REF, "ref", "Ref", 78 AttrProp.CDATA | AttrProp.REQUIRED, 79 null, null); 80 this.createAttribute(SERVER_REF, "disable-timeout-in-minutes", "DisableTimeoutInMinutes", 81 AttrProp.CDATA, 82 null, "30"); 83 this.createAttribute(SERVER_REF, "lb-enabled", "LbEnabled", 84 AttrProp.CDATA, 85 null, "false"); 86 this.createAttribute(SERVER_REF, "enabled", "Enabled", 87 AttrProp.CDATA, 88 null, "true"); 89 this.createProperty("property", ELEMENT_PROPERTY, 90 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 91 ElementProperty.class); 92 this.createAttribute(ELEMENT_PROPERTY, "name", "Name", 93 AttrProp.CDATA | AttrProp.REQUIRED, 94 null, null); 95 this.createAttribute(ELEMENT_PROPERTY, "value", "Value", 96 AttrProp.CDATA | AttrProp.REQUIRED, 97 null, null); 98 this.initialize(options); 99 } 100 101 void initialize(int options) { 103 104 } 105 106 public void setClusterRef(int index, ClusterRef value) { 108 this.setValue(CLUSTER_REF, index, value); 109 } 110 111 public ClusterRef getClusterRef(int index) { 113 return (ClusterRef)this.getValue(CLUSTER_REF, index); 114 } 115 116 public void setClusterRef(ClusterRef[] value) { 118 this.setValue(CLUSTER_REF, value); 119 if (value != null && value.length > 0) { 120 setServerRef(null); 122 } 123 } 124 125 public ClusterRef[] getClusterRef() { 127 return (ClusterRef[])this.getValues(CLUSTER_REF); 128 } 129 130 public int sizeClusterRef() { 132 return this.size(CLUSTER_REF); 133 } 134 135 public int addClusterRef(ClusterRef value) 137 throws ConfigException{ 138 return addClusterRef(value, true); 139 } 140 141 public int addClusterRef(ClusterRef value, boolean overwrite) 143 throws ConfigException{ 144 ClusterRef old = getClusterRefByRef(value.getRef()); 145 if(old != null) { 146 throw new ConfigException(StringManager.getManager(LbConfig.class).getString("cannotAddDuplicate", "ClusterRef")); 147 } 148 return this.addValue(CLUSTER_REF, value, overwrite); 149 } 150 151 public int removeClusterRef(ClusterRef value){ 156 return this.removeValue(CLUSTER_REF, value); 157 } 158 159 public int removeClusterRef(ClusterRef value, boolean overwrite) 165 throws StaleWriteConfigException{ 166 return this.removeValue(CLUSTER_REF, value, overwrite); 167 } 168 169 public ClusterRef getClusterRefByRef(String id) { 170 if (null != id) { id = id.trim(); } 171 ClusterRef[] o = getClusterRef(); 172 if (o == null) return null; 173 174 for (int i=0; i < o.length; i++) { 175 if(o[i].getAttributeValue(Common.convertName(ServerTags.REF)).equals(id)) { 176 return o[i]; 177 } 178 } 179 180 return null; 181 182 } 183 public void setServerRef(int index, ServerRef value) { 185 this.setValue(SERVER_REF, index, value); 186 } 187 188 public ServerRef getServerRef(int index) { 190 return (ServerRef)this.getValue(SERVER_REF, index); 191 } 192 193 public void setServerRef(ServerRef[] value) { 195 this.setValue(SERVER_REF, value); 196 if (value != null && value.length > 0) { 197 setClusterRef(null); 199 } 200 } 201 202 public ServerRef[] getServerRef() { 204 return (ServerRef[])this.getValues(SERVER_REF); 205 } 206 207 public int sizeServerRef() { 209 return this.size(SERVER_REF); 210 } 211 212 public int addServerRef(ServerRef value) 214 throws ConfigException{ 215 return addServerRef(value, true); 216 } 217 218 public int addServerRef(ServerRef value, boolean overwrite) 220 throws ConfigException{ 221 ServerRef old = getServerRefByRef(value.getRef()); 222 if(old != null) { 223 throw new ConfigException(StringManager.getManager(LbConfig.class).getString("cannotAddDuplicate", "ServerRef")); 224 } 225 return this.addValue(SERVER_REF, value, overwrite); 226 } 227 228 public int removeServerRef(ServerRef value){ 233 return this.removeValue(SERVER_REF, value); 234 } 235 236 public int removeServerRef(ServerRef value, boolean overwrite) 242 throws StaleWriteConfigException{ 243 return this.removeValue(SERVER_REF, value, overwrite); 244 } 245 246 public ServerRef getServerRefByRef(String id) { 247 if (null != id) { id = id.trim(); } 248 ServerRef[] o = getServerRef(); 249 if (o == null) return null; 250 251 for (int i=0; i < o.length; i++) { 252 if(o[i].getAttributeValue(Common.convertName(ServerTags.REF)).equals(id)) { 253 return o[i]; 254 } 255 } 256 257 return null; 258 259 } 260 public void setElementProperty(int index, ElementProperty value) { 262 this.setValue(ELEMENT_PROPERTY, index, value); 263 } 264 265 public ElementProperty getElementProperty(int index) { 267 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 268 } 269 270 public void setElementProperty(ElementProperty[] value) { 272 this.setValue(ELEMENT_PROPERTY, value); 273 } 274 275 public ElementProperty[] getElementProperty() { 277 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 278 } 279 280 public int sizeElementProperty() { 282 return this.size(ELEMENT_PROPERTY); 283 } 284 285 public int addElementProperty(ElementProperty value) 287 throws ConfigException{ 288 return addElementProperty(value, true); 289 } 290 291 public int addElementProperty(ElementProperty value, boolean overwrite) 293 throws ConfigException{ 294 ElementProperty old = getElementPropertyByName(value.getName()); 295 if(old != null) { 296 throw new ConfigException(StringManager.getManager(LbConfig.class).getString("cannotAddDuplicate", "ElementProperty")); 297 } 298 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 299 } 300 301 public int removeElementProperty(ElementProperty value){ 306 return this.removeValue(ELEMENT_PROPERTY, value); 307 } 308 309 public int removeElementProperty(ElementProperty value, boolean overwrite) 315 throws StaleWriteConfigException{ 316 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 317 } 318 319 public ElementProperty getElementPropertyByName(String id) { 320 if (null != id) { id = id.trim(); } 321 ElementProperty[] o = getElementProperty(); 322 if (o == null) return null; 323 324 for (int i=0; i < o.length; i++) { 325 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 326 return o[i]; 327 } 328 } 329 330 return null; 331 332 } 333 337 public String getName() { 338 return getAttributeValue(ServerTags.NAME); 339 } 340 345 public void setName(String v, boolean overwrite) throws StaleWriteConfigException { 346 setAttributeValue(ServerTags.NAME, v, overwrite); 347 } 348 352 public void setName(String v) { 353 setAttributeValue(ServerTags.NAME, v); 354 } 355 359 public String getResponseTimeoutInSeconds() { 360 return getAttributeValue(ServerTags.RESPONSE_TIMEOUT_IN_SECONDS); 361 } 362 367 public void setResponseTimeoutInSeconds(String v, boolean overwrite) throws StaleWriteConfigException { 368 setAttributeValue(ServerTags.RESPONSE_TIMEOUT_IN_SECONDS, v, overwrite); 369 } 370 374 public void setResponseTimeoutInSeconds(String v) { 375 setAttributeValue(ServerTags.RESPONSE_TIMEOUT_IN_SECONDS, v); 376 } 377 380 public static String getDefaultResponseTimeoutInSeconds() { 381 return "60".trim(); 382 } 383 387 public boolean isHttpsRouting() { 388 return toBoolean(getAttributeValue(ServerTags.HTTPS_ROUTING)); 389 } 390 395 public void setHttpsRouting(boolean v, boolean overwrite) throws StaleWriteConfigException { 396 setAttributeValue(ServerTags.HTTPS_ROUTING, ""+(v==true), overwrite); 397 } 398 402 public void setHttpsRouting(boolean v) { 403 setAttributeValue(ServerTags.HTTPS_ROUTING, ""+(v==true)); 404 } 405 408 public static String getDefaultHttpsRouting() { 409 return "false".trim(); 410 } 411 415 public String getReloadPollIntervalInSeconds() { 416 return getAttributeValue(ServerTags.RELOAD_POLL_INTERVAL_IN_SECONDS); 417 } 418 423 public void setReloadPollIntervalInSeconds(String v, boolean overwrite) throws StaleWriteConfigException { 424 setAttributeValue(ServerTags.RELOAD_POLL_INTERVAL_IN_SECONDS, v, overwrite); 425 } 426 430 public void setReloadPollIntervalInSeconds(String v) { 431 setAttributeValue(ServerTags.RELOAD_POLL_INTERVAL_IN_SECONDS, v); 432 } 433 436 public static String getDefaultReloadPollIntervalInSeconds() { 437 return "60".trim(); 438 } 439 443 public boolean isMonitoringEnabled() { 444 return toBoolean(getAttributeValue(ServerTags.MONITORING_ENABLED)); 445 } 446 451 public void setMonitoringEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException { 452 setAttributeValue(ServerTags.MONITORING_ENABLED, ""+(v==true), overwrite); 453 } 454 458 public void setMonitoringEnabled(boolean v) { 459 setAttributeValue(ServerTags.MONITORING_ENABLED, ""+(v==true)); 460 } 461 464 public static String getDefaultMonitoringEnabled() { 465 return "false".trim(); 466 } 467 471 public boolean isRouteCookieEnabled() { 472 return toBoolean(getAttributeValue(ServerTags.ROUTE_COOKIE_ENABLED)); 473 } 474 479 public void setRouteCookieEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException { 480 setAttributeValue(ServerTags.ROUTE_COOKIE_ENABLED, ""+(v==true), overwrite); 481 } 482 486 public void setRouteCookieEnabled(boolean v) { 487 setAttributeValue(ServerTags.ROUTE_COOKIE_ENABLED, ""+(v==true)); 488 } 489 492 public static String getDefaultRouteCookieEnabled() { 493 return "true".trim(); 494 } 495 499 public ClusterRef newClusterRef() { 500 return new ClusterRef(); 501 } 502 503 507 public ServerRef newServerRef() { 508 return new ServerRef(); 509 } 510 511 515 public ElementProperty newElementProperty() { 516 return new ElementProperty(); 517 } 518 519 524 protected String getRelativeXPath() { 525 String ret = null; 526 ret = "lb-config" + (canHaveSiblings() ? "[@name='" + getAttributeValue("name") +"']" : "") ; 527 return (null != ret ? ret.trim() : null); 528 } 529 530 533 public static String getDefaultAttributeValue(String attr) { 534 if(attr == null) return null; 535 attr = attr.trim(); 536 if(attr.equals(ServerTags.RESPONSE_TIMEOUT_IN_SECONDS)) return "60".trim(); 537 if(attr.equals(ServerTags.HTTPS_ROUTING)) return "false".trim(); 538 if(attr.equals(ServerTags.RELOAD_POLL_INTERVAL_IN_SECONDS)) return "60".trim(); 539 if(attr.equals(ServerTags.MONITORING_ENABLED)) return "false".trim(); 540 if(attr.equals(ServerTags.ROUTE_COOKIE_ENABLED)) return "true".trim(); 541 return null; 542 } 543 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 545 comparators.add(c); 546 } 547 548 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 550 comparators.remove(c); 551 } 552 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 553 } 554 555 public void dump(StringBuffer str, String indent){ 557 String s; 558 Object o; 559 org.netbeans.modules.schema2beans.BaseBean n; 560 str.append(indent); 561 str.append("ClusterRef["+this.sizeClusterRef()+"]"); for(int i=0; i<this.sizeClusterRef(); i++) 563 { 564 str.append(indent+"\t"); 565 str.append("#"+i+":"); 566 n = (org.netbeans.modules.schema2beans.BaseBean) this.getClusterRef(i); 567 if (n != null) 568 n.dump(str, indent + "\t"); else 570 str.append(indent+"\tnull"); this.dumpAttributes(CLUSTER_REF, i, str, indent); 572 } 573 574 str.append(indent); 575 str.append("ServerRef["+this.sizeServerRef()+"]"); for(int i=0; i<this.sizeServerRef(); i++) 577 { 578 str.append(indent+"\t"); 579 str.append("#"+i+":"); 580 n = (org.netbeans.modules.schema2beans.BaseBean) this.getServerRef(i); 581 if (n != null) 582 n.dump(str, indent + "\t"); else 584 str.append(indent+"\tnull"); this.dumpAttributes(SERVER_REF, i, str, indent); 586 } 587 588 str.append(indent); 589 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 591 { 592 str.append(indent+"\t"); 593 str.append("#"+i+":"); 594 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 595 if (n != null) 596 n.dump(str, indent + "\t"); else 598 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 600 } 601 602 } 603 public String dumpBeanNode(){ 604 StringBuffer str = new StringBuffer (); 605 str.append("LbConfig\n"); this.dump(str, "\n "); return str.toString(); 608 }} 609 610 612 | Popular Tags |