commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1639830 - in /commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2: EvaluatorFactory.java env/minimal/ env/minimal/MinimalContext.java env/minimal/MinimalEvaluator.java
Date Sat, 15 Nov 2014 03:48:38 GMT
Author: ate
Date: Sat Nov 15 03:48:38 2014
New Revision: 1639830

URL: http://svn.apache.org/r1639830
Log:
SCXML-214: Implementation of the SCXML specification required support for the "null" datamodel

Added:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalContext.java
  (with props)
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalEvaluator.java
  (with props)
Modified:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/EvaluatorFactory.java

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/EvaluatorFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/EvaluatorFactory.java?rev=1639830&r1=1639829&r2=1639830&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/EvaluatorFactory.java
(original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/EvaluatorFactory.java
Sat Nov 15 03:48:38 2014
@@ -22,6 +22,7 @@ import java.util.concurrent.ConcurrentHa
 import org.apache.commons.scxml2.env.groovy.GroovyEvaluator;
 import org.apache.commons.scxml2.env.javascript.JSEvaluator;
 import org.apache.commons.scxml2.env.jexl.JexlEvaluator;
+import org.apache.commons.scxml2.env.minimal.MinimalEvaluator;
 import org.apache.commons.scxml2.env.xpath.XPathEvaluator;
 import org.apache.commons.scxml2.model.ModelException;
 import org.apache.commons.scxml2.model.SCXML;
@@ -40,6 +41,7 @@ import static org.apache.commons.scxml2.
  *      <li>datamodel="ecmascript": {@link JSEvaluator.JSEvaluatorProvider}</li>
  *      <li>datamodel="groovy": {@link GroovyEvaluator.GroovyEvaluatorProvider}</li>
  *      <li>datamodel="xpath": {@link XPathEvaluator.XPathEvaluatorProvider}</li>
+ *      <li>datamodel="null": {@link MinimalEvaluator.MinimalEvaluatorProvider}</li>
  *  </ul>
  *  </p>
  *  <p>
@@ -63,6 +65,7 @@ public class EvaluatorFactory {
         providers.put(JSEvaluator.SUPPORTED_DATA_MODEL, new JSEvaluator.JSEvaluatorProvider());
         providers.put(GroovyEvaluator.SUPPORTED_DATA_MODEL, new GroovyEvaluator.GroovyEvaluatorProvider());
         providers.put(JexlEvaluator.SUPPORTED_DATA_MODEL, new JexlEvaluator.JexlEvaluatorProvider());
+        providers.put(MinimalEvaluator.SUPPORTED_DATA_MODEL, new MinimalEvaluator.MinimalEvaluatorProvider());
         providers.put(DEFAULT_DATA_MODEL, providers.get(JexlEvaluator.SUPPORTED_DATA_MODEL));
     }
 

Added: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalContext.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalContext.java?rev=1639830&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalContext.java
(added)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalContext.java
Sat Nov 15 03:48:38 2014
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.env.minimal;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.commons.scxml2.Context;
+import org.apache.commons.scxml2.env.SimpleContext;
+
+/**
+ * MinimalContext implementation for the SCXML Null Data Model.
+ * <p>
+ * This context disables any access to the parent context (other than through getParent())
and
+ * ignores setting any local data.
+ * </p>
+ * <p>
+ * The MinimalContext requires a none MinimalContext based parent Context for creation.
+ * If the parent context is of type MinimalContext, <em>its</em> parent will
be used as the parent of the
+ * new MinimalContext instance
+ * </p>
+ */
+public class MinimalContext extends SimpleContext {
+
+    /** Serial version UID. */
+    private static final long serialVersionUID = 1L;
+
+    private static Context getMinimalContextParent(final Context parent) {
+        if (parent != null) {
+            if (parent instanceof MinimalContext) {
+                return getMinimalContextParent(parent.getParent());
+            }
+            return parent;
+        }
+        throw new IllegalStateException("A MinimalContext instance requires a non MinimalContext
based parent.");
+    }
+
+    public MinimalContext(final Context parent) {
+        super(getMinimalContextParent(parent));
+    }
+
+    @Override
+    public void set(final String name, final Object value) {
+    }
+
+    @Override
+    public Object get(final String name) {
+        return null;
+    }
+
+    @Override
+    public boolean has(final String name) {
+        return false;
+    }
+
+    @Override
+    public boolean hasLocal(final String name) {
+        return false;
+    }
+
+    @Override
+    public void reset() {
+    }
+
+    @Override
+    public void setLocal(final String name, final Object value) {
+    }
+
+    @Override
+    protected void setVars(final Map<String, Object> vars) {
+    }
+
+    @Override
+    public Map<String, Object> getVars() {
+        return Collections.emptyMap();
+    }
+}

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

Propchange: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalEvaluator.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalEvaluator.java?rev=1639830&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalEvaluator.java
(added)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalEvaluator.java
Sat Nov 15 03:48:38 2014
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.env.minimal;
+
+import java.io.Serializable;
+
+import org.apache.commons.scxml2.Builtin;
+import org.apache.commons.scxml2.Context;
+import org.apache.commons.scxml2.Evaluator;
+import org.apache.commons.scxml2.EvaluatorProvider;
+import org.apache.commons.scxml2.SCXMLExpressionException;
+import org.apache.commons.scxml2.model.SCXML;
+
+/**
+ * Minimal Evaluator implementing and providing support for the SCXML Null Data Model.
+ * <p>
+ * The SCXML Null Data Model only supports the SCXML "In(stateId)" builtin function.
+ * </p>
+ */
+public class MinimalEvaluator implements Evaluator, Serializable {
+
+    /** Serial version UID. */
+    private static final long serialVersionUID = 1L;
+
+    public static final String SUPPORTED_DATA_MODEL = Evaluator.NULL_DATA_MODEL;
+
+    public static class MinimalEvaluatorProvider implements EvaluatorProvider {
+
+        @Override
+        public String getSupportedDatamodel() {
+            return SUPPORTED_DATA_MODEL;
+        }
+
+        @Override
+        public Evaluator getEvaluator() {
+            return new MinimalEvaluator();
+        }
+
+        @Override
+        public Evaluator getEvaluator(final SCXML document) {
+            return new MinimalEvaluator();
+        }
+    }
+
+    @Override
+    public String getSupportedDatamodel() {
+        return SUPPORTED_DATA_MODEL;
+    }
+
+    @Override
+    public Object eval(final Context ctx, final String expr) throws SCXMLExpressionException
{
+        return expr;
+    }
+
+    @Override
+    public Boolean evalCond(final Context ctx, final String expr) throws SCXMLExpressionException
{
+        // only support the "In(stateId)" predicate
+        String predicate = expr != null ? expr.trim() : "";
+        if (predicate.startsWith("In(") && predicate.endsWith(")")) {
+            String stateId = predicate.substring(3, predicate.length()-1);
+            return Builtin.isMember(ctx, stateId);
+        }
+        return false;
+    }
+
+    @Override
+    public Object evalLocation(final Context ctx, final String expr) throws SCXMLExpressionException
{
+        return expr;
+    }
+
+    @Override
+    public void evalAssign(final Context ctx, final String location, final Object data, final
AssignType type, final String attr) throws SCXMLExpressionException {
+        throw new UnsupportedOperationException("Assign expressions are not supported by
the \"null\" datamodel");
+    }
+
+    @Override
+    public Object evalScript(final Context ctx, final String script) throws SCXMLExpressionException
{
+        throw new UnsupportedOperationException("Scripts are not supported by the \"null\"
datamodel");
+    }
+
+    @Override
+    public Context newContext(final Context parent) {
+        return parent instanceof MinimalContext ? parent : new MinimalContext(parent);
+    }
+}

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

Propchange: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/minimal/MinimalEvaluator.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message