1 6 7 package com.sun.enterprise.tools.common.dd.webapp; 8 9 import org.w3c.dom.*; 10 import org.netbeans.modules.schema2beans.*; 11 import java.beans.*; 12 import java.util.*; 13 14 16 public class CacheMapping extends com.sun.enterprise.tools.common.dd.SunBaseBean 17 { 18 19 static Vector comparators = new Vector(); 20 21 static public final String SERVLET_NAME = "ServletName"; static public final String URL_PATTERN = "UrlPattern"; static public final String CACHE_HELPER_REF = "CacheHelperRef"; static public final String DISPATCHER = "Dispatcher"; static public final String TIMEOUT = "Timeout"; static public final String TIMEOUTNAME = "TimeoutName"; static public final String TIMEOUTSCOPE = "TimeoutScope"; static public final String REFRESH_FIELD = "RefreshField"; static public final String REFRESHFIELDNAME = "RefreshFieldName"; static public final String REFRESHFIELDSCOPE = "RefreshFieldScope"; static public final String HTTP_METHOD = "HttpMethod"; static public final String KEY_FIELD = "KeyField"; static public final String KEYFIELDNAME = "KeyFieldName"; static public final String KEYFIELDSCOPE = "KeyFieldScope"; static public final String CONSTRAINT_FIELD = "ConstraintField"; 37 public CacheMapping() { 38 this(Common.USE_DEFAULT_VALUES); 39 } 40 41 public CacheMapping(int options) 42 { 43 super(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 44 this.createProperty("servlet-name", SERVLET_NAME, Common.SEQUENCE_OR | 47 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY, 48 String .class); 49 this.createProperty("url-pattern", URL_PATTERN, Common.SEQUENCE_OR | 51 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY, 52 String .class); 53 this.createProperty("cache-helper-ref", CACHE_HELPER_REF, Common.SEQUENCE_OR | 55 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY, 56 String .class); 57 this.createProperty("dispatcher", DISPATCHER, 59 Common.TYPE_0_N | Common.TYPE_STRING | Common.TYPE_KEY, 60 String .class); 61 this.createProperty("timeout", TIMEOUT, 63 Common.TYPE_0_1 | Common.TYPE_STRING | Common.TYPE_KEY, 64 String .class); 65 this.createAttribute(TIMEOUT, "name", "Name", 66 AttrProp.CDATA | AttrProp.IMPLIED, 67 null, null); 68 this.createAttribute(TIMEOUT, "scope", "Scope", 69 AttrProp.CDATA, 70 null, "request.attribute"); 71 this.createProperty("refresh-field", REFRESH_FIELD, 73 Common.TYPE_0_1 | Common.TYPE_BOOLEAN | Common.TYPE_KEY, 74 Boolean .class); 75 this.createAttribute(REFRESH_FIELD, "name", "Name", 76 AttrProp.CDATA | AttrProp.REQUIRED, 77 null, null); 78 this.createAttribute(REFRESH_FIELD, "scope", "Scope", 79 AttrProp.CDATA, 80 null, "request.parameter"); 81 this.createProperty("http-method", HTTP_METHOD, 83 Common.TYPE_0_N | Common.TYPE_STRING | Common.TYPE_KEY, 84 String .class); 85 this.createProperty("key-field", KEY_FIELD, 87 Common.TYPE_0_N | Common.TYPE_BOOLEAN | Common.TYPE_KEY, 88 Boolean .class); 89 this.createAttribute(KEY_FIELD, "name", "Name", 90 AttrProp.CDATA | AttrProp.REQUIRED, 91 null, null); 92 this.createAttribute(KEY_FIELD, "scope", "Scope", 93 AttrProp.CDATA, 94 null, "request.parameter"); 95 this.createProperty("constraint-field", CONSTRAINT_FIELD, 97 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 98 ConstraintField.class); 99 this.createAttribute(CONSTRAINT_FIELD, "name", "Name", 100 AttrProp.CDATA | AttrProp.REQUIRED, 101 null, null); 102 this.createAttribute(CONSTRAINT_FIELD, "scope", "Scope", 103 AttrProp.CDATA, 104 null, "request.parameter"); 105 this.createAttribute(CONSTRAINT_FIELD, "cache-on-match", "CacheOnMatch", 106 AttrProp.CDATA, 107 null, "true"); 108 this.createAttribute(CONSTRAINT_FIELD, "cache-on-match-failure", "CacheOnMatchFailure", 109 AttrProp.CDATA, 110 null, "false"); 111 this.initialize(options); 112 } 113 114 void initialize(int options) 116 { 117 118 } 119 120 public void setServletName(String value) { 122 this.setValue(SERVLET_NAME, value); 123 } 124 125 public String getServletName() { 127 return (String )this.getValue(SERVLET_NAME); 128 } 129 130 public void setUrlPattern(String value) { 132 this.setValue(URL_PATTERN, value); 133 } 134 135 public String getUrlPattern() { 137 return (String )this.getValue(URL_PATTERN); 138 } 139 140 public void setCacheHelperRef(String value) { 142 this.setValue(CACHE_HELPER_REF, value); 143 } 144 145 public String getCacheHelperRef() { 147 return (String )this.getValue(CACHE_HELPER_REF); 148 } 149 150 public void setDispatcher(int index, String value) { 152 this.setValue(DISPATCHER, index, value); 153 } 154 155 public String getDispatcher(int index) { 157 return (String )this.getValue(DISPATCHER, index); 158 } 159 160 public void setDispatcher(String [] value) { 162 this.setValue(DISPATCHER, value); 163 } 164 165 public String [] getDispatcher() { 167 return (String [])this.getValues(DISPATCHER); 168 } 169 170 public int sizeDispatcher() { 172 return this.size(DISPATCHER); 173 } 174 175 public int addDispatcher(String value) { 177 return this.addValue(DISPATCHER, value); 178 } 179 180 public int removeDispatcher(String value) { 185 return this.removeValue(DISPATCHER, value); 186 } 187 188 public void setTimeout(String value) { 190 this.setValue(TIMEOUT, value); 191 } 192 193 public String getTimeout() { 195 return (String )this.getValue(TIMEOUT); 196 } 197 198 public void setTimeoutName(java.lang.String value) { 200 if (size(TIMEOUT) == 0) { 202 setValue(TIMEOUT, ""); 203 } 204 setAttributeValue(TIMEOUT, "Name", value); 205 } 206 207 public java.lang.String getTimeoutName() { 209 if (size(TIMEOUT) == 0) { 211 return null; 212 } else { 213 return getAttributeValue(TIMEOUT, "Name"); 214 } 215 } 216 217 public void setTimeoutScope(java.lang.String value) { 219 if (size(TIMEOUT) == 0) { 221 setValue(TIMEOUT, ""); 222 } 223 setAttributeValue(TIMEOUT, "Scope", value); 224 } 225 226 public java.lang.String getTimeoutScope() { 228 if (size(TIMEOUT) == 0) { 230 return null; 231 } else { 232 return getAttributeValue(TIMEOUT, "Scope"); 233 } 234 } 235 236 public void setRefreshField(boolean value) { 238 this.setValue(REFRESH_FIELD, (value ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE)); 239 } 240 241 public boolean isRefreshField() { 243 Boolean ret = (Boolean )this.getValue(REFRESH_FIELD); 244 if (ret == null) 245 ret = (Boolean )Common.defaultScalarValue(Common.TYPE_BOOLEAN); 246 return ((java.lang.Boolean )ret).booleanValue(); 247 } 248 249 public void setRefreshFieldName(java.lang.String value) { 251 if (size(REFRESH_FIELD) == 0) { 253 setValue(REFRESH_FIELD, ""); 254 } 255 setAttributeValue(REFRESH_FIELD, "Name", value); 256 } 257 258 public java.lang.String getRefreshFieldName() { 260 if (size(REFRESH_FIELD) == 0) { 262 return null; 263 } else { 264 return getAttributeValue(REFRESH_FIELD, "Name"); 265 } 266 } 267 268 public void setRefreshFieldScope(java.lang.String value) { 270 if (size(REFRESH_FIELD) == 0) { 272 setValue(REFRESH_FIELD, ""); 273 } 274 setAttributeValue(REFRESH_FIELD, "Scope", value); 275 } 276 277 public java.lang.String getRefreshFieldScope() { 279 if (size(REFRESH_FIELD) == 0) { 281 return null; 282 } else { 283 return getAttributeValue(REFRESH_FIELD, "Scope"); 284 } 285 } 286 287 public void setHttpMethod(int index, String value) { 289 this.setValue(HTTP_METHOD, index, value); 290 } 291 292 public String getHttpMethod(int index) { 294 return (String )this.getValue(HTTP_METHOD, index); 295 } 296 297 public void setHttpMethod(String [] value) { 299 this.setValue(HTTP_METHOD, value); 300 } 301 302 public String [] getHttpMethod() { 304 return (String [])this.getValues(HTTP_METHOD); 305 } 306 307 public int sizeHttpMethod() { 309 return this.size(HTTP_METHOD); 310 } 311 312 public int addHttpMethod(String value) { 314 return this.addValue(HTTP_METHOD, value); 315 } 316 317 public int removeHttpMethod(String value) { 322 return this.removeValue(HTTP_METHOD, value); 323 } 324 325 public void setKeyField(int index, boolean value) { 327 this.setValue(KEY_FIELD, index, (value ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE)); 328 } 329 330 public boolean isKeyField(int index) { 332 Boolean ret = (Boolean )this.getValue(KEY_FIELD, index); 333 if (ret == null) 334 ret = (Boolean )Common.defaultScalarValue(Common.TYPE_BOOLEAN); 335 return ((java.lang.Boolean )ret).booleanValue(); 336 } 337 338 public void setKeyField(boolean[] value) { 340 Boolean [] values = null; 341 if (value != null) 342 { 343 values = new Boolean [value.length]; 344 for (int i=0; i<value.length; i++) 345 values[i] = new Boolean (value[i]); 346 } 347 this.setValue(KEY_FIELD, values); 348 } 349 350 public boolean[] getKeyField() { 352 boolean[] ret = null; 353 Boolean [] values = (Boolean [])this.getValues(KEY_FIELD); 354 if (values != null) 355 { 356 ret = new boolean[values.length]; 357 for (int i=0; i<values.length; i++) 358 ret[i] = values[i].booleanValue(); 359 } 360 return ret; 361 } 362 363 public int sizeKeyField() { 365 return this.size(KEY_FIELD); 366 } 367 368 public int addKeyField(boolean value) { 370 return this.addValue(KEY_FIELD, (value ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE)); 371 } 372 373 public int removeKeyField(boolean value) { 378 return this.removeValue(KEY_FIELD, (value ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE)); 379 } 380 381 public void removeKeyField(int index) { 385 this.removeValue(KEY_FIELD, index); 386 } 387 388 public void setKeyFieldName(int index, java.lang.String value) { 390 if (size(KEY_FIELD) == 0) { 392 addValue(KEY_FIELD, ""); 393 } 394 setAttributeValue(KEY_FIELD, index, "Name", value); 395 } 396 397 public java.lang.String getKeyFieldName(int index) { 399 if (size(KEY_FIELD) == 0) { 401 return null; 402 } else { 403 return getAttributeValue(KEY_FIELD, index, "Name"); 404 } 405 } 406 407 public void setKeyFieldScope(int index, java.lang.String value) { 409 if (size(KEY_FIELD) == 0) { 411 addValue(KEY_FIELD, ""); 412 } 413 setAttributeValue(KEY_FIELD, index, "Scope", value); 414 } 415 416 public java.lang.String getKeyFieldScope(int index) { 418 if (size(KEY_FIELD) == 0) { 420 return null; 421 } else { 422 return getAttributeValue(KEY_FIELD, index, "Scope"); 423 } 424 } 425 426 public void setConstraintField(int index, ConstraintField value) { 428 this.setValue(CONSTRAINT_FIELD, index, value); 429 } 430 431 public ConstraintField getConstraintField(int index) { 433 return (ConstraintField)this.getValue(CONSTRAINT_FIELD, index); 434 } 435 436 public void setConstraintField(ConstraintField[] value) { 438 this.setValue(CONSTRAINT_FIELD, value); 439 } 440 441 public ConstraintField[] getConstraintField() { 443 return (ConstraintField[])this.getValues(CONSTRAINT_FIELD); 444 } 445 446 public int sizeConstraintField() { 448 return this.size(CONSTRAINT_FIELD); 449 } 450 451 public int addConstraintField(com.sun.enterprise.tools.common.dd.webapp.ConstraintField value) { 453 return this.addValue(CONSTRAINT_FIELD, value); 454 } 455 456 public int removeConstraintField(com.sun.enterprise.tools.common.dd.webapp.ConstraintField value) { 461 return this.removeValue(CONSTRAINT_FIELD, value); 462 } 463 464 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 466 comparators.add(c); 467 } 468 469 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 471 comparators.remove(c); 472 } 473 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 474 boolean restrictionFailure = false; 475 if (getServletName() != null) { 477 } 478 int orCount = 0; 479 if (getServletName() != null) { 480 ++orCount; 481 } 482 if (getUrlPattern() != null) { 484 } 485 if (getUrlPattern() != null) { 486 ++orCount; 487 } 488 if (getCacheHelperRef() != null) { 490 } 491 if (getCacheHelperRef() != null) { 492 ++orCount; 493 } 494 for (int _index = 0; _index < sizeDispatcher(); ++_index) { 496 String element = getDispatcher(_index); 497 if (element != null) { 498 } 499 } 500 if (getTimeout() != null) { 502 } 503 if (getTimeoutName() != null) { 505 } 506 if (getTimeoutScope() == null) { 508 throw new org.netbeans.modules.schema2beans.ValidateException("getTimeoutScope() == null", "timeoutScope", this); } 510 if (getRefreshFieldName() == null) { 513 throw new org.netbeans.modules.schema2beans.ValidateException("getRefreshFieldName() == null", "refreshFieldName", this); } 515 if (getRefreshFieldScope() == null) { 517 throw new org.netbeans.modules.schema2beans.ValidateException("getRefreshFieldScope() == null", "refreshFieldScope", this); } 519 for (int _index = 0; _index < sizeHttpMethod(); ++_index) { 521 String element = getHttpMethod(_index); 522 if (element != null) { 523 } 524 } 525 for (int _index = 0; _index < sizeKeyField(); ++_index) { 527 boolean element = isKeyField(_index); 528 } 529 for (int _index = 0; _index < sizeConstraintField(); ++_index) { 533 com.sun.enterprise.tools.common.dd.webapp.ConstraintField element = getConstraintField(_index); 534 if (element != null) { 535 element.validate(); 536 } 537 } 538 if (orCount != 1) { 539 throw new org.netbeans.modules.schema2beans.ValidateException("orCount ("+orCount+") != 1", "mutually exclusive properties", this); } 541 } 542 543 public void dump(StringBuffer str, String indent){ 545 String s; 546 Object o; 547 org.netbeans.modules.schema2beans.BaseBean n; 548 str.append(indent); 549 str.append("ServletName"); str.append(indent+"\t"); str.append("<"); s = this.getServletName(); 553 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(SERVLET_NAME, 0, str, indent); 556 557 str.append(indent); 558 str.append("UrlPattern"); str.append(indent+"\t"); str.append("<"); s = this.getUrlPattern(); 562 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(URL_PATTERN, 0, str, indent); 565 566 str.append(indent); 567 str.append("CacheHelperRef"); str.append(indent+"\t"); str.append("<"); s = this.getCacheHelperRef(); 571 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(CACHE_HELPER_REF, 0, str, indent); 574 575 str.append(indent); 576 str.append("Dispatcher["+this.sizeDispatcher()+"]"); for(int i=0; i<this.sizeDispatcher(); i++) 578 { 579 str.append(indent+"\t"); 580 str.append("#"+i+":"); 581 str.append(indent+"\t"); str.append("<"); s = this.getDispatcher(i); 584 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(DISPATCHER, i, str, indent); 587 } 588 589 str.append(indent); 590 str.append("Timeout"); str.append(indent+"\t"); str.append("<"); s = this.getTimeout(); 594 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(TIMEOUT, 0, str, indent); 597 598 str.append(indent); 599 str.append("RefreshField"); str.append(indent+"\t"); str.append((this.isRefreshField()?"true":"false")); 602 this.dumpAttributes(REFRESH_FIELD, 0, str, indent); 603 604 str.append(indent); 605 str.append("HttpMethod["+this.sizeHttpMethod()+"]"); for(int i=0; i<this.sizeHttpMethod(); i++) 607 { 608 str.append(indent+"\t"); 609 str.append("#"+i+":"); 610 str.append(indent+"\t"); str.append("<"); s = this.getHttpMethod(i); 613 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(HTTP_METHOD, i, str, indent); 616 } 617 618 str.append(indent); 619 str.append("KeyField["+this.sizeKeyField()+"]"); for(int i=0; i<this.sizeKeyField(); i++) 621 { 622 str.append(indent+"\t"); 623 str.append("#"+i+":"); 624 str.append(indent+"\t"); str.append((this.isKeyField(i)?"true":"false")); 626 this.dumpAttributes(KEY_FIELD, i, str, indent); 627 } 628 629 str.append(indent); 630 str.append("ConstraintField["+this.sizeConstraintField()+"]"); for(int i=0; i<this.sizeConstraintField(); i++) 632 { 633 str.append(indent+"\t"); 634 str.append("#"+i+":"); 635 n = (org.netbeans.modules.schema2beans.BaseBean) this.getConstraintField(i); 636 if (n != null) 637 n.dump(str, indent + "\t"); else 639 str.append(indent+"\tnull"); this.dumpAttributes(CONSTRAINT_FIELD, i, str, indent); 641 } 642 643 } 644 public String dumpBeanNode(){ 645 StringBuffer str = new StringBuffer (); 646 str.append("CacheMapping\n"); this.dump(str, "\n "); return str.toString(); 649 }} 650 651 653 654 676 | Popular Tags |