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 2023/12/30 15:15:09 UTC

(camel) 12/25: CAMEL-19749: Add variables as concept to Camel

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch var
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 61dd45599c77e582b81dd8e0cdd5413061822fe7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Dec 29 19:14:52 2023 +0100

    CAMEL-19749: Add variables as concept to Camel
---
 .../engine/DefaultVariableRepositoryFactory.java   | 28 ++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultVariableRepositoryFactory.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultVariableRepositoryFactory.java
index 5161c43976e..1c4a65569b4 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultVariableRepositoryFactory.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultVariableRepositoryFactory.java
@@ -17,7 +17,9 @@
 package org.apache.camel.impl.engine;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.StaticService;
+import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.VariableRepository;
 import org.apache.camel.spi.VariableRepositoryFactory;
 import org.apache.camel.support.CamelContextHelper;
@@ -33,8 +35,11 @@ public class DefaultVariableRepositoryFactory extends ServiceSupport implements
 
     private static final Logger LOG = LoggerFactory.getLogger(DefaultVariableRepositoryFactory.class);
 
+    public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/variable-repository/";
+
     private final CamelContext camelContext;
     private VariableRepository global;
+    private FactoryFinder factoryFinder;
 
     public DefaultVariableRepositoryFactory(CamelContext camelContext) {
         this.camelContext = camelContext;
@@ -46,13 +51,28 @@ public class DefaultVariableRepositoryFactory extends ServiceSupport implements
             return global;
         }
 
-        // otherwise lookup in registry if the repo exists
         VariableRepository repo = CamelContextHelper.lookup(camelContext, id, VariableRepository.class);
-        if (repo != null) {
-            return repo;
+        if (repo == null) {
+            // try via factory finder
+            Class<?> clazz = factoryFinder.findClass(id).orElse(null);
+            if (clazz != null && VariableRepository.class.isAssignableFrom(clazz)) {
+                repo = (VariableRepository) camelContext.getInjector().newInstance(clazz, true);
+                camelContext.getRegistry().bind(id, repo);
+                try {
+                    camelContext.addService(repo);
+                } catch (Exception e) {
+                    throw RuntimeCamelException.wrapRuntimeException(e);
+                }
+            }
         }
 
-        return null;
+        return repo;
+    }
+
+    @Override
+    protected void doBuild() throws Exception {
+        super.doBuild();
+        this.factoryFinder = camelContext.getCamelContextExtension().getBootstrapFactoryFinder(RESOURCE_PATH);
     }
 
     @Override