Camel Transformer
beve Apr 6, 2011 3:08 AMHi,
I was thinking about transformer and if we could somehow delegate to Camel's Type Converters.
As an example we might create a SwitchYard Transformer that looks somethings like this:
public class CamelTransformer extends BaseTransformer { private CamelContext _camelContext; ... @Override public Object transform(final Object from) { if (from == null) return null; TypeConverter typeConverter = getCamelContext().getTypeConverter(); return typeConverter.convertTo(JavaService.toJavaMessageType(getTo()), from); } }
Now this transformer could be specified as a JavaTransformer in a switchyard.xml file. For example:
<transforms> <transform.java xmlns="urn:switchyard-config:transform:1.0" from="java:java.lang.String" to="java:java.lang.Integer" class="org.switchyard.component.camel.transform.CamelTransformer"/> </transforms>
Camel ships with a number of type converters and users may have their own customer type converter too.
Using a CamelTransformer like the one above would give our users access to the type converters in Camel but they will have to register every 'to' and 'from' type like the above example does or we would have to register the ones that are known.
TomF and I discussed this and Tom suggested that we query Camel for all the type that Camel has registered then we register those types in SwitchYard and use the CamelTransformer. But as far as I can tell we can't query Camel for this. What we can do it ask Camel's TypeConverterRegistry if it has a TypeConverter for a 'to' and 'from' type combination:
TypeConverter lookup(Class<?> toType, Class<?> fromType);
Hmm, what about creating a CamelTransformerRegistry that would first delegate to Camel's TypeConverters and fallback to SwitchYards default, so it would be a wrapper/adapter. This would only be used when the Camel component is in use so it has to be registered. Currently the TransformerRegistry to use is created in AbstractDeployment in the createDomain method. If we make this configurable someway this might be an option.
Any thoughts on this?
/Daniel