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/23 19:31:02 UTC
[camel] 16/18: 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 13557
in repository https://gitbox.apache.org/repos/asf/camel.git
commit dbd439937b0148edfa536bfe5c553d6fc13d398f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu May 23 20:43:30 2019 +0200
CAMEL-13557: Add property binding support to make it convenient to configure components and whatnot.
---
.../DefaultComponentReferencePropertiesTest.java | 4 ++--
.../camel/support/PropertyBindingSupportTest.java | 4 ++--
.../org/apache/camel/support/EndpointHelper.java | 5 ++--
.../camel/support/PropertyBindingSupport.java | 27 ++++++++++++----------
4 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java
index 0ab463e..81fc01b 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentReferencePropertiesTest.java
@@ -199,8 +199,8 @@ public class DefaultComponentReferencePropertiesTest extends ContextTestSupport
MyComponent component = new MyComponent(context);
try {
component.createEndpoint("foo://?special=#dummy");
- fail("Should have throw a ResolveEndpointFailedException");
- } catch (ResolveEndpointFailedException e) {
+ fail("Should have throw a Exception");
+ } catch (Exception e) {
// ok
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
index c372e39..327c919 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/PropertyBindingSupportTest.java
@@ -96,7 +96,7 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
- PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#myWork");
+ PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#bean:myWork");
assertEquals("James", foo.getName());
assertEquals(33, foo.getBar().getAge());
@@ -114,7 +114,7 @@ public class PropertyBindingSupportTest extends ContextTestSupport {
PropertyBindingSupport.bindProperty(context, foo, "bar.age", "33");
PropertyBindingSupport.bindProperty(context, foo, "bar.gold-customer", "true");
PropertyBindingSupport.bindProperty(context, foo, "bar.rider", "true");
- PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#id:myWork");
+ PropertyBindingSupport.bindProperty(context, foo, "bar.work", "#bean:myWork");
assertEquals("James", foo.getName());
assertEquals(33, foo.getBar().getAge());
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
index adc82cd..0dd2adc 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/EndpointHelper.java
@@ -157,9 +157,8 @@ public final class EndpointHelper {
* @throws Exception is thrown if setting property fails
*/
public static void setProperties(CamelContext context, Object bean, Map<String, Object> parameters) throws Exception {
- // TODO: Use more advanced bindingDefaultComponentReferencePropertiesTes
- PropertyBindingSupport.bindProperties(context, bean, parameters);
- //IntrospectionSupport.setProperties(context.getTypeConverter(), bean, parameters);
+ // use the property binding which can do more advanced configuration
+ PropertyBindingSupport.bindProperties(context, bean, parameters);
}
/**
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 99f9638..d992565 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
@@ -34,7 +34,7 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
* <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>reference by id - Values can refer to other beans in the registry by prefixing with #id: or # syntax, eg #id:myBean or #myBean</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 #autowire</li>
* <li>new class - Values can refer to creating new beans by their class name syntax, eg class:com.foo.MyClassType</li>
@@ -43,6 +43,13 @@ import static org.apache.camel.support.IntrospectionSupport.getOrElseProperty;
*/
public final class PropertyBindingSupport {
+ // TODO: Add support for Map/List
+ // TODO: Add option to turn on|off new class
+ // TODO: Add option to turn this binding on|off on component/endpoint level
+
+ /**
+ * To use a fluent builder style to configure this property binding support.
+ */
public static class Builder {
private boolean nesting = true;
@@ -93,8 +100,6 @@ public final class PropertyBindingSupport {
}
- // TODO: Add support for Map/List
-
private PropertyBindingSupport() {
}
@@ -325,9 +330,11 @@ public final class PropertyBindingSupport {
newClass = newTarget.getClass();
}
}
- // okay we found a nested property, then lets change to use that
- target = newTarget;
- name = parts[parts.length - 1];
+ if (newTarget != target) {
+ // okay we found a nested property, then lets change to use that
+ target = newTarget;
+ name = parts[parts.length - 1];
+ }
}
}
@@ -361,13 +368,9 @@ public final class PropertyBindingSupport {
}
}
}
- } else if (value.toString().startsWith("#id:")) {
- // okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
- refName = ((String) value).substring(4);
- value = null;
- } else if (EndpointHelper.isReferenceParameter(value.toString())) {
+ } else if (value.toString().startsWith("#bean:")) {
// okay its a reference so swap to lookup this which is already supported in IntrospectionSupport
- refName = value.toString();
+ refName = ((String) value).substring(6);
value = null;
}
}