1 16 17 package org.apache.struts.chain; 18 19 20 import org.apache.commons.chain.Command; 21 import org.apache.commons.chain.Context; 22 import org.apache.commons.chain.web.WebContext; 23 import org.apache.struts.Globals; 24 import org.apache.struts.chain.Constants; 25 import org.apache.struts.config.ActionConfig; 26 import org.apache.struts.config.ModuleConfig; 27 28 29 36 37 public abstract class AbstractSelectAction implements Command { 38 39 40 42 43 private String actionConfigKey = Constants.ACTION_CONFIG_KEY; 44 private String moduleConfigKey = Constants.MODULE_CONFIG_KEY; 45 46 47 49 50 55 public String getActionConfigKey() { 56 57 return (this.actionConfigKey); 58 59 } 60 61 62 69 public void setActionConfigKey(String actionConfigKey) { 70 71 this.actionConfigKey = actionConfigKey; 72 73 } 74 75 76 81 public String getModuleConfigKey() { 82 83 return (this.moduleConfigKey); 84 85 } 86 87 88 95 public void setModuleConfigKey(String moduleConfigKey) { 96 97 this.moduleConfigKey = moduleConfigKey; 98 99 } 100 101 102 104 105 116 public boolean execute(Context context) throws Exception { 117 118 String path = getPath(context); 120 121 WebContext wcontext = (WebContext) context; 123 ModuleConfig moduleConfig = (ModuleConfig) 124 wcontext.get(getModuleConfigKey()); 125 ActionConfig actionConfig = moduleConfig.findActionConfig(path); 126 127 if (actionConfig == null) { 128 ActionConfig configs[] = moduleConfig.findActionConfigs(); 130 for (int i = 0; i < configs.length; i++) { 131 if (configs[i].getUnknown()) { 132 actionConfig = configs[i]; 133 break; 134 } 135 } 136 137 } 138 139 if (actionConfig == null) { 140 throw new IllegalArgumentException ("No action config for '" + 141 path + "'"); 142 } 143 wcontext.put(getActionConfigKey(), actionConfig); 144 wcontext.getRequestScope().put(Globals.MAPPING_KEY, actionConfig); 145 return (false); 146 147 } 148 149 150 152 153 162 protected abstract String getPath(Context context); 163 164 165 } 166 | Popular Tags |