You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/03/07 04:59:35 UTC
(camel) branch main updated: CAMEL-20507: camel-core - Add enums to expression builders (#13398)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 3aa40cd7221 CAMEL-20507: camel-core - Add enums to expression builders (#13398)
3aa40cd7221 is described below
commit 3aa40cd72218c9b2f7f7291003d0ae5d52defa6a
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Thu Mar 7 05:59:29 2024 +0100
CAMEL-20507: camel-core - Add enums to expression builders (#13398)
---
.../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
+ }
}