Author: mrdon Date: Tue Aug 9 20:27:15 2005 New Revision: 231158 URL: http://svn.apache.org/viewcvs?rev=231158&view=rev Log: * Adding form scoping * Adding form create chain * Adding action execution chain
Added: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/InvokeAction.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainInvokeAction.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionChain.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionInvocation.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteFormAction.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteXWorkAction.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ManageFormScope.java Removed: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteAction.java Modified: struts/sandbox/trunk/ti/project.xml struts/sandbox/trunk/ti/src/java/org/apache/ti/config/spring-config-servlet.xml struts/sandbox/trunk/ti/src/java/org/apache/ti/config/xdocletToXWork.vm struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionInvocation.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionProxyFactory.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/CreateFormChain.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ProcessActionChain.java struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml Modified: struts/sandbox/trunk/ti/project.xml URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/project.xml?rev=231158&r1=231157&r2=231158&view=diff ============================================================================== --- struts/sandbox/trunk/ti/project.xml (original) +++ struts/sandbox/trunk/ti/project.xml Tue Aug 9 20:27:15 2005 @@ -43,9 +43,12 @@ <gumpRepositoryId>struts-ti-svn</gumpRepositoryId> <description> - Struts Ti 2.0 is a simplified Model 2 framework for developing webapps which allows the developer better access to the underlying servlet/portlet environment. It serves a niche of web applications that don.t want the additional complexity of server-side components and verbose configuration, yet want the structure and controller features of a modern web framework. Struts Ti 2.0 builds on the directions of Struts 1.x, yet re-implements the framework to provide a clean slate for the next generation of Struts Ti. It aims to combine the simplicity of Ruby on Rails and NanoWeb, the refinement of WebWork 2, the tool-friendly authoring of Beehive, and the history of Struts 1.x. - - </description> + Struts Ti is a simplified Model 2 framework for developing webapps which allows the developer better access to the + underlying servlet/portlet environment. It serves a niche of web applications that don.t want the additional + complexity of server-side components and verbose configuration, yet want the structure and controller features of a + modern web framework. Struts Ti builds on the directions of Struts 1.x, yet re-implements the framework to provide a + clean slate for the next generation of Struts Ti. It aims to combine the simplicity of Ruby on Rails and NanoWeb, + the refinement of WebWork 2, the tool-friendly authoring of Beehive, and the history of Struts 1.x.</description> <shortDescription>MVC Web Application Framework</shortDescription> <url>http://struts.apache.org/index.html</url> @@ -276,7 +279,7 @@ <dependency> <groupId>eclipse</groupId> <artifactId>jdtcore</artifactId> - <version>3.1.0</version> + <version>3.0.1</version> <properties> <war.bundle>true</war.bundle> </properties> Modified: struts/sandbox/trunk/ti/src/java/org/apache/ti/config/spring-config-servlet.xml URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/config/spring-config-servlet.xml?rev=231158&r1=231157&r2=231158&view=diff ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/config/spring-config-servlet.xml (original) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/config/spring-config-servlet.xml Tue Aug 9 20:27:15 2005 @@ -59,4 +59,6 @@ <property name="controllerContext" ref="controllerContext" /> </bean> + <bean id="invokeAction" class="org.apache.ti.processor.chain.ChainInvokeAction" /> + </beans> Modified: struts/sandbox/trunk/ti/src/java/org/apache/ti/config/xdocletToXWork.vm URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/config/xdocletToXWork.vm?rev=231158&r1=231157&r2=231158&view=diff ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/config/xdocletToXWork.vm (original) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/config/xdocletToXWork.vm Tue Aug 9 20:27:15 2005 @@ -18,6 +18,16 @@ #if( $method.returnType.type.type == "java.lang.String.class" && $method.doc.hasTag("ti.action")) #if( $method.parameters.size() == 0 || $method.parameters.size() == 1) <action name="$method.name" method="$method.name" class="$xclass.qualifiedName"> + + #set( $form = $method.doc.getTag("ti.form")) + #if ($form != null) + #if ($form.getAttributeValue("scope") != null) + <param name="formScope">${form.getAttributeScope("scope")}</param> + #end + #if ($form.getAttributeValue("name") != null) + <param name="formName">${form.getAttributeScope("name")}</param> + #end + #end #set( $forwards = $method.doc.getTags("ti.forward")) #if( $forwards.size() == 0) <result name="success"> Modified: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionInvocation.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionInvocation.java?rev=231158&r1=231157&r2=231158&view=diff ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionInvocation.java (original) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionInvocation.java Tue Aug 9 20:27:15 2005 @@ -31,8 +31,14 @@ protected BeanFactory beanFactory; protected Method actionMethod; +<<<<<<< .mine protected Object form; + protected InvokeAction invokeAction; +======= + protected Object form; + +>>>>>>> .r231157 protected ControllerActionInvocation(ActionProxy proxy) throws Exception { this(proxy, null); } @@ -44,6 +50,10 @@ protected ControllerActionInvocation(ActionProxy proxy, Map extraContext, boolean pushAction) throws Exception { super(proxy, extraContext, pushAction); } + + public void setInvokeAction(InvokeAction inv) { + this.invokeAction = inv; + } public Method getActionMethod() { // TODO: this should be optimized @@ -74,6 +84,31 @@ } return actionMethod; } +<<<<<<< .mine + + public Object getForm() { + return form; + } + + public void setForm(Object o) { + this.form = o; + } + + /** + * Invokes action. If the action method contains one parameter, this method + * handles its execution. Otherwise, it is delegated to the super class. + */ + protected String invokeAction(Object action, ActionConfig actionConfig) throws Exception { + + return invokeAction(action, actionConfig); + } + + public String invokeXWorkAction(Object action, ActionConfig actionConfig) + throws Exception { + return super.invokeAction(action, actionConfig); + } + +======= public Object getForm() { return form; @@ -108,4 +143,5 @@ return super.invokeAction(action, actionConfig); } } +>>>>>>> .r231157 } Modified: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionProxyFactory.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionProxyFactory.java?rev=231158&r1=231157&r2=231158&view=diff ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionProxyFactory.java (original) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/ControllerActionProxyFactory.java Tue Aug 9 20:27:15 2005 @@ -6,7 +6,8 @@ import java.util.Map; -import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.*; +import org.springframework.beans.factory.config.*; import org.springframework.beans.factory.BeanFactoryAware; import com.opensymphony.xwork.ActionInvocation; @@ -17,18 +18,39 @@ /** * Creates special action invocation instances that handle ControllerActions */ -public class ControllerActionProxyFactory extends DefaultActionProxyFactory { +public class ControllerActionProxyFactory extends DefaultActionProxyFactory implements BeanFactoryAware { + private BeanFactory beanFactory; + + public void setBeanFactory(BeanFactory factory) { + this.beanFactory = factory; + } + public ActionInvocation createActionInvocation(ActionProxy actionProxy) throws Exception { - return new ControllerActionInvocation(actionProxy); + ActionInvocation inv = new ControllerActionInvocation(actionProxy); + populate(inv); + return inv; } public ActionInvocation createActionInvocation(ActionProxy actionProxy, Map extraContext) throws Exception { - return new ControllerActionInvocation(actionProxy, extraContext); + ActionInvocation inv = new ControllerActionInvocation(actionProxy, extraContext); + populate(inv); + return inv; } public ActionInvocation createActionInvocation(ActionProxy actionProxy, Map extraContext, boolean pushAction) throws Exception { - return new ControllerActionInvocation(actionProxy, extraContext, pushAction); + ActionInvocation inv = new ControllerActionInvocation(actionProxy, extraContext, pushAction); + populate(inv); + return inv; + } + + private void populate(Object o) { + + ((ControllerActionInvocation)o).setInvokeAction((InvokeAction)beanFactory.getBean("invokeAction")); + if (beanFactory instanceof AutowireCapableBeanFactory) { + AutowireCapableBeanFactory f = (AutowireCapableBeanFactory)beanFactory; + f.autowireBeanProperties(o, f.AUTOWIRE_BY_TYPE, false); + } } } Added: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/InvokeAction.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/InvokeAction.java?rev=231158&view=auto ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/InvokeAction.java (added) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/InvokeAction.java Tue Aug 9 20:27:15 2005 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +package org.apache.ti.processor; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.BeanFactory; + +import com.opensymphony.xwork.Action; +import com.opensymphony.xwork.ActionProxy; +import com.opensymphony.xwork.DefaultActionInvocation; +import com.opensymphony.xwork.config.entities.ActionConfig; + + +/** + * Adds code to handle ControllerActions if detected. + * + * @see com.opensymphony.xwork.DefaultActionInvocation + */ +public interface InvokeAction { + + /** + * Invokes action. If the action method contains one parameter, this method + * handles its execution. Otherwise, it is delegated to the super class. + */ + public String invokeAction(Object action, ActionConfig actionConfig) throws Exception; + +} Added: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainInvokeAction.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainInvokeAction.java?rev=231158&view=auto ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainInvokeAction.java (added) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainInvokeAction.java Tue Aug 9 20:27:15 2005 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2002-2003 by OpenSymphony + * All rights reserved. + */ +package org.apache.ti.processor.chain; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.BeanFactory; + +import org.apache.commons.chain.*; + +import com.opensymphony.xwork.Action; +import com.opensymphony.xwork.ActionProxy; +import com.opensymphony.xwork.DefaultActionInvocation; +import com.opensymphony.xwork.config.entities.ActionConfig; + +import com.opensymphony.xwork.ActionContext; + +import org.apache.ti.processor.InvokeAction; + +/** + * Adds code to handle ControllerActions if detected. + * + * @see com.opensymphony.xwork.DefaultActionInvocation + */ +public class ChainInvokeAction implements InvokeAction { + + private static final Log log = LogFactory.getLog(ChainInvokeAction.class); + + protected String catalogName = "struts-ti"; + protected String executeCmdName = "execute-action"; + public static final String RESULT = "actionResult"; + + public void setExecuteActionCommandName(String name) { + this.executeCmdName = name; + } + + public void setCatalogName(String name) { + this.catalogName = name; + } + + /** + * Invokes action. If the action method contains one parameter, this method + * handles its execution. Otherwise, it is delegated to the super class. + */ + public String invokeAction(Object action, ActionConfig actionConfig) throws Exception { + + CatalogFactory factory = CatalogFactory.getInstance(); + Catalog cat = factory.getCatalog(catalogName); + if (cat == null) { + throw new IllegalStateException("Cannot find catalog '" + + catalogName + "'"); + } + + Command executeCmd = cat.getCommand(executeCmdName); + if (executeCmd == null) { + throw new IllegalStateException("Cannot find execute action command '" + + executeCmdName + "'"); + } + + Context ctx = (Context) ActionContext.getContext().get("webContext"); + + executeCmd.execute(ctx); + + String result = (String) ctx.get(RESULT); + + return result; + } + +} Modified: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java?rev=231158&r1=231157&r2=231158&view=diff ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java (original) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ChainRequestProcessor.java Tue Aug 9 20:27:15 2005 @@ -125,7 +125,7 @@ Command initCmd = catalog.getCommand(initCmdName); if (initCmd == null) { throw new ProcessorException("Cannot find init command '" - + startCmdName + "'"); + + initCmdName + "'"); } initCmd.execute(webContext); Modified: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/CreateFormChain.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/CreateFormChain.java?rev=231158&r1=231157&r2=231158&view=diff ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/CreateFormChain.java (original) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/CreateFormChain.java Tue Aug 9 20:27:15 2005 @@ -46,7 +46,7 @@ ActionContext ctx = ActionContext.getContext(); ControllerActionInvocation inv = (ControllerActionInvocation)ctx.getActionInvocation(); - + Method method = inv.getActionMethod(); Class[] params = method.getParameterTypes(); if (params.length == 1) { Added: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionChain.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionChain.java?rev=231158&view=auto ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionChain.java (added) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionChain.java Tue Aug 9 20:27:15 2005 @@ -0,0 +1,50 @@ +/* + * $Id: ExecuteActionChain.java 230569 2005-08-06 19:41:10Z mrdon $ + * + * Copyright 2005 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. + */ +package org.apache.ti.processor.chain; + +import org.apache.ti.processor.*; +import java.lang.reflect.Method; +import org.apache.commons.chain.Context; +import org.apache.commons.chain.web.WebContext; +import org.apache.commons.chain.impl.ChainBase; + +import com.opensymphony.xwork.ActionContext; +import com.opensymphony.xwork.ActionProxy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Initializes XWork by replacing default factories. + */ +public class ExecuteActionChain extends ChainBase { + + private static final Log log = LogFactory.getLog(ExecuteActionChain.class); + + + public boolean execute(Context origctx) throws Exception { + log.info("Processing execute action chain"); + + boolean retCode = super.execute(origctx); + if (!retCode) { + throw new IllegalStateException("Unable to execute action "+ + ActionContext.getContext().getActionInvocation().getAction()); + } + return false; + } +} Added: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionInvocation.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionInvocation.java?rev=231158&view=auto ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionInvocation.java (added) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteActionInvocation.java Tue Aug 9 20:27:15 2005 @@ -0,0 +1,49 @@ +/* + * $Id: ExecuteAction.java 230535 2005-08-06 07:56:40Z mrdon $ + * + * Copyright 2005 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. + */ +package org.apache.ti.processor.chain; + +import org.apache.commons.chain.Command; +import org.apache.commons.chain.Context; + +import com.opensymphony.xwork.ActionContext; +import com.opensymphony.xwork.ActionProxy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Initializes XWork by replacing default factories. + */ +public class ExecuteActionInvocation implements Command { + + private static final Log log = LogFactory.getLog(ExecuteActionInvocation.class); + + public boolean execute(Context origctx) throws Exception { + log.debug("Executing action invocation"); + + ActionContext ctx = ActionContext.getContext(); + ActionProxy proxy = ctx.getActionInvocation().getProxy(); + + String ret = proxy.execute(); + + origctx.put("result", ret); + return false; + } + + +} Added: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteFormAction.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteFormAction.java?rev=231158&view=auto ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteFormAction.java (added) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteFormAction.java Tue Aug 9 20:27:15 2005 @@ -0,0 +1,70 @@ +/* + * $Id: ExecuteFormAction.java 230535 2005-08-06 07:56:40Z mrdon $ + * + * Copyright 2005 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. + */ +package org.apache.ti.processor.chain; + +import org.apache.commons.chain.Command; +import org.apache.commons.chain.Context; + +import com.opensymphony.xwork.ActionContext; +import com.opensymphony.xwork.ActionProxy; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; + +import org.apache.ti.processor.ControllerActionInvocation; + +/** + * Initializes XWork by replacing default factories. + */ +public class ExecuteFormAction implements Command { + + private static final Log log = LogFactory.getLog(ExecuteFormAction.class); + + public boolean execute(Context origctx) throws Exception { + log.debug("Executing form action"); + boolean result = false; + + ActionContext ctx = ActionContext.getContext(); + ControllerActionInvocation inv = (ControllerActionInvocation)ctx.getActionInvocation(); + Method method = inv.getActionMethod(); + Object form = inv.getForm(); + if (method.getParameterTypes().length == 1) { + try { + String res = (String) method.invoke(inv.getAction(), new Object[] {form}); + origctx.put(ChainInvokeAction.RESULT, res); + result = true; + } catch (InvocationTargetException e) { + // We try to return the source exception. + Throwable t = e.getTargetException(); + + if (t instanceof Exception) { + throw (Exception) t; + } else { + throw e; + } + } + } + + return result; + } + + +} Added: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteXWorkAction.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteXWorkAction.java?rev=231158&view=auto ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteXWorkAction.java (added) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ExecuteXWorkAction.java Tue Aug 9 20:27:15 2005 @@ -0,0 +1,64 @@ +/* + * $Id: ExecuteXWorkAction.java 230535 2005-08-06 07:56:40Z mrdon $ + * + * Copyright 2005 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. + */ +package org.apache.ti.processor.chain; + +import org.apache.ti.processor.ControllerActionInvocation; + +import org.apache.commons.chain.Command; +import org.apache.commons.chain.Context; + +import com.opensymphony.xwork.ActionContext; +import com.opensymphony.xwork.ActionProxy; +import java.lang.reflect.InvocationTargetException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Initializes XWork by replacing default factories. + */ +public class ExecuteXWorkAction implements Command { + + private static final Log log = LogFactory.getLog(ExecuteXWorkAction.class); + + public boolean execute(Context origctx) throws Exception { + log.debug("Executing form action"); + boolean result = false; + + ActionContext ctx = ActionContext.getContext(); + ControllerActionInvocation inv = (ControllerActionInvocation) ctx.getActionInvocation(); + try { + String res = inv.invokeXWorkAction(inv.getAction(), inv.getProxy().getConfig()); + origctx.put(ChainInvokeAction.RESULT, res); + result = true; + } catch (InvocationTargetException e) { + // We try to return the source exception. + Throwable t = e.getTargetException(); + + if (t instanceof Exception) { + throw (Exception) t; + } else { + throw e; + } + } + + return result; + } + + +} Added: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ManageFormScope.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ManageFormScope.java?rev=231158&view=auto ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ManageFormScope.java (added) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ManageFormScope.java Tue Aug 9 20:27:15 2005 @@ -0,0 +1,95 @@ +/* + * $Id: ManageFormScope.java 230535 2005-08-06 07:56:40Z mrdon $ + * + * Copyright 2005 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. + */ +package org.apache.ti.processor.chain; + +import org.apache.commons.chain.*; +import org.apache.commons.chain.web.*; + +import java.util.*; + +import org.apache.ti.processor.*; + +import com.opensymphony.xwork.ActionContext; +import com.opensymphony.xwork.ActionProxy; +import com.opensymphony.xwork.config.entities.ActionConfig; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Tries to instantiate the form class's no-arg constructor. + */ +public class ManageFormScope implements Filter { + + private static final Log log = LogFactory.getLog(ManageFormScope.class); + + public boolean execute(Context origctx) throws Exception { + log.debug("Managing form scope"); + + WebContext webCtx = (WebContext)origctx; + String formName = getFormName(); + Map scope = getFormScope(webCtx); + + if (scope != null) { + Object form = scope.get(formName); + if (form == null) { + origctx.put(CreateFormChain.FORM_OBJECT, form); + return true; + } + } + return false; + } + + public boolean postprocess(Context origctx, Exception ex) { + WebContext webCtx = (WebContext)origctx; + + Map scope = getFormScope(webCtx); + if (scope != null) { + Object form = webCtx.get(CreateFormChain.FORM_OBJECT); + if (form != null) { + String formName = getFormName(); + scope.put(formName, form); + } + } + return false; + } + + protected String getFormName() { + ActionContext ctx = ActionContext.getContext(); + ControllerActionInvocation inv = (ControllerActionInvocation)ctx.getActionInvocation(); + String formName = (String)inv.getProxy().getConfig().getParams().get("formName"); + if (formName == null) { + ActionConfig cfg = inv.getProxy().getConfig(); + formName = cfg.getPackageName() + ":"+cfg.getClassName()+":"+cfg.getMethodName(); + } + return formName; + } + + protected Map getFormScope(WebContext webCtx) { + ActionContext ctx = ActionContext.getContext(); + ControllerActionInvocation inv = (ControllerActionInvocation)ctx.getActionInvocation(); + String scopeType = (String)inv.getProxy().getConfig().getParams().get("formScope"); + Map map = null; + if ("request".equals(scopeType)) { + map = webCtx.getRequestScope(); + } else if ("session".equals(scopeType)) { + map = webCtx.getSessionScope(); + } + return map; + } +} Modified: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ProcessActionChain.java URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ProcessActionChain.java?rev=231158&r1=231157&r2=231158&view=diff ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ProcessActionChain.java (original) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/ProcessActionChain.java Tue Aug 9 20:27:15 2005 @@ -54,6 +54,4 @@ return retCode; } - - } Modified: struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml?rev=231158&r1=231157&r2=231158&view=diff ============================================================================== --- struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml (original) +++ struts/sandbox/trunk/ti/src/java/org/apache/ti/processor/chain/chain-config-servlet.xml Tue Aug 9 20:27:15 2005 @@ -60,11 +60,17 @@ <command name="initControllerContext" /> <lookup catalogName="struts-ti" name="createForm" optional="true" /> <command name="selectLocale" className="org.apache.ti.processor.chain.servlet.SelectLocale" /> - <command name="executeAction" className="org.apache.ti.processor.chain.ExecuteAction" /> + <command name="executeActionInvocation" className="org.apache.ti.processor.chain.ExecuteActionInvocation" /> </chain> <chain name="createForm" className="org.apache.ti.processor.chain.CreateFormChain"> + <command name="manageFormScope" className="org.apache.ti.processor.chain.ManageFormScope" /> <command name="createJavaBeanForm" className="org.apache.ti.processor.chain.CreateJavaBeanForm" /> + </chain> + + <chain name="executeAction" className="org.apache.ti.processor.chain.ExecuteActionChain"> + <command name="executeFormAction" className="org.apache.ti.processor.chain.ExecuteFormAction" /> + <command name="executeXWorkAction" className="org.apache.ti.processor.chain.ExecuteXWorkAction" /> </chain> </catalog> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]