This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 622f031e0bacf9bcd96116fe1b6e28639749cfbf Author: Claus Ibsen <[email protected]> AuthorDate: Thu Jan 21 14:20:44 2021 +0100 CAMEL-16066: camel-core - Add static methods for language expressions in Builder to use for Lambda DSL --- .../java/org/apache/camel/builder/Builder.java | 105 ++++++++++++++++++++- .../org/apache/camel/builder/BuilderSupport.java | 25 ++--- 2 files changed, 110 insertions(+), 20 deletions(-) diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/Builder.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/Builder.java index 32efe96..e1c5cc0 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/builder/Builder.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/Builder.java @@ -17,9 +17,12 @@ package org.apache.camel.builder; import org.apache.camel.Expression; +import org.apache.camel.model.language.CSimpleExpression; import org.apache.camel.model.language.ConstantExpression; import org.apache.camel.model.language.ExchangePropertyExpression; import org.apache.camel.model.language.HeaderExpression; +import org.apache.camel.model.language.JoorExpression; +import org.apache.camel.model.language.JsonPathExpression; import org.apache.camel.model.language.LanguageExpression; import org.apache.camel.model.language.MethodCallExpression; import org.apache.camel.model.language.SimpleExpression; @@ -49,9 +52,11 @@ public final class Builder { * * @param beanOrBeanRef either an instanceof a bean or a reference to bean to lookup in the Registry * @return the builder + * @deprecated use {@link #method(Object)} */ + @Deprecated public static ValueBuilder bean(final Object beanOrBeanRef) { - return bean(beanOrBeanRef, null); + return method(beanOrBeanRef, null); } /** @@ -62,8 +67,48 @@ public final class Builder { * @param beanOrBeanRef either an instanceof a bean or a reference to bean to lookup in the Registry * @param method the method name * @return the builder + * @deprecated use {@link #method(Class, String)} (Object, String)} */ + @Deprecated public static ValueBuilder bean(Object beanOrBeanRef, String method) { + return method(beanOrBeanRef, method); + } + + /** + * Returns a <a href="http://camel.apache.org/bean-language.html">bean expression</a> value builder + * + * @param beanType the bean class which will be invoked + * @param method name of method to invoke + * @return the builder + * @deprecated use {@link #method(Class, String)} + */ + @Deprecated + public static ValueBuilder bean(Class<?> beanType, String method) { + return method(beanType, method); + } + + /** + * Returns a <a href="http://camel.apache.org/bean-language.html">method call expression</a> value builder. + * <p/> + * This method accepts dual parameters. Either an bean instance or a reference to a bean (String). + * + * @param beanOrBeanRef either an instanceof a bean or a reference to bean to lookup in the Registry + * @return the builder + */ + public static ValueBuilder method(final Object beanOrBeanRef) { + return method(beanOrBeanRef, null); + } + + /** + * Returns a <a href="http://camel.apache.org/bean-language.html">method call expression</a> value builder. + * <p/> + * This method accepts dual parameters. Either an bean instance or a reference to a bean (String). + * + * @param beanOrBeanRef either an instanceof a bean or a reference to bean to lookup in the Registry + * @param method the method name + * @return the builder + */ + public static ValueBuilder method(Object beanOrBeanRef, String method) { Expression exp; if (beanOrBeanRef instanceof String) { exp = new MethodCallExpression((String) beanOrBeanRef, method); @@ -74,13 +119,13 @@ public final class Builder { } /** - * Returns a <a href="http://camel.apache.org/bean-language.html">bean expression</a> value builder + * Returns a <a href="http://camel.apache.org/bean-language.html">method call expression</a> value builder * * @param beanType the bean class which will be invoked * @param method name of method to invoke * @return the builder */ - public static ValueBuilder bean(Class<?> beanType, String method) { + public static ValueBuilder method(Class<?> beanType, String method) { Expression exp = new MethodCallExpression(beanType, method); return new ValueBuilder(exp); } @@ -107,6 +152,23 @@ public final class Builder { } /** + * Returns a csimple expression + */ + public static ValueBuilder csimple(String value) { + Expression exp = new CSimpleExpression(value); + return new ValueBuilder(exp); + } + + /** + * Returns a csimple expression + */ + public static ValueBuilder csimple(String value, Class<?> resultType) { + CSimpleExpression exp = new CSimpleExpression(value); + exp.setResultType(resultType); + return new ValueBuilder(exp); + } + + /** * Returns a simple expression */ public static ValueBuilder simple(String value) { @@ -124,6 +186,43 @@ public final class Builder { } /** + * Returns a JOOR expression value builder + */ + public static ValueBuilder joor(String value) { + JoorExpression exp = new JoorExpression(value); + return new ValueBuilder(exp); + } + + /** + * Returns a JOOR expression value builder + */ + public static ValueBuilder joor(String value, Class<?> resultType) { + JoorExpression exp = new JoorExpression(value); + exp.setResultType(resultType); + return new ValueBuilder(exp); + } + + /** + * Returns a JSonPath expression value builder + */ + public static ValueBuilder jsonpath(String value) { + JsonPathExpression exp = new JsonPathExpression(value); + return new ValueBuilder(exp); + } + + /** + * Returns a JSonPath expression value builder + * + * @param value The JSonPath expression + * @param resultType The result type that the JSonPath expression will return. + */ + public static ValueBuilder jsonpath(String value, Class<?> resultType) { + JsonPathExpression exp = new JsonPathExpression(value); + exp.setResultType(resultType); + return new ValueBuilder(exp); + } + + /** * Returns a predicate and value builder for headers on an exchange */ public static ValueBuilder header(String name) { diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/BuilderSupport.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/BuilderSupport.java index ace4279..d8d8703 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/builder/BuilderSupport.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/BuilderSupport.java @@ -108,25 +108,21 @@ public abstract class BuilderSupport { * Returns a JOOR expression value builder */ public ValueBuilder joor(String value) { - JoorExpression exp = new JoorExpression(value); - return new ValueBuilder(exp); + return Builder.joor(value); } /** * Returns a JOOR expression value builder */ public ValueBuilder joor(String value, Class<?> resultType) { - JoorExpression exp = new JoorExpression(value); - exp.setResultType(resultType); - return new ValueBuilder(exp); + return Builder.joor(value, resultType); } /** * Returns a JSonPath expression value builder */ public ValueBuilder jsonpath(String value) { - JsonPathExpression exp = new JsonPathExpression(value); - return new ValueBuilder(exp); + return Builder.jsonpath(value); } /** @@ -136,26 +132,21 @@ public abstract class BuilderSupport { * @param resultType The result type that the JSonPath expression will return. */ public ValueBuilder jsonpath(String value, Class<?> resultType) { - JsonPathExpression exp = new JsonPathExpression(value); - exp.setResultType(resultType); - return new ValueBuilder(exp); + return Builder.jsonpath(value, resultType); } /** * Returns a compiled simple expression value builder */ public ValueBuilder csimple(String value) { - CSimpleExpression exp = new CSimpleExpression(value); - return new ValueBuilder(exp); + return Builder.csimple(value); } /** * Returns a compiled simple expression value builder */ public ValueBuilder csimple(String value, Class<?> resultType) { - CSimpleExpression exp = new CSimpleExpression(value); - exp.setResultType(resultType); - return new ValueBuilder(exp); + return Builder.csimple(value, resultType); } /** @@ -298,7 +289,7 @@ public abstract class BuilderSupport { * @return the builder */ public ValueBuilder method(Object beanOrBeanRef, String method) { - return Builder.bean(beanOrBeanRef, method); + return Builder.method(beanOrBeanRef, method); } /** @@ -308,7 +299,7 @@ public abstract class BuilderSupport { * @return the builder */ public ValueBuilder method(Class<?> beanType) { - return Builder.bean(beanType); + return Builder.method(beanType); } /**
