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 2020/03/22 09:07:08 UTC

[camel] 01/13: CAMEL-14762: camel-core - Configurer to include API for method name and type

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 21d8ad32d6be4830e069fdb2778cb61321bc44d9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Mar 21 19:23:08 2020 +0100

    CAMEL-14762: camel-core - Configurer to include API for method name and type
---
 .../camel/spi/PropertyOptionsConfigurer.java       | 34 ++++++++++++++++++++++
 .../packaging/PropertyConfigurerGenerator.java     | 31 ++++++++++++++++++--
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/PropertyOptionsConfigurer.java b/core/camel-api/src/main/java/org/apache/camel/spi/PropertyOptionsConfigurer.java
new file mode 100644
index 0000000..9c7b3e9
--- /dev/null
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/PropertyOptionsConfigurer.java
@@ -0,0 +1,34 @@
+/*
+ * 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.spi;
+
+import java.util.Map;
+
+/**
+ * A marker interface to identify the object as being a configurer which can
+ * provide details about the options the configurer supports.
+ */
+public interface PropertyOptionsConfigurer {
+
+    /**
+     * Provides a map of which options the cofigurer supports and their class type.
+     *
+     * @return options as map name -> class type.
+     */
+    Map<String, Object> options();
+
+}
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyConfigurerGenerator.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyConfigurerGenerator.java
index bd3e683..86229bf 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyConfigurerGenerator.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyConfigurerGenerator.java
@@ -36,15 +36,19 @@ public final class PropertyConfigurerGenerator {
         w.write("/* " + AbstractGeneratorMojo.GENERATED_MSG + " */\n");
         w.write("package " + pn + ";\n");
         w.write("\n");
+        w.write("import java.util.Map;\n");
+        w.write("\n");
         w.write("import org.apache.camel.CamelContext;\n");
         w.write("import org.apache.camel.spi.GeneratedPropertyConfigurer;\n");
+        w.write("import org.apache.camel.spi.PropertyOptionsConfigurer;\n");
+        w.write("import org.apache.camel.util.CaseInsensitiveMap;\n");
         w.write("import "  + pfqn + ";\n");
         w.write("\n");
         w.write("/**\n");
         w.write(" * " + AbstractGeneratorMojo.GENERATED_MSG + "\n");
         w.write(" */\n");
         w.write("@SuppressWarnings(\"unchecked\")\n");
-        w.write("public class " + cn + " extends " + psn + " implements GeneratedPropertyConfigurer {\n");
+        w.write("public class " + cn + " extends " + psn + " implements GeneratedPropertyConfigurer, PropertyOptionsConfigurer {\n");
         w.write("\n");
         if (!options.isEmpty() || !hasSuper) {
 
@@ -83,8 +87,31 @@ public final class PropertyConfigurerGenerator {
                 w.write("        }\n");
             }
             w.write("    }\n");
+
+            // generate API that returns which
+            w.write("\n");
+            w.write("    @Override\n");
+            w.write("    public Map<String, Object> options() {\n");
+            if (hasSuper) {
+                w.write("        Map<String, Object> answer = super.options();\n");
+            } else {
+                w.write("        Map<String, Object> answer = new CaseInsensitiveMap();\n");
+            }
+            if (!options.isEmpty() || !hasSuper) {
+                for (BaseOptionModel option : options) {
+                    // type may contain generics so remove those
+                    String type = option.getJavaType();
+                    if (type.indexOf('<') != -1) {
+                        type = type.substring(0, type.indexOf('<'));
+                    }
+                    type = type.replace('$', '.');
+                    w.write(String.format("        answer.put(\"%s\", %s.class);\n", option.getName(), type));
+                }
+                w.write("        return answer;\n");
+                w.write("    }\n");
+            }
         }
-        w.write("\n");
+
         w.write("}\n");
         w.write("\n");
     }