Author: rich Date: Tue Dec 20 23:11:58 2005 New Revision: 358223 URL: http://svn.apache.org/viewcvs?rev=358223&view=rev Log: Some work on Struts 1.x wrappers for XWork config objects (ActionForward, ExceptionConfig, ActionMapping, ModuleConfig). First checkin. :)
tests passed: phase1/jars/legacy Added: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionForward.java (with props) struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionMapping.java (with props) struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperExceptionConfig.java (with props) struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperModuleConfig.java (with props) struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml (with props) Modified: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java Modified: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java?rev=358223&r1=358222&r2=358223&view=diff ============================================================================== --- struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java (original) +++ struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/PlugInInterceptor.java Tue Dec 20 23:11:58 2005 @@ -45,6 +45,7 @@ private String className; private Map params = new HashMap(); + private String modulePrefix; private PlugIn plugin = null; private static final Log LOG = LogFactory.getLog(PlugInInterceptor.class); @@ -58,8 +59,13 @@ public Map getParams() { return params; - } - + } + + // TODO: we should be able to find the package name/namespace during init time, but for now it's passed in as param. + public void setModulePrefix(String modulePrefix) { + this.modulePrefix = modulePrefix; + } + public void setServletContext(final ServletContext servletContext) { ActionServlet servlet = new ActionServlet() { public ServletContext getServletContext() { @@ -67,7 +73,9 @@ } }; - ModuleConfig modConfig = StrutsFactory.getStrutsFactory().createModuleConfig(); + // Create a ModuleConfig based on the module prefix. This assumes that there is an existing XWork package + // configuration with the given module prefix. + ModuleConfig modConfig = StrutsFactory.getStrutsFactory().createModuleConfig(modulePrefix); try { plugin = (PlugIn) ObjectFactory.getObjectFactory().buildBean(className, null); Modified: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java?rev=358223&r1=358222&r2=358223&view=diff ============================================================================== --- struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java (original) +++ struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/StrutsFactory.java Tue Dec 20 23:11:58 2005 @@ -20,9 +20,13 @@ import com.opensymphony.xwork.*; import com.opensymphony.xwork.config.entities.ActionConfig; +import com.opensymphony.xwork.config.entities.ResultConfig; +import com.opensymphony.xwork.config.entities.ExceptionMappingConfig; import org.apache.struts.action.*; import org.apache.struts.config.*; -import java.util.*; + +import java.util.Iterator; +import java.util.Arrays; /** @@ -43,18 +47,70 @@ return FACTORY; } - public ModuleConfig createModuleConfig() { - return null; + /** + * Create a Struts 1.x ModuleConfig based on an XWork package configuration. + * + * @param packageName the name of the XWork package configuration to wrap. This becomes the module prefix for the + * newly-created ModuleConfig. + * @return a wrapper Struts 1.x ModuleConfig. + */ + public ModuleConfig createModuleConfig(String packageName) { + assert packageName != null; + return new WrapperModuleConfig(packageName); } + /** + * Create a Struts 1.x ActionMapping from an XWork ActionConfig. + * + * @param cfg the XWork ActionConfig. + * @return a wrapper Struts 1.x ActionMapping. + */ public ActionMapping createActionMapping(ActionConfig cfg) { - return null; + assert cfg != null; + return new WrapperActionMapping(cfg); + } + + /** + * Create a Struts 1.x ActionMapping from an XWork ActionConfig. This version provides an existing action path + * and ModuleConfig. Package-protected for now; may not need to be exposed publicly. + * + * @param cfg the XWork ActionConfig. + * @param actionPath the Struts 1.x-style action path ('/' + action-name). + * @param moduleConfig the Struts 1.x ModuleConfig that contains the ActionMapping. + * @return a wrapper Struts 1.x ActionMapping. + */ + ActionMapping createActionMapping(ActionConfig cfg, String actionPath, ModuleConfig moduleConfig) { + assert cfg != null; + assert moduleConfig != null; + return new WrapperActionMapping(cfg, actionPath, moduleConfig); + } + + /** + * Create a Struts 1.x ActionForward from an XWork ResultConfig. + * + * @param cfg the XWork ResultConfig. + * @return a wrapper Struts 1.x ActionMapping. + */ + public ActionForward createActionForward(ResultConfig cfg) { + assert cfg != null; + return new WrapperActionForward(cfg); + } + + /** + * Create a Struts 1.x ExceptionConfig from an XWork ExceptionMappingConfig. + * + * @param cfg the XWork ExceptionMappingConfig. + * @return a wrapper Struts 1.x ExceptionConfig. + */ + public ExceptionConfig createExceptionConfig(ExceptionMappingConfig cfg) { + assert cfg != null; + return new WrapperExceptionConfig(cfg); } public void convertErrors(ActionErrors errors, Object action) { ValidationAware vaction = null; TextProvider text = null; - + if (action instanceof ValidationAware) { vaction = (ValidationAware)action; } @@ -77,8 +133,8 @@ msg = text.getText(error.getKey(), Arrays.asList(values)); } else { msg = text.getText(error.getKey()); - } - } + } + } if (vaction != null) { if (field == errors.GLOBAL_MESSAGE) { vaction.addActionError(msg); @@ -90,5 +146,5 @@ } } } - } + } } Added: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionForward.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionForward.java?rev=358223&view=auto ============================================================================== --- struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionForward.java (added) +++ struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionForward.java Tue Dec 20 23:11:58 2005 @@ -0,0 +1,56 @@ +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Header:$ + */ +package org.apache.ti.legacy; + +import org.apache.struts.action.ActionForward; +import com.opensymphony.xwork.config.entities.ResultConfig; + +/** + * Wrapper for a Struts 1.x ActionForward based on an XWork ResultConfig. Using a wrapper object + * allows us to be explicit about what is and isn't implemented. + */ +class WrapperActionForward extends ActionForward { + + private ResultConfig delegate; + + public WrapperActionForward(ResultConfig delegate) { + super(delegate.getName()); + this.delegate = delegate; + freeze(); + } + + public String getName() { + return delegate.getName(); + } + + public String getPath() { + throw new UnsupportedOperationException("NYI"); + } + + public String getModule() { + throw new UnsupportedOperationException("NYI"); + } + + public boolean getRedirect() { + throw new UnsupportedOperationException("NYI"); + } + + public String toString() { + return "wrapper -> " + delegate.toString(); + } +} Propchange: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionForward.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionMapping.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionMapping.java?rev=358223&view=auto ============================================================================== --- struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionMapping.java (added) +++ struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionMapping.java Tue Dec 20 23:11:58 2005 @@ -0,0 +1,282 @@ +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Header:$ + */ +package org.apache.ti.legacy; + +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.ActionForward; +import org.apache.struts.config.ModuleConfig; +import org.apache.struts.config.ExceptionConfig; +import org.apache.struts.config.ForwardConfig; +import com.opensymphony.xwork.config.entities.ActionConfig; +import com.opensymphony.xwork.config.entities.ResultConfig; +import com.opensymphony.xwork.config.entities.ExceptionMappingConfig; + +import java.util.Iterator; +import java.util.Map; +import java.util.List; +import java.util.HashMap; + +/** + * Wrapper for a Struts 1.x ActionMapping based on an XWork ActionConfig. Using a wrapper object + * allows us to be explicit about what is and isn't implemented. + */ +class WrapperActionMapping extends ActionMapping { + + private ActionConfig delegate; + private String actionPath; + + public WrapperActionMapping(ActionConfig delegate) { + this.delegate = delegate; + forwards = null; + exceptions = null; + } + + public WrapperActionMapping(ActionConfig delegate, String actionPath, ModuleConfig moduleConfig) { + this(delegate); + this.moduleConfig = moduleConfig; + this.actionPath = actionPath; + } + + /** + * Add Struts ForwardConfigs (from XWork ResultConfigs). + */ + private void initActionForwards() { + if (forwards == null) { + forwards = new HashMap(); + StrutsFactory strutsFactory = StrutsFactory.getStrutsFactory(); + Map results = delegate.getResults(); + for (Iterator i = results.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + ActionForward wrapper = strutsFactory.createActionForward((ResultConfig) entry.getValue()); + forwards.put(wrapper.getName(), wrapper); + } + } + } + + /** + * Add XWork ExceptionConfigs (from XWork ExceptionMappingConfigs) + */ + private void initExceptionConfigs() { + if (exceptions == null) { + exceptions = new HashMap(); + StrutsFactory strutsFactory = StrutsFactory.getStrutsFactory(); + List exceptionMappings = delegate.getExceptionMappings(); + for (Iterator i = exceptionMappings.iterator(); i.hasNext();) { + ExceptionConfig wrapper = strutsFactory.createExceptionConfig((ExceptionMappingConfig) i.next()); + exceptions.put(wrapper.getType(), wrapper); + } + } + } + + public ActionForward findForward(String name) { + initActionForwards(); + return super.findForward(name); + } + + public String[] findForwards() { + initActionForwards(); + return super.findForwards(); + } + + public ForwardConfig findForwardConfig(String name) { + initActionForwards(); + return super.findForwardConfig(name); + } + + public ForwardConfig[] findForwardConfigs() { + initActionForwards(); + return super.findForwardConfigs(); + } + + public ExceptionConfig findExceptionConfig(String type) { + initExceptionConfigs(); + return super.findExceptionConfig(type); + } + + public ExceptionConfig[] findExceptionConfigs() { + initExceptionConfigs(); + return super.findExceptionConfigs(); + } + + public ExceptionConfig findException(Class type) { + initExceptionConfigs(); + return super.findException(type); + } + + public ActionForward getInputForward() { + throw new UnsupportedOperationException("NYI"); + } + + public ModuleConfig getModuleConfig() { + if (moduleConfig == null) { + StrutsFactory strutsFactory = StrutsFactory.getStrutsFactory(); + moduleConfig = strutsFactory.createModuleConfig(delegate.getPackageName()); + } + + return moduleConfig; + } + + public void setModuleConfig(ModuleConfig moduleConfig) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getAttribute() { + throw new UnsupportedOperationException("NYI"); + } + + public void setAttribute(String attribute) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getForward() { + throw new UnsupportedOperationException("NYI"); + } + + public void setForward(String forward) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getInclude() { + throw new UnsupportedOperationException("NYI"); + } + + public void setInclude(String include) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getInput() { + throw new UnsupportedOperationException("NYI"); + } + + public void setInput(String input) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getMultipartClass() { + throw new UnsupportedOperationException("NYI"); + } + + public void setMultipartClass(String multipartClass) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getName() { + // Note: in Struts, this is a name reference to a form bean defined in the config file. + throw new UnsupportedOperationException("NYI"); + } + + public void setName(String name) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getParameter() { + throw new UnsupportedOperationException("NYI"); + } + + public void setParameter(String parameter) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getPath() { + return actionPath; + } + + public void setPath(String path) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getPrefix() { + throw new UnsupportedOperationException("NYI"); + } + + public void setPrefix(String prefix) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getRoles() { + throw new UnsupportedOperationException("NYI"); + } + + public void setRoles(String roles) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String[] getRoleNames() { + throw new UnsupportedOperationException("NYI"); + } + + public String getScope() { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void setScope(String scope) { + throw new UnsupportedOperationException("NYI"); + } + + public String getSuffix() { + throw new UnsupportedOperationException("NYI"); + } + + public void setSuffix(String suffix) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getType() { + throw new UnsupportedOperationException("NYI"); + } + + public void setType(String type) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public boolean getUnknown() { + throw new UnsupportedOperationException("NYI"); + } + + public void setUnknown(boolean unknown) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public boolean getValidate() { + throw new UnsupportedOperationException("NYI"); + } + + public void setValidate(boolean validate) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void removeExceptionConfig(ExceptionConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void removeForwardConfig(ForwardConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void addExceptionConfig(ExceptionConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void addForwardConfig(ForwardConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String toString() { + return "wrapper -> " + delegate.toString(); + } +} Propchange: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperActionMapping.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperExceptionConfig.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperExceptionConfig.java?rev=358223&view=auto ============================================================================== --- struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperExceptionConfig.java (added) +++ struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperExceptionConfig.java Tue Dec 20 23:11:58 2005 @@ -0,0 +1,63 @@ +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Header:$ + */ +package org.apache.ti.legacy; + +import com.opensymphony.xwork.config.entities.ExceptionMappingConfig; +import org.apache.struts.config.ExceptionConfig; + +/** + * Wrapper for a Struts 1.x ExceptionConfig based on an XWork ExceptionMappingConfig. Using a + * wrapper object allows us to be explicit about what is and isn't implemented. + */ +class WrapperExceptionConfig extends ExceptionConfig { + + private ExceptionMappingConfig delegate; + + public WrapperExceptionConfig(ExceptionMappingConfig delegate) { + this.delegate = delegate; + freeze(); + } + + public String getBundle() { + throw new UnsupportedOperationException("NYI"); + } + + public String getHandler() { + throw new UnsupportedOperationException("NYI"); + } + + public String getKey() { + throw new UnsupportedOperationException("NYI"); + } + + public String getPath() { + throw new UnsupportedOperationException("NYI"); + } + + public String getScope() { + throw new UnsupportedOperationException("NYI"); + } + + public String getType() { + return delegate.getExceptionClassName(); + } + + public String toString() { + return "wrapper -> " + delegate.toString(); + } +} Propchange: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperExceptionConfig.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperModuleConfig.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperModuleConfig.java?rev=358223&view=auto ============================================================================== --- struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperModuleConfig.java (added) +++ struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperModuleConfig.java Tue Dec 20 23:11:58 2005 @@ -0,0 +1,258 @@ +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Header:$ + */ +package org.apache.ti.legacy; + +import org.apache.struts.config.ModuleConfig; +import org.apache.struts.config.ControllerConfig; +import org.apache.struts.config.DataSourceConfig; +import org.apache.struts.config.ExceptionConfig; +import org.apache.struts.config.FormBeanConfig; +import org.apache.struts.config.ForwardConfig; +import org.apache.struts.config.MessageResourcesConfig; +import org.apache.struts.config.PlugInConfig; +import org.apache.struts.config.ActionConfig; +import com.opensymphony.xwork.config.ConfigurationManager; +import com.opensymphony.xwork.config.entities.PackageConfig; +import com.opensymphony.xwork.config.entities.ExceptionMappingConfig; +import com.opensymphony.xwork.config.entities.ResultConfig; + +import java.util.Map; +import java.util.Iterator; +import java.util.HashMap; + +/** + * Wrapper for a Struts 1.x ModuleConfig based on an XWork PackageConfig. Using a wrapper object + * allows us to be explicit about what is and isn't implemented. + */ +class WrapperModuleConfig implements ModuleConfig { + + private PackageConfig delegate; + private Map _actionMappings; + private Map _exceptionConfigs; + private Map _actionForwards; + + public WrapperModuleConfig(String packageName) { + delegate = ConfigurationManager.getConfiguration().getPackageConfig(packageName); + } + + /** + * Add Struts ActionMappings (from XWork ExceptionConfigs). + */ + private void initActionMappings() { + + if (_actionMappings == null) { + _actionMappings = new HashMap(); + StrutsFactory strutsFactory = StrutsFactory.getStrutsFactory(); + for (Iterator i = delegate.getActionConfigs().entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + String actionPath = '/' + (String) entry.getKey(); + com.opensymphony.xwork.config.entities.ActionConfig actionConfig = + (com.opensymphony.xwork.config.entities.ActionConfig) entry.getValue(); + _actionMappings.put(actionPath, strutsFactory.createActionMapping(actionConfig, actionPath, this)); + } + } + } + + /** + * Add Struts ExceptionConfigs (from XWork ExceptionMappingConfigs). + */ + private void initExceptionConfigs() { + if (_exceptionConfigs == null) { + _exceptionConfigs = new HashMap(); + StrutsFactory strutsFactory = StrutsFactory.getStrutsFactory(); + for (Iterator i = delegate.getGlobalExceptionMappingConfigs().iterator(); i.hasNext();) { + ExceptionMappingConfig config = (ExceptionMappingConfig) i.next(); + _exceptionConfigs.put(config.getExceptionClassName(), strutsFactory.createExceptionConfig(config)); + } + } + } + + /** + * Add Struts ActionForwards (from XWork ResultConfigs). + */ + private void initActionForwards() { + if (_actionForwards == null) { + _actionForwards = new HashMap(); + StrutsFactory strutsFactory = StrutsFactory.getStrutsFactory(); + for (Iterator i = delegate.getGlobalResultConfigs().entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + String name = (String) entry.getKey(); + ResultConfig config = (ResultConfig) entry.getValue(); + _actionForwards.put(name, strutsFactory.createActionForward(config)); + } + } + } + + public String getPrefix() { + return delegate.getNamespace(); + } + + public void setPrefix(String prefix) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public boolean getConfigured() { + return true; + } + + public ControllerConfig getControllerConfig() { + throw new UnsupportedOperationException("NYI"); + } + + public void setControllerConfig(ControllerConfig cc) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getActionFormBeanClass() { + throw new UnsupportedOperationException("NYI"); + } + + public void setActionFormBeanClass(String actionFormBeanClass) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getActionMappingClass() { + throw new UnsupportedOperationException("NYI"); + } + + public void setActionMappingClass(String actionMappingClass) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void addActionConfig(ActionConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void addDataSourceConfig(DataSourceConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void addExceptionConfig(ExceptionConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void addFormBeanConfig(FormBeanConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public String getActionForwardClass() { + throw new UnsupportedOperationException("NYI"); + } + + public void setActionForwardClass(String actionForwardClass) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void addForwardConfig(ForwardConfig config) { + throw new UnsupportedOperationException("NYI"); + } + + public void addMessageResourcesConfig(MessageResourcesConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void addPlugInConfig(PlugInConfig plugInConfig) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public ActionConfig findActionConfig(String path) { + initActionMappings(); + return (ActionConfig) _actionMappings.get(path); + } + + public ActionConfig[] findActionConfigs() { + initActionMappings(); + return (ActionConfig[]) _actionMappings.values().toArray(new ActionConfig[_actionMappings.size()]); + } + + public DataSourceConfig findDataSourceConfig(String key) { + throw new UnsupportedOperationException("NYI"); + } + + public DataSourceConfig[] findDataSourceConfigs() { + throw new UnsupportedOperationException("NYI"); + } + + public ExceptionConfig findExceptionConfig(String type) { + initExceptionConfigs(); + return (ExceptionConfig) _exceptionConfigs.get(type); + } + + public ExceptionConfig[] findExceptionConfigs() { + initExceptionConfigs(); + return (ExceptionConfig[]) _exceptionConfigs.values().toArray(new ExceptionConfig[_exceptionConfigs.size()]); + } + + public FormBeanConfig findFormBeanConfig(String name) { + throw new UnsupportedOperationException("NYI"); + } + + public FormBeanConfig[] findFormBeanConfigs() { + throw new UnsupportedOperationException("NYI"); + } + + public ForwardConfig findForwardConfig(String name) { + initActionForwards(); + return (ForwardConfig) _actionForwards.get(name); + } + + public ForwardConfig[] findForwardConfigs() { + initActionForwards(); + return (ForwardConfig[]) _actionForwards.values().toArray(new ForwardConfig[_actionForwards.size()]); + } + + public MessageResourcesConfig findMessageResourcesConfig(String key) { + throw new UnsupportedOperationException("NYI"); + } + + public MessageResourcesConfig[] findMessageResourcesConfigs() { + throw new UnsupportedOperationException("NYI"); + } + + public PlugInConfig[] findPlugInConfigs() { + throw new UnsupportedOperationException("NYI"); + } + + public void freeze() { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void removeActionConfig(ActionConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void removeExceptionConfig(ExceptionConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void removeDataSourceConfig(DataSourceConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void removeFormBeanConfig(FormBeanConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void removeForwardConfig(ForwardConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } + + public void removeMessageResourcesConfig(MessageResourcesConfig config) { + throw new UnsupportedOperationException("Not implemented - immutable"); + } +} Propchange: struts/sandbox/trunk/ti/phase1/jars/legacy/src/java/org/apache/ti/legacy/WrapperModuleConfig.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java?rev=358223&r1=358222&r2=358223&view=diff ============================================================================== --- struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java (original) +++ struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/TestStrutsFactory.java Tue Dec 20 23:11:58 2005 @@ -1,19 +1,32 @@ package org.apache.ti.legacy; import junit.framework.*; -import java.io.*; -import java.util.*; -import org.apache.commons.beanutils.*; +import com.opensymphony.xwork.config.providers.XmlConfigurationProvider; +import com.opensymphony.xwork.config.ConfigurationManager; +import com.opensymphony.xwork.config.Configuration; +import com.opensymphony.xwork.config.ConfigurationProvider; +import com.opensymphony.xwork.config.entities.PackageConfig; +import com.opensymphony.xwork.config.entities.ResultConfig; +import com.opensymphony.xwork.config.entities.ExceptionMappingConfig; import com.opensymphony.xwork.ActionSupport; -import ognl.*; import org.apache.struts.action.*; import org.apache.struts.config.*; -/** Description of the Class */ +import java.io.InputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +/** + * Test of StrutsFactory, which creates Struts 1.x wrappers around XWork config objects. + */ public class TestStrutsFactory extends TestCase { - protected StrutsFactory factory = null; + private static final String PACKAGE_NAME = "/org/apache/ti/legacy"; + protected StrutsFactory factory = null; + protected Configuration config; + public TestStrutsFactory(String name) throws Exception { super(name); } @@ -24,15 +37,173 @@ } /** + * This allows running of the test within an IDE; the ConfigurationProvider can accept a root directory specified + * in a System property, to avoid having to depend on loading a resource through ClassLoader. + */ + private class TestConfigurationProvider extends XmlConfigurationProvider { + + public TestConfigurationProvider(String filename) { + super(filename); + } + + protected InputStream getInputStream(String fileName) { + String rootDir = System.getProperty("configRootDir"); + try { + return rootDir != null ? new FileInputStream(rootDir + fileName) : super.getInputStream(fileName); + } catch (IOException e) { + fail(e.getMessage()); + return null; + } + } + } + + /** * Set up instance variables required by this test case. */ - public void setUp() throws Exception { - - factory = new StrutsFactory(); + public void setUp() { + ConfigurationProvider provider = new TestConfigurationProvider(PACKAGE_NAME + "/test-struts-factory.xml"); + ConfigurationManager.addConfigurationProvider(provider); + config = ConfigurationManager.getConfiguration(); + factory = StrutsFactory.getStrutsFactory(); } + /** + * Test the creation of a Struts 1.x ModuleConfig wrapper around an XWork PackageConfig. + * The PackageConfig is loaded from test-struts-factory.xml. + */ + public void testCreateModuleConfig() { + ModuleConfig moduleConfig = factory.createModuleConfig(PACKAGE_NAME); + assertNotNull(moduleConfig); + + assertEquals(PACKAGE_NAME, moduleConfig.getPrefix()); + + ActionConfig actionConfig = moduleConfig.findActionConfig("/action1"); + assertNotNull(actionConfig); + assertEquals("/action1", actionConfig.getPath()); + + ActionConfig[] actionConfigs = moduleConfig.findActionConfigs(); + assertNotNull(actionConfigs); + assertEquals(2, actionConfigs.length); + + ExceptionConfig exceptionConfig = moduleConfig.findExceptionConfig(Exception.class.getName()); + assertNotNull(exceptionConfig); + assertEquals(Exception.class.getName(), exceptionConfig.getType()); + + ExceptionConfig[] exceptionConfigs = moduleConfig.findExceptionConfigs(); + assertNotNull(exceptionConfigs); + assertEquals(1, exceptionConfigs.length); + + ForwardConfig fwdConfig = moduleConfig.findForwardConfig("globalResult"); + assertNotNull(fwdConfig); + assertEquals("globalResult", fwdConfig.getName()); + + // These methods are currently not implemented -- replace as functionality is added. + assertNYI(moduleConfig, "getControllerConfig", null); + assertNYI(moduleConfig, "getActionFormBeanClass", null); + assertNYI(moduleConfig, "getActionMappingClass", null); + assertNYI(moduleConfig, "getActionForwardClass", null); + assertNYI(moduleConfig, "findDataSourceConfig", String.class); + assertNYI(moduleConfig, "findDataSourceConfigs", null); + assertNYI(moduleConfig, "findFormBeanConfig", String.class); + assertNYI(moduleConfig, "findFormBeanConfigs", null); + assertNYI(moduleConfig, "findMessageResourcesConfig", String.class); + assertNYI(moduleConfig, "findMessageResourcesConfigs", null); + assertNYI(moduleConfig, "findPlugInConfigs", null); + } + + /** + * Test the creation of a Struts 1.x ActionMapping wrapper around an XWork ActionConfig. + * The ActionConfig is loaded from test-struts-factory.xml. + */ + public void testCreateActionMapping() { + PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME); + com.opensymphony.xwork.config.entities.ActionConfig actionConfig = + (com.opensymphony.xwork.config.entities.ActionConfig) packageConfig.getActionConfigs().get("action1"); + ActionMapping mapping = factory.createActionMapping(actionConfig); + assertNotNull(mapping); + + assertNotNull(mapping.findForward("result1")); + assertNotNull(mapping.findForwardConfig("result2")); + + ForwardConfig[] configs = mapping.findForwardConfigs(); + assertNotNull(configs); + assertEquals(2, configs.length); + + String[] forwards = mapping.findForwards(); + assertNotNull(forwards); + assertEquals(2, forwards.length); + + ActionForward fwd = mapping.findForward("result1"); + assertNotNull(fwd); + assertEquals("result1", fwd.getName()); + + assertNotNull(mapping.findException(NullPointerException.class)); + assertNotNull(mapping.findExceptionConfig("java.lang.IllegalStateException")); + + ExceptionConfig[] exceptionConfigs = mapping.findExceptionConfigs(); + assertNotNull(exceptionConfigs); + assertEquals(3, exceptionConfigs.length); + + ModuleConfig moduleConfig = mapping.getModuleConfig(); + assertNotNull(moduleConfig); + + // For now, the path will be null if the ActionMapping was created on its own (as opposed to from a + // WrapperModuleConfig, which knows the path). + assertNull(mapping.getPath()); + + // These methods are currently not implemented -- replace as functionality is added. + assertNYI(mapping, "getInputForward", null); + assertNYI(mapping, "getAttribute", null); + assertNYI(mapping, "getForward", null); + assertNYI(mapping, "getInclude", null); + assertNYI(mapping, "getInput", null); + assertNYI(mapping, "getMultipartClass", null); + assertNYI(mapping, "getName", null); + assertNYI(mapping, "getParameter", null); + assertNYI(mapping, "getPrefix", null); + assertNYI(mapping, "getRoles", null); + assertNYI(mapping, "getRoleNames", null); + assertNYI(mapping, "getScope", null); + assertNYI(mapping, "getSuffix", null); + assertNYI(mapping, "getType", null); + assertNYI(mapping, "getUnknown", null); + assertNYI(mapping, "getValidate", null); + } + /** + * Test the creation of a Struts 1.x ActionForward wrapper around an XWork ResultConfig. + * The ResultConfig is loaded from test-struts-factory.xml. + */ + public void testCreateActionForward() { + PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME); + ResultConfig resultConfig = (ResultConfig) packageConfig.getGlobalResultConfigs().get("globalResult"); + ActionForward fwd = factory.createActionForward(resultConfig); + assertNotNull(fwd); + assertEquals("globalResult", fwd.getName()); + + // These methods are currently not implemented -- replace as functionality is added. + assertNYI(fwd, "getPath", null); + assertNYI(fwd, "getModule", null); + assertNYI(fwd, "getRedirect", null); + } + /** + * Test the creation of a Struts 1.x ExceptionConfig wrapper around an XWork ExceptionHandlerConfig. + * The ExceptionConfig is loaded from test-struts-factory.xml. + */ + public void testCreateExceptionConfig() { + PackageConfig packageConfig = config.getPackageConfig(PACKAGE_NAME); + ExceptionMappingConfig cfg = (ExceptionMappingConfig) packageConfig.getGlobalExceptionMappingConfigs().get(0); + ExceptionConfig exceptionConfig = factory.createExceptionConfig(cfg); + assertNotNull(exceptionConfig); + assertEquals(Exception.class.getName(), exceptionConfig.getType()); + + assertNYI(exceptionConfig, "getBundle", null); + assertNYI(exceptionConfig, "getHandler", null); + assertNYI(exceptionConfig, "getKey", null); + assertNYI(exceptionConfig, "getPath", null); + assertNYI(exceptionConfig, "getScope", null); + } public void testConvertErrors() throws Exception { @@ -48,5 +219,25 @@ assertTrue(1 == action.getActionErrors().size()); assertTrue(1 == action.getFieldErrors().size()); } -} + /** + * Assert that the given method throws UnsupportedOperationException. + */ + private void assertNYI(Object o, String methodName, Class argType) { + try { + Class[] argTypes = argType != null ? new Class[]{argType} : null; + Object[] args = argType != null ? new Object[]{argType.newInstance()} : null; + o.getClass().getMethod(methodName, argTypes).invoke(o, args); + } catch (InvocationTargetException e) { + Throwable cause = e.getCause(); + assertEquals(cause.getMessage(), UnsupportedOperationException.class, cause.getClass()); + + // OK -- it's what we expected + return; + } catch (Exception e) { + fail(e.getClass().getName() + ": " + e.getMessage()); + } + + fail("Expected UnsupportedOperationException for " + methodName + "() on " + o.getClass().getName()); + } +} Added: struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml?rev=358223&view=auto ============================================================================== --- struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml (added) +++ struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml Tue Dec 20 23:11:58 2005 @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.1.dtd"> + +<!-- Used by the TestStrutsFactory TestCase. --> +<xwork> + <package name="/org/apache/ti/legacy" namespace="/org/apache/ti/legacy"> + <result-types> + <result-type class="com.opensymphony.webwork.dispatcher.ServletDispatcherResult" name="servletDispatcherResult"/> + </result-types> + <global-results> + <result name="globalResult" type="servletDispatcherResult"> + <param name="location">noexist.jsp</param> + </result> + </global-results> + <global-exception-mappings> + <exception-mapping + name="globalException" + exception="java.lang.Exception" + result="globalResult"/> + </global-exception-mappings> + <action class="com.opensymphony.xwork.ActionSupport" name="action1"> + <result name="result1" type="servletDispatcherResult"> + <param name="location">result1.jsp</param> + </result> + <result name="result2" type="servletDispatcherResult"> + <param name="location">result1.jsp</param> + </result> + <exception-mapping + name="exception1" + exception="java.lang.NullPointerException" + result="someResult"/> + <exception-mapping + name="exception2" + exception="java.lang.IllegalStateException" + result="anotherResult"/> + </action> + <action class="com.opensymphony.xwork.ActionSupport" name="action2"/> + </package> +</xwork> + Propchange: struts/sandbox/trunk/ti/phase1/jars/legacy/src/test/org/apache/ti/legacy/test-struts-factory.xml ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]