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 WebModule 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 DESCRIPTION = "Description"; 50 static public final String WEB_SERVICE_ENDPOINT = "WebServiceEndpoint"; 51 static public final String ELEMENT_PROPERTY = "ElementProperty"; 52 53 public WebModule() { 54 this(Common.USE_DEFAULT_VALUES); 55 } 56 57 public WebModule(int options) 58 { 59 super(comparators, runtimeVersion); 60 initPropertyTables(3); 62 this.createProperty("description", DESCRIPTION, 63 Common.TYPE_0_1 | Common.TYPE_STRING | Common.TYPE_KEY, 64 String .class); 65 this.createProperty("web-service-endpoint", WEB_SERVICE_ENDPOINT, 66 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 67 WebServiceEndpoint.class); 68 this.createAttribute(WEB_SERVICE_ENDPOINT, "name", "Name", 69 AttrProp.CDATA | AttrProp.REQUIRED, 70 null, null); 71 this.createAttribute(WEB_SERVICE_ENDPOINT, "monitoring", "Monitoring", 72 AttrProp.CDATA, 73 null, "OFF"); 74 this.createAttribute(WEB_SERVICE_ENDPOINT, "max-history-size", "MaxHistorySize", 75 AttrProp.CDATA, 76 null, "25"); 77 this.createAttribute(WEB_SERVICE_ENDPOINT, "jbi-enabled", "JbiEnabled", 78 AttrProp.CDATA, 79 null, "true"); 80 this.createProperty("property", ELEMENT_PROPERTY, 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 100 public String getDescription() { 101 return (String ) getValue(ServerTags.DESCRIPTION); 102 } 103 107 public void setDescription(String v){ 108 setValue(ServerTags.DESCRIPTION, (null != v ? v.trim() : null)); 109 } 110 public void setWebServiceEndpoint(int index, WebServiceEndpoint value) { 112 this.setValue(WEB_SERVICE_ENDPOINT, index, value); 113 } 114 115 public WebServiceEndpoint getWebServiceEndpoint(int index) { 117 return (WebServiceEndpoint)this.getValue(WEB_SERVICE_ENDPOINT, index); 118 } 119 120 public void setWebServiceEndpoint(WebServiceEndpoint[] value) { 122 this.setValue(WEB_SERVICE_ENDPOINT, value); 123 } 124 125 public WebServiceEndpoint[] getWebServiceEndpoint() { 127 return (WebServiceEndpoint[])this.getValues(WEB_SERVICE_ENDPOINT); 128 } 129 130 public int sizeWebServiceEndpoint() { 132 return this.size(WEB_SERVICE_ENDPOINT); 133 } 134 135 public int addWebServiceEndpoint(WebServiceEndpoint value) 137 throws ConfigException{ 138 return addWebServiceEndpoint(value, true); 139 } 140 141 public int addWebServiceEndpoint(WebServiceEndpoint value, boolean overwrite) 143 throws ConfigException{ 144 WebServiceEndpoint old = getWebServiceEndpointByName(value.getName()); 145 if(old != null) { 146 throw new ConfigException(StringManager.getManager(WebModule.class).getString("cannotAddDuplicate", "WebServiceEndpoint")); 147 } 148 return this.addValue(WEB_SERVICE_ENDPOINT, value, overwrite); 149 } 150 151 public int removeWebServiceEndpoint(WebServiceEndpoint value){ 156 return this.removeValue(WEB_SERVICE_ENDPOINT, value); 157 } 158 159 public int removeWebServiceEndpoint(WebServiceEndpoint value, boolean overwrite) 165 throws StaleWriteConfigException{ 166 return this.removeValue(WEB_SERVICE_ENDPOINT, value, overwrite); 167 } 168 169 public WebServiceEndpoint getWebServiceEndpointByName(String id) { 170 if (null != id) { id = id.trim(); } 171 WebServiceEndpoint[] o = getWebServiceEndpoint(); 172 if (o == null) return null; 173 174 for (int i=0; i < o.length; i++) { 175 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 176 return o[i]; 177 } 178 } 179 180 return null; 181 182 } 183 public void setElementProperty(int index, ElementProperty value) { 185 this.setValue(ELEMENT_PROPERTY, index, value); 186 } 187 188 public ElementProperty getElementProperty(int index) { 190 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 191 } 192 193 public void setElementProperty(ElementProperty[] value) { 195 this.setValue(ELEMENT_PROPERTY, value); 196 } 197 198 public ElementProperty[] getElementProperty() { 200 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 201 } 202 203 public int sizeElementProperty() { 205 return this.size(ELEMENT_PROPERTY); 206 } 207 208 public int addElementProperty(ElementProperty value) 210 throws ConfigException{ 211 return addElementProperty(value, true); 212 } 213 214 public int addElementProperty(ElementProperty value, boolean overwrite) 216 throws ConfigException{ 217 ElementProperty old = getElementPropertyByName(value.getName()); 218 if(old != null) { 219 throw new ConfigException(StringManager.getManager(WebModule.class).getString("cannotAddDuplicate", "ElementProperty")); 220 } 221 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 222 } 223 224 public int removeElementProperty(ElementProperty value){ 229 return this.removeValue(ELEMENT_PROPERTY, value); 230 } 231 232 public int removeElementProperty(ElementProperty value, boolean overwrite) 238 throws StaleWriteConfigException{ 239 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 240 } 241 242 public ElementProperty getElementPropertyByName(String id) { 243 if (null != id) { id = id.trim(); } 244 ElementProperty[] o = getElementProperty(); 245 if (o == null) return null; 246 247 for (int i=0; i < o.length; i++) { 248 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 249 return o[i]; 250 } 251 } 252 253 return null; 254 255 } 256 260 public String getName() { 261 return getAttributeValue(ServerTags.NAME); 262 } 263 268 public void setName(String v, boolean overwrite) throws StaleWriteConfigException { 269 setAttributeValue(ServerTags.NAME, v, overwrite); 270 } 271 275 public void setName(String v) { 276 setAttributeValue(ServerTags.NAME, v); 277 } 278 282 public String getContextRoot() { 283 return getAttributeValue(ServerTags.CONTEXT_ROOT); 284 } 285 290 public void setContextRoot(String v, boolean overwrite) throws StaleWriteConfigException { 291 setAttributeValue(ServerTags.CONTEXT_ROOT, v, overwrite); 292 } 293 297 public void setContextRoot(String v) { 298 setAttributeValue(ServerTags.CONTEXT_ROOT, v); 299 } 300 304 public String getLocation() { 305 return getAttributeValue(ServerTags.LOCATION); 306 } 307 312 public void setLocation(String v, boolean overwrite) throws StaleWriteConfigException { 313 setAttributeValue(ServerTags.LOCATION, v, overwrite); 314 } 315 319 public void setLocation(String v) { 320 setAttributeValue(ServerTags.LOCATION, v); 321 } 322 326 public String getObjectType() { 327 return getAttributeValue(ServerTags.OBJECT_TYPE); 328 } 329 334 public void setObjectType(String v, boolean overwrite) throws StaleWriteConfigException { 335 setAttributeValue(ServerTags.OBJECT_TYPE, v, overwrite); 336 } 337 341 public void setObjectType(String v) { 342 setAttributeValue(ServerTags.OBJECT_TYPE, v); 343 } 344 347 public static String getDefaultObjectType() { 348 return "user".trim(); 349 } 350 354 public boolean isEnabled() { 355 return toBoolean(getAttributeValue(ServerTags.ENABLED)); 356 } 357 362 public void setEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException { 363 setAttributeValue(ServerTags.ENABLED, ""+(v==true), overwrite); 364 } 365 369 public void setEnabled(boolean v) { 370 setAttributeValue(ServerTags.ENABLED, ""+(v==true)); 371 } 372 375 public static String getDefaultEnabled() { 376 return "true".trim(); 377 } 378 382 public String getLibraries() { 383 return getAttributeValue(ServerTags.LIBRARIES); 384 } 385 390 public void setLibraries(String v, boolean overwrite) throws StaleWriteConfigException { 391 setAttributeValue(ServerTags.LIBRARIES, v, overwrite); 392 } 393 397 public void setLibraries(String v) { 398 setAttributeValue(ServerTags.LIBRARIES, v); 399 } 400 404 public boolean isAvailabilityEnabled() { 405 return toBoolean(getAttributeValue(ServerTags.AVAILABILITY_ENABLED)); 406 } 407 412 public void setAvailabilityEnabled(boolean v, boolean overwrite) throws StaleWriteConfigException { 413 setAttributeValue(ServerTags.AVAILABILITY_ENABLED, ""+(v==true), overwrite); 414 } 415 419 public void setAvailabilityEnabled(boolean v) { 420 setAttributeValue(ServerTags.AVAILABILITY_ENABLED, ""+(v==true)); 421 } 422 425 public static String getDefaultAvailabilityEnabled() { 426 return "false".trim(); 427 } 428 432 public boolean isDirectoryDeployed() { 433 return toBoolean(getAttributeValue(ServerTags.DIRECTORY_DEPLOYED)); 434 } 435 440 public void setDirectoryDeployed(boolean v, boolean overwrite) throws StaleWriteConfigException { 441 setAttributeValue(ServerTags.DIRECTORY_DEPLOYED, ""+(v==true), overwrite); 442 } 443 447 public void setDirectoryDeployed(boolean v) { 448 setAttributeValue(ServerTags.DIRECTORY_DEPLOYED, ""+(v==true)); 449 } 450 453 public static String getDefaultDirectoryDeployed() { 454 return "false".trim(); 455 } 456 460 public WebServiceEndpoint newWebServiceEndpoint() { 461 return new WebServiceEndpoint(); 462 } 463 464 468 public ElementProperty newElementProperty() { 469 return new ElementProperty(); 470 } 471 472 477 protected String getRelativeXPath() { 478 String ret = null; 479 ret = "web-module" + (canHaveSiblings() ? "[@name='" + getAttributeValue("name") +"']" : "") ; 480 return (null != ret ? ret.trim() : null); 481 } 482 483 486 public static String getDefaultAttributeValue(String attr) { 487 if(attr == null) return null; 488 attr = attr.trim(); 489 if(attr.equals(ServerTags.OBJECT_TYPE)) return "user".trim(); 490 if(attr.equals(ServerTags.ENABLED)) return "true".trim(); 491 if(attr.equals(ServerTags.AVAILABILITY_ENABLED)) return "false".trim(); 492 if(attr.equals(ServerTags.DIRECTORY_DEPLOYED)) return "false".trim(); 493 return null; 494 } 495 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 497 comparators.add(c); 498 } 499 500 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 502 comparators.remove(c); 503 } 504 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 505 } 506 507 public void dump(StringBuffer str, String indent){ 509 String s; 510 Object o; 511 org.netbeans.modules.schema2beans.BaseBean n; 512 str.append(indent); 513 str.append("Description"); str.append(indent+"\t"); str.append("<"); o = this.getDescription(); 517 str.append((o==null?"null":o.toString().trim())); str.append(">\n"); this.dumpAttributes(DESCRIPTION, 0, str, indent); 520 521 str.append(indent); 522 str.append("WebServiceEndpoint["+this.sizeWebServiceEndpoint()+"]"); for(int i=0; i<this.sizeWebServiceEndpoint(); i++) 524 { 525 str.append(indent+"\t"); 526 str.append("#"+i+":"); 527 n = (org.netbeans.modules.schema2beans.BaseBean) this.getWebServiceEndpoint(i); 528 if (n != null) 529 n.dump(str, indent + "\t"); else 531 str.append(indent+"\tnull"); this.dumpAttributes(WEB_SERVICE_ENDPOINT, i, str, indent); 533 } 534 535 str.append(indent); 536 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 538 { 539 str.append(indent+"\t"); 540 str.append("#"+i+":"); 541 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 542 if (n != null) 543 n.dump(str, indent + "\t"); else 545 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 547 } 548 549 } 550 public String dumpBeanNode(){ 551 StringBuffer str = new StringBuffer (); 552 str.append("WebModule\n"); this.dump(str, "\n "); return str.toString(); 555 }} 556 557 559 | Popular Tags |