[
https://issues.apache.org/activemq/browse/CAMEL-895?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=47905#action_47905 ]
Claus Ibsen commented on CAMEL-895:
-----------------------------------
I had to try a little experiment and got it working very nicely
{code:java}
/**
* Sets the reference properties on the given bean
* <p/>
* This is convention over configuration, setting all <tt>xxxRef</tt> parameters by looking it up in registry
* and setting it on the bean if possible.
*/
protected void setRefProperties(Object bean, Map parameters) throws Exception {
Iterator it = parameters.keySet().iterator();
while (it.hasNext()) {
String key = it.next().toString();
if (key.endsWith("Ref")) {
String value = (String) parameters.get(key);
Object ref = lookup(value);
if (ref != null) {
String name = key.substring(0, key.lastIndexOf("Ref"));
boolean hit = IntrospectionSupport.setProperty(getCamelContext().getTypeConverter(), bean, name, ref);
if (hit) {
LOG.debug("Configued property: " + name + " on bean: " + bean + " with value: " + ref);
// must remove as its a valid option and we could configure it
it.remove();
}
}
}
}
}
{code}
Now it's possible to get rid of duplicated code in components and offer this convention right out-of-the-box for all URI options, making it much easier to set URI options leveraging the Registry.
Using Spring XML this is very powerful.
For instance all this code can be removed:
{code}
// lookup idempotent repository in registry if provided
String ref = getAndRemoveParameter(parameters, "idempotentRepositoryRef", String.class);
if (ref != null) {
IdempotentRepository repository = mandatoryLookup(ref, IdempotentRepository.class);
result.setIdempotentRepository(repository);
}
// lookup file filter in registry if provided
ref = getAndRemoveParameter(parameters, "fileFilterRef", String.class);
if (ref != null) {
FileFilter filter = mandatoryLookup(ref, FileFilter.class);
result.setFilter(filter);
}
// lookup sorter in registry if provided
ref = getAndRemoveParameter(parameters, "sorterRef", String.class);
if (ref != null) {
Comparator<File> sorter = mandatoryLookup(ref, Comparator.class);
result.setFileSorter(sorter);
}
{code}
> DefaultComponent - setProperties should be able to lookup ref in registry
> -------------------------------------------------------------------------
>
> Key: CAMEL-895
> URL:
https://issues.apache.org/activemq/browse/CAMEL-895> Project: Apache Camel
> Issue Type: Improvement
> Components: camel-core
> Affects Versions: 1.5.0
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.0.0
>
>
> URI configuration of endpoints sometimes supports being able to reference a bean in the registry.
> For instance camel-mina has the codec option. Currently this is speically manually coded in the component factory.
> Would be lovely if setProperties(configBean, parameters) would be able to determine this itself and lookup beans in registry.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.