Author: ate
Date: Fri Jan 17 13:27:45 2014
New Revision: 1559098
URL: http://svn.apache.org/r1559098
Log:
SCXML-186: Goovy Expression evaluator support
- promote JexlEvaluator$EffectiveContextMap inner class to standalone so as to
make it reusable by the GroovyEvaluator
Added:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/EffectiveContextMap.java
(with props)
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java
Added:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/EffectiveContextMap.java
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/EffectiveContextMap.java?rev=1559098&view=auto
==============================================================================
---
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/EffectiveContextMap.java
(added)
+++
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/EffectiveContextMap.java
Fri Jan 17 13:27:45 2014
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.AbstractMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.scxml2.Context;
+
+/**
+ * A map that will back the effective {@link Context} for an {@link
org.apache.commons.scxml2.Evaluator} execution.
+ * The effective context enables the chaining of contexts all the way from the
current state node to the root.
+ */
+public final class EffectiveContextMap extends AbstractMap<String, Object>
implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** The {@link org.apache.commons.scxml2.Context} for the current state. */
+ private final Context leaf;
+
+ /** Constructor. */
+ public EffectiveContextMap(final Context ctx) {
+ super();
+ this.leaf = ctx;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Entry<String, Object>> entrySet() {
+ Set<Entry<String, Object>> entrySet = new HashSet<Entry<String,
Object>>();
+ Context current = leaf;
+ while (current != null) {
+ entrySet.addAll(current.getVars().entrySet());
+ current = current.getParent();
+ }
+ return entrySet;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object put(final String key, final Object value) {
+ Object old = leaf.get(key);
+ if (leaf.has(key)) {
+ leaf.set(key, value);
+ } else {
+ leaf.setLocal(key, value);
+ }
+ return old;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object get(final Object key) {
+ if (key != null) {
+ Context current = leaf;
+ while (current != null) {
+ if (current.getVars().containsKey(key.toString())) {
+ return current.getVars().get(key);
+ }
+ current = current.getParent();
+ }
+ }
+ return null;
+ }
+}
Propchange:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/EffectiveContextMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/EffectiveContextMap.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java
URL:
http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java?rev=1559098&r1=1559097&r2=1559098&view=diff
==============================================================================
---
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java
(original)
+++
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/jexl/JexlEvaluator.java
Fri Jan 17 13:27:45 2014
@@ -17,11 +17,8 @@
package org.apache.commons.scxml2.env.jexl;
import java.io.Serializable;
-import java.util.AbstractMap;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import org.apache.commons.jexl2.Expression;
import org.apache.commons.jexl2.JexlEngine;
@@ -29,6 +26,7 @@ import org.apache.commons.jexl2.Script;
import org.apache.commons.scxml2.Context;
import org.apache.commons.scxml2.Evaluator;
import org.apache.commons.scxml2.SCXMLExpressionException;
+import org.apache.commons.scxml2.env.EffectiveContextMap;
import org.w3c.dom.Node;
/**
@@ -281,67 +279,5 @@ public class JexlEvaluator implements Ev
private JexlContext getEffectiveContext(final JexlContext nodeCtx) {
return new JexlContext(new EffectiveContextMap(nodeCtx));
}
-
- /**
- * The map that will back the effective context for the
- * {@link JexlEvaluator}. The effective context enables the chaining of
- * {@link Context}s all the way from the current state node to the root.
- *
- */
- private static final class EffectiveContextMap extends AbstractMap<String,
Object> {
-
- /** The {@link Context} for the current state. */
- private final Context leaf;
-
- /** Constructor. */
- public EffectiveContextMap(final JexlContext ctx) {
- super();
- this.leaf = ctx;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Set<Map.Entry<String, Object>> entrySet() {
- Set<Map.Entry<String, Object>> entrySet = new
HashSet<Map.Entry<String, Object>>();
- Context current = leaf;
- while (current != null) {
- entrySet.addAll(current.getVars().entrySet());
- current = current.getParent();
- }
- return entrySet;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object put(final String key, final Object value) {
- Object old = leaf.get(key);
- if (leaf.has(key)) {
- leaf.set(key, value);
- } else {
- leaf.setLocal(key, value);
- }
- return old;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object get(final Object key) {
- Context current = leaf;
- while (current != null) {
- if (current.getVars().containsKey(key)) {
- return current.getVars().get(key);
- }
- current = current.getParent();
- }
- return null;
- }
- }
-
}