1 18 19 package org.apache.struts.config.impl; 20 21 import java.io.Serializable ; 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.HashMap ; 25 26 import org.apache.struts.config.ActionConfig; 27 import org.apache.struts.config.ActionConfigMatcher; 28 import org.apache.struts.config.ControllerConfig; 29 import org.apache.struts.config.DataSourceConfig; 30 import org.apache.struts.config.ExceptionConfig; 31 import org.apache.struts.config.FormBeanConfig; 32 import org.apache.struts.config.ForwardConfig; 33 import org.apache.struts.config.MessageResourcesConfig; 34 import org.apache.struts.config.ModuleConfig; 35 import org.apache.struts.config.PlugInConfig; 36 37 49 public class ModuleConfigImpl implements Serializable , ModuleConfig { 50 51 57 public ModuleConfigImpl(String prefix) { 58 super(); 59 this.prefix = prefix; 60 this.actionConfigs = new HashMap (); 61 this.actionConfigList = new ArrayList (); 62 this.actionFormBeanClass = "org.apache.struts.action.ActionFormBean"; 63 this.actionMappingClass = "org.apache.struts.action.ActionMapping"; 64 this.actionForwardClass = "org.apache.struts.action.ActionForward"; 65 this.configured = false; 66 this.controllerConfig = null; 67 this.dataSources = new HashMap (); 68 this.exceptions = new HashMap (); 69 this.formBeans = new HashMap (); 70 this.forwards = new HashMap (); 71 this.messageResources = new HashMap (); 72 this.plugIns = new ArrayList (); 73 } 74 75 76 78 83 public boolean getConfigured() { 84 return (this.configured); 85 } 86 87 90 public ControllerConfig getControllerConfig() { 91 if (this.controllerConfig == null) { 92 this.controllerConfig = new ControllerConfig(); 93 } 94 return (this.controllerConfig); 95 } 96 97 101 public void setControllerConfig(ControllerConfig cc) { 102 if (configured) { 103 throw new IllegalStateException ("Configuration is frozen"); 104 } 105 this.controllerConfig = cc; 106 } 107 108 114 public String getPrefix() { 115 return (this.prefix); 116 } 117 118 124 public void setPrefix(String prefix) { 125 if (configured) { 126 throw new IllegalStateException ("Configuration is frozen"); 127 } 128 this.prefix = prefix; 129 } 130 131 135 public String getActionFormBeanClass() { 136 return this.actionFormBeanClass; 137 } 138 139 146 public void setActionFormBeanClass(String actionFormBeanClass) { 147 this.actionFormBeanClass = actionFormBeanClass; 148 } 149 150 153 public String getActionMappingClass() { 154 return this.actionMappingClass; 155 } 156 157 163 public void setActionMappingClass(String actionMappingClass) { 164 this.actionMappingClass = actionMappingClass; 165 } 166 167 176 public void addActionConfig(ActionConfig config) { 177 178 if (configured) { 179 throw new IllegalStateException ("Configuration is frozen"); 180 } 181 config.setModuleConfig(this); 182 actionConfigs.put(config.getPath(), config); 183 actionConfigList.add(config); 184 185 } 186 187 196 public void addDataSourceConfig(DataSourceConfig config) { 197 198 if (configured) { 199 throw new IllegalStateException ("Configuration is frozen"); 200 } 201 dataSources.put(config.getKey(), config); 202 203 } 204 205 214 public void addExceptionConfig(ExceptionConfig config) { 215 216 if (configured) { 217 throw new IllegalStateException ("Configuration is frozen"); 218 } 219 exceptions.put(config.getType(), config); 220 221 } 222 223 232 public void addFormBeanConfig(FormBeanConfig config) { 233 234 if (configured) { 235 throw new IllegalStateException ("Configuration is frozen"); 236 } 237 formBeans.put(config.getName(), config); 238 239 } 240 241 244 public String getActionForwardClass() { 245 return this.actionForwardClass; 246 } 247 248 254 public void setActionForwardClass(String actionForwardClass) { 255 this.actionForwardClass= actionForwardClass; 256 } 257 258 267 public void addForwardConfig(ForwardConfig config) { 268 269 if (configured) { 270 throw new IllegalStateException ("Configuration is frozen"); 271 } 272 forwards.put(config.getName(), config); 273 274 } 275 276 285 public void addMessageResourcesConfig(MessageResourcesConfig config) { 286 287 if (configured) { 288 throw new IllegalStateException ("Configuration is frozen"); 289 } 290 messageResources.put(config.getKey(), config); 291 292 } 293 294 300 public void addPlugInConfig(PlugInConfig plugInConfig) { 301 302 if (configured) { 303 throw new IllegalStateException ("Configuration is frozen"); 304 } 305 plugIns.add(plugInConfig); 306 307 } 308 309 316 public ActionConfig findActionConfig(String path) { 317 318 ActionConfig config = (ActionConfig) actionConfigs.get(path); 319 320 if (config == null) { 323 config = matcher.match(path); 324 } 325 326 return config; 327 328 } 329 330 334 public ActionConfig[] findActionConfigs() { 335 336 ActionConfig results[] = new ActionConfig[actionConfigList.size()]; 337 return ((ActionConfig[]) actionConfigList.toArray(results)); 338 339 } 340 341 347 public DataSourceConfig findDataSourceConfig(String key) { 348 349 return ((DataSourceConfig) dataSources.get(key)); 350 351 } 352 353 357 public DataSourceConfig[] findDataSourceConfigs() { 358 359 DataSourceConfig results[] = new DataSourceConfig[dataSources.size()]; 360 return ((DataSourceConfig[]) dataSources.values().toArray(results)); 361 362 } 363 364 370 public ExceptionConfig findExceptionConfig(String type) { 371 372 return ((ExceptionConfig) exceptions.get(type)); 373 374 } 375 376 380 public ExceptionConfig[] findExceptionConfigs() { 381 382 ExceptionConfig results[] = new ExceptionConfig[exceptions.size()]; 383 return ((ExceptionConfig[]) exceptions.values().toArray(results)); 384 385 } 386 387 393 public FormBeanConfig findFormBeanConfig(String name) { 394 395 return ((FormBeanConfig) formBeans.get(name)); 396 397 } 398 399 403 public FormBeanConfig[] findFormBeanConfigs() { 404 405 FormBeanConfig results[] = new FormBeanConfig[formBeans.size()]; 406 return ((FormBeanConfig[]) formBeans.values().toArray(results)); 407 408 } 409 410 416 public ForwardConfig findForwardConfig(String name) { 417 418 return ((ForwardConfig) forwards.get(name)); 419 420 } 421 422 426 public ForwardConfig[] findForwardConfigs() { 427 428 ForwardConfig results[] = new ForwardConfig[forwards.size()]; 429 return ((ForwardConfig[]) forwards.values().toArray(results)); 430 431 } 432 433 439 public MessageResourcesConfig findMessageResourcesConfig(String key) { 440 441 return ((MessageResourcesConfig) messageResources.get(key)); 442 443 } 444 445 449 public MessageResourcesConfig[] findMessageResourcesConfigs() { 450 451 MessageResourcesConfig results[] = 452 new MessageResourcesConfig[messageResources.size()]; 453 return ((MessageResourcesConfig[]) 454 messageResources.values().toArray(results)); 455 456 } 457 458 462 public PlugInConfig[] findPlugInConfigs() { 463 464 PlugInConfig results[] = new PlugInConfig[plugIns.size()]; 465 return ((PlugInConfig[]) plugIns.toArray(results)); 466 467 } 468 469 474 public void freeze() { 475 476 this.configured = true; 477 478 ActionConfig[] aconfigs = findActionConfigs(); 479 for (int i = 0; i < aconfigs.length; i++) { 480 aconfigs[i].freeze(); 481 } 482 matcher = new ActionConfigMatcher(aconfigs); 483 484 getControllerConfig().freeze(); 485 486 DataSourceConfig[] dsconfigs = findDataSourceConfigs(); 487 for (int i = 0; i < dsconfigs.length; i++) { 488 dsconfigs[i].freeze(); 489 } 490 491 ExceptionConfig[] econfigs = findExceptionConfigs(); 492 for (int i = 0; i < econfigs.length; i++) { 493 econfigs[i].freeze(); 494 } 495 496 FormBeanConfig[] fbconfigs = findFormBeanConfigs(); 497 for (int i = 0; i < fbconfigs.length; i++) { 498 fbconfigs[i].freeze(); 499 } 500 501 ForwardConfig[] fconfigs = findForwardConfigs(); 502 for (int i = 0; i < fconfigs.length; i++) { 503 fconfigs[i].freeze(); 504 } 505 506 MessageResourcesConfig[] mrconfigs = findMessageResourcesConfigs(); 507 for (int i = 0; i < mrconfigs.length; i++) { 508 mrconfigs[i].freeze(); 509 } 510 511 PlugInConfig[] piconfigs = findPlugInConfigs(); 512 for (int i = 0; i < piconfigs.length; i++) { 513 piconfigs[i].freeze(); 514 } 515 } 516 517 525 public void removeActionConfig(ActionConfig config) { 526 527 if (configured) { 528 throw new IllegalStateException ("Configuration is frozen"); 529 } 530 config.setModuleConfig(null); 531 actionConfigs.remove(config.getPath()); 532 actionConfigList.remove(config); 533 534 } 535 536 544 public void removeExceptionConfig(ExceptionConfig config) { 545 546 if (configured) { 547 throw new IllegalStateException ("Configuration is frozen"); 548 } 549 exceptions.remove(config.getType()); 550 551 } 552 553 561 public void removeDataSourceConfig(DataSourceConfig config) { 562 563 if (configured) { 564 throw new IllegalStateException ("Configuration is frozen"); 565 } 566 dataSources.remove(config.getKey()); 567 568 } 569 570 578 public void removeFormBeanConfig(FormBeanConfig config) { 579 580 if (configured) { 581 throw new IllegalStateException ("Configuration is frozen"); 582 } 583 formBeans.remove(config.getName()); 584 585 } 586 587 595 public void removeForwardConfig(ForwardConfig config) { 596 597 if (configured) { 598 throw new IllegalStateException ("Configuration is frozen"); 599 } 600 forwards.remove(config.getName()); 601 602 } 603 604 612 public void removeMessageResourcesConfig(MessageResourcesConfig config) { 613 614 if (configured) { 615 throw new IllegalStateException ("Configuration is frozen"); 616 } 617 messageResources.remove(config.getKey()); 618 619 } 620 621 624 625 629 protected HashMap actionConfigs = null; 630 631 635 protected List actionConfigList = null; 636 637 641 protected HashMap dataSources = null; 642 643 647 protected HashMap exceptions = null; 648 649 653 protected HashMap formBeans = null; 654 655 659 protected HashMap forwards = null; 660 661 665 protected HashMap messageResources = null; 666 667 671 protected ArrayList plugIns = null; 672 673 678 protected boolean configured = false; 679 680 683 protected ControllerConfig controllerConfig = null; 684 685 691 protected String prefix = null; 692 693 697 protected String actionFormBeanClass = "org.apache.struts.action.ActionFormBean"; 698 699 702 protected String actionMappingClass = "org.apache.struts.action.ActionMapping"; 703 704 707 protected String actionForwardClass = "org.apache.struts.action.ActionForward"; 708 709 712 protected ActionConfigMatcher matcher = null; 713 714 } 715 | Popular Tags |