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 2019/05/30 12:44:19 UTC
[camel] 02/03: CAMEL-13557: Add property binding support to make it
convenient to configure components and whatnot.
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 db1738e407c0159c5fe9181d3811a62c85377b69
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu May 30 13:56:34 2019 +0200
CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
.../camel/support/PropertyBindingSupportMapTest.java | 19 +++++++++++++++++++
.../apache/camel/support/PropertyBindingSupport.java | 5 ++---
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportMapTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportMapTest.java
index 561d9dc..f46e976 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportMapTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportMapTest.java
@@ -104,6 +104,25 @@ public class PropertyBindingSupportMapTest extends ContextTestSupport {
}
@Test
+ public void testPropertiesMapFirst() throws Exception {
+ Bar bar = new Bar();
+
+ Map<String, Object> prop = new LinkedHashMap<>();
+ prop.put("works[acme]", "#bean:company1");
+ prop.put("works[acme].id", "666");
+ prop.put("works[burger]", "#bean:company2");
+ prop.put("works[burger].name", "I changed this");
+
+ PropertyBindingSupport.bindProperties(context, bar, prop);
+
+ assertEquals(2, bar.getWorks().size());
+ assertEquals(666, bar.getWorks().get("acme").getId());
+ assertEquals("Acme", bar.getWorks().get("acme").getName());
+ assertEquals(456, bar.getWorks().get("burger").getId());
+ assertEquals("I changed this", bar.getWorks().get("burger").getName());
+ }
+
+ @Test
public void testPropertiesNotMap() throws Exception {
Foo foo = new Foo();
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 1781c79..760029c 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -36,6 +36,7 @@ import static org.apache.camel.support.IntrospectionSupport.findSetterMethods;
* <ul>
* <li>property placeholders - Keys and values using Camels property placeholder will be resolved</li>
* <li>nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123</li>
+ * <li>keys with map</li> - Properties can lookup in Map's using map syntax, eg foo[bar] where foo is the name of the property that is a Map instance, and bar is the name of the key.</li>
* <li>reference by bean id - Values can refer to other beans in the registry by prefixing with #nean: eg #bean:myBean</li>
* <li>reference by type - Values can refer to singleton beans by their type in the registry by prefixing with #type: syntax, eg #type:com.foo.MyClassType</li>
* <li>autowire by type - Values can refer to singleton beans by auto wiring by setting the value to #autowired</li>
@@ -45,7 +46,7 @@ import static org.apache.camel.support.IntrospectionSupport.findSetterMethods;
*/
public final class PropertyBindingSupport {
- // TODO: Add support for Map/List in keys
+ // TODO: Add support for List in keys
/**
* To use a fluent builder style to configure this property binding support.
@@ -360,8 +361,6 @@ public final class PropertyBindingSupport {
}
}
- // TODO: support key without nested dots
-
// if name has dot then we need to OGNL walk it
if (nesting) {
if (name.indexOf('.') > 0) {