activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james.strac...@gmail.com>
Subject [CAMEL] Heads up - generic type conversion mechanism implemented
Date Thu, 29 Mar 2007 16:07:26 GMT
Its very common when routing from one endpoint to another to need to
convert the body payloads from one type to another such as to/from
objects of types

byte[]/ByteBuffer/String/InputStream/OutputStream/Reader/Writer/Document/Source/File

I've added a default implementation of the TypeConverter which is
capable of converting between types.  It works by searching the
classpath for files called:
META-INF/services/org/apache/camel/TypeConverter which the contents
are expected to be comma separated package names. These packages are
then recursively searched for any objects with the @Converter
annotation. Then any method marked with @Converter is assumed to be a
conversion method; where the parameter is the from value and the
return is the to value.

e.g. the following shows how to register a converter from File -> InputStream

@Converter
public class IOConverter {

    @Converter
    public static InputStream toInputStream(File file) throws
FileNotFoundException {
        return new BufferedInputStream(new FileInputStream(file));
    }
}


I think we've most of the common converters done. I've documented how
this all works in a little more detail here

http://cwiki.apache.org/CAMEL/type-converter.html

Note this mechanism isn't a replacement for all transformers; custom
transformers can still be plugged into a pipeline. Its just to
automate away lots of the drudgery of turning byte[] into String or
Document or Source etc.
-- 

James
-------
http://radio.weblogs.com/0112098/

Mime
View raw message