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 VirtualServer 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 HTTP_ACCESS_LOG = "HttpAccessLog"; 50 static public final String ELEMENT_PROPERTY = "ElementProperty"; 51 52 public VirtualServer() { 53 this(Common.USE_DEFAULT_VALUES); 54 } 55 56 public VirtualServer(int options) 57 { 58 super(comparators, runtimeVersion); 59 initPropertyTables(2); 61 this.createProperty("http-access-log", HTTP_ACCESS_LOG, 62 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 63 HttpAccessLog.class); 64 this.createAttribute(HTTP_ACCESS_LOG, "log-directory", "LogDirectory", 65 AttrProp.CDATA, 66 null, "${com.sun.aas.instanceRoot}/logs/access"); 67 this.createAttribute(HTTP_ACCESS_LOG, "iponly", "Iponly", 68 AttrProp.CDATA, 69 null, "true"); 70 this.createProperty("property", ELEMENT_PROPERTY, 71 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 72 ElementProperty.class); 73 this.createAttribute(ELEMENT_PROPERTY, "name", "Name", 74 AttrProp.CDATA | AttrProp.REQUIRED, 75 null, null); 76 this.createAttribute(ELEMENT_PROPERTY, "value", "Value", 77 AttrProp.CDATA | AttrProp.REQUIRED, 78 null, null); 79 this.initialize(options); 80 } 81 82 void initialize(int options) { 84 85 } 86 87 public void setHttpAccessLog(HttpAccessLog value) { 89 this.setValue(HTTP_ACCESS_LOG, value); 90 } 91 92 public HttpAccessLog getHttpAccessLog() { 94 return (HttpAccessLog)this.getValue(HTTP_ACCESS_LOG); 95 } 96 97 public void setElementProperty(int index, ElementProperty value) { 99 this.setValue(ELEMENT_PROPERTY, index, value); 100 } 101 102 public ElementProperty getElementProperty(int index) { 104 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 105 } 106 107 public void setElementProperty(ElementProperty[] value) { 109 this.setValue(ELEMENT_PROPERTY, value); 110 } 111 112 public ElementProperty[] getElementProperty() { 114 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 115 } 116 117 public int sizeElementProperty() { 119 return this.size(ELEMENT_PROPERTY); 120 } 121 122 public int addElementProperty(ElementProperty value) 124 throws ConfigException{ 125 return addElementProperty(value, true); 126 } 127 128 public int addElementProperty(ElementProperty value, boolean overwrite) 130 throws ConfigException{ 131 ElementProperty old = getElementPropertyByName(value.getName()); 132 if(old != null) { 133 throw new ConfigException(StringManager.getManager(VirtualServer.class).getString("cannotAddDuplicate", "ElementProperty")); 134 } 135 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 136 } 137 138 public int removeElementProperty(ElementProperty value){ 143 return this.removeValue(ELEMENT_PROPERTY, value); 144 } 145 146 public int removeElementProperty(ElementProperty value, boolean overwrite) 152 throws StaleWriteConfigException{ 153 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 154 } 155 156 public ElementProperty getElementPropertyByName(String id) { 157 if (null != id) { id = id.trim(); } 158 ElementProperty[] o = getElementProperty(); 159 if (o == null) return null; 160 161 for (int i=0; i < o.length; i++) { 162 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 163 return o[i]; 164 } 165 } 166 167 return null; 168 169 } 170 174 public String getId() { 175 return getAttributeValue(ServerTags.ID); 176 } 177 182 public void setId(String v, boolean overwrite) throws StaleWriteConfigException { 183 setAttributeValue(ServerTags.ID, v, overwrite); 184 } 185 189 public void setId(String v) { 190 setAttributeValue(ServerTags.ID, v); 191 } 192 196 public String getHttpListeners() { 197 return getAttributeValue(ServerTags.HTTP_LISTENERS); 198 } 199 204 public void setHttpListeners(String v, boolean overwrite) throws StaleWriteConfigException { 205 setAttributeValue(ServerTags.HTTP_LISTENERS, v, overwrite); 206 } 207 211 public void setHttpListeners(String v) { 212 setAttributeValue(ServerTags.HTTP_LISTENERS, v); 213 } 214 218 public String getDefaultWebModule() { 219 return getAttributeValue(ServerTags.DEFAULT_WEB_MODULE); 220 } 221 226 public void setDefaultWebModule(String v, boolean overwrite) throws StaleWriteConfigException { 227 setAttributeValue(ServerTags.DEFAULT_WEB_MODULE, v, overwrite); 228 } 229 233 public void setDefaultWebModule(String v) { 234 setAttributeValue(ServerTags.DEFAULT_WEB_MODULE, v); 235 } 236 240 public String getHosts() { 241 return getAttributeValue(ServerTags.HOSTS); 242 } 243 248 public void setHosts(String v, boolean overwrite) throws StaleWriteConfigException { 249 setAttributeValue(ServerTags.HOSTS, v, overwrite); 250 } 251 255 public void setHosts(String v) { 256 setAttributeValue(ServerTags.HOSTS, v); 257 } 258 262 public String getState() { 263 return getAttributeValue(ServerTags.STATE); 264 } 265 270 public void setState(String v, boolean overwrite) throws StaleWriteConfigException { 271 setAttributeValue(ServerTags.STATE, v, overwrite); 272 } 273 277 public void setState(String v) { 278 setAttributeValue(ServerTags.STATE, v); 279 } 280 283 public static String getDefaultState() { 284 return "on".trim(); 285 } 286 290 public String getDocroot() { 291 return getAttributeValue(ServerTags.DOCROOT); 292 } 293 298 public void setDocroot(String v, boolean overwrite) throws StaleWriteConfigException { 299 setAttributeValue(ServerTags.DOCROOT, v, overwrite); 300 } 301 305 public void setDocroot(String v) { 306 setAttributeValue(ServerTags.DOCROOT, v); 307 } 308 312 public String getLogFile() { 313 return getAttributeValue(ServerTags.LOG_FILE); 314 } 315 320 public void setLogFile(String v, boolean overwrite) throws StaleWriteConfigException { 321 setAttributeValue(ServerTags.LOG_FILE, v, overwrite); 322 } 323 327 public void setLogFile(String v) { 328 setAttributeValue(ServerTags.LOG_FILE, v); 329 } 330 333 public static String getDefaultLogFile() { 334 return "${com.sun.aas.instanceRoot}/logs/server.log".trim(); 335 } 336 340 public HttpAccessLog newHttpAccessLog() { 341 return new HttpAccessLog(); 342 } 343 344 348 public ElementProperty newElementProperty() { 349 return new ElementProperty(); 350 } 351 352 357 protected String getRelativeXPath() { 358 String ret = null; 359 ret = "virtual-server" + (canHaveSiblings() ? "[@id='" + getAttributeValue("id") +"']" : "") ; 360 return (null != ret ? ret.trim() : null); 361 } 362 363 366 public static String getDefaultAttributeValue(String attr) { 367 if(attr == null) return null; 368 attr = attr.trim(); 369 if(attr.equals(ServerTags.STATE)) return "on".trim(); 370 if(attr.equals(ServerTags.LOG_FILE)) return "${com.sun.aas.instanceRoot}/logs/server.log".trim(); 371 return null; 372 } 373 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 375 comparators.add(c); 376 } 377 378 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 380 comparators.remove(c); 381 } 382 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 383 } 384 385 public void dump(StringBuffer str, String indent){ 387 String s; 388 Object o; 389 org.netbeans.modules.schema2beans.BaseBean n; 390 str.append(indent); 391 str.append("HttpAccessLog"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getHttpAccessLog(); 393 if (n != null) 394 n.dump(str, indent + "\t"); else 396 str.append(indent+"\tnull"); this.dumpAttributes(HTTP_ACCESS_LOG, 0, str, indent); 398 399 str.append(indent); 400 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 402 { 403 str.append(indent+"\t"); 404 str.append("#"+i+":"); 405 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 406 if (n != null) 407 n.dump(str, indent + "\t"); else 409 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 411 } 412 413 } 414 public String dumpBeanNode(){ 415 StringBuffer str = new StringBuffer (); 416 str.append("VirtualServer\n"); this.dump(str, "\n "); return str.toString(); 419 }} 420 421 423 | Popular Tags |