This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch lan-markup in repository https://gitbox.apache.org/repos/asf/camel.git
commit e368fa141ee1a9ec633d0186e2283a13b40c92b8 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Aug 15 18:04:46 2024 +0200 CAMEL-20569: camel-catalog - Markup languages which functions they support for better doc and tooling. --- .../org/apache/camel/spi/annotations/Language.java | 13 ++++ .../modules/languages/pages/simple-language.adoc | 2 +- .../camel/language/simple/SimpleConstants.java | 69 ++++++++++++++++++++++ .../camel/language/simple/SimpleLanguage.java | 2 +- .../org/apache/camel/spi/annotations/Language.java | 13 ++++ 5 files changed, 97 insertions(+), 2 deletions(-) diff --git a/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/Language.java b/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/Language.java index 1a986577836..a619f4e481e 100644 --- a/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/Language.java +++ b/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/Language.java @@ -30,4 +30,17 @@ public @interface Language { String value(); + /** + * The class that contains all the name of functions that are supported by the language. The name of the functions + * are defined as {@code String} constants in the functions class. + * <p/> + * The class to provide can be any class but by convention, we would expect a class whose name is of type + * <i>xxxConstants</i> where <i>xxx</i> is the name of the corresponding language like for example + * <i>SimpleConstants</i> for the language <i>camel-simple</i>. + * <p/> + * The metadata of a given functions are retrieved directly from the annotation {@code @Metadata} added to the + * {@code String} constant representing its name and defined in the functions class. + */ + Class<?> functionsClass() default void.class; + } diff --git a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc index ac47f5fafee..961d107de88 100644 --- a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc +++ b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc @@ -75,7 +75,7 @@ OGNL expression. |id |String |the message id -|messageTimestamp |String |the message timestamp (millis since epoc) that this message originates from. +|messageTimestamp |long |the message timestamp (millis since epoc) that this message originates from. Some systems like JMS, Kafka, AWS have a timestamp on the event/message that Camel received. This method returns the timestamp if a timestamp exists. The message timestamp and exchange created are different. An exchange always has a created timestamp which is the diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleConstants.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleConstants.java new file mode 100644 index 00000000000..64c221ca50f --- /dev/null +++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleConstants.java @@ -0,0 +1,69 @@ +/* + * 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.camel.language.simple; + +import org.apache.camel.spi.Metadata; + +public final class SimpleConstants { + + @Metadata(description = "The message body", label = "function") + public static final String BODY = "body"; + @Metadata(description = "Converts the body to a String, and attempts to pretty print if JSon or XML; otherwise the body is returned as the String value.", javaType = "String", label = "function") + public static final String PRETTY_BODY = "prettyBody"; + @Metadata(description = "Converts the body to a String and removes all line-breaks, so the string is in one line.", javaType = "String", label = "function") + public static final String BODY_ONE_LINE = "bodyOneLine"; + @Metadata(description = "The original incoming body (only available if allowUseOriginalMessage=true).", label = "function") + public static final String ORIGINAL_BODY = "originalBody"; + @Metadata(description = "The message id", javaType = "String", label = "function") + public static final String ID = "id"; + @Metadata(description = "The message timestamp (millis since epoc) that this message originates from." + + " Some systems like JMS, Kafka, AWS have a timestamp on the event/message that Camel received. This method returns the timestamp if a timestamp exists." + + " The message timestamp and exchange created are different. An exchange always has a created timestamp which is the" + + " local timestamp when Camel created the exchange. The message timestamp is only available in some Camel components" + + " when the consumer is able to extract the timestamp from the source event." + + " If the message has no timestamp, then 0 is returned.", javaType = "long", label = "function") + public static final String MESSAGE_TIMESTAMP = "messageTimestamp"; + @Metadata(description = "The exchange id", javaType = "String", label = "function") + public static final String EXCHANGE_ID = "exchangeId"; + @Metadata(description = "The exchange", javaType = "Exchange", label = "function") + public static final String EXCHANGE = "exchange"; + @Metadata(description = "The exception object on the exchange (also from caught exceptions), is null if no exception present.", javaType = "Exception", label = "function") + public static final String EXCEPTION = "exception"; + @Metadata(description = "The exception message (also from caught exceptions), is null if no exception present.", javaType = "String", label = "function") + public static final String EXCEPTION_MESSAGE = "exception.message"; + @Metadata(description = "The exception stacktrace (also from caught exceptions), is null if no exception present.", javaType = "String", label = "function") + public static final String EXCEPTION_STACKTRACE = "exception.stackTrace"; + @Metadata(description = "Returns the id of the current thread. Can be used for logging.", javaType = "long", label = "function") + public static final String THREAD_ID = "threadId"; + @Metadata(description = "Returns the name of the current thread. Can be used for logging.", javaType = "String", label = "function") + public static final String THREAD_NAME = "threadName"; + @Metadata(description = "Returns the local hostname (may be empty if not possible to resolve).", javaType = "String", label = "function") + public static final String HOST_NAME = "hostName"; + @Metadata(description = "The name of the CamelContext", javaType = "String", label = "function") + public static final String CAMEL_ID = "camelId"; + @Metadata(description = "The route id of the current route the Exchange is being routed", javaType = "String", label = "function") + public static final String ROUTE_ID = "routeId"; + @Metadata(description = "The original route id where this exchange was created.", javaType = "String", label = "function") + public static final String FROM_ROUTE_ID = "fromRouteId"; + @Metadata(description = "Returns the route group of the current route the Exchange is being routed. Not all routes have a group assigned, so this may be null.", javaType = "String", label = "function") + public static final String ROUTE_GROUP = "routeGroup"; + @Metadata(description = "Returns the id of the current step the Exchange is being routed.", javaType = "String", label = "function") + public static final String STEP_ID = "stepId"; + @Metadata(description = "Represents a null value", label = "function") + public static final String NULL = "null"; + +} diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java index 723c34b3e2d..85c4b07d7bf 100644 --- a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java +++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java @@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory; /** * The Camel simple language. */ -@Language("simple") +@Language(value = "simple", functionsClass = SimpleConstants.class) public class SimpleLanguage extends LanguageSupport implements StaticService { private static final Logger LOG = LoggerFactory.getLogger(SimpleLanguage.class); diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/Language.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/Language.java index 1a986577836..a619f4e481e 100644 --- a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/Language.java +++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/Language.java @@ -30,4 +30,17 @@ public @interface Language { String value(); + /** + * The class that contains all the name of functions that are supported by the language. The name of the functions + * are defined as {@code String} constants in the functions class. + * <p/> + * The class to provide can be any class but by convention, we would expect a class whose name is of type + * <i>xxxConstants</i> where <i>xxx</i> is the name of the corresponding language like for example + * <i>SimpleConstants</i> for the language <i>camel-simple</i>. + * <p/> + * The metadata of a given functions are retrieved directly from the annotation {@code @Metadata} added to the + * {@code String} constant representing its name and defined in the functions class. + */ + Class<?> functionsClass() default void.class; + }