You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2024/03/06 19:12:49 UTC

(camel) branch CAMEL-20507/add-enum-to-expression-builder created (now 5683a1337ae)

This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a change to branch CAMEL-20507/add-enum-to-expression-builder
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 5683a1337ae CAMEL-20507: camel-core - Add enums to expression builders

This branch includes the following new commits:

     new 5683a1337ae CAMEL-20507: camel-core - Add enums to expression builders

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-20507: camel-core - Add enums to expression builders

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-20507/add-enum-to-expression-builder
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5683a1337ae92403e4abe5e86a65276d3b87e82c
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Wed Mar 6 20:12:24 2024 +0100

    CAMEL-20507: camel-core - Add enums to expression builders
---
 .../JsonPathSplitSingleListOptionTest.java         |  5 ++--
 .../camel/model/language/JsonPathExpression.java   | 24 +++++++++++++++
 .../camel/model/language/MethodCallExpression.java | 34 ++++++++++++++++++++++
 .../model/language/XMLTokenizerExpression.java     | 25 ++++++++++++++++
 .../camel/model/language/XPathExpression.java      | 24 ++++++++++++++-
 5 files changed, 109 insertions(+), 3 deletions(-)

diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSplitSingleListOptionTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSplitSingleListOptionTest.java
index bc611180fc0..8c624dd20a2 100644
--- a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSplitSingleListOptionTest.java
+++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSplitSingleListOptionTest.java
@@ -19,9 +19,9 @@ package org.apache.camel.jsonpath;
 import java.io.File;
 import java.util.Map;
 
-import com.jayway.jsonpath.Option;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.language.JsonPathExpression;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Test;
 
@@ -38,7 +38,8 @@ public class JsonPathSplitSingleListOptionTest extends CamelTestSupport {
             public void configure() {
                 // use option to force returning a list even for a single element selected
                 var jsonpath
-                        = expression().jsonpath().option(Option.ALWAYS_RETURN_LIST.name()).expression("$.store.book[0]").end();
+                        = expression().jsonpath().option(JsonPathExpression.Option.ALWAYS_RETURN_LIST)
+                                .expression("$.store.book[0]").end();
 
                 from("direct:start")
                         .split(jsonpath)
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/language/JsonPathExpression.java b/core/camel-core-model/src/main/java/org/apache/camel/model/language/JsonPathExpression.java
index 11457bcccbc..360677c8abe 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/language/JsonPathExpression.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/language/JsonPathExpression.java
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.model.language;
 
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
 import jakarta.xml.bind.annotation.XmlAccessType;
 import jakarta.xml.bind.annotation.XmlAccessorType;
 import jakarta.xml.bind.annotation.XmlAttribute;
@@ -241,9 +245,29 @@ public class JsonPathExpression extends SingleInputTypedExpressionDefinition {
             return this;
         }
 
+        /**
+         * To configure additional options on JSONPath.
+         */
+        public Builder option(Option... options) {
+            this.option = Arrays.stream(options).map(Objects::toString).collect(Collectors.joining(","));
+            return this;
+        }
+
         @Override
         public JsonPathExpression end() {
             return new JsonPathExpression(this);
         }
     }
+
+    /**
+     * {@code Option} defines the possible json path options that can be used.
+     */
+    @XmlTransient
+    public enum Option {
+        DEFAULT_PATH_LEAF_TO_NULL,
+        ALWAYS_RETURN_LIST,
+        AS_PATH_LIST,
+        SUPPRESS_EXCEPTIONS,
+        REQUIRE_PROPERTIES;
+    }
 }
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/language/MethodCallExpression.java b/core/camel-core-model/src/main/java/org/apache/camel/model/language/MethodCallExpression.java
index fb867e1b1c1..d0e22ac947b 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/language/MethodCallExpression.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/language/MethodCallExpression.java
@@ -294,6 +294,24 @@ public class MethodCallExpression extends TypedExpressionDefinition {
             return this;
         }
 
+        /**
+         * Scope of bean.
+         *
+         * When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime
+         * of the endpoint. The bean should be thread-safe in case concurrent threads is calling the bean at the same
+         * time. When using request scope the bean is created or looked up once per request (exchange). This can be used
+         * if you want to store state on a bean while processing a request and you want to call the same bean instance
+         * multiple times while processing the request. The bean does not have to be thread-safe as the instance is only
+         * called from the same request. When using prototype scope, then the bean will be looked up or created per
+         * call. However in case of lookup then this is delegated to the bean registry such as Spring or CDI (if in
+         * use), which depends on their configuration can act as either singleton or prototype scope. So when using
+         * prototype scope then this depends on the bean registry implementation.
+         */
+        public Builder scope(Scope scope) {
+            this.scope = scope == null ? null : scope.value;
+            return this;
+        }
+
         /**
          * Whether to validate the bean has the configured method.
          */
@@ -315,4 +333,20 @@ public class MethodCallExpression extends TypedExpressionDefinition {
             return new MethodCallExpression(this);
         }
     }
+
+    /**
+     * {@code Scope} defines the possible bean scopes that can be used.
+     */
+    @XmlTransient
+    public enum Scope {
+        SINGLETON("Singleton"),
+        REQUEST("Request"),
+        PROTOTYPE("Prototype");
+
+        private final String value;
+
+        Scope(String value) {
+            this.value = value;
+        }
+    }
 }
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/language/XMLTokenizerExpression.java b/core/camel-core-model/src/main/java/org/apache/camel/model/language/XMLTokenizerExpression.java
index 5dfed81e3c2..d8713eec259 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/language/XMLTokenizerExpression.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/language/XMLTokenizerExpression.java
@@ -113,6 +113,14 @@ public class XMLTokenizerExpression extends NamespaceAwareExpression {
             return this;
         }
 
+        /**
+         * The extraction mode.
+         */
+        public Builder mode(Mode mode) {
+            this.mode = mode == null ? null : mode.value;
+            return this;
+        }
+
         /**
          * To group N parts together
          */
@@ -134,4 +142,21 @@ public class XMLTokenizerExpression extends NamespaceAwareExpression {
             return new XMLTokenizerExpression(this);
         }
     }
+
+    /**
+     * {@code Mode} defines the possible extraction modes that can be used.
+     */
+    @XmlTransient
+    public enum Mode {
+        INJECTING_CONTEXTUAL_NAMESPACE_BINDINGS("i"),
+        WRAPPING_EXTRACTED_TOKEN("w"),
+        UNWRAPPING_EXTRACTED_TOKEN("u"),
+        EXTRACTING_TEXT_CONTENT("t");
+
+        private final String value;
+
+        Mode(String value) {
+            this.value = value;
+        }
+    }
 }
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/language/XPathExpression.java b/core/camel-core-model/src/main/java/org/apache/camel/model/language/XPathExpression.java
index 171ccbfe38d..6952bb58a72 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/language/XPathExpression.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/language/XPathExpression.java
@@ -265,11 +265,21 @@ public class XPathExpression extends NamespaceAwareExpression {
          * <p/>
          * The default result type is NodeSet
          */
-        public Builder resultQName(String resultTypeName) {
+        public Builder resultQName(String resultQName) {
             this.resultQName = resultQName;
             return this;
         }
 
+        /**
+         * Sets the class name of the result type (type from output)
+         * <p/>
+         * The default result type is NodeSet
+         */
+        public Builder resultQName(ResultQName resultQName) {
+            this.resultQName = resultQName == null ? null : resultQName.name();
+            return this;
+        }
+
         /**
          * Whether to use Saxon.
          */
@@ -377,4 +387,16 @@ public class XPathExpression extends NamespaceAwareExpression {
             return new XPathExpression(this);
         }
     }
+
+    /**
+     * {@code ResultQName} defines the possible class name of the result types that can be used.
+     */
+    @XmlTransient
+    public enum ResultQName {
+        NUMBER,
+        STRING,
+        BOOLEAN,
+        NODESET,
+        NODE
+    }
 }