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/08/31 18:30:28 UTC

[camel] branch blueprint-noosgi created (now ee519679c19)

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

davsclaus pushed a change to branch blueprint-noosgi
in repository https://gitbox.apache.org/repos/asf/camel.git


      at ee519679c19 CAMEL-19806: camel-jbang - Use aries blueprint-noosgi for parsing blueprint xml files. Experiemtal and WIP.

This branch includes the following new commits:

     new ee519679c19 CAMEL-19806: camel-jbang - Use aries blueprint-noosgi for parsing blueprint xml files. Experiemtal and WIP.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel] 01/01: CAMEL-19806: camel-jbang - Use aries blueprint-noosgi for parsing blueprint xml files. Experiemtal and WIP.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ee519679c19c41a8e784e4261371dacec829ae69
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 31 20:29:55 2023 +0200

    CAMEL-19806: camel-jbang - Use aries blueprint-noosgi for parsing blueprint xml files. Experiemtal and WIP.
---
 dsl/camel-kamelet-main/pom.xml                     |  7 +++
 .../xml/blueprint/BlueprintXmlBeansHandler.java    | 73 +++++++++++++++++++++-
 2 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/dsl/camel-kamelet-main/pom.xml b/dsl/camel-kamelet-main/pom.xml
index 1b80da944a8..481c9f0b2cc 100644
--- a/dsl/camel-kamelet-main/pom.xml
+++ b/dsl/camel-kamelet-main/pom.xml
@@ -40,6 +40,13 @@
 
     <dependencies>
 
+        <!-- TODO: experiment -->
+        <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint.noosgi</artifactId>
+            <version>1.2.0</version>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-main</artifactId>
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/xml/blueprint/BlueprintXmlBeansHandler.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/xml/blueprint/BlueprintXmlBeansHandler.java
index 15a2e88b342..09ceb59d868 100644
--- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/xml/blueprint/BlueprintXmlBeansHandler.java
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/xml/blueprint/BlueprintXmlBeansHandler.java
@@ -16,27 +16,38 @@
  */
 package org.apache.camel.main.xml.blueprint;
 
+import java.net.URI;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringJoiner;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.container.BlueprintContainerImpl;
+import org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet;
 import org.apache.camel.CamelContext;
 import org.apache.camel.main.MainConfigurationProperties;
 import org.apache.camel.main.util.XmlHelper;
 import org.apache.camel.model.Model;
 import org.apache.camel.model.app.RegistryBeanDefinition;
+import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.Resource;
 import org.apache.camel.spi.ResourceLoader;
 import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.util.StringHelper;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -67,7 +78,11 @@ public class BlueprintXmlBeansHandler {
             if (id.startsWith("camel-xml-io-dsl-blueprint-xml:")) {
                 // this is a camel bean via camel-xml-io-dsl
                 String fileName = StringHelper.afterLast(id, ":");
-                discoverBeans(camelContext, fileName, doc);
+                try {
+                    discoverBeans(camelContext, fileName, doc);
+                } catch (Exception e) {
+                    LOG.warn("Error due: " + e.getMessage(), e);
+                }
             }
         });
     }
@@ -76,6 +91,48 @@ public class BlueprintXmlBeansHandler {
      * Invoked at later stage to create and register Blueprint beans into Camel {@link org.apache.camel.spi.Registry}.
      */
     public void createAndRegisterBeans(CamelContext camelContext) {
+
+        for (Resource resource : resources.values()) {
+            SimpleNamespaceHandlerSet ns = new SimpleNamespaceHandlerSet();
+            ns.addNamespace(URI.create("http://camel.apache.org/schema/blueprint"), null, new NamespaceHandler() {
+                @Override
+                public URL getSchemaLocation(String s) {
+                    return null;
+                }
+
+                @Override
+                public Set<Class> getManagedClasses() {
+                    return null;
+                }
+
+                @Override
+                public Metadata parse(Element element, ParserContext parserContext) {
+                    return null;
+                }
+
+                @Override
+                public ComponentMetadata decorate(Node node, ComponentMetadata componentMetadata, ParserContext parserContext) {
+                    return null;
+                }
+            });
+
+            try {
+                ClassLoader cl = new MyClassLoader(camelContext.getClassResolver());
+                BlueprintContainerImpl container
+                        = new BlueprintContainerImpl(
+                                cl, List.of(resource.getURL()), null,
+                                ns, false);
+                System.out.println(container);
+                container.init(false);
+                System.out.println(container.getComponentIds());
+                for (String id : container.getComponentIds()) {
+                    System.out.println(container.getComponentMetadata(id));
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
         if (delayedBeans.isEmpty()) {
             return;
         }
@@ -224,4 +281,18 @@ public class BlueprintXmlBeansHandler {
         }
     }
 
+    private class MyClassLoader extends ClassLoader {
+
+        private final ClassResolver classResolver;
+
+        private MyClassLoader(ClassResolver classResolver) {
+            this.classResolver = classResolver;
+        }
+
+        @Override
+        public Class<?> loadClass(String name) throws ClassNotFoundException {
+            return classResolver.resolveMandatoryClass(name);
+        }
+    }
+
 }