Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » s1 » [javadoc | source]
    1   /*
    2    * $Id: WrapperModuleConfig.java 667778 2008-06-14 12:14:42Z hermanns $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   
   22   package org.apache.struts2.s1;
   23   
   24   import java.util.HashMap;
   25   import java.util.Iterator;
   26   import java.util.Map;
   27   
   28   import org.apache.struts.config.ActionConfig;
   29   import org.apache.struts.config.ControllerConfig;
   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   import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
   38   import com.opensymphony.xwork2.config.entities.PackageConfig;
   39   import com.opensymphony.xwork2.config.entities.ResultConfig;
   40   
   41   /**
   42    * Wrapper for a Struts 1.x ModuleConfig based on an XWork PackageConfig.  Using a wrapper object
   43    * allows us to be explicit about what is and isn't implemented.
   44    */
   45   class WrapperModuleConfig implements ModuleConfig {
   46   
   47       private Struts1Factory strutsFactory;
   48       private PackageConfig delegate;
   49       private Map _actionMappings;
   50       private Map _exceptionConfigs;
   51       private Map _actionForwards;
   52   
   53       public WrapperModuleConfig(Struts1Factory factory, PackageConfig config) {
   54           delegate = config;
   55           this.strutsFactory = factory;
   56       }
   57   
   58       /**
   59        * Add Struts ActionMappings (from XWork ExceptionConfigs).
   60        */
   61       private void initActionMappings() {
   62   
   63           if (_actionMappings == null) {
   64               _actionMappings = new HashMap();
   65               for (Iterator i = delegate.getActionConfigs().entrySet().iterator(); i.hasNext();) {
   66                   Map.Entry entry = (Map.Entry) i.next();
   67                   String actionPath = '/' + (String) entry.getKey();
   68                   com.opensymphony.xwork2.config.entities.ActionConfig actionConfig =
   69                           (com.opensymphony.xwork2.config.entities.ActionConfig) entry.getValue();
   70                   _actionMappings.put(actionPath, strutsFactory.createActionMapping(actionConfig, actionPath, this));
   71               }
   72           }
   73       }
   74   
   75       /**
   76        * Add Struts ExceptionConfigs (from XWork ExceptionMappingConfigs).
   77        */
   78       private void initExceptionConfigs() {
   79           if (_exceptionConfigs == null) {
   80               _exceptionConfigs = new HashMap();
   81               for (Iterator i = delegate.getGlobalExceptionMappingConfigs().iterator(); i.hasNext();) {
   82                   ExceptionMappingConfig config = (ExceptionMappingConfig) i.next();
   83                   _exceptionConfigs.put(config.getExceptionClassName(), strutsFactory.createExceptionConfig(config));
   84               }
   85           }
   86       }
   87   
   88       /**
   89        * Add Struts ActionForwards (from XWork ResultConfigs).
   90        */
   91       private void initActionForwards() {
   92           if (_actionForwards == null) {
   93               _actionForwards = new HashMap();
   94               for (Iterator i = delegate.getGlobalResultConfigs().entrySet().iterator(); i.hasNext();) {
   95                   Map.Entry entry = (Map.Entry) i.next();
   96                   String name = (String) entry.getKey();
   97                   ResultConfig config = (ResultConfig) entry.getValue();
   98                   _actionForwards.put(name, strutsFactory.createActionForward(config));
   99               }
  100           }
  101       }
  102   
  103       public String getPrefix() {
  104           return delegate.getNamespace();
  105       }
  106   
  107       public void setPrefix(String prefix) {
  108           throw new UnsupportedOperationException("Not implemented - immutable");
  109       }
  110   
  111       public boolean getConfigured() {
  112           return true;
  113       }
  114   
  115       public ControllerConfig getControllerConfig() {
  116           throw new UnsupportedOperationException("NYI");
  117       }
  118   
  119       public void setControllerConfig(ControllerConfig cc) {
  120           throw new UnsupportedOperationException("Not implemented - immutable");
  121       }
  122   
  123       public String getActionFormBeanClass() {
  124           throw new UnsupportedOperationException("NYI");
  125       }
  126   
  127       public void setActionFormBeanClass(String actionFormBeanClass) {
  128           throw new UnsupportedOperationException("Not implemented - immutable");
  129       }
  130   
  131       public String getActionMappingClass() {
  132           throw new UnsupportedOperationException("NYI");
  133       }
  134   
  135       public void setActionMappingClass(String actionMappingClass) {
  136           throw new UnsupportedOperationException("Not implemented - immutable");
  137       }
  138   
  139       public void addActionConfig(ActionConfig config) {
  140           throw new UnsupportedOperationException("Not implemented - immutable");
  141       }
  142   
  143       public void addExceptionConfig(ExceptionConfig config) {
  144           throw new UnsupportedOperationException("Not implemented - immutable");
  145       }
  146   
  147       public void addFormBeanConfig(FormBeanConfig config) {
  148           throw new UnsupportedOperationException("Not implemented - immutable");
  149       }
  150   
  151       public String getActionForwardClass() {
  152           throw new UnsupportedOperationException("NYI");
  153       }
  154   
  155       public void setActionForwardClass(String actionForwardClass) {
  156           throw new UnsupportedOperationException("Not implemented - immutable");
  157       }
  158   
  159       public void addForwardConfig(ForwardConfig config) {
  160           throw new UnsupportedOperationException("NYI");
  161       }
  162   
  163       public void addMessageResourcesConfig(MessageResourcesConfig config) {
  164           throw new UnsupportedOperationException("Not implemented - immutable");
  165       }
  166   
  167       public void addPlugInConfig(PlugInConfig plugInConfig) {
  168           throw new UnsupportedOperationException("Not implemented - immutable");
  169       }
  170   
  171       public ActionConfig findActionConfig(String path) {
  172           initActionMappings();
  173           return (ActionConfig) _actionMappings.get(path);
  174       }
  175   
  176       public ActionConfig[] findActionConfigs() {
  177           initActionMappings();
  178           return (ActionConfig[]) _actionMappings.values().toArray(new ActionConfig[_actionMappings.size()]);
  179       }
  180   
  181       public ExceptionConfig findExceptionConfig(String type) {
  182           initExceptionConfigs();
  183           return (ExceptionConfig) _exceptionConfigs.get(type);
  184       }
  185   
  186       public ExceptionConfig[] findExceptionConfigs() {
  187           initExceptionConfigs();
  188           return (ExceptionConfig[]) _exceptionConfigs.values().toArray(new ExceptionConfig[_exceptionConfigs.size()]);
  189       }
  190   
  191       public FormBeanConfig findFormBeanConfig(String name) {
  192           throw new UnsupportedOperationException("NYI");
  193       }
  194   
  195       public FormBeanConfig[] findFormBeanConfigs() {
  196           throw new UnsupportedOperationException("NYI");
  197       }
  198   
  199       public ForwardConfig findForwardConfig(String name) {
  200           initActionForwards();
  201           return (ForwardConfig) _actionForwards.get(name);
  202       }
  203   
  204       public ForwardConfig[] findForwardConfigs() {
  205           initActionForwards();
  206           return (ForwardConfig[]) _actionForwards.values().toArray(new ForwardConfig[_actionForwards.size()]);
  207       }
  208   
  209       public ActionConfig findActionConfigId(String s) {
  210           throw new UnsupportedOperationException("NYI");
  211       }
  212   
  213       public MessageResourcesConfig findMessageResourcesConfig(String key) {
  214           throw new UnsupportedOperationException("NYI");
  215       }
  216   
  217       public MessageResourcesConfig[] findMessageResourcesConfigs() {
  218           throw new UnsupportedOperationException("NYI");
  219       }
  220   
  221       public PlugInConfig[] findPlugInConfigs() {
  222           throw new UnsupportedOperationException("NYI");
  223       }
  224   
  225       public void freeze() {
  226           throw new UnsupportedOperationException("Not implemented - immutable");
  227       }
  228   
  229       public void removeActionConfig(ActionConfig config) {
  230           throw new UnsupportedOperationException("Not implemented - immutable");
  231       }
  232   
  233       public void removeExceptionConfig(ExceptionConfig config) {
  234           throw new UnsupportedOperationException("Not implemented - immutable");
  235       }
  236   
  237       public void removeFormBeanConfig(FormBeanConfig config) {
  238           throw new UnsupportedOperationException("Not implemented - immutable");
  239       }
  240   
  241       public void removeForwardConfig(ForwardConfig config) {
  242           throw new UnsupportedOperationException("Not implemented - immutable");
  243       }
  244   
  245       public void removeMessageResourcesConfig(MessageResourcesConfig config) {
  246           throw new UnsupportedOperationException("Not implemented - immutable");
  247       }
  248   
  249       public ExceptionConfig findException(Class arg0) {
  250           throw new UnsupportedOperationException("NYI");
  251       }
  252   }

Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » s1 » [javadoc | source]