You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by at...@apache.org on 2014/03/19 02:19:58 UTC

svn commit: r1579108 - in /commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2: io/SCXMLReader.java io/SCXMLWriter.java model/Transition.java model/TransitionType.java

Author: ate
Date: Wed Mar 19 01:19:58 2014
New Revision: 1579108

URL: http://svn.apache.org/r1579108
Log:
SCXML-196: preliminary Transition internal|external type attribute support

Added:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/TransitionType.java   (with props)
Modified:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.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/Transition.java

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java?rev=1579108&r1=1579107&r2=1579108&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/io/SCXMLReader.java Wed Mar 19 01:19:58 2014
@@ -84,6 +84,7 @@ import org.apache.commons.scxml2.model.S
 import org.apache.commons.scxml2.model.State;
 import org.apache.commons.scxml2.model.Transition;
 import org.apache.commons.scxml2.model.TransitionTarget;
+import org.apache.commons.scxml2.model.TransitionType;
 import org.apache.commons.scxml2.model.Var;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
@@ -214,6 +215,13 @@ public final class SCXMLReader {
 
     /**
      * Error message when the target of the URI fragment in a <state>'s
+     * "src" attribute is not defined in the referenced document.
+     */
+    private static final String ERR_UNSUPPORTED_TRANSITION_TYPE = "Unsupported transition type "
+            + "for <transition type=\"{0}\"> at {1}.";
+
+    /**
+     * Error message when the target of the URI fragment in a &lt;state&gt;'s
      * &quot;src&quot; attribute is not a &lt;state&gt; or &lt;final&gt; in
      * the referenced document.
      */
@@ -1376,6 +1384,18 @@ public final class SCXMLReader {
         t.setCond(readAV(reader, ATTR_COND));
         t.setEvent(readAV(reader, ATTR_EVENT));
         t.setNext(readAV(reader, ATTR_TARGET));
+        String type = readAV(reader, ATTR_TYPE);
+        if (type != null) {
+            try {
+                t.setType(TransitionType.valueOf(type));
+            }
+            catch (IllegalArgumentException e) {
+                MessageFormat msgFormat = new MessageFormat(ERR_UNSUPPORTED_TRANSITION_TYPE);
+                String errMsg = msgFormat.format(new Object[] {type, reader.getLocation()});
+                throw new ModelException(errMsg);
+            }
+        }
+
         readNamespaces(configuration, t);
 
         readExecutableContext(reader, configuration, tt, t, null);

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=1579108&r1=1579107&r2=1579108&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 01:19:58 2014
@@ -710,6 +710,9 @@ public class SCXMLWriter {
         writeAV(writer, ATTR_EVENT, transition.getEvent());
         writeAV(writer, ATTR_COND, SCXMLHelper.escapeXML(transition.getCond()));
         writeAV(writer, ATTR_TARGET, transition.getNext());
+        if (transition.getType() != null) {
+            writeAV(writer, ATTR_TYPE, transition.getType().name());
+        }
         writeExecutableContent(writer, transition.getActions());
         writer.writeEndElement();
     }

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java?rev=1579108&r1=1579107&r2=1579108&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/Transition.java Wed Mar 19 01:19:58 2014
@@ -36,6 +36,18 @@ public class Transition extends Executab
     private static final long serialVersionUID = 2L;
 
     /**
+     * The Transition type: internal or external (default)
+     * @see {@link #isTypeInternal()}
+     */
+    private TransitionType type;
+
+    /**
+     * Derived effective Transition type.
+     * @see #isTypeInternal()
+     */
+    private Boolean typeInternal;
+
+    /**
      * Property that specifies the trigger for this transition.
      */
     private String event;
@@ -81,6 +93,64 @@ public class Transition extends Executab
     }
 
     /**
+     * @return true if Transition type == internal or false if type == external (default)
+     */
+    public final TransitionType getType() {
+        return type;
+    }
+
+    /**
+     * Sets the Transition type
+     * @param type the Transition type
+     */
+    public final void setType(final TransitionType type) {
+        this.type = type;
+    }
+
+    /**
+     * Returns the effective Transition type.
+     * <p>
+     * A transition type is only effectively internal if:
+     * <ul>
+     *   <li>its {@link #getType()} == {@link TransitionType#internal}</li>
+     *   <li>its source state {@link #getParent()} {@link State#isComposite()}</li>
+     *   <li>all its {@link #getTargets()} are proper descendants of its {@link #getParent()}</li>
+     * </ul>
+     * Otherwise it is treated (for determining its exit states) as if it is of type {@link TransitionType#external}
+     * </p>
+     * @see <a href="http://www.w3.org/TR/2014/CR-scxml-20140313/#SelectingTransitions">
+     *     http://www.w3.org/TR/2014/CR-scxml-20140313/#SelectingTransitions</a>
+     * </p>
+     * @return true if the effective Transition type is {@link TransitionType#internal}
+     */
+    public final boolean isTypeInternal() {
+        if (typeInternal == null) {
+            // derive typeInternal
+
+            boolean internal = TransitionType.internal == type;
+
+            if (internal) {
+                internal = (getParent() != null && getParent() instanceof State && ((State)getParent()).isComposite());
+            }
+
+            if (internal && targets.size() > 0) {
+                for (Path p : getPaths()) {
+                    // TODO: testing the following actual works and always is correct
+                    if (p.getPathScope() == null || p.getPathScope() == getParent()) {
+                        continue;
+                    }
+                    // not a proper descendant
+                    internal = false;
+                    break;
+                }
+            }
+
+            typeInternal = internal;
+        }
+        return typeInternal;
+    }
+
+    /**
      * Get the guard condition (may be null).
      *
      * @return Returns the cond.

Added: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/TransitionType.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/TransitionType.java?rev=1579108&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/TransitionType.java (added)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/TransitionType.java Wed Mar 19 01:19:58 2014
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2014 Hippo B.V. (http://www.onehippo.com)
+ *
+ * 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.commons.scxml2.model;
+
+/**
+ * Defines the allowable Transition type attribute values,
+ * <p>
+ * The Transition type determines whether the source state is exited in transitions
+ * whose target state is a descendant of the source state.
+ * </p>
+ * @see <a href="http://www.w3.org/TR/2014/CR-scxml-20140313/#transition">
+ *     http://www.w3.org/TR/2014/CR-scxml-20140313/#transition</a>
+ */
+public enum TransitionType {
+    internal,
+    external
+}

Propchange: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/TransitionType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/model/TransitionType.java
------------------------------------------------------------------------------
    svn:keywords = Id