1 18 19 package org.apache.struts.config; 20 21 import java.io.Serializable ; 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 25 26 34 public class ActionConfig implements Serializable { 35 36 37 39 40 43 protected boolean configured = false; 44 45 46 50 protected HashMap exceptions = new HashMap (); 51 52 53 57 protected HashMap forwards = new HashMap (); 58 59 60 62 63 66 protected ModuleConfig moduleConfig = null; 67 68 71 public ModuleConfig getModuleConfig() { 72 return (this.moduleConfig); 73 } 74 75 78 public void setModuleConfig(ModuleConfig moduleConfig) { 79 if (configured) { 80 throw new IllegalStateException ("Configuration is frozen"); 81 } 82 83 this.moduleConfig = moduleConfig; 84 } 85 86 87 92 protected String attribute = null; 93 94 100 public String getAttribute() { 101 if (this.attribute == null) { 102 return (this.name); 103 } else { 104 return (this.attribute); 105 } 106 } 107 108 115 public void setAttribute(String attribute) { 116 if (configured) { 117 throw new IllegalStateException ("Configuration is frozen"); 118 } 119 this.attribute = attribute; 120 } 121 122 123 130 protected String forward = null; 131 132 138 public String getForward() { 139 return (this.forward); 140 } 141 142 150 public void setForward(String forward) { 151 if (configured) { 152 throw new IllegalStateException ("Configuration is frozen"); 153 } 154 this.forward = forward; 155 } 156 157 158 165 protected String include = null; 166 167 173 public String getInclude() { 174 return (this.include); 175 } 176 177 185 public void setInclude(String include) { 186 if (configured) { 187 throw new IllegalStateException ("Configuration is frozen"); 188 } 189 this.include = include; 190 } 191 192 193 198 protected String input = null; 199 200 206 public String getInput() { 207 return (this.input); 208 } 209 210 217 public void setInput(String input) { 218 if (configured) { 219 throw new IllegalStateException ("Configuration is frozen"); 220 } 221 this.input = input; 222 } 223 224 225 230 protected String multipartClass = null; 231 232 237 public String getMultipartClass() { 238 return (this.multipartClass); 239 } 240 241 248 public void setMultipartClass(String multipartClass) { 249 if (configured) { 250 throw new IllegalStateException ("Configuration is frozen"); 251 } 252 this.multipartClass = multipartClass; 253 } 254 255 256 259 protected String name = null; 260 261 264 public String getName() { 265 return (this.name); 266 } 267 268 271 public void setName(String name) { 272 if (configured) { 273 throw new IllegalStateException ("Configuration is frozen"); 274 } 275 this.name = name; 276 } 277 278 279 284 protected String parameter = null; 285 286 291 public String getParameter() { 292 return (this.parameter); 293 } 294 295 301 public void setParameter(String parameter) { 302 if (configured) { 303 throw new IllegalStateException ("Configuration is frozen"); 304 } 305 this.parameter = parameter; 306 } 307 308 309 314 protected String path = null; 315 316 321 public String getPath() { 322 return (this.path); 323 } 324 325 331 public void setPath(String path) { 332 if (configured) { 333 throw new IllegalStateException ("Configuration is frozen"); 334 } 335 this.path = path; 336 } 337 338 339 343 protected String prefix = null; 344 345 349 public String getPrefix() { 350 return (this.prefix); 351 } 352 353 357 public void setPrefix(String prefix) { 358 if (configured) { 359 throw new IllegalStateException ("Configuration is frozen"); 360 } 361 this.prefix = prefix; 362 } 363 364 365 369 protected String roles = null; 370 371 public String getRoles() { 372 return (this.roles); 373 } 374 375 public void setRoles(String roles) { 376 if (configured) { 377 throw new IllegalStateException ("Configuration is frozen"); 378 } 379 this.roles = roles; 380 if (roles == null) { 381 roleNames = new String [0]; 382 return; 383 } 384 ArrayList list = new ArrayList (); 385 while (true) { 386 int comma = roles.indexOf(','); 387 if (comma < 0) 388 break; 389 list.add(roles.substring(0, comma).trim()); 390 roles = roles.substring(comma + 1); 391 } 392 roles = roles.trim(); 393 if (roles.length() > 0) 394 list.add(roles); 395 roleNames = (String []) list.toArray(new String [list.size()]); 396 } 397 398 399 403 protected String [] roleNames = new String [0]; 404 405 409 public String [] getRoleNames() { 410 return (this.roleNames); 411 } 412 413 414 418 protected String scope = "session"; 419 420 424 public String getScope() { 425 return (this.scope); 426 } 427 428 432 public void setScope(String scope) { 433 if (configured) { 434 throw new IllegalStateException ("Configuration is frozen"); 435 } 436 this.scope = scope; 437 } 438 439 440 444 protected String suffix = null; 445 446 450 public String getSuffix() { 451 return (this.suffix); 452 } 453 454 458 public void setSuffix(String suffix) { 459 if (configured) { 460 throw new IllegalStateException ("Configuration is frozen"); 461 } 462 this.suffix = suffix; 463 } 464 465 466 473 protected String type = null; 474 475 public String getType() { 476 return (this.type); 477 } 478 479 public void setType(String type) { 480 if (configured) { 481 throw new IllegalStateException ("Configuration is frozen"); 482 } 483 this.type = type; 484 } 485 486 487 491 protected boolean unknown = false; 492 493 497 public boolean getUnknown() { 498 return (this.unknown); 499 } 500 501 505 public void setUnknown(boolean unknown) { 506 if (configured) { 507 throw new IllegalStateException ("Configuration is frozen"); 508 } 509 this.unknown = unknown; 510 } 511 512 516 protected boolean validate = true; 517 518 public boolean getValidate() { 519 return (this.validate); 520 } 521 522 public void setValidate(boolean validate) { 523 if (configured) { 524 throw new IllegalStateException ("Configuration is frozen"); 525 } 526 this.validate = validate; 527 } 528 529 530 532 533 542 public void addExceptionConfig(ExceptionConfig config) { 543 544 if (configured) { 545 throw new IllegalStateException ("Configuration is frozen"); 546 } 547 exceptions.put(config.getType(), config); 548 549 } 550 551 552 561 public void addForwardConfig(ForwardConfig config) { 562 563 if (configured) { 564 throw new IllegalStateException ("Configuration is frozen"); 565 } 566 forwards.put(config.getName(), config); 567 568 } 569 570 571 577 public ExceptionConfig findExceptionConfig(String type) { 578 579 return ((ExceptionConfig) exceptions.get(type)); 580 581 } 582 583 584 588 public ExceptionConfig[] findExceptionConfigs() { 589 590 ExceptionConfig results[] = new ExceptionConfig[exceptions.size()]; 591 return ((ExceptionConfig[]) exceptions.values().toArray(results)); 592 593 } 594 595 609 public ExceptionConfig findException(Class type) { 610 611 ExceptionConfig config = null; 613 while (true) { 614 615 String name = type.getName(); 617 config = findExceptionConfig(name); 618 if (config != null) { 619 return (config); 620 } 621 622 config = getModuleConfig().findExceptionConfig(name); 624 if (config != null) { 625 return (config); 626 } 627 628 type = type.getSuperclass(); 630 if (type == null) { 631 break; 632 } 633 634 } 635 return (null); 637 } 638 639 640 641 647 public ForwardConfig findForwardConfig(String name) { 648 649 return ((ForwardConfig) forwards.get(name)); 650 651 } 652 653 654 658 public ForwardConfig[] findForwardConfigs() { 659 660 ForwardConfig results[] = new ForwardConfig[forwards.size()]; 661 return ((ForwardConfig[]) forwards.values().toArray(results)); 662 663 } 664 665 666 669 public void freeze() { 670 671 configured = true; 672 673 ExceptionConfig[] econfigs = findExceptionConfigs(); 674 for (int i = 0; i < econfigs.length; i++) { 675 econfigs[i].freeze(); 676 } 677 678 ForwardConfig[] fconfigs = findForwardConfigs(); 679 for (int i = 0; i < fconfigs.length; i++) { 680 fconfigs[i].freeze(); 681 } 682 683 } 684 685 686 694 public void removeExceptionConfig(ExceptionConfig config) { 695 696 if (configured) { 697 throw new IllegalStateException ("Configuration is frozen"); 698 } 699 exceptions.remove(config.getType()); 700 701 } 702 703 704 712 public void removeForwardConfig(ForwardConfig config) { 713 714 if (configured) { 715 throw new IllegalStateException ("Configuration is frozen"); 716 } 717 forwards.remove(config.getName()); 718 719 } 720 721 722 725 public String toString() { 726 727 StringBuffer sb = new StringBuffer ("ActionConfig["); 728 sb.append("path="); 729 sb.append(path); 730 if (attribute != null) { 731 sb.append(",attribute="); 732 sb.append(attribute); 733 } 734 if (forward != null) { 735 sb.append(",forward="); 736 sb.append(forward); 737 } 738 if (include != null) { 739 sb.append(",include="); 740 sb.append(include); 741 } 742 if (input != null) { 743 sb.append(",input="); 744 sb.append(input); 745 } 746 if (multipartClass != null) { 747 sb.append(",multipartClass="); 748 sb.append(multipartClass); 749 } 750 if (name != null) { 751 sb.append(",name="); 752 sb.append(name); 753 } 754 if (parameter != null) { 755 sb.append(",parameter="); 756 sb.append(parameter); 757 } 758 if (prefix != null) { 759 sb.append(",prefix="); 760 sb.append(prefix); 761 } 762 if (roles != null) { 763 sb.append(",roles="); 764 sb.append(roles); 765 } 766 if (scope != null) { 767 sb.append(",scope="); 768 sb.append(scope); 769 } 770 if (suffix != null) { 771 sb.append(",suffix="); 772 sb.append(suffix); 773 } 774 if (type != null) { 775 sb.append(",type="); 776 sb.append(type); 777 } 778 return (sb.toString()); 779 780 } 781 782 783 } 784 | Popular Tags |