commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1579092 - in /commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2: io/ModelUpdater.java io/SCXMLWriter.java model/Initial.java model/State.java
Date Wed, 19 Mar 2014 00:12:13 GMT
Author: ate
Date: Wed Mar 19 00:12:13 2014
New Revision: 1579092

URL: http://svn.apache.org/r1579092
Log:
SCXML-196: - generate <initial> element for composite states if none is defined or
- mark Initial been generated for the above or when created through <state> initial
attribute
- don't write out generated <initial> elements
- disallow <initial> elements for atomic states
- code cleanup

Modified:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Initial.java
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/State.java

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java?rev=1579092&r1=1579091&r2=1579092&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java
(original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/ModelUpdater.java
Wed Mar 19 00:12:13 2014
@@ -17,7 +17,6 @@
 package org.apache.commons.scxml2.io;
 
 import java.text.MessageFormat;
-import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -52,11 +51,10 @@ final class ModelUpdater {
             + "with ID \"{0}\" found; illegal initial state for SCXML document";
 
     /**
-     * Error message when a state element specifies an initial state which
-     * cannot be found.
+     * Error message when SCXML document specifies an illegal initial state.
      */
-    private static final String ERR_STATE_NO_INIT = "No initial element "
-            + "available for {0}";
+    private static final String ERR_UNSUPPORTED_INIT = "Initial attribute or element not
supported for "
+            + "atomic {0}";
 
     /**
      * Error message when a state element specifies an initial state which
@@ -157,78 +155,80 @@ final class ModelUpdater {
      * @param scxml The SCXML object (output from SCXMLReader)
      * @throws ModelException If the object model is flawed
      */
-   static void updateSCXML(final SCXML scxml) throws ModelException {
-       String initial = scxml.getInitial();
-       Transition initialTransition = new Transition();
-
-       if (initial != null) {
-
-           initialTransition.setNext(scxml.getInitial());
-           updateTransition(initialTransition, scxml.getTargets());
-
-           if (initialTransition.getTargets().size() == 0) {
-               logAndThrowModelError(ERR_SCXML_NO_INIT, new Object[] {
-                   initial });
-           }
-       } else {
-           // If 'initial' is not specified, the default initial state is
-           // the first child state in document order.
-           initialTransition.getTargets().add(scxml.getFirstChild());
-           initialTransition.getPaths(); // init paths
-       }
-
-       scxml.setInitialTransition(initialTransition);
-       Map<String, TransitionTarget> targets = scxml.getTargets();
-       Map<String, TransitionTarget> children = scxml.getChildren();
-       for (TransitionTarget tt : children.values()) {
-           if (tt instanceof State) {
-               updateState((State) tt, targets);
-           } else {
-               updateParallel((Parallel) tt, targets);
-           }
-       }
-   }
-
-    /**
-      * Update this State object (part of post-read processing).
-      * Also checks for any errors in the document.
-      *
-      * @param s The State object
-      * @param targets The global Map of all transition targets
-      * @throws ModelException If the object model is flawed
-      */
+    static void updateSCXML(final SCXML scxml) throws ModelException {
+        String initial = scxml.getInitial();
+        Transition initialTransition = new Transition();
+
+        if (initial != null) {
+
+            initialTransition.setNext(scxml.getInitial());
+            updateTransition(initialTransition, scxml.getTargets());
+
+            if (initialTransition.getTargets().size() == 0) {
+                logAndThrowModelError(ERR_SCXML_NO_INIT, new Object[] {
+                        initial });
+            }
+        } else {
+            // If 'initial' is not specified, the default initial state is
+            // the first child state in document order.
+            initialTransition.getTargets().add(scxml.getFirstChild());
+            initialTransition.getPaths(); // init paths
+        }
+
+        scxml.setInitialTransition(initialTransition);
+        Map<String, TransitionTarget> targets = scxml.getTargets();
+        Map<String, TransitionTarget> children = scxml.getChildren();
+        for (TransitionTarget tt : children.values()) {
+            if (tt instanceof State) {
+                updateState((State) tt, targets);
+            } else {
+                updateParallel((Parallel) tt, targets);
+            }
+        }
+    }
+
+    /**
+     * Update this State object (part of post-read processing).
+     * Also checks for any errors in the document.
+     *
+     * @param s The State object
+     * @param targets The global Map of all transition targets
+     * @throws ModelException If the object model is flawed
+     */
     private static void updateState(final State s, final Map<String, TransitionTarget>
targets)
-    throws ModelException {
-        //initialize next / inital
-        Initial ini = s.getInitial();
+            throws ModelException {
         Map<String, TransitionTarget> c = s.getChildren();
-        List<TransitionTarget> initialStates = null;
-        if (!c.isEmpty()) {
+        if (s.isComposite()) {
+            //initialize next / initial
+            Initial ini = s.getInitial();
             if (ini == null) {
-                logAndThrowModelError(ERR_STATE_NO_INIT,
-                    new Object[] {getName(s)});
+                s.setFirst(c.keySet().iterator().next());
+                ini = s.getInitial();
             }
             Transition initialTransition = ini.getTransition();
             updateTransition(initialTransition, targets);
-            initialStates = initialTransition.getTargets();
+            List<TransitionTarget> initialStates = initialTransition.getTargets();
             // we have to allow for an indirect descendant initial (targets)
             //check that initialState is a descendant of s
             if (initialStates.size() == 0) {
                 logAndThrowModelError(ERR_STATE_BAD_INIT,
-                    new Object[] {getName(s)});
+                        new Object[] {getName(s)});
             } else {
                 for (TransitionTarget initialState : initialStates) {
                     if (!SCXMLHelper.isDescendant(initialState, s)) {
                         logAndThrowModelError(ERR_STATE_BAD_INIT,
-                            new Object[] {getName(s)});
+                                new Object[] {getName(s)});
                     }
                 }
             }
         }
+        else if (s.getInitial() != null) {
+            logAndThrowModelError(ERR_UNSUPPORTED_INIT, new Object[] {getName(s)});
+        }
         List<History> histories = s.getHistory();
         if (histories.size() > 0 && s.isSimple()) {
             logAndThrowModelError(ERR_HISTORY_SIMPLE_STATE,
-                new Object[] {getName(s)});
+                    new Object[] {getName(s)});
         }
         for (History h : histories) {
             updateHistory(h, targets, s);
@@ -244,20 +244,20 @@ final class ModelUpdater {
             String type = inv.getType();
             if (type == null || type.trim().length() == 0) {
                 logAndThrowModelError(ERR_INVOKE_NO_TYPE,
-                    new Object[] {getName(s)});
+                        new Object[] {getName(s)});
             }
             String src = inv.getSrc();
             boolean noSrc = (src == null || src.trim().length() == 0);
             String srcexpr = inv.getSrcexpr();
             boolean noSrcexpr = (srcexpr == null
-                                 || srcexpr.trim().length() == 0);
+                    || srcexpr.trim().length() == 0);
             if (noSrc && noSrcexpr) {
                 logAndThrowModelError(ERR_INVOKE_NO_SRC,
-                    new Object[] {getName(s)});
+                        new Object[] {getName(s)});
             }
             if (!noSrc && !noSrcexpr) {
                 logAndThrowModelError(ERR_INVOKE_AMBIGUOUS_SRC,
-                    new Object[] {getName(s)});
+                        new Object[] {getName(s)});
             }
         } else {
             for (TransitionTarget tt : c.values()) {
@@ -271,14 +271,14 @@ final class ModelUpdater {
     }
 
     /**
-      * Update this Parallel object (part of post-read processing).
-      *
-      * @param p The Parallel object
-      * @param targets The global Map of all transition targets
-      * @throws ModelException If the object model is flawed
-      */
+     * Update this Parallel object (part of post-read processing).
+     *
+     * @param p The Parallel object
+     * @param targets The global Map of all transition targets
+     * @throws ModelException If the object model is flawed
+     */
     private static void updateParallel(final Parallel p, final Map<String, TransitionTarget>
targets)
-    throws ModelException {
+            throws ModelException {
         for (TransitionTarget tt : p.getChildren()) {
             updateState((State) tt, targets);
         }
@@ -292,62 +292,64 @@ final class ModelUpdater {
     }
 
     /**
-      * Update this History object (part of post-read processing).
-      *
-      * @param h The History object
-      * @param targets The global Map of all transition targets
-      * @param parent The parent TransitionTarget for this History
-      * @throws ModelException If the object model is flawed
-      */
+     * Update this History object (part of post-read processing).
+     *
+     * @param h The History object
+     * @param targets The global Map of all transition targets
+     * @param parent The parent TransitionTarget for this History
+     * @throws ModelException If the object model is flawed
+     */
     private static void updateHistory(final History h,
-            final Map<String, TransitionTarget> targets,
-            final TransitionTarget parent)
-    throws ModelException {
+                                      final Map<String, TransitionTarget> targets,
+                                      final TransitionTarget parent)
+            throws ModelException {
         Transition historyTransition = h.getTransition();
         if (historyTransition == null || historyTransition.getNext() == null) {
             logAndThrowModelError(ERR_HISTORY_NO_DEFAULT,
                     new Object[] {h.getId(), getName(parent)});
         }
-        updateTransition(historyTransition, targets);
-        List<TransitionTarget> historyStates = historyTransition.getTargets();
-        if (historyStates.size() == 0) {
-            logAndThrowModelError(ERR_STATE_NO_HIST,
-                new Object[] {getName(parent)});
-        }
-        for (TransitionTarget historyState : historyStates) {
-            if (!h.isDeep()) {
-                // Shallow history
-                boolean shallow = false;
-                if (parent instanceof State) {
-                    shallow = ((State) parent).getChildren().
-                        containsValue(historyState);
-                } else if (parent instanceof Parallel) {
-                    shallow = ((Parallel) parent).getChildren().
-                        contains(historyState);
-                }
-                if (!shallow) {
-                    logAndThrowModelError(ERR_STATE_BAD_SHALLOW_HIST,
-                        new Object[] {getName(parent)});
-                }
-            } else {
-                // Deep history
-                if (!SCXMLHelper.isDescendant(historyState, parent)) {
-                    logAndThrowModelError(ERR_STATE_BAD_DEEP_HIST,
+        else {
+            updateTransition(historyTransition, targets);
+            List<TransitionTarget> historyStates = historyTransition.getTargets();
+            if (historyStates.size() == 0) {
+                logAndThrowModelError(ERR_STATE_NO_HIST,
                         new Object[] {getName(parent)});
+            }
+            for (TransitionTarget historyState : historyStates) {
+                if (!h.isDeep()) {
+                    // Shallow history
+                    boolean shallow = false;
+                    if (parent instanceof State) {
+                        shallow = ((State) parent).getChildren().
+                                containsValue(historyState);
+                    } else if (parent instanceof Parallel) {
+                        shallow = ((Parallel) parent).getChildren().
+                                contains(historyState);
+                    }
+                    if (!shallow) {
+                        logAndThrowModelError(ERR_STATE_BAD_SHALLOW_HIST,
+                                new Object[] {getName(parent)});
+                    }
+                } else {
+                    // Deep history
+                    if (!SCXMLHelper.isDescendant(historyState, parent)) {
+                        logAndThrowModelError(ERR_STATE_BAD_DEEP_HIST,
+                                new Object[] {getName(parent)});
+                    }
                 }
             }
         }
     }
 
     /**
-      * Update this Transition object (part of post-read processing).
-      *
-      * @param t The Transition object
-      * @param targets The global Map of all transition targets
-      * @throws ModelException If the object model is flawed
-      */
+     * Update this Transition object (part of post-read processing).
+     *
+     * @param t The Transition object
+     * @param targets The global Map of all transition targets
+     * @throws ModelException If the object model is flawed
+     */
     private static void updateTransition(final Transition t,
-            final Map<String, TransitionTarget> targets) throws ModelException {
+                                         final Map<String, TransitionTarget> targets)
throws ModelException {
         String next = t.getNext();
         if (next == null) { // stay transition
             return;
@@ -361,7 +363,7 @@ final class ModelUpdater {
                 TransitionTarget tt = targets.get(id);
                 if (tt == null) {
                     logAndThrowModelError(ERR_TARGET_NOT_FOUND, new Object[] {
-                        id });
+                            id });
                 }
                 tts.add(tt);
             }
@@ -377,18 +379,18 @@ final class ModelUpdater {
     }
 
     /**
-      * Log an error discovered in post-read processing.
-      *
-      * @param errType The type of error
-      * @param msgArgs The arguments for formatting the error message
-      * @throws ModelException The model error, always thrown.
-      */
+     * Log an error discovered in post-read processing.
+     *
+     * @param errType The type of error
+     * @param msgArgs The arguments for formatting the error message
+     * @throws ModelException The model error, always thrown.
+     */
     private static void logAndThrowModelError(final String errType,
-            final Object[] msgArgs) throws ModelException {
+                                              final Object[] msgArgs) throws ModelException
{
         MessageFormat msgFormat = new MessageFormat(errType);
         String errMsg = msgFormat.format(msgArgs);
         org.apache.commons.logging.Log log = LogFactory.
-            getLog(ModelUpdater.class);
+                getLog(ModelUpdater.class);
         log.error(errMsg);
         throw new ModelException(errMsg);
     }
@@ -450,10 +452,6 @@ final class ModelUpdater {
                 return false; // One per region
             }
         }
-        if (regions.size() != p.getChildren().size()) {
-            return false; // Must represent all regions
-        }
-        return true;
+        return regions.size() == p.getChildren().size();
     }
-}
-
+}
\ No newline at end of file

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java?rev=1579092&r1=1579091&r2=1579092&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java
(original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java
Wed Mar 19 00:12:13 2014
@@ -73,7 +73,6 @@ import org.apache.commons.scxml2.model.T
 import org.apache.commons.scxml2.model.Var;
 import org.w3c.dom.Node;
 
-
 /**
  * <p>Utility class for serializing the Commons SCXML Java object
  * model. Class uses the visitor pattern to trace through the
@@ -199,10 +198,9 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     public static String write(final SCXML scxml)
-    throws IOException, XMLStreamException {
+            throws IOException, XMLStreamException {
 
         return write(scxml, new Configuration(true, true));
-
     }
 
     /**
@@ -219,7 +217,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     public static String write(final SCXML scxml, final Configuration configuration)
-    throws IOException, XMLStreamException {
+            throws IOException, XMLStreamException {
 
         // Must be true since we want to return a string
         configuration.writeToString = true;
@@ -230,7 +228,6 @@ public class SCXMLWriter {
             configuration.internalWriter.flush();
             return configuration.internalWriter.toString();
         }
-
     }
 
     /**
@@ -244,10 +241,9 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     public static void write(final SCXML scxml, final OutputStream scxmlStream)
-    throws IOException, XMLStreamException {
+            throws IOException, XMLStreamException {
 
         write(scxml, scxmlStream, new Configuration());
-
     }
 
     /**
@@ -262,7 +258,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     public static void write(final SCXML scxml, final OutputStream scxmlStream, final Configuration
configuration)
-    throws IOException, XMLStreamException {
+            throws IOException, XMLStreamException {
 
         if (scxmlStream == null) {
             throw new IllegalArgumentException(ERR_NULL_OSTR);
@@ -272,7 +268,6 @@ public class SCXMLWriter {
             scxmlStream.flush();
             scxmlStream.close();
         }
-
     }
 
     /**
@@ -286,10 +281,9 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     public static void write(final SCXML scxml, final Writer scxmlWriter)
-    throws IOException, XMLStreamException {
+            throws IOException, XMLStreamException {
 
         write(scxml, scxmlWriter, new Configuration());
-
     }
 
     /**
@@ -304,7 +298,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     public static void write(final SCXML scxml, final Writer scxmlWriter, final Configuration
configuration)
-    throws IOException, XMLStreamException {
+            throws IOException, XMLStreamException {
 
         if (scxmlWriter == null) {
             throw new IllegalArgumentException(ERR_NULL_WRIT);
@@ -314,7 +308,6 @@ public class SCXMLWriter {
             scxmlWriter.flush();
             scxmlWriter.close();
         }
-
     }
 
     /**
@@ -328,10 +321,9 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     public static void write(final SCXML scxml, final Result scxmlResult)
-    throws IOException, XMLStreamException {
+            throws IOException, XMLStreamException {
 
         write(scxml, scxmlResult, new Configuration());
-
     }
 
     /**
@@ -346,13 +338,12 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     public static void write(final SCXML scxml, final Result scxmlResult, final Configuration
configuration)
-    throws IOException, XMLStreamException {
+            throws IOException, XMLStreamException {
 
         if (scxmlResult == null) {
             throw new IllegalArgumentException(ERR_NULL_RES);
         }
         writeInternal(scxml, configuration, null, null, scxmlResult);
-
     }
 
     //---------------------- PRIVATE UTILITY METHODS ----------------------//
@@ -370,8 +361,8 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeInternal(final SCXML scxml, final Configuration configuration,
-            final OutputStream scxmlStream, final Writer scxmlWriter, final Result scxmlResult)
-    throws IOException, XMLStreamException {
+                                      final OutputStream scxmlStream, final Writer scxmlWriter,
final Result scxmlResult)
+            throws IOException, XMLStreamException {
 
         XMLStreamWriter writer = getWriter(configuration, scxmlStream, scxmlWriter, scxmlResult);
         writeDocument(writer, configuration, scxml);
@@ -388,7 +379,6 @@ public class SCXMLWriter {
                 configuration.prettyPrintOutput = prettyPrintWriter.toString();
             }
         }
-
     }
 
     /**
@@ -402,8 +392,8 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeDocument(final XMLStreamWriter writer, final Configuration configuration,
-            final SCXML scxml)
-    throws XMLStreamException {
+                                      final SCXML scxml)
+            throws XMLStreamException {
 
         String encoding = "UTF-8";
         if (configuration.encoding != null) {
@@ -412,7 +402,6 @@ public class SCXMLWriter {
         writer.writeStartDocument(encoding, "1.0");
         writeSCXML(writer, scxml);
         writer.writeEndDocument();
-
     }
 
     /**
@@ -424,7 +413,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeSCXML(final XMLStreamWriter writer, final SCXML scxml)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         // Start
         writer.writeStartElement(ELEM_SCXML);
@@ -471,7 +460,6 @@ public class SCXMLWriter {
 
         // End
         writer.writeEndElement();
-
     }
 
     /**
@@ -483,7 +471,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeDatamodel(final XMLStreamWriter writer, final Datamodel datamodel)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         if (datamodel == null) {
             return;
@@ -507,7 +495,6 @@ public class SCXMLWriter {
             }
         }
         writer.writeEndElement();
-
     }
 
     /**
@@ -519,7 +506,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeState(final XMLStreamWriter writer, final State state)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         writer.writeStartElement(ELEM_STATE);
         writeAV(writer, ATTR_ID, state.getId());
@@ -555,7 +542,6 @@ public class SCXMLWriter {
 
         writeOnExit(writer, state.getOnExit());
         writer.writeEndElement();
-
     }
 
     /**
@@ -567,7 +553,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeParallel(final XMLStreamWriter writer, final Parallel parallel)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         writer.writeStartElement(ELEM_PARALLEL);
         writeAV(writer, ATTR_ID, parallel.getId());
@@ -590,7 +576,6 @@ public class SCXMLWriter {
 
         writeOnExit(writer, parallel.getOnExit());
         writer.writeEndElement();
-
     }
 
     /**
@@ -602,7 +587,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeFinal(final XMLStreamWriter writer, final Final end)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         writer.writeStartElement(ELEM_FINAL);
         writeAV(writer, ATTR_ID, end.getId());
@@ -610,7 +595,6 @@ public class SCXMLWriter {
         // params
         writeOnExit(writer, end.getOnExit());
         writer.writeEndElement();
-
     }
 
     /**
@@ -622,16 +606,15 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeInitial(final XMLStreamWriter writer, final Initial initial)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
-        if (initial == null) {
+        if (initial == null || initial.isGenerated()) {
             return;
         }
 
         writer.writeStartElement(ELEM_INITIAL);
         writeTransition(writer, initial.getTransition());
         writer.writeEndElement();
-
     }
 
     /**
@@ -644,7 +627,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeHistory(final XMLStreamWriter writer, final List<History>
history)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         if (history == null) {
             return;
@@ -661,7 +644,6 @@ public class SCXMLWriter {
             writeTransition(writer, h.getTransition());
             writer.writeEndElement();
         }
-
     }
 
     /**
@@ -673,14 +655,13 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeOnEntry(final XMLStreamWriter writer, final OnEntry onentry)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         if (onentry != null && onentry.getActions().size() > 0) {
             writer.writeStartElement(ELEM_ONENTRY);
             writeExecutableContent(writer, onentry.getActions());
             writer.writeEndElement();
         }
-
     }
 
     /**
@@ -692,14 +673,13 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeOnExit(final XMLStreamWriter writer, final OnExit onexit)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         if (onexit != null && onexit.getActions().size() > 0) {
             writer.writeStartElement(ELEM_ONEXIT);
             writeExecutableContent(writer, onexit.getActions());
             writer.writeEndElement();
         }
-
     }
 
     /**
@@ -711,7 +691,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeTransition(final XMLStreamWriter writer, final Transition transition)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         writer.writeStartElement(ELEM_TRANSITION);
         writeAV(writer, ATTR_EVENT, transition.getEvent());
@@ -719,7 +699,6 @@ public class SCXMLWriter {
         writeAV(writer, ATTR_TARGET, transition.getNext());
         writeExecutableContent(writer, transition.getActions());
         writer.writeEndElement();
-
     }
 
     /**
@@ -731,7 +710,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeInvoke(final XMLStreamWriter writer, final Invoke invoke)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         writer.writeStartElement(ELEM_INVOKE);
         writeAV(writer, ATTR_SRC, invoke.getSrc());
@@ -747,7 +726,6 @@ public class SCXMLWriter {
         writeFinalize(writer, invoke.getFinalize());
 
         writer.writeEndElement();
-
     }
 
     /**
@@ -759,14 +737,13 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeFinalize(final XMLStreamWriter writer, final Finalize finalize)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         if (finalize != null && finalize.getActions().size() > 0) {
             writer.writeStartElement(ELEM_FINALIZE);
             writeExecutableContent(writer, finalize.getActions());
             writer.writeEndElement();
         }
-
     }
 
     /**
@@ -779,7 +756,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeExecutableContent(final XMLStreamWriter writer, final List<Action>
actions)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         if (actions == null) {
             return;
@@ -837,7 +814,6 @@ public class SCXMLWriter {
                 writer.writeComment("Custom action with class name '" + a.getClass().getName()
+ "' not serialized");
             }
         }
-
     }
 
     /**
@@ -849,7 +825,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeSend(final XMLStreamWriter writer, final Send send)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         writer.writeStartElement(XMLNS_SCXML, ELEM_SEND);
         writeAV(writer, ATTR_SENDID, send.getSendid());
@@ -863,7 +839,6 @@ public class SCXMLWriter {
         writeExternalContent(writer, send);
 
         writer.writeEndElement();
-
     }
 
     /**
@@ -875,7 +850,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeIf(final XMLStreamWriter writer, final If iff)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         writer.writeStartElement(ELEM_IF);
         writeAV(writer, ATTR_COND, SCXMLHelper.escapeXML(iff.getCond()));
@@ -911,8 +886,8 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeExternalContent(final XMLStreamWriter writer,
-            final ExternalContent externalContent)
-    throws XMLStreamException {
+                                             final ExternalContent externalContent)
+            throws XMLStreamException {
 
         List<Node> externalNodes = externalContent.getExternalNodes();
 
@@ -923,7 +898,6 @@ public class SCXMLWriter {
                 writeNode(writer, n);
             }
         }
-
     }
 
     /**
@@ -935,7 +909,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeNode(final XMLStreamWriter writer, final Node node)
-    throws XMLStreamException {
+            throws XMLStreamException {
 
         Source input = new DOMSource(node);
         StringWriter out = new StringWriter();
@@ -948,7 +922,6 @@ public class SCXMLWriter {
             writer.writeComment("TransformerException: Node was not serialized");
         }
         writer.writeCharacters(out.toString());
-
     }
 
     /**
@@ -961,7 +934,7 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writeAV(final XMLStreamWriter writer, final String localName, final
String value)
-    throws XMLStreamException {
+            throws XMLStreamException {
         if (value != null) {
             writer.writeAttribute(localName, value);
         }
@@ -981,8 +954,8 @@ public class SCXMLWriter {
      * @throws XMLStreamException An exception processing the underlying {@link XMLStreamWriter}.
      */
     private static void writePretty(final Configuration configuration, final OutputStream
scxmlStream,
-            final Writer scxmlWriter, final Result scxmlResult)
-    throws IOException, XMLStreamException {
+                                    final Writer scxmlWriter, final Result scxmlResult)
+            throws IOException, XMLStreamException {
 
         // There isn't any portable way to write pretty using the JDK 1.6 StAX API
         configuration.internalWriter.flush();
@@ -1007,7 +980,6 @@ public class SCXMLWriter {
         } catch (TransformerException te) {
             throw new XMLStreamException("TransformerException while pretty printing SCXML",
te);
         }
-
     }
 
     /**
@@ -1024,15 +996,17 @@ public class SCXMLWriter {
      * @throws XMLStreamException A problem with the XML stream creation.
      */
     private static XMLStreamWriter getWriter(final Configuration configuration, final OutputStream
stream,
-            final Writer writer, final Result result)
-    throws XMLStreamException {
+                                             final Writer writer, final Result result)
+            throws XMLStreamException {
 
         // Instantiate the XMLOutputFactory
         XMLOutputFactory factory = XMLOutputFactory.newInstance();
+        /*
         if (configuration.factoryId != null && configuration.factoryClassLoader !=
null) {
             // TODO StAX API bug means we can't use custom factories yet
             //factory = XMLOutputFactory.newInstance(configuration.factoryId, configuration.factoryClassLoader);
         }
+        */
         for (Map.Entry<String, Object> property : configuration.properties.entrySet())
{
             factory.setProperty(property.getKey(), property.getValue());
         }
@@ -1052,7 +1026,6 @@ public class SCXMLWriter {
             xsw = factory.createXMLStreamWriter(result);
         }
         return xsw;
-
     }
 
     /**
@@ -1061,7 +1034,7 @@ public class SCXMLWriter {
      * @return Transformer The indenting {@link Transformer} instance.
      */
     private static Transformer getTransformer() {
-        Transformer transformer = null;
+        Transformer transformer;
         Properties outputProps = new Properties();
         outputProps.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
         outputProps.put(OutputKeys.STANDALONE, "no");
@@ -1167,7 +1140,6 @@ public class SCXMLWriter {
         public Configuration() {
 
             this(null, null, null, null, false, false, false);
-
         }
 
         /**
@@ -1187,11 +1159,10 @@ public class SCXMLWriter {
          * @param closeUnderlyingWhenDone Whether to close the underlying stream or writer
passed by the caller.
          */
         public Configuration(final String factoryId, final ClassLoader factoryClassLoader,
-                final Map<String, Object> properties, final String encoding, final
boolean usePrettyPrint,
-                final boolean closeUnderlyingWhenDone) {
+                             final Map<String, Object> properties, final String encoding,
final boolean usePrettyPrint,
+                             final boolean closeUnderlyingWhenDone) {
 
             this(factoryId, factoryClassLoader, properties, encoding, usePrettyPrint, closeUnderlyingWhenDone,
false);
-
         }
 
         /*
@@ -1206,7 +1177,6 @@ public class SCXMLWriter {
         Configuration(final boolean writeToString, final boolean usePrettyPrint) {
 
             this(null, null, null, null, usePrettyPrint, false, writeToString);
-
         }
 
         /**
@@ -1225,8 +1195,8 @@ public class SCXMLWriter {
          * @param writeToString Whether to maintain an internal writer to return the serialization
as a string.
          */
         Configuration(final String factoryId, final ClassLoader factoryClassLoader,
-                final Map<String, Object> properties, final String encoding, final
boolean usePrettyPrint,
-                final boolean closeUnderlyingWhenDone, final boolean writeToString) {
+                      final Map<String, Object> properties, final String encoding,
final boolean usePrettyPrint,
+                      final boolean closeUnderlyingWhenDone, final boolean writeToString)
{
 
             this.factoryId = factoryId;
             this.factoryClassLoader = factoryClassLoader;
@@ -1240,10 +1210,6 @@ public class SCXMLWriter {
             } else {
                 this.internalWriter = null;
             }
-
         }
-
     }
-
 }
-

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Initial.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Initial.java?rev=1579092&r1=1579091&r2=1579092&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Initial.java
(original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Initial.java
Wed Mar 19 00:12:13 2014
@@ -36,6 +36,11 @@ public class Initial extends TransitionT
     private Transition transition;
 
     /**
+     * Indicator if this Initial was automatically generated and not loaded from the SCXML
Document itself
+     */
+    private boolean generated;
+
+    /**
      * Constructor.
      */
     public Initial() {
@@ -61,5 +66,18 @@ public class Initial extends TransitionT
         this.transition.setParent(this);
     }
 
+    /**
+     * @return true if this Initial was automatically generated and not loaded from the SCXML
Document itself
+     */
+    public final boolean isGenerated() {
+        return generated;
+    }
+
+    /**
+     * Marks this Initial as automatically generated after loading the SCXML Document
+     */
+    public final void setGenerated() {
+        this.generated = true;
+    }
 }
 

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/State.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/State.java?rev=1579092&r1=1579091&r2=1579092&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/State.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/State.java Wed
Mar 19 00:12:13 2014
@@ -55,6 +55,11 @@ public class State extends TransitionTar
     private boolean isFinal;
 
     /**
+     * The id of the initial child of this composite, corresponding with the state initial
attribute
+     */
+    private String first;
+
+    /**
      * A child which identifies initial state for state machines that
      * have substates.
      */
@@ -125,6 +130,7 @@ public class State extends TransitionTar
      *            The target to set.
      */
     public final void setInitial(final Initial target) {
+        this.first = null;
         this.initial = target;
         target.setParent(this);
     }
@@ -135,10 +141,7 @@ public class State extends TransitionTar
      * @return The initial state's string ID.
      */
     public final String getFirst() {
-        if (initial != null) {
-            return initial.getTransition().getNext();
-        }
-        return null;
+        return first;
     }
 
     /**
@@ -148,9 +151,11 @@ public class State extends TransitionTar
      *            The initial target's ID to set.
      */
     public final void setFirst(final String target) {
+        this.first = target;
         Transition t = new Transition();
         t.setNext(target);
         Initial ini = new Initial();
+        ini.setGenerated();
         ini.setTransition(t);
         ini.setParent(this);
         this.initial = ini;



Mime
View raw message