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/15 11:49:32 UTC

[camel] 01/02: CAMEL-14671: Make PropertiesFunction part of the PropertiesComponent SPI

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 03a502d1ce22c25039a06edd295c72f74ffa2a83
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Mar 15 12:38:00 2020 +0100

    CAMEL-14671: Make PropertiesFunction part of the PropertiesComponent SPI
---
 .../org/apache/camel/spi}/PropertiesFunction.java  |  2 +-
 .../org/apache/camel/spi/PropertiesComponent.java  |  5 +++
 .../converter/TimePatternConverterLoader.java      | 36 ++++++++++++++++++++++
 .../services/org/apache/camel/TypeConverterLoader  |  1 +
 .../properties/DefaultPropertiesParser.java        |  1 +
 .../properties/EnvPropertiesFunction.java          |  3 +-
 .../component/properties/PropertiesComponent.java  | 17 +++++-----
 .../properties/ServiceHostPropertiesFunction.java  |  1 +
 .../properties/ServicePortPropertiesFunction.java  |  3 +-
 .../properties/ServicePropertiesFunction.java      |  3 +-
 .../properties/SysPropertiesFunction.java          |  1 +
 .../core/xml/AbstractCamelContextFactoryBean.java  |  4 +--
 .../PropertiesComponentFunctionTest.java           |  3 +-
 .../modules/ROOT/pages/camel-3x-upgrade-guide.adoc |  5 +++
 .../modules/ROOT/pages/properties-component.adoc   |  4 +--
 .../ROOT/pages/using-propertyplaceholder.adoc      |  4 +--
 16 files changed, 74 insertions(+), 19 deletions(-)

diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesFunction.java b/core/camel-api/src/generated/java/org/apache/camel/spi/PropertiesFunction.java
similarity index 96%
rename from core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesFunction.java
rename to core/camel-api/src/generated/java/org/apache/camel/spi/PropertiesFunction.java
index c5977bf..111efec 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesFunction.java
+++ b/core/camel-api/src/generated/java/org/apache/camel/spi/PropertiesFunction.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.properties;
+package org.apache.camel.spi;
 
 /**
  * A function that is applied instead of looking up a property placeholder.
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java b/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java
index ff73a77..1dfa693 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java
@@ -105,6 +105,11 @@ public interface PropertiesComponent extends StaticService {
     void addPropertiesSource(PropertiesSource propertiesSource);
 
     /**
+     * Registers the {@link PropertiesFunction} as a function to this component.
+     */
+    void addPropertiesFunction(PropertiesFunction function);
+
+    /**
      * Whether to silently ignore if a location cannot be located, such as a properties file not found.
      */
     void setIgnoreMissingLocation(boolean ignoreMissingLocation);
diff --git a/core/camel-base/src/generated/java/org/apache/camel/converter/TimePatternConverterLoader.java b/core/camel-base/src/generated/java/org/apache/camel/converter/TimePatternConverterLoader.java
new file mode 100644
index 0000000..4f26a00
--- /dev/null
+++ b/core/camel-base/src/generated/java/org/apache/camel/converter/TimePatternConverterLoader.java
@@ -0,0 +1,36 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.converter;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConversionException;
+import org.apache.camel.TypeConverterLoaderException;
+import org.apache.camel.spi.TypeConverterLoader;
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.support.SimpleTypeConverter;
+import org.apache.camel.support.TypeConverterSupport;
+import org.apache.camel.util.DoubleMap;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public final class TimePatternConverterLoader implements TypeConverterLoader {
+
+    public TimePatternConverterLoader() {
+    }
+
+    @Override
+    public void load(TypeConverterRegistry registry) throws TypeConverterLoaderException {
+        registerConverters(registry);
+    }
+
+    private void registerConverters(TypeConverterRegistry registry) {
+        addTypeConverter(registry, long.class, java.lang.String.class, false,
+            (type, exchange, value) -> org.apache.camel.converter.TimePatternConverter.toMilliSeconds((java.lang.String) value));
+    }
+
+    private static void addTypeConverter(TypeConverterRegistry registry, Class<?> toType, Class<?> fromType, boolean allowNull, SimpleTypeConverter.ConversionMethod method) { 
+        registry.addTypeConverter(toType, fromType, new SimpleTypeConverter(allowNull, method));
+    }
+
+}
diff --git a/core/camel-base/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader b/core/camel-base/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
index a16a584..b0702fe 100644
--- a/core/camel-base/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
+++ b/core/camel-base/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
@@ -7,4 +7,5 @@ org.apache.camel.converter.IOConverterLoader
 org.apache.camel.converter.NIOConverterLoader
 org.apache.camel.converter.ObjectConverterLoader
 org.apache.camel.converter.SQLConverterLoader
+org.apache.camel.converter.TimePatternConverterLoader
 org.apache.camel.impl.converter.UriTypeConverterLoader
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
index a72e178..2ec35aa 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.properties;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
 import org.slf4j.Logger;
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/EnvPropertiesFunction.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/EnvPropertiesFunction.java
index 5febc96..905c9e4 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/EnvPropertiesFunction.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/EnvPropertiesFunction.java
@@ -16,10 +16,11 @@
  */
 package org.apache.camel.component.properties;
 
+import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.util.StringHelper;
 
 /**
- * A {@link org.apache.camel.component.properties.PropertiesFunction} that lookup the property value from
+ * A {@link PropertiesFunction} that lookup the property value from
  * OS environment variables.
  */
 public class EnvPropertiesFunction implements PropertiesFunction {
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 78feca3..138d223 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -35,6 +35,7 @@ import org.apache.camel.api.management.ManagedAttribute;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.LoadablePropertiesSource;
+import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.spi.PropertiesSource;
 import org.apache.camel.spi.annotations.JdkService;
 import org.apache.camel.support.OrderedComparator;
@@ -117,11 +118,11 @@ public class PropertiesComponent extends ServiceSupport implements org.apache.ca
 
     public PropertiesComponent() {
         // include out of the box functions
-        addFunction(new EnvPropertiesFunction());
-        addFunction(new SysPropertiesFunction());
-        addFunction(new ServicePropertiesFunction());
-        addFunction(new ServiceHostPropertiesFunction());
-        addFunction(new ServicePortPropertiesFunction());
+        addPropertiesFunction(new EnvPropertiesFunction());
+        addPropertiesFunction(new SysPropertiesFunction());
+        addPropertiesFunction(new ServicePropertiesFunction());
+        addPropertiesFunction(new ServiceHostPropertiesFunction());
+        addPropertiesFunction(new ServicePortPropertiesFunction());
     }
 
     /**
@@ -441,14 +442,14 @@ public class PropertiesComponent extends ServiceSupport implements org.apache.ca
     }
 
     /**
-     * Registers the {@link org.apache.camel.component.properties.PropertiesFunction} as a function to this component.
+     * Registers the {@link PropertiesFunction} as a function to this component.
      */
-    public void addFunction(PropertiesFunction function) {
+    public void addPropertiesFunction(PropertiesFunction function) {
         this.functions.put(function.getName(), function);
     }
 
     /**
-     * Is there a {@link org.apache.camel.component.properties.PropertiesFunction} with the given name?
+     * Is there a {@link PropertiesFunction} with the given name?
      */
     public boolean hasFunction(String name) {
         return functions.containsKey(name);
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java
index de2b03e..502c97e 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/ServiceHostPropertiesFunction.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.properties;
 
 import java.util.Locale;
 
+import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.util.StringHelper;
 
 /**
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java
index 1c80de4..bdafb96 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/ServicePortPropertiesFunction.java
@@ -18,10 +18,11 @@ package org.apache.camel.component.properties;
 
 import java.util.Locale;
 
+import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.util.StringHelper;
 
 /**
- * A {@link org.apache.camel.component.properties.PropertiesFunction} that lookup the property value from
+ * A {@link PropertiesFunction} that lookup the property value from
  * OS environment variables using the service idiom.
  * <p/>
  * A service is defined using two environment variables where name is name of the service:
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/ServicePropertiesFunction.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/ServicePropertiesFunction.java
index cb9691f..fdd5078 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/ServicePropertiesFunction.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/ServicePropertiesFunction.java
@@ -18,10 +18,11 @@ package org.apache.camel.component.properties;
 
 import java.util.Locale;
 
+import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.util.StringHelper;
 
 /**
- * A {@link org.apache.camel.component.properties.PropertiesFunction} that lookup the property value from
+ * A {@link PropertiesFunction} that lookup the property value from
  * OS environment variables using the service idiom.
  * <p/>
  * A service is defined using two environment variables where name is name of the service:
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/SysPropertiesFunction.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/SysPropertiesFunction.java
index 0b0400d..57ba7f2 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/SysPropertiesFunction.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/SysPropertiesFunction.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.properties;
 
+import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.util.StringHelper;
 
 /**
diff --git a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index a0df2b1..b2f22c5 100644
--- a/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/core/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -46,7 +46,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.cloud.ServiceRegistry;
 import org.apache.camel.cluster.CamelClusterService;
 import org.apache.camel.component.properties.PropertiesComponent;
-import org.apache.camel.component.properties.PropertiesFunction;
+import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.component.properties.PropertiesLocation;
 import org.apache.camel.component.properties.PropertiesParser;
 import org.apache.camel.health.HealthCheckRegistry;
@@ -694,7 +694,7 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
                 for (CamelPropertyPlaceholderFunctionDefinition function : def.getFunctions()) {
                     String ref = function.getRef();
                     PropertiesFunction pf = CamelContextHelper.mandatoryLookup(getContext(), ref, PropertiesFunction.class);
-                    pc.addFunction(pf);
+                    pc.addPropertiesFunction(pf);
                 }
             }
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
index a110c26..ac34e34 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentFunctionTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.properties;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.PropertiesFunction;
 import org.junit.Test;
 
 public class PropertiesComponentFunctionTest extends ContextTestSupport {
@@ -43,7 +44,7 @@ public class PropertiesComponentFunctionTest extends ContextTestSupport {
     @Test
     public void testFunction() throws Exception {
         PropertiesComponent pc = (PropertiesComponent) context.getPropertiesComponent();
-        pc.addFunction(new MyFunction());
+        pc.addPropertiesFunction(new MyFunction());
 
         context.addRoutes(new RouteBuilder() {
             @Override
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
index ddef34b..5ea257c 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
@@ -813,3 +813,8 @@ within an `FailedToResolveEndpoint`.
 The `org.apache.camel.impl.engine.JavaUuidGenerator` class has been removed.
 Its a very slow UUID generator and its not recommended to be used.
 
+==== PropertiesComponent
+
+The `org.apache.camel.component.properties.PropertiesFunction` has been moved to `org.apache.camel.spi.PropertiesFunction`
+and its now possible to add custom functions on the `org.apache.camel.spi.PropertiesComponent` interface.
+
diff --git a/docs/user-manual/modules/ROOT/pages/properties-component.adoc b/docs/user-manual/modules/ROOT/pages/properties-component.adoc
index 3bd3121..b2d438d 100644
--- a/docs/user-manual/modules/ROOT/pages/properties-component.adoc
+++ b/docs/user-manual/modules/ROOT/pages/properties-component.adoc
@@ -792,7 +792,7 @@ public static final class MyBeerFunction implements PropertiesFunction {
 ----
 
 The function must implement
-the `org.apache.camel.component.properties.PropertiesFunction`
+the `org.apache.camel.spi.PropertiesFunction`
 interface. The method `getName` is  the name of the function, eg beer.
 And the `apply` method is where we implement the custom logic to do. As
 the sample code is from an unit test, it just returns a value to refer
@@ -802,7 +802,7 @@ To register a custom function from Java code is as shown below:
 
 [source,java]
 ----
-PropertiesComponent pc = (org.apache.camel.componennt.properties.PropertiesComponent) context.getPropertiesComponent();
+PropertiesComponent pc = context.getPropertiesComponent();
 pc.addFunction(new MyBeerFunction());
 ----
  
diff --git a/docs/user-manual/modules/ROOT/pages/using-propertyplaceholder.adoc b/docs/user-manual/modules/ROOT/pages/using-propertyplaceholder.adoc
index cc8fabe..f11ef69 100644
--- a/docs/user-manual/modules/ROOT/pages/using-propertyplaceholder.adoc
+++ b/docs/user-manual/modules/ROOT/pages/using-propertyplaceholder.adoc
@@ -1083,7 +1083,7 @@ public static final class MyBeerFunction implements PropertiesFunction {
 ----
 
 The function must implement
-the `org.apache.camel.component.properties.PropertiesFunction`
+the `org.apache.camel.spi.PropertiesFunction`
 interface. The method `getName` is  the name of the function, e.g.,
 `beer`. And the `apply` method is where we implement the custom
 logic to do. As the sample code is from an unit test, it just returns a
@@ -1093,7 +1093,7 @@ To register a custom function from Java code is as shown below:
 
 [source,java]
 ----
-PropertiesComponent pc = (org.apache.camel.componennt.properties.PropertiesComponent) context.getPropertiesComponent();
+PropertiesComponent pc = context.getPropertiesComponent();
 pc.addFunction(new MyBeerFunction());
 ----