You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "orpiske (via GitHub)" <gi...@apache.org> on 2023/08/23 08:36:36 UTC

[GitHub] [camel] orpiske commented on a diff in pull request #11181: Camel19772

orpiske commented on code in PR #11181:
URL: https://github.com/apache/camel/pull/11181#discussion_r1302680683


##########
core/camel-xml-io/src/main/java/org/apache/camel/xml/LwModelToXMLDumper.java:
##########
@@ -258,4 +283,55 @@ private static NamespaceAware getNamespaceAwareFromExpression(ExpressionNode exp
         return na;
     }
 
+    private static class BeanModelWriter implements CamelContextAware {
+
+        private final StringWriter buffer;
+        private CamelContext camelContext;
+
+        public BeanModelWriter(StringWriter buffer) {
+            this.buffer = buffer;
+        }
+
+        @Override
+        public CamelContext getCamelContext() {
+            return camelContext;
+        }
+
+        @Override
+        public void setCamelContext(CamelContext camelContext) {
+            this.camelContext = camelContext;
+        }
+
+        public void start() {
+            // noop
+        }
+
+        public void stop() {
+            // noop
+        }
+
+        public void writeBeans(List<RegistryBeanDefinition> beans) {
+            if (beans.isEmpty()) {
+                return;
+            }
+            for (RegistryBeanDefinition b : beans) {
+                doWriteRegistryBeanDefinition(b);
+            }
+        }
+
+        private void doWriteRegistryBeanDefinition(RegistryBeanDefinition b) {
+            buffer.write(String.format("    <bean name=\"%s\" type=\"%s\">%n", b.getName(), b.getType()));
+            if (b.getProperties() != null && !b.getProperties().isEmpty()) {
+                buffer.write(String.format("        <properties>%n"));
+                for (Map.Entry<String, Object> entry : b.getProperties().entrySet()) {
+                    String key = entry.getKey();
+                    Object value = entry.getValue();
+                    buffer.write(String.format("            <property key=\"%s\" value=\"%s\"/>%n", key, value));
+                }
+                buffer.write(String.format("        </properties>%n"));
+            }
+            buffer.write(String.format("    </bean>%n"));
+        }
+    }

Review Comment:
   @davsclaus this is a little bit off-topic but, I think it's something we should start thinking about for the future (maybe we'll need to create a ticket about it). 
   
   We have a lot of places with code-to-be-generated that are built-in in the code base. IMHO, this is extremely hard to read, maintain and debug. At some point in 4.x, I believe, we should start investigating how to move this to some kind of template library.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org