commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1634436 - in /commons/proper/scxml/trunk: ./ src/main/java/org/apache/commons/scxml2/ src/main/java/org/apache/commons/scxml2/env/xpath/
Date Mon, 27 Oct 2014 01:31:53 GMT
Author: ate
Date: Mon Oct 27 01:31:53 2014
New Revision: 1634436

URL: http://svn.apache.org/r1634436
Log:
SCXML-214: Replace JAXP xpath expression evaluation with Commons JXPath

Added:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/ContextVariables.java
  (with props)
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathFunctions.java
  (with props)
Removed:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/FunctionResolver.java
Modified:
    commons/proper/scxml/trunk/pom.xml
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/Builtin.java
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathContext.java
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathEvaluator.java
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/package.html

Modified: commons/proper/scxml/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/pom.xml?rev=1634436&r1=1634435&r2=1634436&view=diff
==============================================================================
--- commons/proper/scxml/trunk/pom.xml (original)
+++ commons/proper/scxml/trunk/pom.xml Mon Oct 27 01:31:53 2014
@@ -155,11 +155,21 @@
       <optional>true</optional>
     </dependency>
     <dependency>
+      <groupId>commons-jxpath</groupId>
+      <artifactId>commons-jxpath</artifactId>
+      <version>1.3</version>
+    </dependency>
+    <dependency>
       <groupId>org.codehaus.groovy</groupId>
       <artifactId>groovy</artifactId>
       <version>2.2.2</version>
       <optional>true</optional>
     </dependency>
+    <dependency>
+      <groupId>commons-beanutils</groupId>
+      <artifactId>commons-beanutils</artifactId>
+      <version>1.9.2</version>
+    </dependency>
   </dependencies>
 
   <distributionManagement>

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/Builtin.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/Builtin.java?rev=1634436&r1=1634435&r2=1634436&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/Builtin.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/Builtin.java Mon Oct
27 01:31:53 2014
@@ -17,18 +17,12 @@
 package org.apache.commons.scxml2;
 
 import java.io.Serializable;
-import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.JXPathException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.scxml2.model.TransitionTarget;
@@ -92,9 +86,9 @@ public class Builtin implements Serializ
             return null;
         }
         Node dataNode = (Node) data;
-        NodeList result = null;
+        List result;
         try {
-            XPath xpath = XPathFactory.newInstance().newXPath();
+            JXPathContext context = JXPathContext.newContext(dataNode);
             if (namespaces == null || namespaces.size() == 0) {
                 Log log = LogFactory.getLog(Builtin.class);
                 if (log.isDebugEnabled()) {
@@ -103,16 +97,17 @@ public class Builtin implements Serializ
                         + path);
                 }
             } else {
-                xpath.setNamespaceContext(new ExpressionNSContext(namespaces));
+                for (String prefix : namespaces.keySet()) {
+                    context.registerNamespace(prefix, namespaces.get(prefix));
+                }
             }
-            result = (NodeList) xpath.evaluate(path, dataNode,
-                XPathConstants.NODESET);
-        } catch (XPathExpressionException xee) {
+            result = context.selectNodes(path);
+        } catch (JXPathException xee) {
             Log log = LogFactory.getLog(Builtin.class);
             log.error(xee.getMessage(), xee);
             return null;
         }
-        int length = result.getLength();
+        int length = result.size();
         if (length == 0) {
             Log log = LogFactory.getLog(Builtin.class);
             log.warn("Data(): No nodes matching the XPath expression \""
@@ -124,7 +119,7 @@ public class Builtin implements Serializ
                 log.warn("Data(): Multiple (" + length + ") nodes matching XPath expression
\""
                     + path + "\", returning first");
             }
-            return result.item(0);
+            return (Node)result.get(0);
         }
     }
 
@@ -166,7 +161,7 @@ public class Builtin implements Serializ
     /**
      * Retrieve a DOM node value as a string depending on its type.
      *
-     * @param node A node to be retreived
+     * @param node A node to be retrieved
      * @return The value as a string
      */
     private static String getNodeValue(final Node node) {
@@ -201,94 +196,5 @@ public class Builtin implements Serializ
         }
         return result.trim();
     }
-
-    /**
-     * XPath {@link NamespaceContext} for Commons SCXML expressions.
-     *
-     * <b>Code duplication:</b> Also in XPathEvaluator.java. Class is not
-     * meant to be part of any public API and will be removed when parser
-     * is no longer using Commons Digester.
-     */
-    private static final class ExpressionNSContext
-    implements Serializable, NamespaceContext {
-
-        /** Serial version UID. */
-        private static final long serialVersionUID = 8620558582288851315L;
-        private final Map<String, String> namespaces;
-
-        /**
-         * Constructor.
-         *
-         * @param namespaces The current namespace map.
-         */
-        ExpressionNSContext(final Map<String, String> namespaces) {
-            this.namespaces = namespaces;
-        }
-
-        /**
-         * @see NamespaceContext#getNamespaceURI(String)
-         */
-        @Override
-        public String getNamespaceURI(final String prefix) {
-            return namespaces.get(prefix);
-        }
-
-        /**
-         * @see NamespaceContext#getPrefix(String)
-         *
-         * First matching key in iteration order is returned, and the
-         * iteration order depends on the underlying <code>namespaces</code>
-         * {@link Map} implementation.
-         */
-        @Override
-        public String getPrefix(final String namespaceURI) {
-            return (String) getKeys(namespaceURI, true);
-        }
-
-        /**
-         * @see NamespaceContext#getPrefixes(String)
-         *
-         * The iteration order depends on the underlying <code>namespaces</code>
-         * {@link Map} implementation.
-         */
-        @Override
-        @SuppressWarnings("unchecked")
-        public Iterator<String> getPrefixes(final String namespaceURI) {
-            return (Iterator<String>) getKeys(namespaceURI, false);
-        }
-
-        /**
-         * Get prefix key(s) for given namespaceURI value.
-         *
-         * If <code>one</code>, first matching key in iteration order is
-         * returned, and the iteration order depends on the underlying
-         * <code>namespaces</code> {@link Map} implementation.
-         * Otherwise, an iterator to all matching keys is returned.
-         *
-         * @param value The value whose key is required
-         * @param one At most one matching key is returned
-         * @return The required prefix key(s)
-         */
-        private Object getKeys(final String value, final boolean one) {
-            List<String> prefixes = new LinkedList<String>();
-            if (namespaces.containsValue(value)) {
-                for (Map.Entry<String, String> entry : namespaces.entrySet()) {
-                    String v = entry.getValue();
-                    if ((value == null && v == null) ||
-                            (value != null && value.equals(v))) {
-                        String prefix = entry.getKey();
-                        if (one) {
-                            return prefix;
-                        } else {
-                            prefixes.add(prefix);
-                        }
-                    }
-                }
-            }
-            return one ? null : prefixes.iterator();
-        }
-
-    }
-
 }
 

Added: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/ContextVariables.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/ContextVariables.java?rev=1634436&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/ContextVariables.java
(added)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/ContextVariables.java
Mon Oct 27 01:31:53 2014
@@ -0,0 +1,61 @@
+/*
+ * 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.xpath;
+
+import org.apache.commons.jxpath.Variables;
+import org.apache.commons.scxml2.Context;
+
+/**
+ * JXPath Variables mapping for SCXML Context
+ */
+public class ContextVariables implements Variables {
+
+    private final Context ctx;
+
+    public ContextVariables(Context ctx) {
+        this.ctx = ctx;
+    }
+
+    @Override
+    public boolean isDeclaredVariable(final String varName) {
+        return ctx.has(varName);
+    }
+
+    @Override
+    public Object getVariable(final String varName) {
+        return ctx.get(varName);
+    }
+
+    @Override
+    public void declareVariable(final String varName, final Object value) {
+        ctx.set(varName, value);
+    }
+
+    @Override
+    public void undeclareVariable(final String varName) {
+        if (ctx.has(varName)) {
+            Context cctx = ctx;
+            while (!cctx.hasLocal(varName)) {
+                cctx = cctx.getParent();
+                if (cctx == null) {
+                    return;
+                }
+            }
+            cctx.getVars().remove(varName);
+        }
+    }
+}

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

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

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathContext.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathContext.java?rev=1634436&r1=1634435&r2=1634436&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathContext.java
(original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathContext.java
Mon Oct 27 01:31:53 2014
@@ -16,18 +16,16 @@
  */
 package org.apache.commons.scxml2.env.xpath;
 
-import javax.xml.namespace.QName;
-import javax.xml.xpath.XPathVariableResolver;
-
+import org.apache.commons.jxpath.Variables;
 import org.apache.commons.scxml2.Context;
 import org.apache.commons.scxml2.env.SimpleContext;
 
 /**
- * A {@link Context} implementation for XPath environments.
+ * A {@link Context} implementation for JXPath environments.
  *
  */
 public class XPathContext extends SimpleContext
-implements Context, XPathVariableResolver {
+implements Context, Variables {
 
     /** Serial version UID. */
     private static final long serialVersionUID = -6803159294612685806L;
@@ -49,17 +47,32 @@ implements Context, XPathVariableResolve
         super(parent);
     }
 
-    /**
-     * Resolve variable by checking the backing {@link Context}.
-     * TODO: Investigate alternatives to String representation.
-     *
-     * @param variableName The QName whose String representation is the
-     *                     variable in the backing {@link Context}
-     * @return The variable value.
-     */
     @Override
-    public Object resolveVariable(final QName variableName) {
-        return get(variableName.toString());
+    public boolean isDeclaredVariable(final String varName) {
+        return has(varName);
+    }
+
+    @Override
+    public Object getVariable(final String varName) {
+        return get(varName);
+    }
+
+    @Override
+    public void declareVariable(final String varName, final Object value) {
+        set(varName, value);
     }
 
+    @Override
+    public void undeclareVariable(final String varName) {
+        if (has(varName)) {
+            Context ctx = this;
+            while (!ctx.hasLocal(varName)) {
+                ctx = ctx.getParent();
+                if (ctx == null) {
+                    return;
+                }
+            }
+            ctx.getVars().remove(varName);
+        }
+    }
 }

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathEvaluator.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathEvaluator.java?rev=1634436&r1=1634435&r2=1634436&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathEvaluator.java
(original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathEvaluator.java
Mon Oct 27 01:31:53 2014
@@ -17,27 +17,21 @@
 package org.apache.commons.scxml2.env.xpath;
 
 import java.io.Serializable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 import java.util.regex.Pattern;
 
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-import javax.xml.xpath.XPathFunction;
-
+import org.apache.commons.jxpath.ClassFunctions;
+import org.apache.commons.jxpath.FunctionLibrary;
+import org.apache.commons.jxpath.Functions;
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.JXPathException;
+import org.apache.commons.jxpath.PackageFunctions;
 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.env.xpath.FunctionResolver.FunctionKey;
+import org.apache.commons.scxml2.env.EffectiveContextMap;
 import org.apache.commons.scxml2.model.SCXML;
-import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
 /**
@@ -75,31 +69,34 @@ public class XPathEvaluator implements E
     /** Pattern for recognizing the Commons SCXML Data() builtin function. */
     private static final Pattern dataFct = Pattern.compile("Data\\(");
 
-    /** The factory specialized for the Commons SCXML environment. */
-    private final XPathFactory factory;
-    /** The XPathFunctionResolver in use. */
-    private final FunctionResolver fnResolver;
-    /** The dummyContextNode node for XPath evaluation. */
-    private final Document dummyContextNode;
+    private static final JXPathContext jxpathRootContext = JXPathContext.newContext(null);
+
+    static {
+        FunctionLibrary xpathFunctions = new FunctionLibrary();
+        xpathFunctions.addFunctions(new ClassFunctions(XPathFunctions.class, "cs"));
+        xpathFunctions.addFunctions(new ClassFunctions(XPathFunctions.class, null));
+        // default generic JXPath functions
+        xpathFunctions.addFunctions(new PackageFunctions("", null));
+        jxpathRootContext.setFunctions(xpathFunctions);
+    }
+
+    private JXPathContext jxpathContext;
 
     /**
      * No argument constructor.
      */
     public XPathEvaluator() {
-        fnResolver = new FunctionResolver();
-        factory = XPathFactory.newInstance();
-        factory.setXPathFunctionResolver(fnResolver);
-        dummyContextNode = getDummyContextNode();
+        jxpathContext = jxpathRootContext;
     }
 
     /**
-     * Constructor supporting user-defined {@link XPathFunction}s.
+     * Constructor supporting user-defined JXPath {@link Functions}.
      *
-     * @param functions The user-defined XPath functions to use.
+     * @param functions The user-defined JXPath functions to use.
      */
-    public XPathEvaluator(final Map<FunctionKey, XPathFunction> functions) {
-        this();
-        fnResolver.addFunctions(functions);
+    public XPathEvaluator(final Functions functions) {
+        jxpathContext = JXPathContext.newContext(jxpathRootContext, null);
+        jxpathContext.setFunctions(functions);
     }
 
     @Override
@@ -113,10 +110,11 @@ public class XPathEvaluator implements E
     @Override
     public Object eval(final Context ctx, final String expr)
             throws SCXMLExpressionException {
-        XPath xpath = getXPath(ctx);
+        JXPathContext context = getContext(ctx);
+        String evalExpr = dataFct.matcher(expr).replaceFirst("DataNode(");
         try {
-            return xpath.evaluate(expr, dummyContextNode, XPathConstants.STRING);
-        } catch (XPathExpressionException xee) {
+            return context.getValue(evalExpr, String.class);
+        } catch (JXPathException xee) {
             throw new SCXMLExpressionException(xee.getMessage(), xee);
         }
     }
@@ -127,10 +125,10 @@ public class XPathEvaluator implements E
     @Override
     public Boolean evalCond(final Context ctx, final String expr)
             throws SCXMLExpressionException {
-        XPath xpath = getXPath(ctx);
+        JXPathContext context = getContext(ctx);
         try {
-            return (Boolean) xpath.evaluate(expr, dummyContextNode, XPathConstants.BOOLEAN);
-        } catch (XPathExpressionException xee) {
+            return (Boolean)context.getValue(expr, Boolean.class);
+        } catch (JXPathException xee) {
             throw new SCXMLExpressionException(xee.getMessage(), xee);
         }
     }
@@ -143,10 +141,10 @@ public class XPathEvaluator implements E
             throws SCXMLExpressionException {
         String evalExpr = dataFct.matcher(expr).
             replaceFirst("DataNode(");
-        XPath xpath = getXPath(ctx);
+        JXPathContext context = getContext(ctx);
         try {
-            return (Node) xpath.evaluate(evalExpr, dummyContextNode, XPathConstants.NODE);
-        } catch (XPathExpressionException xee) {
+            return (Node)context.selectSingleNode(evalExpr);
+        } catch (JXPathException xee) {
             throw new SCXMLExpressionException(xee.getMessage(), xee);
         }
     }
@@ -167,126 +165,17 @@ public class XPathEvaluator implements E
         return new XPathContext(parent);
     }
 
-    /**
-     * Get configures XPath from the factory.
-     */
-    @SuppressWarnings("unchecked")
-    private XPath getXPath(final Context ctx) throws SCXMLExpressionException {
-        if (!(ctx instanceof XPathContext)) {
-            throw new SCXMLExpressionException("XPathEvaluator needs XPathContext");
-        }
-        XPathContext xctx = (XPathContext) ctx;
-        factory.setXPathVariableResolver(xctx);
-        fnResolver.setContext(xctx);
-        XPath xpath = factory.newXPath();
-        NamespaceContext nsCtx =
-            new ExpressionNSContext((Map<String, String>) ctx.get(Context.NAMESPACES_KEY));
-        xpath.setNamespaceContext(nsCtx);
-        return xpath;
-    }
-
-    /**
-     * Create dummy context node for XPath evaluation context.
-     */
-    private Document getDummyContextNode() throws RuntimeException {
-        try {
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            dbf.setNamespaceAware(true);
-            return dbf.newDocumentBuilder().newDocument();
-        } catch (RuntimeException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new RuntimeException("Cannot create dummy context node for XPath evaluator");
-        }
-    }
-
-
-    /**
-     * XPath {@link NamespaceContext} for Commons SCXML expressions.
-     *
-     * <b>Code duplication:</b> Also in Builtin.java. Class is not meant to be
-     * part of any public API and will be removed when parser is no longer
-     * using Commons Digester.
-     */
-    private static final class ExpressionNSContext
-    implements Serializable, NamespaceContext {
-
-        /** Serial version UID. */
-        private static final long serialVersionUID = 8620558582288851315L;
-        private final Map<String, String> namespaces;
-
-        /**
-         * Constructor.
-         *
-         * @param namespaces The current namespace map.
-         */
-        ExpressionNSContext(final Map<String, String> namespaces) {
-            this.namespaces = namespaces;
-        }
 
-        /**
-         * @see NamespaceContext#getNamespaceURI(String)
-         */
-        @Override
-        public String getNamespaceURI(final String prefix) {
-            return namespaces.get(prefix);
-        }
-
-        /**
-         * @see NamespaceContext#getPrefix(String)
-         *
-         * First matching key in iteration order is returned, and the
-         * iteration order depends on the underlying <code>namespaces</code>
-         * {@link Map} implementation.
-         */
-        @Override
-        public String getPrefix(final String namespaceURI) {
-            return (String) getKeys(namespaceURI, true);
-        }
-
-        /**
-         * @see NamespaceContext#getPrefixes(String)
-         *
-         * The iteration order depends on the underlying <code>namespaces</code>
-         * {@link Map} implementation.
-         */
-        @Override
-        @SuppressWarnings("unchecked")
-        public Iterator<String> getPrefixes(final String namespaceURI) {
-            return (Iterator<String>) getKeys(namespaceURI, false);
-        }
-
-        /**
-         * Get prefix key(s) for given namespaceURI value.
-         *
-         * If <code>one</code>, first matching key in iteration order is
-         * returned, and the iteration order depends on the underlying
-         * <code>namespaces</code> {@link Map} implementation.
-         * Otherwise, an iterator to all matching keys is returned.
-         *
-         * @param value The value whose key is required
-         * @param one At most one matching key is returned
-         * @return The required prefix key(s)
-         */
-        private Object getKeys(final String value, final boolean one) {
-            List<String> prefixes = new LinkedList<String>();
-            if (namespaces.containsValue(value)) {
-                for (Map.Entry<String, String> entry : namespaces.entrySet()) {
-                    String v = entry.getValue();
-                    if ((value == null && v == null) ||
-                            (value != null && value.equals(v))) {
-                        String prefix = entry.getKey();
-                        if (one) {
-                            return prefix;
-                        } else {
-                            prefixes.add(prefix);
-                        }
-                    }
-                }
+    @SuppressWarnings("unchecked")
+    private JXPathContext getContext(final Context ctx) throws SCXMLExpressionException {
+        JXPathContext context = JXPathContext.newContext(jxpathContext, new EffectiveContextMap(ctx));
+        context.setVariables(new ContextVariables(ctx));
+        Map<String, String> namespaces = (Map<String, String>) ctx.get(Context.NAMESPACES_KEY);
+        if (namespaces != null) {
+            for (String prefix : namespaces.keySet()) {
+                context.registerNamespace(prefix, namespaces.get(prefix));
             }
-            return one ? null : prefixes.iterator();
         }
-
+        return context;
     }
-
 }

Added: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathFunctions.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathFunctions.java?rev=1634436&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathFunctions.java
(added)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/XPathFunctions.java
Mon Oct 27 01:31:53 2014
@@ -0,0 +1,38 @@
+/*
+ * 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.xpath;
+
+import java.util.Set;
+
+import org.apache.commons.jxpath.ExpressionContext;
+import org.apache.commons.jxpath.Variables;
+import org.apache.commons.scxml2.Builtin;
+import org.apache.commons.scxml2.SCXMLSystemContext;
+import org.apache.commons.scxml2.model.EnterableState;
+
+/**
+ * JXPath custom extension functions providing the SCXML In() function
+ */
+public class XPathFunctions {
+
+    @SuppressWarnings("unchecked")
+    public static boolean In(ExpressionContext expressionContext, String state) {
+        Variables variables = expressionContext.getJXPathContext().getVariables();
+        Set<EnterableState> allStates = (Set<EnterableState>) variables.getVariable(SCXMLSystemContext.ALL_STATES_KEY);
+        return Builtin.isMember(allStates, state);
+    }
+}

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

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

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/package.html
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/package.html?rev=1634436&r1=1634435&r2=1634436&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/package.html
(original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/xpath/package.html
Mon Oct 27 01:31:53 2014
@@ -20,7 +20,7 @@
 <body>
 
   <p>A collection of classes that allow XPath to be used in expressions
-     within SCXML documents via the <code>javax.xml.xpath</code> API.</p>
+     within SCXML documents via Commons JXPath</p>
 
 </body>
 </html>



Mime
View raw message