activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r523731 [1/2] - in /activemq/camel/trunk: camel-core/ camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/xpath/ camel-core/src/main/java/org/apache/camel/converter/ camel-core/src/main/java/org/apac...
Date Thu, 29 Mar 2007 14:58:22 GMT
Author: jstrachan
Date: Thu Mar 29 07:58:08 2007
New Revision: 523731

URL: http://svn.apache.org/viewvc?view=rev&rev=523731
Log:
added an initial implementation of a generic type coercion library so that the Message.getBody(Class) can do the common conversions folks need such as to/from byte[]/ByteBuffer/String/InputStream/OutputStream/Reader/Writer/Document/Source/File

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Converter.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/JAXPConverter.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/package.html   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/package.html   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java   (contents, props changed)
      - copied, changed from r523614, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultTypeConverter.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/Injector.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ReflectionInjector.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterLoader.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterRegistry.java   (with props)
    activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java   (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/JaxpTest.java   (with props)
Removed:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultTypeConverter.java
Modified:
    activemq/camel/trunk/camel-core/pom.xml
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xpath/XPathBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties
    activemq/camel/trunk/camel-core/src/test/resources/log4j.properties
    activemq/camel/trunk/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java

Modified: activemq/camel/trunk/camel-core/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/pom.xml?view=diff&rev=523731&r1=523730&r2=523731
==============================================================================
--- activemq/camel/trunk/camel-core/pom.xml (original)
+++ activemq/camel/trunk/camel-core/pom.xml Thu Mar 29 07:58:08 2007
@@ -37,12 +37,17 @@
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
-      <optional>false</optional>
     </dependency>
 
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Converter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Converter.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Converter.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Converter.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,16 @@
+package org.apache.camel;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/**
+ * An annotation used to mark classes and methods to indicate code capable of converting from a type to another type
+ *
+ * @version $Revision$
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD})
+public @interface Converter {
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Converter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Converter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Converter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xpath/XPathBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xpath/XPathBuilder.java?view=diff&rev=523731&r1=523730&r2=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xpath/XPathBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xpath/XPathBuilder.java Thu Mar 29 07:58:08 2007
@@ -22,7 +22,7 @@
 import org.apache.camel.Predicate;
 import org.apache.camel.RuntimeExpressionException;
 import org.apache.camel.Message;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.converter.ObjectConverter;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 
@@ -66,7 +66,7 @@
     }
 
     public boolean matches(E exchange) {
-        return ObjectHelper.toBoolean(evaluateAs(exchange, XPathConstants.BOOLEAN));
+        return ObjectConverter.toBoolean(evaluateAs(exchange, XPathConstants.BOOLEAN));
     }
 
     public Object evaluate(E exchange) {

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,85 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter;
+
+import org.apache.camel.Converter;
+
+import java.io.*;
+import java.nio.ByteBuffer;
+
+/**
+ * Some core java.io based converters
+ *
+ * @version $Revision$
+ */
+@Converter
+public class IOConverter {
+
+    @Converter
+    public static InputStream toInputStream(File file) throws FileNotFoundException {
+        return new BufferedInputStream(new FileInputStream(file));
+    }
+
+    @Converter
+    public static BufferedReader toReader(File file) throws FileNotFoundException {
+        return new BufferedReader(new FileReader(file));
+    }
+
+    @Converter
+    public static OutputStream toOutputStream(File file) throws FileNotFoundException {
+        return new BufferedOutputStream(new FileOutputStream(file));
+    }
+
+    @Converter
+    public static BufferedWriter toWriter(File file) throws IOException {
+        return new BufferedWriter(new FileWriter(file));
+    }
+
+    @Converter
+    public static Reader toReader(InputStream in) throws FileNotFoundException {
+        return new InputStreamReader(in);
+    }
+
+    @Converter
+    public static Writer toWriter(OutputStream out) throws FileNotFoundException {
+        return new OutputStreamWriter(out);
+    }
+
+
+    @Converter
+    public static StringReader toInputStream(String text) {
+        // TODO could we automatically find this?
+        return new StringReader(text);
+    }
+
+    @Converter
+    public static byte[] toByteArray(String text) {
+        // TODO could we automatically find this?
+        return text.getBytes();
+    }
+
+    @Converter
+    public static String toString(byte[] data) {
+        return new String(data);
+    }
+
+    @Converter
+    public static InputStream toInputStream(byte[] data) {
+        return new ByteArrayInputStream(data);
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,42 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter;
+
+import org.apache.camel.Converter;
+
+import java.io.*;
+import java.nio.ByteBuffer;
+
+/**
+ * Some core java.nio based converters
+ *
+ * @version $Revision$
+ */
+@Converter
+public class NIOConverter {
+
+    @Converter
+    public static byte[] toByteArray(ByteBuffer buffer) {
+        return buffer.array();
+    }
+
+    @Converter
+    public static ByteBuffer toByteBuffer(byte[] data) {
+        return ByteBuffer.wrap(data);
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,68 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter;
+
+import org.apache.camel.Converter;
+
+import java.util.Iterator;
+import java.util.Collections;
+import java.util.Collection;
+import java.util.Arrays;
+
+/**
+ * Some core java.lang based converters
+ * 
+ * @version $Revision$
+ */
+@Converter
+public class ObjectConverter {
+    /**
+     * Creates an iterator over the value if the value is a collection, an Object[] or a primitive type array; otherwise
+     * to simplify the caller's code, we just create a singleton collection iterator over a single value
+     */
+    @Converter
+    public static Iterator iterator(Object value) {
+        if (value == null) {
+            return Collections.EMPTY_LIST.iterator();
+        }
+        else if (value instanceof Collection) {
+            Collection collection = (Collection) value;
+            return collection.iterator();
+        }
+        else if (value.getClass().isArray()) {
+            return Arrays.asList(value).iterator();
+        }
+        else {
+            return Collections.singletonList(value).iterator();
+        }
+    }
+
+    /**
+     * Converts the given value to a boolean, handling strings or Boolean objects; otherwise returning true if non-null
+     */
+    @Converter
+    public static boolean toBoolean(Object value) {
+        if (value instanceof Boolean) {
+            return (Boolean) value;
+        }
+        if (value instanceof String) {
+            return "true".equalsIgnoreCase(value.toString());
+        }
+        return value != null;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter.jaxp;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+/**
+ * A helper class which provides a JAXP {@link Source} from a byte[]
+ * which can be read as many times as required.
+ *
+ * @version $Revision$
+ */
+public class BytesSource extends StreamSource {
+    private byte[] data;
+
+    public BytesSource(byte[] data) {
+        this.data = data;
+    }
+
+    public BytesSource(byte[] data, String systemId) {
+        this.data = data;
+        setSystemId(systemId);
+    }
+
+    public InputStream getInputStream() {
+        return new ByteArrayInputStream(data);
+    }
+
+    public Reader getReader() {
+        return new InputStreamReader(getInputStream());
+    }
+
+    public byte[] getData() {
+        return data;
+    }
+
+    public String toString() {
+        return "BytesSource[" + new String(data) + "]";
+    }
+
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/JAXPConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/JAXPConverter.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/JAXPConverter.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/JAXPConverter.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,521 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter.jaxp;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.lang.reflect.Constructor;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.Converter;
+
+/**
+ * A helper class to transform to and from various JAXB types such as {@link Source} and {@link Document}
+ *
+ * @version $Revision$
+ */
+@Converter
+public class JAXPConverter {
+    public static final String DEFAULT_CHARSET_PROPERTY = "org.apache.camel.default.charset";
+
+    public static String defaultCharset = ObjectHelper.getSystemProperty(DEFAULT_CHARSET_PROPERTY, "UTF-8");
+
+    private DocumentBuilderFactory documentBuilderFactory;
+    private TransformerFactory transformerFactory;
+
+    /*
+     * When converting a DOM tree to a SAXSource,
+     * we try to use Xalan internal DOM parser if
+     * available.  Else, transform the DOM tree
+     * to a String and build a SAXSource on top of
+     * it.
+     */
+    private static final Class dom2SaxClass;
+
+    static {
+        Class cl = null;
+        try {
+            cl = Class.forName("org.apache.xalan.xsltc.trax.DOM2SAX");
+        } catch (Throwable t) {}
+        dom2SaxClass = cl;
+    }
+
+
+    public JAXPConverter() {
+    }
+
+    public JAXPConverter(DocumentBuilderFactory documentBuilderFactory) {
+        this.documentBuilderFactory = documentBuilderFactory;
+    }
+
+
+    /**
+     * Converts the given input Source into the required result
+     */
+    public void toResult(Source source, Result result) throws TransformerException {
+        if (source == null) {
+            return;
+        }
+        Transformer transformer = createTransfomer();
+        if (transformer == null) {
+            throw new TransformerException("Could not create a transformer - JAXP is misconfigured!");
+        }
+        transformer.setOutputProperty(OutputKeys.ENCODING, defaultCharset);
+        transformer.transform(source, result);
+    }
+
+    /**
+     * Converts the given byte[] to a Source
+     */
+    @Converter
+    public BytesSource toSource(byte[] data) {
+        return new BytesSource(data);
+    }
+
+
+    /**
+     * Converts the given String to a Source
+     */
+    @Converter
+    public StringSource toSource(String data) {
+        return new StringSource(data);
+    }
+
+
+    /**
+     * Converts the given input Source into text
+     */
+    @Converter
+    public String toString(Source source) throws TransformerException {
+        if (source == null) {
+            return null;
+        } else if (source instanceof StringSource) {
+            return ((StringSource) source).getText();
+        } else if (source instanceof BytesSource) {
+            return new String(((BytesSource) source).getData());
+        } else {
+            StringWriter buffer = new StringWriter();
+            toResult(source, new StreamResult(buffer));
+            return buffer.toString();
+        }
+    }
+
+    /**
+     * Converts the given input Node into text
+     */
+    @Converter
+    public String toString(Node node) throws TransformerException {
+        return toString(new DOMSource(node));
+    }
+
+    /**
+     * Converts the source instance to a {@link DOMSource} or returns null if the conversion is not
+     * supported (making it easy to derive from this class to add new kinds of conversion).
+     */
+    @Converter
+    public DOMSource toDOMSource(Source source) throws ParserConfigurationException, IOException, SAXException, TransformerException {
+        if (source instanceof DOMSource) {
+            return (DOMSource) source;
+        }
+        else if (source instanceof SAXSource) {
+            return toDOMSourceFromSAX((SAXSource) source);
+        }
+        else if (source instanceof StreamSource) {
+            return toDOMSourceFromStream((StreamSource) source);
+        }
+        else {
+            return null;
+        }
+    }
+
+    /**
+     * Converts the source instance to a {@link SAXSource} or returns null if the conversion is not
+     * supported (making it easy to derive from this class to add new kinds of conversion).
+     */
+    @Converter
+    public SAXSource toSAXSource(Source source) throws IOException, SAXException, TransformerException {
+        if (source instanceof SAXSource) {
+            return (SAXSource) source;
+        }
+        else if (source instanceof DOMSource) {
+            return toSAXSourceFromDOM((DOMSource) source);
+        }
+        else if (source instanceof StreamSource) {
+            return toSAXSourceFromStream((StreamSource) source);
+        }
+        else {
+            return null;
+        }
+    }
+
+    @Converter
+    public StreamSource toStreamSource(Source source) throws TransformerException {
+        if (source instanceof StreamSource) {
+            return (StreamSource) source;
+        } else if (source instanceof DOMSource) {
+            return toStreamSourceFromDOM((DOMSource) source);
+        } else if (source instanceof SAXSource) {
+            return toStreamSourceFromSAX((SAXSource) source);
+        } else {
+            return null;
+        }
+    }
+
+    @Converter
+    public StreamSource toStreamSourceFromSAX(SAXSource source) throws TransformerException {
+        InputSource inputSource = source.getInputSource();
+        if (inputSource != null) {
+            if (inputSource.getCharacterStream() != null) {
+                return new StreamSource(inputSource.getCharacterStream());
+            }
+            if (inputSource.getByteStream() != null) {
+                return new StreamSource(inputSource.getByteStream());
+            }
+        }
+        String result = toString(source);
+        return new StringSource(result);
+    }
+
+    @Converter
+    public StreamSource toStreamSourceFromDOM(DOMSource source) throws TransformerException {
+        String result = toString(source);
+        return new StringSource(result);
+    }
+
+    @Converter
+    public SAXSource toSAXSourceFromStream(StreamSource source) {
+        InputSource inputSource;
+        if (source.getReader() != null) {
+            inputSource = new InputSource(source.getReader());
+        } else {
+            inputSource = new InputSource(source.getInputStream());
+        }
+        inputSource.setSystemId(source.getSystemId());
+        inputSource.setPublicId(source.getPublicId());
+        return new SAXSource(inputSource);
+    }
+
+    @Converter
+    public Reader toReaderFromSource(Source src) throws TransformerException {
+        StreamSource stSrc = toStreamSource(src);
+        Reader r = stSrc.getReader();
+        if (r == null) {
+            r = new InputStreamReader(stSrc.getInputStream());
+        }
+        return r;
+    }
+
+    @Converter
+    public DOMSource toDOMSourceFromStream(StreamSource source) throws ParserConfigurationException, IOException, SAXException {
+        DocumentBuilder builder = createDocumentBuilder();
+        String systemId = source.getSystemId();
+        Document document = null;
+        Reader reader = source.getReader();
+        if (reader != null) {
+            document = builder.parse(new InputSource(reader));
+        } else {
+            InputStream inputStream = source.getInputStream();
+            if (inputStream != null) {
+                InputSource inputsource = new InputSource(inputStream);
+                inputsource.setSystemId(systemId);
+                document = builder.parse(inputsource);
+            }
+            else {
+                throw new IOException("No input stream or reader available");
+            }
+        }
+        return new DOMSource(document, systemId);
+    }
+
+    @Converter
+    public SAXSource toSAXSourceFromDOM(DOMSource source) throws TransformerException {
+        if (dom2SaxClass != null) {
+            try {
+                Constructor cns = dom2SaxClass.getConstructor(new Class[] { Node.class });
+                XMLReader converter = (XMLReader) cns.newInstance(new Object[] { source.getNode() });
+                return new SAXSource(converter, new InputSource());
+            } catch (Exception e) {
+                throw new TransformerException(e);
+            }
+        } else {
+            String str = toString(source);
+            StringReader reader = new StringReader(str);
+            return new SAXSource(new InputSource(reader));
+        }
+    }
+
+    @Converter
+    public DOMSource toDOMSourceFromSAX(SAXSource source) throws IOException, SAXException, ParserConfigurationException, TransformerException {
+        return new DOMSource(toDOMNodeFromSAX(source));
+    }
+
+    @Converter
+    public Node toDOMNodeFromSAX(SAXSource source) throws ParserConfigurationException, IOException, SAXException, TransformerException {
+        DOMResult result = new DOMResult();
+        toResult(source, result);
+        return result.getNode();
+    }
+
+    /**
+     * Converts the given TRaX Source into a W3C DOM node
+     * @throws SAXException
+     * @throws IOException
+     * @throws ParserConfigurationException
+     */
+    @Converter
+    public Node toDOMNode(Source source) throws TransformerException, ParserConfigurationException, IOException, SAXException {
+        DOMSource domSrc = toDOMSource(source);
+        return domSrc != null ? domSrc.getNode() :  null;
+    }
+
+    /**
+     * Create a DOM element from the given source.
+     *
+     * @param source
+     * @return
+     * @throws TransformerException
+     * @throws ParserConfigurationException
+     * @throws IOException
+     * @throws SAXException
+     */
+    @Converter
+    public Element toDOMElement(Source source) throws TransformerException, ParserConfigurationException, IOException, SAXException {
+        Node node = toDOMNode(source);
+        return toDOMElement(node);
+    }
+
+    /**
+     * Create a DOM element from the DOM node.
+     * Simply cast if the node is an Element, or
+     * return the root element if it is a Document.
+     *
+     * @param node
+     * @return
+     * @throws TransformerException
+     */
+    @Converter
+    public Element toDOMElement(Node node) throws TransformerException {
+        // If the node is an document, return the root element
+        if (node instanceof Document) {
+            return ((Document) node).getDocumentElement();
+        // If the node is an element, just cast it
+        } else if (node instanceof Element) {
+            return (Element) node;
+        // Other node types are not handled
+        } else {
+            throw new TransformerException("Unable to convert DOM node to an Element");
+        }
+    }
+
+    /**
+     * Converts the given data to a DOM document
+     *
+     * @param data is the data to be parsed
+     * @return the parsed document
+     */
+    @Converter
+    public Document toDOMDocument(byte[] data) throws IOException, SAXException, ParserConfigurationException {
+        DocumentBuilder documentBuilder = getDocumentBuilderFactory().newDocumentBuilder();
+        return documentBuilder.parse(new ByteArrayInputStream(data));
+    }
+
+    /**
+     * Converts the given {@link InputStream} to a DOM document
+     *
+     * @param in is the data to be parsed
+     * @return the parsed document
+     */
+    @Converter
+    public Document toDOMDocument(InputStream in) throws IOException, SAXException, ParserConfigurationException {
+        DocumentBuilder documentBuilder = getDocumentBuilderFactory().newDocumentBuilder();
+        return documentBuilder.parse(in);
+    }
+
+    /**
+     * Converts the given {@link InputSource} to a DOM document
+     *
+     * @param in is the data to be parsed
+     * @return the parsed document
+     */
+    @Converter
+    public Document toDOMDocument(InputSource in) throws IOException, SAXException, ParserConfigurationException {
+        DocumentBuilder documentBuilder = getDocumentBuilderFactory().newDocumentBuilder();
+        return documentBuilder.parse(in);
+    }
+
+    /**
+     * Converts the given {@link String} to a DOM document
+     *
+     * @param text is the data to be parsed
+     * @return the parsed document
+     */
+    @Converter
+    public Document toDOMDocument(String text) throws IOException, SAXException, ParserConfigurationException {
+        return toDOMDocument(text.getBytes());
+    }
+
+    /**
+     * Converts the given {@link File} to a DOM document
+     *
+     * @param file is the data to be parsed
+     * @return the parsed document
+     */
+    @Converter
+    public Document toDOMDocument(File file) throws IOException, SAXException, ParserConfigurationException {
+        DocumentBuilder documentBuilder = getDocumentBuilderFactory().newDocumentBuilder();
+        return documentBuilder.parse(file);
+    }
+
+
+    /**
+     * Create a DOM document from the given source.
+     *
+     * @param source
+     * @return
+     * @throws TransformerException
+     * @throws ParserConfigurationException
+     * @throws IOException
+     * @throws SAXException
+     */
+    @Converter
+    public Document toDOMDocument(Source source) throws TransformerException, ParserConfigurationException, IOException, SAXException {
+        Node node = toDOMNode(source);
+        return toDOMDocument(node);
+    }
+
+    /**
+     * Create a DOM document from the given Node.
+     * If the node is an document, just cast it,
+     * if the node is an root element, retrieve its
+     * owner element or create a new document and import
+     * the node.
+     *
+     * @param node
+     * @return
+     * @throws ParserConfigurationException
+     * @throws TransformerException
+     */
+    @Converter
+    public Document toDOMDocument(Node node) throws ParserConfigurationException, TransformerException {
+        // If the node is the document, just cast it
+        if (node instanceof Document) {
+            return (Document) node;
+        // If the node is an element
+        } else if (node instanceof Element) {
+            Element elem = (Element) node;
+            // If this is the root element, return its owner document
+            if (elem.getOwnerDocument().getDocumentElement() == elem) {
+                return elem.getOwnerDocument();
+            // else, create a new doc and copy the element inside it
+            } else {
+                Document doc = createDocument();
+                doc.appendChild(doc.importNode(node, true));
+                return doc;
+            }
+        // other element types are not handled
+        } else {
+            throw new TransformerException("Unable to convert DOM node to a Document");
+        }
+    }
+
+    // Properties
+    //-------------------------------------------------------------------------
+    public DocumentBuilderFactory getDocumentBuilderFactory() {
+        if (documentBuilderFactory == null) {
+            documentBuilderFactory = createDocumentBuilderFactory();
+        }
+        return documentBuilderFactory;
+    }
+
+    public void setDocumentBuilderFactory(DocumentBuilderFactory documentBuilderFactory) {
+        this.documentBuilderFactory = documentBuilderFactory;
+    }
+
+
+    // Helper methods
+    //-------------------------------------------------------------------------
+    public DocumentBuilderFactory createDocumentBuilderFactory() {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setIgnoringElementContentWhitespace(true);
+        factory.setIgnoringComments(true);
+        return factory;
+    }
+
+
+    public DocumentBuilder createDocumentBuilder() throws ParserConfigurationException {
+        DocumentBuilderFactory factory = getDocumentBuilderFactory();
+        return factory.newDocumentBuilder();
+    }
+
+    public Document createDocument() throws ParserConfigurationException {
+        DocumentBuilder builder = createDocumentBuilder();
+        return builder.newDocument();
+    }
+
+    public TransformerFactory getTransformerFactory() {
+        if (transformerFactory == null) {
+            transformerFactory = createTransformerFactory();
+        }
+        return transformerFactory;
+    }
+
+    public void setTransformerFactory(TransformerFactory transformerFactory) {
+        this.transformerFactory = transformerFactory;
+    }
+
+    public Transformer createTransfomer() throws TransformerConfigurationException {
+        TransformerFactory factory = getTransformerFactory();
+        return factory.newTransformer();
+    }
+
+    public TransformerFactory createTransformerFactory() {
+        TransformerFactory answer = TransformerFactory.newInstance();
+        return answer;
+    }
+
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/JAXPConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/JAXPConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/JAXPConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter.jaxp;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.Serializable;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+/**
+ * A helper class which provides a JAXP {@link Source} from a String
+ * which can be read as many times as required.
+ *
+ * @version $Revision$
+ */
+public class StringSource extends StreamSource implements Serializable {
+
+    private final String text;
+    private String encoding = "UTF-8";
+
+    public StringSource(String text) {
+        if (text == null) {
+            throw new NullPointerException("text can not be null");
+        }
+        this.text = text;
+    }
+
+    public StringSource(String text, String systemId) {
+        this(text);
+        setSystemId(systemId);
+    }
+
+    public StringSource(String text, String systemId, String encoding) {
+        this.text = text;
+        this.encoding=encoding;
+        setSystemId(systemId);
+    }
+
+    public InputStream getInputStream() {
+        try {
+            return new ByteArrayInputStream(text.getBytes(encoding));
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public Reader getReader() {
+        return new StringReader(text);
+    }
+
+    public String toString() {
+        return "StringSource[" + text + "]";
+    }
+
+    public String getText() {
+        return text;
+    }
+
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/package.html
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/package.html?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/package.html (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/package.html Thu Mar 29 07:58:08 2007
@@ -0,0 +1,26 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+   
+    http://www.apache.org/licenses/LICENSE-2.0
+   
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+</head>
+<body>
+
+A number of JAXP related helper classes for converting to and from various JAXP related classes like Document and Source to be used by a 
+<a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/TypeConverter.html">TypeConverter</a>
+
+</body>
+</html>

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/package.html
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/package.html?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/package.html (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/package.html Thu Mar 29 07:58:08 2007
@@ -0,0 +1,26 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+   
+    http://www.apache.org/licenses/LICENSE-2.0
+   
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+</head>
+<body>
+
+A set of helper classes for converting from different types of Java object to be used by a
+<a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/TypeConverter.html">TypeConverter</a>
+
+</body>
+</html>

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=523731&r1=523730&r2=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Thu Mar 29 07:58:08 2007
@@ -18,6 +18,7 @@
 package org.apache.camel.impl;
 
 import org.apache.camel.*;
+import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.util.ServiceHelper;
 import org.apache.commons.logging.Log;

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,158 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.converter;
+
+import org.apache.camel.Converter;
+import org.apache.camel.util.ResolverUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.reflect.Method;
+import static java.lang.reflect.Modifier.*;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+/**
+ * A class which will auto-discover converter objects and methods to pre-load
+ * the registry of converters on startup
+ *
+ * @version $Revision$
+ */
+public class AnnotationTypeConverterLoader implements TypeConverterLoader {
+    public static final String META_INF_SERVICES = "META-INF/services/org/apache/camel/TypeConverter";
+    private static final transient Log log = LogFactory.getLog(AnnotationTypeConverterLoader.class);
+    private ResolverUtil resolver = new ResolverUtil();
+    private Set<Class> visitedClasses = new HashSet<Class>();
+
+    public void load(TypeConverterRegistry registry) throws Exception {
+        String[] packageNames = findPackageNames();
+        resolver.findAnnotated(Converter.class, packageNames);
+        Set<Class> classes = resolver.getClasses();
+        for (Class type : classes) {
+            loadConverterMethods(registry, type);
+        }
+    }
+
+    /**
+     * Finds the names of the packages to search for on the classpath looking for text files on the classpath
+     * at the  @{link #META_INF_SERVICES} location
+     *
+     * @return a collection of packages to search for
+     * @throws IOException
+     */
+    protected String[] findPackageNames() throws IOException {
+        Set<String> packages = new HashSet<String>();
+        findPackages(packages, Thread.currentThread().getContextClassLoader());
+        findPackages(packages, getClass().getClassLoader());
+        return packages.toArray(new String[packages.size()]);
+    }
+
+    protected void findPackages(Set<String> packages, ClassLoader classLoader) throws IOException {
+        Enumeration<URL> resources = classLoader.getResources(META_INF_SERVICES);
+        while (resources.hasMoreElements()) {
+            URL url = resources.nextElement();
+            if (url != null) {
+                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
+                try {
+                    while (true) {
+                        String line = reader.readLine();
+                        if (line == null) {
+                            break;
+                        }
+                        tokenize(packages, line);
+                    }
+                }
+                finally {
+                    try {
+                        reader.close();
+                    }
+                    catch (IOException e) {
+                        log.warn("Caught exception closing stream: " + e, e);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Tokenizes the line from the META-IN/services file using commas and ignoring whitespace between packages
+     */
+    protected void tokenize(Set<String> packages, String line) {
+        StringTokenizer iter = new StringTokenizer(line, ",");
+        while (iter.hasMoreTokens()) {
+            String name = iter.nextToken().trim();
+            if (name.length() > 0) {
+                packages.add(name);
+            }
+        }
+    }
+
+    /**
+     * Loads all of the converter methods for the given type
+     */
+    protected void loadConverterMethods(TypeConverterRegistry registry, Class type) {
+        if (visitedClasses.contains(type)) {
+            return;
+        }
+        visitedClasses.add(type);
+        Method[] methods = type.getDeclaredMethods();
+        for (Method method : methods) {
+            Converter annotation = method.getAnnotation(Converter.class);
+            if (annotation != null) {
+                Class<?>[] parameterTypes = method.getParameterTypes();
+                if (parameterTypes == null || parameterTypes.length != 1) {
+                    log.warn("Ignoring bad converter on type: " + type.getName()
+                            + " method: " + method + " as a converter method should have one parameter");
+                }
+                else {
+                    int modifiers = method.getModifiers();
+                    if (isAbstract(modifiers) || !isPublic(modifiers)) {
+                        log.warn("Ignoring bad converter on type: " + type.getName()
+                                + " method: " + method + " as a converter method is not a public and concrete method");
+                    }
+                    else {
+                        Class toType = method.getReturnType();
+                        if (toType.equals(Void.class)) {
+                            log.warn("Ignoring bad converter on type: " + type.getName()
+                                    + " method: " + method + " as a converter method returns a void method");
+                        }
+                        else {
+                            Class fromType = parameterTypes[0];
+                            if (isStatic(modifiers)) {
+                                registry.addTypeConverter(fromType, toType, new StaticMethodTypeConverter(method));
+                            }
+                            else {
+                                registry.addTypeConverter(fromType, toType, new InstanceMethodTypeConverter(registry, type, method));
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        Class superclass = type.getSuperclass();
+        if (superclass != null && !superclass.equals(Object.class)) {
+            loadConverterMethods(registry, superclass);
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java (from r523614, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultTypeConverter.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java?view=diff&rev=523731&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultTypeConverter.java&r1=523614&p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java&r2=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultTypeConverter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java Thu Mar 29 07:58:08 2007
@@ -15,23 +15,189 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.impl;
+package org.apache.camel.impl.converter;
 
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @version $Revision$
  */
-public class DefaultTypeConverter implements TypeConverter {
-    public <T> T convertTo(Class<T> type, Object value) {
-        if (type.isInstance(value)) {
-            return type.cast(value);
+public class DefaultTypeConverter implements TypeConverter, TypeConverterRegistry {
+    private static final transient Log log = LogFactory.getLog(DefaultTypeConverter.class);
+    private Map<TypeMapping, TypeConverter> typeMappings = new HashMap<TypeMapping, TypeConverter>();
+    private Injector injector;
+    private List<TypeConverterLoader> typeConverterLoaders = new ArrayList<TypeConverterLoader>();
+    private boolean loaded;
+
+    public DefaultTypeConverter() {
+        typeConverterLoaders.add(new AnnotationTypeConverterLoader());
+    }
+
+    public <T> T convertTo(Class<T> toType, Object value) {
+        if (toType.isInstance(value)) {
+            return toType.cast(value);
+        }
+        checkLoaded();
+        TypeConverter converter = getConverter(toType, value);
+        if (converter != null) {
+            return converter.convertTo(toType, value);
         }
         if (value != null) {
-            if (type.equals(String.class)) {
+            if (toType.equals(String.class)) {
                 return (T) value.toString();
             }
         }
         return null;
+    }
+
+    public void addTypeConverter(Class fromType, Class toType, TypeConverter typeConverter) {
+        TypeMapping key = new TypeMapping(fromType, toType);
+        synchronized (typeMappings) {
+            TypeConverter converter = typeMappings.get(key);
+            if (converter != null) {
+                log.warn("Overriding type converter from: " + converter + " to: " + typeConverter);
+            }
+            typeMappings.put(key, typeConverter);
+        }
+    }
+
+    public TypeConverter getTypeConverter(Class fromType, Class toType) {
+        TypeMapping key = new TypeMapping(fromType, toType);
+        synchronized (typeMappings) {
+            return typeMappings.get(key);
+        }
+    }
+
+    public Injector getInjector() {
+        if (injector == null) {
+            injector = new ReflectionInjector();
+        }
+        return injector;
+    }
+
+    public void setInjector(Injector injector) {
+        this.injector = injector;
+    }
+
+    protected <T> TypeConverter getConverter(Class toType, Object value) {
+        Class fromType = null;
+        if (value != null) {
+            fromType = value.getClass();
+        }
+        TypeMapping key = new TypeMapping(fromType, toType);
+        TypeConverter converter;
+        synchronized (typeMappings) {
+            converter = typeMappings.get(key);
+            if (converter == null) {
+                converter = findTypeConverter(toType, fromType, value);
+                if (converter != null) {
+                    typeMappings.put(key, converter);
+                }
+            }
+        }
+        return converter;
+    }
+
+    /**
+     * Tries to auto-discover any available type converters
+     */
+    protected TypeConverter findTypeConverter(Class toType, Class fromType, Object value) {
+        // lets try the super classes of the to type
+        for (Class toSuperClass = toType.getSuperclass();
+             toSuperClass != null && !toSuperClass.equals(Object.class);
+             toSuperClass = toSuperClass.getSuperclass()) {
+
+            TypeConverter converter = getTypeConverter(fromType, toSuperClass);
+            if (converter != null) {
+                return converter;
+            }
+        }
+
+        // TODO should we filter out any interfaces which are super-interfaces?
+        for (Class type : toType.getInterfaces()) {
+            TypeConverter converter = getTypeConverter(fromType, type);
+            if (converter != null) {
+                return converter;
+            }
+        }
+
+        // lets try the super classes of the from type
+        Class fromSuperClass = fromType.getSuperclass();
+        if (fromSuperClass != null && !fromSuperClass.equals(Object.class)) {
+            return findTypeConverter(toType, fromSuperClass, value);
+        }
+        for (Class type : fromType.getInterfaces()) {
+            TypeConverter converter = getTypeConverter(type, toType);
+            if (converter != null) {
+                return converter;
+            }
+        }
+        // TODO look at constructors of toType?
+        return null;
+    }
+
+    /**
+     * Checks if the registry is loaded and if not lazily load it
+     */
+    protected synchronized void checkLoaded() {
+        if (!loaded) {
+            loaded = true;
+            for (TypeConverterLoader typeConverterLoader : typeConverterLoaders) {
+                try {
+                    typeConverterLoader.load(this);
+                }
+                catch (Exception e) {
+                    throw new RuntimeCamelException(e);
+                }
+            }
+        }
+    }
+
+    /**
+     * Represents a mapping from one type (which can be null) to another
+     */
+    protected static class TypeMapping {
+        Class fromType;
+        Class toType;
+
+        public TypeMapping(Class fromType, Class toType) {
+            this.fromType = fromType;
+            this.toType = toType;
+        }
+
+        public Class getFromType() {
+            return fromType;
+        }
+
+        public Class getToType() {
+            return toType;
+        }
+
+        @Override
+        public boolean equals(Object object) {
+            if (object instanceof TypeMapping) {
+                TypeMapping that = (TypeMapping) object;
+                return ObjectHelper.equals(this.fromType, that.fromType) && ObjectHelper.equals(this.toType, that.toType);
+            }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            int answer = toType.hashCode();
+            if (fromType != null) {
+                answer *= 37 + fromType.hashCode();
+            }
+            return answer;
+        }
     }
 }

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/Injector.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/Injector.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/Injector.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/Injector.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,34 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.converter;
+
+/**
+ * A pluggable strategy for creating and possibly dependency injecting objects
+ * which could be implemented using straight forward reflection or using Spring or Guice to perform dependency injection.
+ *
+ * @version $Revision$
+ */
+public interface Injector<T> {
+    /**
+     * Instantiates a new instance of the given type possibly injecting values into the object in the process
+     *
+     * @param type the type of object to create
+     * @return a newly created instance
+     */
+    T newInstance(Class<T> type);
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/Injector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/Injector.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/Injector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,72 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.converter;
+
+import org.apache.camel.TypeConverter;
+import org.apache.camel.RuntimeCamelException;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * A {@link TypeConverter} implementation which instantiates an object
+ * so that an instance method can be used as a type converter
+ *
+ * @version $Revision$
+ */
+public class InstanceMethodTypeConverter implements TypeConverter {
+    private Object instance;
+    private final TypeConverterRegistry repository;
+    private final Class type;
+    private final Method method;
+
+    public InstanceMethodTypeConverter(TypeConverterRegistry repository, Class type, Method method) {
+        this.repository = repository;
+        this.type = type;
+        this.method = method;
+    }
+
+
+    @Override
+    public String toString() {
+        return "InstanceMethodTypeConverter: " + method;
+    }
+
+
+    public synchronized <T> T convertTo(Class<T> type, Object value) {
+        if (instance == null) {
+            instance = createInstance();
+            if (instance == null) {
+                throw new RuntimeCamelException("Could not instantiate aninstance of: " + type.getName());
+            }
+        }
+        try {
+            return (T) method.invoke(instance, value);
+        }
+        catch (IllegalAccessException e) {
+            throw new RuntimeCamelException(e);
+        }
+        catch (InvocationTargetException e) {
+            throw new RuntimeCamelException(e.getCause());
+        }
+    }
+
+    protected Object createInstance() {
+        return repository.getInjector().newInstance(type);
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ReflectionInjector.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ReflectionInjector.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ReflectionInjector.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ReflectionInjector.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,41 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.converter;
+
+import org.apache.camel.RuntimeCamelException;
+
+/**
+ * A simple implementation of {@link Injector} which just uses reflection to instantiate new objects
+ * using their zero argument constructor. For more complex implementations try the Spring or Guice implementations.
+ *
+ * @version $Revision$
+ */
+public class ReflectionInjector<T> implements Injector<T> {
+    
+    public T newInstance(Class<T> type) {
+        try {
+            return type.newInstance();
+        }
+        catch (InstantiationException e) {
+            throw new RuntimeCamelException(e.getCause());
+        }
+        catch (IllegalAccessException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ReflectionInjector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ReflectionInjector.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ReflectionInjector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,56 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.converter;
+
+import org.apache.camel.TypeConverter;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * A {@link TypeConverter} implementation which invokes a static method to convert from a type to another type
+ *
+ * @version $Revision$
+ */
+public class StaticMethodTypeConverter implements TypeConverter {
+    private final Method method;
+
+    public StaticMethodTypeConverter(Method method) {
+        this.method = method;
+    }
+
+    @Override
+    public String toString() {
+        return "StaticMethodTypeConverter: " + method;
+    }
+
+    public <T> T convertTo(Class<T> type, Object value) {
+        try {
+            return (T) method.invoke(null, value);
+        }
+        catch (IllegalAccessException e) {
+            throw new RuntimeCamelException(e);
+        }
+        catch (InvocationTargetException e) {
+            throw new RuntimeCamelException(e.getCause());
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/StaticMethodTypeConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterLoader.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterLoader.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterLoader.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterLoader.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,31 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.converter;
+
+/**
+ * @version $Revision$
+ */
+public interface TypeConverterLoader {
+    /**
+     * A pluggable strategy to load type converters into a registry from some kind of mechanism
+     *
+     * @param registry the registry to load the type converters into
+     * @throws Exception if the type converters could not be loaded
+     */
+    void load(TypeConverterRegistry registry) throws Exception;
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterLoader.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterRegistry.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterRegistry.java?view=auto&rev=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterRegistry.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterRegistry.java Thu Mar 29 07:58:08 2007
@@ -0,0 +1,36 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.converter;
+
+import org.apache.camel.TypeConverter;
+
+/**
+ * @version $Revision$
+ */
+public interface TypeConverterRegistry {
+    /**
+     * Allows a new type converter to be bregistered
+     *
+     * @param fromType      the type to convert from
+     * @param toType        the type to convert to
+     * @param typeConverter the type converter to use
+     */
+    void addTypeConverter(Class fromType, Class toType, TypeConverter typeConverter);
+
+    Injector getInjector();
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/TypeConverterRegistry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java?view=diff&rev=523731&r1=523730&r2=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java Thu Mar 29 07:58:08 2007
@@ -21,9 +21,9 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Processor;
+import org.apache.camel.converter.ObjectConverter;
 import org.apache.camel.impl.ServiceSupport;
 import org.apache.camel.util.ExchangeHelper;
-import org.apache.camel.util.ObjectHelper;
 import static org.apache.camel.util.ObjectHelper.notNull;
 import org.apache.camel.util.ProducerCache;
 
@@ -51,7 +51,7 @@
 
     public void onExchange(E exchange) {
         Object receipientList = expression.evaluate(exchange);
-        Iterator iter = ObjectHelper.iterator(receipientList);
+        Iterator iter = ObjectConverter.iterator(receipientList);
         while (iter.hasNext()) {
             Object recipient = iter.next();
             Endpoint<E> endpoint = resolveEndpoint(exchange, recipient);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java?view=diff&rev=523731&r1=523730&r2=523731
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Splitter.java Thu Mar 29 07:58:08 2007
@@ -20,8 +20,8 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Processor;
+import org.apache.camel.converter.ObjectConverter;
 import org.apache.camel.impl.ServiceSupport;
-import static org.apache.camel.util.ObjectHelper.iterator;
 import static org.apache.camel.util.ObjectHelper.notNull;
 import org.apache.camel.util.ServiceHelper;
 
@@ -51,7 +51,7 @@
 
     public void onExchange(E exchange) {
         Object value = expression.evaluate(exchange);
-        Iterator iter = iterator(value);
+        Iterator iter = ObjectConverter.iterator(value);
         while (iter.hasNext()) {
             Object part = iter.next();
             E newExchange = (E) exchange.copy();



Mime
View raw message