commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r452661 - in /jakarta/commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml/env/ main/java/org/apache/commons/scxml/model/ test/java/org/apache/commons/scxml/
Date Tue, 03 Oct 2006 22:42:57 GMT
Author: rahul
Date: Tue Oct  3 15:42:56 2006
New Revision: 452661

URL: http://svn.apache.org/viewvc?view=rev&rev=452661
Log:
The Commons SCXML object model is now Serializable. Includes some non-functional changes such
as reorganization of imports.

To demonstrate serializability, the test suite has been altered such that for each relevant
test involving SCXML document IO, the following sequence is followed:

a) SCXMLDigester parses the document
b) The parsed result is serialized
c) The serialized form is read back into an SCXML object

The result in (c) is now used to run the tests, as against the result in (a) earlier. The
build leaves behind the serialized objects in the "target/serialization" directory (and these
get cleaned up on a clean build).

SCXML-29

Modified:
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/URLResolver.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/CustomAction.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Data.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Datamodel.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Executable.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Invoke.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Param.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/URLResolver.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/URLResolver.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/URLResolver.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/URLResolver.java
Tue Oct  3 15:42:56 2006
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.scxml.env;
 
+import java.io.Serializable;
 import java.net.MalformedURLException;
 import java.net.URL;
 
@@ -29,7 +30,7 @@
  *
  * @see org.apache.commons.scxml.PathResolver
  */
-public class URLResolver implements PathResolver {
+public class URLResolver implements PathResolver, Serializable {
 
     /** Implementation independent log category. */
     private Log log = LogFactory.getLog(PathResolver.class);

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Action.java
Tue Oct  3 15:42:56 2006
@@ -1,6 +1,6 @@
 /*
  *
- *   Copyright 2005 The Apache Software Foundation.
+ *   Copyright 2005-2006 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.
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.io.Serializable;
 import java.util.Collection;
 
 import org.apache.commons.logging.Log;
@@ -30,7 +31,7 @@
  * such as <assign>, <log> etc.
  *
  */
-public abstract class Action {
+public abstract class Action implements Serializable {
 
     /**
      * Link to its parent or container.

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/CustomAction.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/CustomAction.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/CustomAction.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/CustomAction.java
Tue Oct  3 15:42:56 2006
@@ -109,7 +109,7 @@
             throw new IllegalArgumentException(ERR_NO_LOCAL_NAME);
         }
         if (actionClass == null
-                || !SCXMLHelper.subtypeOf(actionClass, Action.class)) {
+                || !Action.class.isAssignableFrom(actionClass)) {
             log.error(ERR_NOT_AN_ACTION);
             throw new IllegalArgumentException(ERR_NOT_AN_ACTION);
         }

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Data.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Data.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Data.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Data.java
Tue Oct  3 15:42:56 2006
@@ -17,6 +17,8 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.io.Serializable;
+
 import org.w3c.dom.Node;
 
 /**
@@ -24,7 +26,7 @@
  * <data> child element of the <datamodel> element.
  *
  */
-public class Data {
+public class Data implements Serializable {
 
     /**
      * The name of this data instance, that is used as its identifier.

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Datamodel.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Datamodel.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Datamodel.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Datamodel.java
Tue Oct  3 15:42:56 2006
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -25,7 +26,7 @@
  * <datamodel> element.
  *
  */
-public class Datamodel {
+public class Datamodel implements Serializable {
 
    /**
     * The set of <data> elements, parsed as Elements, that are

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Executable.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Executable.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Executable.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Executable.java
Tue Oct  3 15:42:56 2006
@@ -1,6 +1,6 @@
 /*
  *
- *   Copyright 2005 The Apache Software Foundation.
+ *   Copyright 2005-2006 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.
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -25,7 +26,7 @@
  * such as <onentry> and <onexit>.
  *
  */
-public abstract class Executable {
+public abstract class Executable implements Serializable {
 
     /**
      * The set of executable elements (those that inheriting from

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Invoke.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Invoke.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Invoke.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Invoke.java
Tue Oct  3 15:42:56 2006
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -27,7 +28,7 @@
  * <invoke> SCXML element.
  *
  */
-public class Invoke implements PathResolverHolder {
+public class Invoke implements PathResolverHolder, Serializable {
 
     /**
      * The type of target to be invoked.

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Param.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Param.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Param.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Param.java
Tue Oct  3 15:42:56 2006
@@ -17,12 +17,14 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.io.Serializable;
+
 /**
  * The class in this SCXML object model that corresponds to the
  * <param> SCXML element.
  *
  */
-public class Param {
+public class Param implements Serializable {
 
     /**
      * The param name.

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/Path.java
Tue Oct  3 15:42:56 2006
@@ -1,6 +1,6 @@
 /*
  *
- *   Copyright 2005 The Apache Software Foundation.
+ *   Copyright 2005-2006 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.
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -34,7 +35,7 @@
  * down to the target of the Transition.
  *
  */
-public class Path {
+public class Path implements Serializable {
 
     /**
      * The list of TransitionTargets in the "up segment".

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
Tue Oct  3 15:42:56 2006
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -28,7 +29,7 @@
  * root".
  *
  */
-public class SCXML {
+public class SCXML implements Serializable {
 
     /**
      * The SCXML XMLNS.
@@ -54,7 +55,7 @@
     /**
      * The initial state ID (used by XML Digester only).
      */
-    private transient String initialstate;
+    private String initialstate;
 
     /**
      * Optional property holding the data model for this SCXML document.

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
Tue Oct  3 15:42:56 2006
@@ -17,12 +17,14 @@
  */
 package org.apache.commons.scxml.model;
 
+import java.io.Serializable;
+
 /**
  * An abstract base class for elements in SCXML that can serve as a
  * <target> for a <transition>, such as State or Parallel.
  *
  */
-public abstract class TransitionTarget {
+public abstract class TransitionTarget implements Serializable {
 
     /**
      * Identifier for this transition target. Other parts of the SCXML

Modified: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java?view=diff&rev=452661&r1=452660&r2=452661
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/SCXMLTestHelper.java
Tue Oct  3 15:42:56 2006
@@ -15,6 +15,12 @@
  */
 package org.apache.commons.scxml;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.net.URL;
 import java.util.List;
 import java.util.Set;
@@ -23,7 +29,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.commons.scxml.env.SimpleDispatcher;
 import org.apache.commons.scxml.env.Tracer;
 import org.apache.commons.scxml.env.jexl.JexlContext;
@@ -31,13 +36,22 @@
 import org.apache.commons.scxml.io.SCXMLDigester;
 import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.TransitionTarget;
-
 import org.xml.sax.ErrorHandler;
 /**
  * Helper methods for running SCXML unit tests.
  */
 public class SCXMLTestHelper {
 
+    /**
+     * Serialized Commons SCXML object model temporary store.
+     * Assumes the default build artifacts are generated in the
+     * "target" directory (so it can be removed via a clean build).
+     */
+    public static final String SERIALIZATION_DIR = "target/serialization";
+    public static final String SERIALIZATION_FILE_PREFIX =
+        SERIALIZATION_DIR + "/scxml";
+    public static final String SERIALIZATION_FILE_SUFFIX = ".ser";
+
     public static SCXML digest(final URL url) {
         return digest(url, null, null);
     }
@@ -63,7 +77,8 @@
             Assert.fail(e.getMessage());
         }
         Assert.assertNotNull(scxml);
-        return scxml;
+        SCXML roundtrip = testModelSerializability(scxml);
+        return roundtrip;
     }
 
     public static SCXMLExecutor getExecutor(final URL url) {
@@ -207,6 +222,31 @@
             Assert.fail(e.getMessage());
         }
         return exec.getCurrentStatus().getStates();
+    }
+
+    public static SCXML testModelSerializability(final SCXML scxml) {
+        File fileDir = new File(SERIALIZATION_DIR);
+        if (!fileDir.exists() && !fileDir.mkdir()) {
+            return null;
+        }
+        String filename = SERIALIZATION_FILE_PREFIX
+            + System.currentTimeMillis() + SERIALIZATION_FILE_SUFFIX;
+        SCXML roundtrip = null;
+        try {
+            ObjectOutputStream out =
+                new ObjectOutputStream(new FileOutputStream(filename));
+            out.writeObject(scxml);
+            out.close();
+            ObjectInputStream in =
+                new ObjectInputStream(new FileInputStream(filename));
+            roundtrip = (SCXML) in.readObject();
+            in.close();
+        } catch(IOException ex) {
+            ex.printStackTrace();
+        } catch(ClassNotFoundException ex) {
+            ex.printStackTrace();
+        }
+        return roundtrip;
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message