Commits

jcarreira  committed 9de68b7

Making ActionContext, ActionProxy, ActionInvocation, OgnlValueStack, etc. Serializable

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk/src@41e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits bed6c84

Comments (0)

Files changed (8)

File java/com/opensymphony/xwork/ActionContext.java

 
 import com.opensymphony.xwork.util.OgnlValueStack;
 
+import java.io.Serializable;
+
 import java.util.Locale;
 import java.util.Map;
 
  * @author $Author$
  * @version $Revision$
  */
-public class ActionContext {
+public class ActionContext implements Serializable {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     static ThreadLocal actionContext = new ActionContextThreadLocal();

File java/com/opensymphony/xwork/ActionInvocation.java

 
 import com.opensymphony.xwork.util.OgnlValueStack;
 
+import java.io.Serializable;
+
 
 /**
  * ActionInvocation
  * @author Jason Carreira
  * Created Jun 9, 2003 11:37:27 AM
  */
-public interface ActionInvocation {
+public interface ActionInvocation extends Serializable {
     //~ Methods ////////////////////////////////////////////////////////////////
 
     Action getAction();

File java/com/opensymphony/xwork/ActionProxy.java

 import com.opensymphony.xwork.config.entities.ActionConfig;
 import com.opensymphony.xwork.util.OgnlValueStack;
 
+import java.io.Serializable;
+
 
 /**
  * ActionProxy
  * @author Jason Carreira
  * Created Jun 9, 2003 11:27:55 AM
  */
-public interface ActionProxy {
+public interface ActionProxy extends Serializable {
     //~ Methods ////////////////////////////////////////////////////////////////
 
     Action getAction();

File java/com/opensymphony/xwork/Result.java

  */
 package com.opensymphony.xwork;
 
+import java.io.Serializable;
+
 
 /**
  * All results (except for NONE) of an Action are mapped to a View implementation.
  * @author $Author$
  * @version $Revision$
  */
-public interface Result {
+public interface Result extends Serializable {
     //~ Methods ////////////////////////////////////////////////////////////////
 
     /**

File java/com/opensymphony/xwork/config/entities/ActionConfig.java

 
 import com.opensymphony.xwork.interceptor.Interceptor;
 
+import java.io.Serializable;
+
 import java.lang.reflect.Method;
 
 import java.util.ArrayList;
  * @author $Author$
  * @version $Revision$
  */
-public class ActionConfig implements InterceptorListHolder, Parameterizable {
+public class ActionConfig implements InterceptorListHolder, Parameterizable, Serializable {
     //~ Instance fields ////////////////////////////////////////////////////////
 
     protected List interceptors;

File java/com/opensymphony/xwork/util/OgnlValueStack.java

 import ognl.OgnlException;
 import ognl.OgnlRuntime;
 
+import java.io.IOException;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+
 import java.util.Map;
 
 
  * @author $Author$
  * @version $Revision$
  */
-public class OgnlValueStack {
+public class OgnlValueStack implements Serializable {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     public static final String VALUE_STACK = "com.opensymphony.xwork.util.OgnlValueStack.ValueStack";
     //~ Instance fields ////////////////////////////////////////////////////////
 
     CompoundRoot root;
-    Map context;
+    transient Map context;
 
     //~ Constructors ///////////////////////////////////////////////////////////
 
     public OgnlValueStack() {
-        this.root = new CompoundRoot();
-        this.context = Ognl.createDefaultContext(this.root, accessor, XWorkConverter.getInstance());
-        context.put(VALUE_STACK, this);
-        Ognl.setClassResolver(context, accessor);
+        setRoot(new CompoundRoot());
     }
 
     //~ Methods ////////////////////////////////////////////////////////////////
     public int size() {
         return root.size();
     }
+
+    private void setRoot(CompoundRoot compoundRoot) {
+        this.root = compoundRoot;
+        this.context = Ognl.createDefaultContext(this.root, accessor, XWorkConverter.getInstance());
+        context.put(VALUE_STACK, this);
+        Ognl.setClassResolver(context, accessor);
+    }
+
+    private Object readResolve() throws ObjectStreamException {
+        OgnlValueStack aStack = new OgnlValueStack();
+        aStack.setRoot(this.root);
+
+        return aStack;
+    }
 }

File test/com/opensymphony/xwork/util/Dog.java

  */
 package com.opensymphony.xwork.util;
 
+import java.io.Serializable;
+
 
 /**
  *
  * @author $Author$
  * @version $Revision$
  */
-public class Dog {
+public class Dog implements Serializable {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     public static final String SCIENTIFIC_NAME = "Canine";

File test/com/opensymphony/xwork/util/OgnlValueStackTest.java

 
 import junit.framework.TestCase;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 import java.math.BigDecimal;
 
 
         assertEquals("Rover", vs.findValue("[1].name"));
     }
 
+    public void testSerializable() throws IOException, ClassNotFoundException {
+        OgnlValueStack vs = new OgnlValueStack();
+
+        Dog dog = new Dog();
+        dog.setAge(12);
+        dog.setName("Rover");
+
+        vs.push(dog);
+        assertEquals("Rover", vs.findValue("name", String.class));
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+        oos.writeObject(vs);
+        oos.flush();
+
+        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        ObjectInputStream ois = new ObjectInputStream(bais);
+
+        OgnlValueStack newVs = (OgnlValueStack) ois.readObject();
+        assertEquals("Rover", newVs.findValue("name", String.class));
+    }
+
     public void testSettingDogGender() {
         OgnlValueStack vs = new OgnlValueStack();