You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/10/31 09:25:49 UTC

[camel] branch master updated (e9d46fe -> 9486680)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from e9d46fe  CAMEL-15778: camel-core - Optimize to allow to clear bootstrap configurer.
     new f9b80bd  CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order
     new 6495703  CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order
     new 92099d3  CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order
     new ade99f7  CAMEL-15778: camel-core - Optimize to allow to clear bootstrap configurer.
     new 9486680  CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/java/org/apache/camel/Converter.java  |   6 +
 .../camel/impl/engine/AbstractCamelContext.java    |   6 +-
 .../converter/CamelBaseBulkConverterLoader.java    | 120 ++++++------
 .../org/apache/camel/converter/CamelConverter.java |  16 +-
 .../camel/converter/CollectionConverter.java       |  27 +--
 .../apache/camel/converter/DateTimeConverter.java  |   6 +-
 .../apache/camel/converter/DurationConverter.java  |   8 +-
 .../org/apache/camel/converter/IOConverter.java    |  76 ++++----
 .../org/apache/camel/converter/NIOConverter.java   |  24 +--
 .../apache/camel/converter/ObjectConverter.java    |  58 +++---
 .../org/apache/camel/converter/SQLConverter.java   |   4 +-
 .../apache/camel/converter/UriTypeConverter.java   |   6 +-
 .../camel/impl/converter/UriTypeConverterTest.java |   2 +-
 .../converter/stream/StreamCacheConverter.java     |  12 +-
 .../jaxp/CamelXmlJaxpBulkConverterLoader.java      |  68 +++----
 .../apache/camel/converter/jaxp/DomConverter.java  |  14 +-
 .../apache/camel/converter/jaxp/StaxConverter.java |  36 ++--
 .../apache/camel/converter/jaxp/XmlConverter.java  | 216 ++++++++++-----------
 .../camel/util/xml/StreamSourceConverter.java      |   8 +-
 .../TypeConverterLoaderGeneratorMojo.java          |  21 +-
 20 files changed, 367 insertions(+), 367 deletions(-)


[camel] 01/05: CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f9b80bd56e5592a244ddd1481730bab3084203c0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Oct 31 09:47:17 2020 +0100

    CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order
---
 .../src/main/java/org/apache/camel/Converter.java  |   6 +
 .../converter/CamelBaseBulkConverterLoader.java    |   2 +-
 .../org/apache/camel/converter/CamelConverter.java |  16 +--
 .../camel/converter/CollectionConverter.java       |  27 ++--
 .../apache/camel/converter/DateTimeConverter.java  |   6 +-
 .../apache/camel/converter/DurationConverter.java  |   8 +-
 .../org/apache/camel/converter/IOConverter.java    |  72 +++++------
 .../org/apache/camel/converter/NIOConverter.java   |  24 ++--
 .../apache/camel/converter/ObjectConverter.java    |  58 ++++-----
 .../org/apache/camel/converter/SQLConverter.java   |   4 +-
 .../apache/camel/converter/UriTypeConverter.java   |   6 +-
 .../camel/impl/converter/UriTypeConverterTest.java |   2 +-
 .../converter/stream/StreamCacheConverter.java     |  12 +-
 .../apache/camel/converter/jaxp/DomConverter.java  |  14 +--
 .../apache/camel/converter/jaxp/StaxConverter.java |  36 +++---
 .../apache/camel/converter/jaxp/XmlConverter.java  | 136 ++++++++++-----------
 .../camel/util/xml/StreamSourceConverter.java      |   8 +-
 17 files changed, 222 insertions(+), 215 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/Converter.java b/core/camel-api/src/main/java/org/apache/camel/Converter.java
index 6a45624..fef34e4 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Converter.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Converter.java
@@ -80,4 +80,10 @@ public @interface Converter {
      */
     boolean generateBulkLoader() default false;
 
+    /**
+     * To be used for ordering converter methods when source code generating bulk loaders.
+     * The order is lowest to highest, eg 1, 2, 3.
+     */
+    int order() default 0;
+
 }
diff --git a/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java b/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java
index 15a7ce6..1758c61 100644
--- a/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java
+++ b/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java
@@ -179,7 +179,7 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             }
         } else if (to == java.lang.CharSequence.class) {
             if (value instanceof java.net.URI) {
-                return org.apache.camel.converter.UriTypeConverter.toCharSequence((java.net.URI) value);
+                return org.apache.camel.converter.UriTypeConverter.toString((java.net.URI) value);
             }
         } else if (to == java.lang.Character.class || to == char.class) {
             if (value instanceof java.lang.String) {
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/CamelConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/CamelConverter.java
index 80ffdcc..043aa83 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/CamelConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/CamelConverter.java
@@ -35,22 +35,22 @@ public final class CamelConverter {
     private CamelConverter() {
     }
 
-    @Converter
-    public static Processor toProcessor(final Predicate predicate) {
+    @Converter(order = 1)
+    public static Processor toProcessor(final Expression expression) {
         return exchange -> {
-            // the response from a predicate should be set on OUT
-            boolean answer = predicate.matches(exchange);
+            // the response from a expression should be set on OUT
+            Object answer = expression.evaluate(exchange, Object.class);
             Message out = exchange.getOut();
             out.copyFrom(exchange.getIn());
             out.setBody(answer);
         };
     }
 
-    @Converter
-    public static Processor toProcessor(final Expression expression) {
+    @Converter(order = 2)
+    public static Processor toProcessor(final Predicate predicate) {
         return exchange -> {
-            // the response from a expression should be set on OUT
-            Object answer = expression.evaluate(exchange, Object.class);
+            // the response from a predicate should be set on OUT
+            boolean answer = predicate.matches(exchange);
             Message out = exchange.getOut();
             out.copyFrom(exchange.getIn());
             out.setBody(answer);
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/CollectionConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/CollectionConverter.java
index fc3c331..d702bac 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/CollectionConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/CollectionConverter.java
@@ -46,7 +46,7 @@ public final class CollectionConverter {
     /**
      * Converts a collection to an array
      */
-    @Converter
+    @Converter(order = 1)
     public static Object[] toArray(Collection<?> value) {
         return value.toArray();
     }
@@ -54,7 +54,7 @@ public final class CollectionConverter {
     /**
      * Converts an array to a collection
      */
-    @Converter
+    @Converter(order = 2)
     public static List<Object> toList(Object[] array) {
         return Arrays.asList(array);
     }
@@ -62,7 +62,7 @@ public final class CollectionConverter {
     /**
      * Converts a collection to a List if it is not already
      */
-    @Converter
+    @Converter(order = 3)
     public static <T> List<T> toList(Collection<T> collection) {
         return new ArrayList<>(collection);
     }
@@ -70,7 +70,7 @@ public final class CollectionConverter {
     /**
      * Converts an {@link Iterator} to a {@link ArrayList}
      */
-    @Converter
+    @Converter(order = 4)
     public static <T> ArrayList<T> toArrayList(Iterator<T> it) {
         if (it instanceof ArrayList) {
             return (ArrayList<T>) it;
@@ -85,7 +85,7 @@ public final class CollectionConverter {
     /**
      * Converts an {@link Iterable} to a {@link ArrayList}
      */
-    @Converter
+    @Converter(order = 5)
     public static <T> ArrayList<T> toArrayList(Iterable<T> it) {
         if (it instanceof ArrayList) {
             return (ArrayList<T>) it;
@@ -97,36 +97,36 @@ public final class CollectionConverter {
         return list;
     }
 
-    @Converter
+    @Converter(order = 6)
     public static Set<Object> toSet(Object[] array) {
         Set<Object> answer = new HashSet<>();
         answer.addAll(Arrays.asList(array));
         return answer;
     }
 
-    @Converter
+    @Converter(order = 7)
     public static <T> Set<T> toSet(Collection<T> collection) {
         return new HashSet<>(collection);
     }
 
-    @Converter
+    @Converter(order = 8)
     public static <K, V> Set<Map.Entry<K, V>> toSet(Map<K, V> map) {
         return map.entrySet();
     }
 
-    @Converter
+    @Converter(order = 9)
     public static Properties toProperties(Map<Object, Object> map) {
         Properties answer = new Properties();
         answer.putAll(map);
         return answer;
     }
 
-    @Converter
+    @Converter(order = 10)
     public static <K, V> Hashtable<K, V> toHashtable(Map<? extends K, ? extends V> map) {
         return new Hashtable<>(map);
     }
 
-    @Converter
+    @Converter(order = 11)
     public static <K, V> HashMap<K, V> toHashMap(Map<? extends K, ? extends V> map) {
         return new HashMap<>(map);
     }
@@ -134,7 +134,7 @@ public final class CollectionConverter {
     /**
      * Converts an {@link Iterable} into a {@link List}
      */
-    @Converter
+    @Converter(order = 12)
     public static <T> List<T> toList(Iterable<T> iterable) {
         if (iterable instanceof List) {
             return (List<T>) iterable;
@@ -149,7 +149,7 @@ public final class CollectionConverter {
     /**
      * Converts an {@link Iterator} into a {@link List}
      */
-    @Converter
+    @Converter(order = 13)
     public static <T> List<T> toList(Iterator<T> it) {
         if (it instanceof List) {
             return (List<T>) it;
@@ -160,4 +160,5 @@ public final class CollectionConverter {
         }
         return result;
     }
+
 }
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/DateTimeConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/DateTimeConverter.java
index fa76e10..230a44e 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/DateTimeConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/DateTimeConverter.java
@@ -33,17 +33,17 @@ public final class DateTimeConverter {
     private DateTimeConverter() {
     }
 
-    @Converter
+    @Converter(order = 1)
     public static TimeZone toTimeZone(String s) {
         return TimeZone.getTimeZone(s);
     }
 
-    @Converter
+    @Converter(order = 2)
     public static Date toDate(Long l) {
         return new Date(l);
     }
 
-    @Converter
+    @Converter(order = 3)
     public static Long toLong(Date date) {
         return date.getTime();
     }
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/DurationConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/DurationConverter.java
index 0efeff3..68e3600 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/DurationConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/DurationConverter.java
@@ -33,17 +33,17 @@ public final class DurationConverter {
     private DurationConverter() {
     }
 
-    @Converter
+    @Converter(order = 1)
     public static Long toMilliSeconds(Duration source) {
         return source.toMillis();
     }
 
-    @Converter
+    @Converter(order = 2)
     public static Duration toDuration(Long source) {
         return Duration.ofMillis(source);
     }
 
-    @Converter
+    @Converter(order = 3)
     public static Duration toDuration(String source) {
         if (source.startsWith("P") || source.startsWith("-P") || source.startsWith("p") || source.startsWith("-p")) {
             return Duration.parse(source);
@@ -52,7 +52,7 @@ public final class DurationConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 4)
     public static String toString(Duration source) {
         return source.toString();
     }
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java
index 63f56cb..6833dc7 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java
@@ -65,96 +65,96 @@ public final class IOConverter {
     private IOConverter() {
     }
 
-    @Converter
+    @Converter(order = 1)
     public static InputStream toInputStream(Stream stream, Exchange exchange) {
         Iterator it = stream.iterator();
         return new InputStreamIterator(exchange.getContext().getTypeConverter(), it);
     }
 
-    @Converter
+    @Converter(order = 2)
     public static InputStream toInputStream(URL url) throws IOException {
         return IOHelper.buffered(url.openStream());
     }
 
-    @Converter
+    @Converter(order = 3)
     public static InputStream toInputStream(File file) throws IOException {
         return IOHelper.buffered(new FileInputStream(file));
     }
 
-    @Converter
+    @Converter(order = 4)
     public static BufferedReader toReader(File file, Exchange exchange) throws IOException {
         return IOHelper.toReader(file, ExchangeHelper.getCharsetName(exchange));
     }
 
-    @Converter
+    @Converter(order = 5)
     public static File toFile(String name) {
         return new File(name);
     }
 
-    @Converter
+    @Converter(order = 6)
     public static OutputStream toOutputStream(File file) throws FileNotFoundException {
         return IOHelper.buffered(new FileOutputStream(file));
     }
 
-    @Converter
+    @Converter(order = 7)
     public static BufferedWriter toWriter(File file, Exchange exchange) throws IOException {
         FileOutputStream os = new FileOutputStream(file, false);
         return IOHelper.toWriter(os, ExchangeHelper.getCharsetName(exchange));
     }
 
-    @Converter
+    @Converter(order = 8)
     public static Reader toReader(InputStream in, Exchange exchange) throws IOException {
         return IOHelper.buffered(new InputStreamReader(in, ExchangeHelper.getCharsetName(exchange)));
     }
 
-    @Converter
+    @Converter(order = 9)
     public static Reader toReader(byte[] data, Exchange exchange) throws IOException {
         return toReader(new ByteArrayInputStream(data), exchange);
     }
 
-    @Converter
+    @Converter(order = 10)
     public static Writer toWriter(OutputStream out, Exchange exchange) throws IOException {
         return IOHelper.buffered(new OutputStreamWriter(out, ExchangeHelper.getCharsetName(exchange)));
     }
 
-    @Converter
+    @Converter(order = 11)
     public static Reader toReader(String text) {
         // no buffering required as the complete string input is already passed
         // over as a whole
         return new StringReader(text);
     }
 
-    @Converter
+    @Converter(order = 12)
     public static InputStream toInputStream(String text, Exchange exchange) throws IOException {
         return toInputStream(text.getBytes(ExchangeHelper.getCharsetName(exchange)));
     }
 
-    @Converter
+    @Converter(order = 13)
     public static InputStream toInputStream(StringBuffer buffer, Exchange exchange) throws IOException {
         return toInputStream(buffer.toString(), exchange);
     }
 
-    @Converter
+    @Converter(order = 14)
     public static InputStream toInputStream(StringBuilder builder, Exchange exchange) throws IOException {
         return toInputStream(builder.toString(), exchange);
     }
 
-    @Converter
+    @Converter(order = 15)
     public static InputStream toInputStream(BufferedReader buffer, Exchange exchange) throws IOException {
         return toInputStream(toString(buffer), exchange);
     }
 
-    @Converter
+    @Converter(order = 16)
     public static String toString(byte[] data, Exchange exchange) throws IOException {
         return new String(data, ExchangeHelper.getCharsetName(exchange));
     }
 
-    @Converter
+    @Converter(order = 17)
     public static String toString(File file, Exchange exchange) throws IOException {
         return toString(toReader(file, exchange));
     }
 
-    @Converter
+    @Converter(order = 18)
     public static byte[] toByteArray(File file) throws IOException {
         InputStream is = toInputStream(file);
         try {
@@ -164,12 +164,12 @@ public final class IOConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 19)
     public static byte[] toByteArray(Reader reader, Exchange exchange) throws IOException {
         return toByteArray(IOHelper.buffered(reader), exchange);
     }
 
-    @Converter
+    @Converter(order = 20)
     public static String toString(URL url, Exchange exchange) throws IOException {
         InputStream is = toInputStream(url);
         try {
@@ -179,40 +179,40 @@ public final class IOConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 21)
     public static String toString(Reader reader) throws IOException {
         return IOHelper.toString(reader);
     }
 
-    @Converter
+    @Converter(order = 22)
     public static String toString(BufferedReader reader) throws IOException {
         return IOHelper.toString(reader);
     }
 
-    @Converter
+    @Converter(order = 23)
     public static byte[] toByteArray(BufferedReader reader, Exchange exchange) throws IOException {
         String s = toString(reader);
         return toByteArray(s, exchange);
     }
 
-    @Converter
+    @Converter(order = 24)
     public static byte[] toByteArray(String value, Exchange exchange) throws IOException {
         return value.getBytes(ExchangeHelper.getCharsetName(exchange));
     }
 
-    @Converter
+    @Converter(order = 25)
     public static String toString(InputStream in, Exchange exchange) throws IOException {
         return toString(toReader(in, exchange));
     }
 
-    @Converter
+    @Converter(order = 26)
     public static InputStream toInputStream(byte[] data) {
         // no buffering required as the complete byte input is already passed
         // over as a whole
         return new ByteArrayInputStream(data);
     }
 
-    @Converter
+    @Converter(order = 27)
     public static ObjectOutput toObjectOutput(OutputStream stream) throws IOException {
         if (stream instanceof ObjectOutput) {
             return (ObjectOutput) stream;
@@ -221,7 +221,7 @@ public final class IOConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 28)
     public static ObjectInput toObjectInput(final InputStream stream, final Exchange exchange) throws IOException {
         if (stream instanceof ObjectInput) {
             return (ObjectInput) stream;
@@ -248,7 +248,7 @@ public final class IOConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 29)
     public static byte[] toBytes(InputStream stream) throws IOException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         IOHelper.copy(IOHelper.buffered(stream), bos);
@@ -258,36 +258,36 @@ public final class IOConverter {
         return bos.toByteArray();
     }
 
-    @Converter
+    @Converter(order = 30)
     public static byte[] toByteArray(ByteArrayOutputStream os) {
         return os.toByteArray();
     }
 
-    @Converter
+    @Converter(order = 31)
     public static ByteBuffer covertToByteBuffer(InputStream is) throws IOException {
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         IOHelper.copyAndCloseInput(is, os);
         return ByteBuffer.wrap(os.toByteArray());
     }
 
-    @Converter
+    @Converter(order = 32)
     public static String toString(ByteArrayOutputStream os, Exchange exchange) throws IOException {
         return os.toString(ExchangeHelper.getCharsetName(exchange));
     }
 
-    @Converter
+    @Converter(order = 33)
     public static InputStream toInputStream(ByteArrayOutputStream os) {
         // no buffering required as the complete byte array input is already
         // passed over as a whole
         return new ByteArrayInputStream(os.toByteArray());
     }
 
-    @Converter
+    @Converter(order = 34)
     public static Properties toProperties(File file) throws IOException {
         return toProperties(new FileInputStream(file));
     }
 
-    @Converter
+    @Converter(order = 35)
     public static Properties toProperties(InputStream is) throws IOException {
         Properties prop = new Properties();
         try {
@@ -298,7 +298,7 @@ public final class IOConverter {
         return prop;
     }
 
-    @Converter
+    @Converter(order = 36)
     public static Properties toProperties(Reader reader) throws IOException {
         Properties prop = new Properties();
         try {
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/NIOConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/NIOConverter.java
index 9e72460..d961cd1 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/NIOConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/NIOConverter.java
@@ -46,29 +46,29 @@ public final class NIOConverter {
     private NIOConverter() {
     }
 
-    @Converter
+    @Converter(order = 1)
     public static byte[] toByteArray(ByteBuffer buffer) {
         byte[] bArray = new byte[buffer.limit()];
         buffer.get(bArray);
         return bArray;
     }
 
-    @Converter
+    @Converter(order = 2)
     public static String toString(ByteBuffer buffer, Exchange exchange) throws IOException {
         return IOConverter.toString(toByteArray(buffer), exchange);
     }
 
-    @Converter
+    @Converter(order = 3)
     public static ByteBuffer toByteBuffer(byte[] data) {
         return ByteBuffer.wrap(data);
     }
 
-    @Converter
+    @Converter(order = 4)
     public static ByteBuffer toByteBuffer(ByteArrayOutputStream baos) {
         return ByteBuffer.wrap(baos.toByteArray());
     }
 
-    @Converter
+    @Converter(order = 5)
     public static ByteBuffer toByteBuffer(File file) throws IOException {
         InputStream in = null;
         try {
@@ -87,7 +87,7 @@ public final class NIOConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 6)
     public static ByteBuffer toByteBuffer(String value, Exchange exchange) {
         byte[] bytes = null;
         if (exchange != null) {
@@ -106,7 +106,7 @@ public final class NIOConverter {
         return ByteBuffer.wrap(bytes);
     }
 
-    @Converter
+    @Converter(order = 7)
     public static ByteBuffer toByteBuffer(Short value) {
         ByteBuffer buf = ByteBuffer.allocate(2);
         buf.putShort(value);
@@ -114,7 +114,7 @@ public final class NIOConverter {
         return buf;
     }
 
-    @Converter
+    @Converter(order = 8)
     public static ByteBuffer toByteBuffer(Integer value) {
         ByteBuffer buf = ByteBuffer.allocate(4);
         buf.putInt(value);
@@ -122,7 +122,7 @@ public final class NIOConverter {
         return buf;
     }
 
-    @Converter
+    @Converter(order = 9)
     public static ByteBuffer toByteBuffer(Long value) {
         ByteBuffer buf = ByteBuffer.allocate(8);
         buf.putLong(value);
@@ -130,7 +130,7 @@ public final class NIOConverter {
         return buf;
     }
 
-    @Converter
+    @Converter(order = 10)
     public static ByteBuffer toByteBuffer(Float value) {
         ByteBuffer buf = ByteBuffer.allocate(4);
         buf.putFloat(value);
@@ -138,7 +138,7 @@ public final class NIOConverter {
         return buf;
     }
 
-    @Converter
+    @Converter(order = 11)
     public static ByteBuffer toByteBuffer(Double value) {
         ByteBuffer buf = ByteBuffer.allocate(8);
         buf.putDouble(value);
@@ -146,7 +146,7 @@ public final class NIOConverter {
         return buf;
     }
 
-    @Converter
+    @Converter(order = 12)
     public static InputStream toInputStream(ByteBuffer bufferbuffer) {
         return IOConverter.toInputStream(toByteArray(bufferbuffer));
     }
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/ObjectConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/ObjectConverter.java
index 557985a..5cbb113 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/ObjectConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/ObjectConverter.java
@@ -39,7 +39,7 @@ public final class ObjectConverter {
      * Converts the given value to a boolean, handling strings or Boolean objects; otherwise returning false if the
      * value could not be converted to a boolean
      */
-    @Converter
+    @Converter(order = 1)
     public static boolean toBool(Object value) {
         Boolean answer = toBoolean(value);
         if (answer == null) {
@@ -52,7 +52,7 @@ public final class ObjectConverter {
      * Converts the given value to a Boolean, handling strings or Boolean objects; otherwise returning null if the value
      * cannot be converted to a boolean
      */
-    @Converter
+    @Converter(order = 2)
     public static Boolean toBoolean(Object value) {
         return org.apache.camel.util.ObjectHelper.toBoolean(value);
     }
@@ -60,7 +60,7 @@ public final class ObjectConverter {
     /**
      * Creates an iterator over the value
      */
-    @Converter
+    @Converter(order = 3)
     public static Iterator<?> iterator(Object value) {
         return ObjectHelper.createIterator(value);
     }
@@ -68,7 +68,7 @@ public final class ObjectConverter {
     /**
      * Creates an iterable over the value
      */
-    @Converter
+    @Converter(order = 4)
     public static Iterable<?> iterable(Object value) {
         return ObjectHelper.createIterable(value);
     }
@@ -76,7 +76,7 @@ public final class ObjectConverter {
     /**
      * Returns the converted value, or null if the value is null
      */
-    @Converter(allowNull = true)
+    @Converter(order = 5, allowNull = true)
     public static Byte toByte(Number value) {
         if (org.apache.camel.util.ObjectHelper.isNaN(value)) {
             return null;
@@ -84,22 +84,22 @@ public final class ObjectConverter {
         return value.byteValue();
     }
 
-    @Converter
+    @Converter(order = 6)
     public static Byte toByte(String value) {
         return Byte.valueOf(value);
     }
 
-    @Converter
+    @Converter(order = 7)
     public static char[] toCharArray(String value) {
         return value.toCharArray();
     }
 
-    @Converter
+    @Converter(order = 8)
     public static Character toCharacter(String value) {
         return toChar(value);
     }
 
-    @Converter
+    @Converter(order = 9)
     public static char toChar(String value) {
         // must be string with the length of 1
         if (value.length() != 1) {
@@ -108,7 +108,7 @@ public final class ObjectConverter {
         return value.charAt(0);
     }
 
-    @Converter
+    @Converter(order = 10)
     public static String fromCharArray(char[] value) {
         return new String(value);
     }
@@ -116,7 +116,7 @@ public final class ObjectConverter {
     /**
      * Returns the converted value, or null if the value is null
      */
-    @Converter
+    @Converter(order = 11)
     public static Class<?> toClass(String value, Exchange exchange) {
         // prefer to use class resolver API
         if (exchange != null) {
@@ -129,7 +129,7 @@ public final class ObjectConverter {
     /**
      * Returns the converted value, or null if the value is null
      */
-    @Converter(allowNull = true)
+    @Converter(order = 12, allowNull = true)
     public static Short toShort(Number value) {
         if (org.apache.camel.util.ObjectHelper.isNaN(value)) {
             return null;
@@ -137,7 +137,7 @@ public final class ObjectConverter {
         return value.shortValue();
     }
 
-    @Converter
+    @Converter(order = 13)
     public static Short toShort(String value) {
         return Short.valueOf(value);
     }
@@ -145,7 +145,7 @@ public final class ObjectConverter {
     /**
      * Returns the converted value, or null if the value is null
      */
-    @Converter(allowNull = true)
+    @Converter(order = 14, allowNull = true)
     public static Integer toInteger(Number value) {
         if (org.apache.camel.util.ObjectHelper.isNaN(value)) {
             return null;
@@ -153,7 +153,7 @@ public final class ObjectConverter {
         return value.intValue();
     }
 
-    @Converter
+    @Converter(order = 15)
     public static Integer toInteger(String value) {
         return Integer.valueOf(value);
     }
@@ -161,7 +161,7 @@ public final class ObjectConverter {
     /**
      * Returns the converted value, or null if the value is null
      */
-    @Converter(allowNull = true)
+    @Converter(order = 16, allowNull = true)
     public static Long toLong(Number value) {
         if (org.apache.camel.util.ObjectHelper.isNaN(value)) {
             return null;
@@ -169,7 +169,7 @@ public final class ObjectConverter {
         return value.longValue();
     }
 
-    @Converter
+    @Converter(order = 17)
     public static Long toLong(String value) {
         return Long.valueOf(value);
     }
@@ -177,7 +177,7 @@ public final class ObjectConverter {
     /**
      * Returns the converted value, or null if the value is null
      */
-    @Converter(allowNull = true)
+    @Converter(order = 18, allowNull = true)
     public static BigInteger toBigInteger(Object value) {
         if (org.apache.camel.util.ObjectHelper.isNaN(value)) {
             return null;
@@ -201,7 +201,7 @@ public final class ObjectConverter {
     /**
      * Returns the converted value, or null if the value is null
      */
-    @Converter
+    @Converter(order = 19)
     public static Float toFloat(Number value) {
         if (org.apache.camel.util.ObjectHelper.isNaN(value)) {
             return Float.NaN;
@@ -209,7 +209,7 @@ public final class ObjectConverter {
         return value.floatValue();
     }
 
-    @Converter
+    @Converter(order = 20)
     public static Float toFloat(String value) {
         return Float.valueOf(value);
     }
@@ -217,7 +217,7 @@ public final class ObjectConverter {
     /**
      * Returns the converted value, or null if the value is null
      */
-    @Converter
+    @Converter(order = 21)
     public static Double toDouble(Number value) {
         if (org.apache.camel.util.ObjectHelper.isNaN(value)) {
             return Double.NaN;
@@ -225,44 +225,44 @@ public final class ObjectConverter {
         return value.doubleValue();
     }
 
-    @Converter
+    @Converter(order = 22)
     public static Double toDouble(String value) {
         return Double.valueOf(value);
     }
 
     // add fast type converters from most common used
 
-    @Converter
+    @Converter(order = 23)
     public static String toString(Integer value) {
         return value.toString();
     }
 
-    @Converter
+    @Converter(order = 24)
     public static String toString(Long value) {
         return value.toString();
     }
 
-    @Converter
+    @Converter(order = 25)
     public static String toString(Boolean value) {
         return value.toString();
     }
 
-    @Converter
+    @Converter(order = 26)
     public static String toString(StringBuffer value) {
         return value.toString();
     }
 
-    @Converter
+    @Converter(order = 27)
     public static String toString(StringBuilder value) {
         return value.toString();
     }
 
-    @Converter
+    @Converter(order = 28)
     public static Boolean toBoolean(String value) {
         return org.apache.camel.util.ObjectHelper.toBoolean(value);
     }
 
-    @Converter
+    @Converter(order = 29)
     public static Number toNumber(String text) {
         // what kind of numeric is it
         boolean dot = text.indexOf('.') != -1;
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/SQLConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/SQLConverter.java
index 60b671c..c47bee8 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/SQLConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/SQLConverter.java
@@ -32,12 +32,12 @@ public final class SQLConverter {
     private SQLConverter() {
     }
 
-    @Converter
+    @Converter(order = 1)
     public static Timestamp toTimestamp(Long l) {
         return new Timestamp(l);
     }
 
-    @Converter
+    @Converter(order = 2)
     public static Long toLong(Timestamp ts) {
         return ts.getTime();
     }
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/UriTypeConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/UriTypeConverter.java
index 8b7b3ac..47f2878 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/UriTypeConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/UriTypeConverter.java
@@ -33,12 +33,12 @@ public final class UriTypeConverter {
         // utility class
     }
 
-    @Converter
-    public static CharSequence toCharSequence(final URI value) {
+    @Converter(order = 1)
+    public static String toString(final URI value) {
         return value.toString();
     }
 
-    @Converter
+    @Converter(order = 2)
     public static URI toUri(final CharSequence value) {
         final String stringValue = String.valueOf(value);
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
index c0715d1..8dd45ccf 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/converter/UriTypeConverterTest.java
@@ -45,7 +45,7 @@ public class UriTypeConverterTest {
 
     @Test
     public void shouldConvertFromUrisToStrings() {
-        assertEquals(EXAMPLE, UriTypeConverter.toCharSequence(EXAMPLE_URI));
+        assertEquals(EXAMPLE, UriTypeConverter.toString(EXAMPLE_URI));
     }
 
 }
diff --git a/core/camel-support/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java b/core/camel-support/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
index d8e1290..b919a95 100644
--- a/core/camel-support/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
+++ b/core/camel-support/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
@@ -41,12 +41,12 @@ public final class StreamCacheConverter {
     private StreamCacheConverter() {
     }
 
-    @Converter
+    @Converter(order = 1)
     public static StreamCache convertToStreamCache(ByteArrayInputStream stream, Exchange exchange) throws IOException {
         return new ByteArrayInputStreamCache(stream);
     }
 
-    @Converter
+    @Converter(order = 2)
     public static StreamCache convertToStreamCache(InputStream stream, Exchange exchange) throws IOException {
         // transfer the input stream to a cached output stream, and then creates a new stream cache view
         // of the data, which ensures the input stream is cached and re-readable.
@@ -55,18 +55,18 @@ public final class StreamCacheConverter {
         return cos.newStreamCache();
     }
 
-    @Converter
+    @Converter(order = 3)
     public static StreamCache convertToStreamCache(CachedOutputStream cos, Exchange exchange) throws IOException {
         return cos.newStreamCache();
     }
 
-    @Converter
+    @Converter(order = 4)
     public static StreamCache convertToStreamCache(Reader reader, Exchange exchange) throws IOException {
         String data = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, reader);
         return new ReaderCache(data);
     }
 
-    @Converter
+    @Converter(order = 5)
     public static byte[] convertToByteArray(StreamCache cache, Exchange exchange) throws IOException {
         // lets serialize it as a byte array
         ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -74,7 +74,7 @@ public final class StreamCacheConverter {
         return os.toByteArray();
     }
 
-    @Converter
+    @Converter(order = 6)
     public static ByteBuffer convertToByteBuffer(StreamCache cache, Exchange exchange) throws IOException {
         byte[] array = convertToByteArray(cache, exchange);
         return ByteBuffer.wrap(array);
diff --git a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java
index a9a5cde..dc9af03 100644
--- a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java
+++ b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java
@@ -48,7 +48,7 @@ public final class DomConverter {
         xml = new XmlConverter();
     }
 
-    @Converter
+    @Converter(order = 1)
     public String toString(NodeList nodeList, Exchange exchange) throws TransformerException {
         // converting NodeList to String is more tricky
         // sometimes the NodeList is a Node which we can then leverage
@@ -87,7 +87,7 @@ public final class DomConverter {
         return buffer.toString();
     }
 
-    @Converter
+    @Converter(order = 2)
     public String toString(Node node, Exchange exchange) throws TransformerException {
         String s;
         if (node instanceof Text) {
@@ -107,7 +107,7 @@ public final class DomConverter {
         return s;
     }
 
-    @Converter
+    @Converter(order = 3)
     public static Integer toInteger(NodeList nodeList) {
         StringBuilder buffer = new StringBuilder();
         append(buffer, nodeList);
@@ -115,7 +115,7 @@ public final class DomConverter {
         return Integer.valueOf(s);
     }
 
-    @Converter
+    @Converter(order = 4)
     public static Long toLong(NodeList nodeList) {
         StringBuilder buffer = new StringBuilder();
         append(buffer, nodeList);
@@ -123,7 +123,7 @@ public final class DomConverter {
         return Long.valueOf(s);
     }
 
-    @Converter
+    @Converter(order = 5)
     public static List<?> toList(NodeList nodeList) {
         List<Object> answer = new ArrayList<>();
         Iterator<?> it = ObjectHelper.createIterator(nodeList);
@@ -133,13 +133,13 @@ public final class DomConverter {
         return answer;
     }
 
-    @Converter
+    @Converter(order = 6)
     public InputStream toInputStream(NodeList nodeList, Exchange exchange)
             throws TransformerException, UnsupportedEncodingException {
         return new ByteArrayInputStream(toByteArray(nodeList, exchange));
     }
 
-    @Converter
+    @Converter(order = 7)
     public byte[] toByteArray(NodeList nodeList, Exchange exchange) throws TransformerException, UnsupportedEncodingException {
         String data = toString(nodeList, exchange);
         return data.getBytes(ExchangeHelper.getCharsetName(exchange));
diff --git a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
index c2da4e6..0d9a1f4 100644
--- a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
+++ b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
@@ -94,7 +94,7 @@ public class StaxConverter {
     private XMLInputFactory inputFactory;
     private XMLOutputFactory outputFactory;
 
-    @Converter
+    @Converter(order = 1)
     public XMLEventWriter createXMLEventWriter(OutputStream out, Exchange exchange) throws XMLStreamException {
         XMLOutputFactory factory = getOutputFactory();
         try {
@@ -104,7 +104,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 2)
     public XMLEventWriter createXMLEventWriter(Writer writer) throws XMLStreamException {
         XMLOutputFactory factory = getOutputFactory();
         try {
@@ -114,7 +114,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 3)
     public XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException {
         XMLOutputFactory factory = getOutputFactory();
         try {
@@ -124,7 +124,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 4)
     public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream, Exchange exchange) throws XMLStreamException {
         XMLOutputFactory factory = getOutputFactory();
         try {
@@ -134,7 +134,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 5)
     public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException {
         XMLOutputFactory factory = getOutputFactory();
         try {
@@ -144,7 +144,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 6)
     public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException {
         XMLOutputFactory factory = getOutputFactory();
         try {
@@ -154,7 +154,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 7)
     public XMLStreamReader createXMLStreamReader(InputStream in, Exchange exchange) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
@@ -169,7 +169,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 8)
     public XMLStreamReader createXMLStreamReader(File file, Exchange exchange)
             throws XMLStreamException, FileNotFoundException {
         XMLInputFactory factory = getInputFactory();
@@ -181,7 +181,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 9)
     public XMLStreamReader createXMLStreamReader(Reader reader) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
@@ -191,7 +191,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 10)
     public XMLStreamReader createXMLStreamReader(Source in) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
@@ -201,7 +201,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 11)
     public XMLStreamReader createXMLStreamReader(String string) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
@@ -211,7 +211,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 12)
     public XMLEventReader createXMLEventReader(InputStream in, Exchange exchange) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
@@ -226,7 +226,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 13)
     public XMLEventReader createXMLEventReader(File file, Exchange exchange) throws XMLStreamException, FileNotFoundException {
         XMLInputFactory factory = getInputFactory();
         try {
@@ -237,7 +237,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 14)
     public XMLEventReader createXMLEventReader(Reader reader) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
@@ -247,7 +247,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 15)
     public XMLEventReader createXMLEventReader(XMLStreamReader reader) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
@@ -257,7 +257,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 16)
     public XMLEventReader createXMLEventReader(Source in) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
@@ -267,7 +267,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 17)
     public InputStream createInputStream(XMLStreamReader reader, Exchange exchange) {
         XMLOutputFactory factory = getOutputFactory();
         try {
@@ -278,7 +278,7 @@ public class StaxConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 18)
     public Reader createReader(XMLStreamReader reader, Exchange exchange) {
         XMLOutputFactory factory = getOutputFactory();
         try {
diff --git a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
index cf7ab88..6b9e7c7 100644
--- a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
+++ b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
@@ -108,14 +108,6 @@ public class XmlConverter {
     }
 
     /**
-     * Converts the given string to a QName.
-     */
-    @Converter
-    public QName toQName(String str) {
-        return QName.valueOf(str);
-    }
-
-    /**
      * Returns the default set of output properties for conversions.
      */
     public Properties defaultOutputProperties() {
@@ -154,9 +146,17 @@ public class XmlConverter {
     }
 
     /**
+     * Converts the given string to a QName.
+     */
+    @Converter(order = 1)
+    public QName toQName(String str) {
+        return QName.valueOf(str);
+    }
+
+    /**
      * Converts the given NodeList to a boolean
      */
-    @Converter
+    @Converter(order = 2)
     public Boolean toBoolean(NodeList list) {
         return list.getLength() > 0;
     }
@@ -164,7 +164,7 @@ public class XmlConverter {
     /**
      * Converts the given byte[] to a Source
      */
-    @Converter
+    @Converter(order = 3)
     public BytesSource toBytesSource(byte[] data) {
         return new BytesSource(data);
     }
@@ -172,7 +172,7 @@ public class XmlConverter {
     /**
      * Converts the given String to a Source
      */
-    @Converter
+    @Converter(order = 4)
     public StringSource toStringSource(String data) {
         return new StringSource(data);
     }
@@ -180,7 +180,7 @@ public class XmlConverter {
     /**
      * Converts the given Document to a DOMSource
      */
-    @Converter
+    @Converter(order = 5)
     public DOMSource toDOMSource(Document document) {
         return new DOMSource(document);
     }
@@ -188,7 +188,7 @@ public class XmlConverter {
     /**
      * Converts the given Node to a Source
      */
-    @Converter
+    @Converter(order = 6)
     public DOMSource toDOMSource(Node node) throws ParserConfigurationException, TransformerException {
         Document document = toDOMDocument(node);
         return new DOMSource(document);
@@ -197,7 +197,7 @@ public class XmlConverter {
     /**
      * Converts the given String to a Source
      */
-    @Converter
+    @Converter(order = 7)
     public Source toSource(String data) {
         return new StringSource(data);
     }
@@ -205,7 +205,7 @@ public class XmlConverter {
     /**
      * Converts the given input Source into text
      */
-    @Converter
+    @Converter(order = 8)
     public String toString(Source source, Exchange exchange) throws TransformerException {
         if (source == null) {
             return null;
@@ -233,7 +233,7 @@ public class XmlConverter {
     /**
      * Converts the given input Source into bytes
      */
-    @Converter
+    @Converter(order = 9)
     public byte[] toByteArray(Source source, Exchange exchange) throws TransformerException {
         if (source instanceof BytesSource) {
             return ((BytesSource) source).getData();
@@ -276,7 +276,7 @@ public class XmlConverter {
      * 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
+    @Converter(order = 10)
     public DOMSource toDOMSource(String text)
             throws ParserConfigurationException, IOException, SAXException, TransformerException {
         Source source = toSource(text);
@@ -287,7 +287,7 @@ public class XmlConverter {
      * 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
+    @Converter(order = 11)
     public DOMSource toDOMSource(byte[] bytes) throws IOException, SAXException, ParserConfigurationException {
         InputStream is = new ByteArrayInputStream(bytes);
         try {
@@ -301,7 +301,7 @@ public class XmlConverter {
      * 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
+    @Converter(order = 12)
     public SAXSource toSAXSource(String source, Exchange exchange) throws IOException, SAXException, TransformerException {
         return toSAXSource(toSource(source), exchange);
     }
@@ -310,7 +310,7 @@ public class XmlConverter {
      * Converts the source instance to a {@link StAXSource} or returns null if the conversion is not supported (making
      * it easy to derive from this class to add new kinds of conversion).
      */
-    @Converter
+    @Converter(order = 13)
     public StAXSource toStAXSource(String source, Exchange exchange) throws XMLStreamException {
         XMLStreamReader r = new StaxConverter().createXMLStreamReader(new StringReader(source));
         return new StAXSource(r);
@@ -320,7 +320,7 @@ public class XmlConverter {
      * Converts the source instance to a {@link StAXSource} or returns null if the conversion is not supported (making
      * it easy to derive from this class to add new kinds of conversion).
      */
-    @Converter
+    @Converter(order = 14)
     public StAXSource toStAXSource(byte[] in, Exchange exchange) throws XMLStreamException {
         XMLStreamReader r = new StaxConverter().createXMLStreamReader(new ByteArrayInputStream(in), exchange);
         return new StAXSource(r);
@@ -330,7 +330,7 @@ public class XmlConverter {
      * 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
+    @Converter(order = 15)
     public SAXSource toSAXSource(InputStream source, Exchange exchange) throws IOException, SAXException, TransformerException {
         return toSAXSource(toStreamSource(source), exchange);
     }
@@ -339,7 +339,7 @@ public class XmlConverter {
      * 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
+    @Converter(order = 16)
     public SAXSource toSAXSource(byte[] in, Exchange exchange) throws IOException, SAXException, TransformerException {
         return toSAXSource(toStreamSource(in, exchange), exchange);
     }
@@ -348,7 +348,7 @@ public class XmlConverter {
      * Converts the source instance to a {@link StAXSource} or returns null if the conversion is not supported (making
      * it easy to derive from this class to add new kinds of conversion).
      */
-    @Converter
+    @Converter(order = 17)
     public StAXSource toStAXSource(InputStream source, Exchange exchange) throws XMLStreamException {
         XMLStreamReader r = new StaxConverter().createXMLStreamReader(source, exchange);
         return new StAXSource(r);
@@ -358,7 +358,7 @@ public class XmlConverter {
      * 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
+    @Converter(order = 18)
     public SAXSource toSAXSource(File file, Exchange exchange) throws IOException, SAXException, TransformerException {
         InputStream is = IOHelper.buffered(new FileInputStream(file));
         return toSAXSource(is, exchange);
@@ -368,46 +368,46 @@ public class XmlConverter {
      * Converts the source instance to a {@link StAXSource} or returns null if the conversion is not supported (making
      * it easy to derive from this class to add new kinds of conversion).
      */
-    @Converter
+    @Converter(order = 19)
     public StAXSource toStAXSource(File file, Exchange exchange) throws FileNotFoundException, XMLStreamException {
         InputStream is = IOHelper.buffered(new FileInputStream(file));
         XMLStreamReader r = new StaxConverter().createXMLStreamReader(is, exchange);
         return new StAXSource(r);
     }
 
-    @Converter
+    @Converter(order = 20)
     public StreamSource toStreamSource(String in) {
         return new StreamSource(new ByteArrayInputStream(in.getBytes()));
     }
 
-    @Converter
+    @Converter(order = 21)
     public StreamSource toStreamSource(InputStream in) {
         return new StreamSource(in);
     }
 
-    @Converter
+    @Converter(order = 22)
     public StreamSource toStreamSource(Reader in) {
         return new StreamSource(in);
     }
 
-    @Converter
+    @Converter(order = 23)
     public StreamSource toStreamSource(File in) {
         return new StreamSource(in);
     }
 
-    @Converter
+    @Converter(order = 24)
     public StreamSource toStreamSource(byte[] in, Exchange exchange) throws TransformerException {
         InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange, in);
         return new StreamSource(is);
     }
 
-    @Converter
+    @Converter(order = 25)
     public StreamSource toStreamSource(ByteBuffer in, Exchange exchange) throws TransformerException {
         InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange, in);
         return new StreamSource(is);
     }
 
-    @Converter
+    @Converter(order = 26)
     public StreamSource toStreamSourceFromSAX(SAXSource source, Exchange exchange) throws TransformerException {
         InputSource inputSource = source.getInputSource();
         if (inputSource != null) {
@@ -422,19 +422,19 @@ public class XmlConverter {
         return new StringSource(result);
     }
 
-    @Converter
+    @Converter(order = 27)
     public StreamSource toStreamSourceFromDOM(DOMSource source, Exchange exchange) throws TransformerException {
         String result = toString(source, exchange);
         return new StringSource(result);
     }
 
-    @Converter
+    @Converter(order = 28)
     public StreamSource toStreamSourceFromStAX(StAXSource source, Exchange exchange) throws TransformerException {
         String result = toString(source, exchange);
         return new StringSource(result);
     }
 
-    @Converter
+    @Converter(order = 29)
     public SAXSource toSAXSourceFromStream(StreamSource source, Exchange exchange) throws SAXException {
         InputSource inputSource;
         if (source.getReader() != null) {
@@ -469,7 +469,7 @@ public class XmlConverter {
         return new SAXSource(xmlReader, inputSource);
     }
 
-    @Converter
+    @Converter(order = 30)
     public Reader toReader(StreamSource source) {
         Reader r = source.getReader();
         if (r == null) {
@@ -478,7 +478,7 @@ public class XmlConverter {
         return r;
     }
 
-    @Converter
+    @Converter(order = 31)
     public Reader toReaderFromSource(Source src, Exchange exchange) throws TransformerException {
         StreamSource stSrc = toStreamSource(src, exchange);
         Reader r = stSrc.getReader();
@@ -488,7 +488,7 @@ public class XmlConverter {
         return r;
     }
 
-    @Converter
+    @Converter(order = 32)
     public DOMSource toDOMSource(InputStream is, Exchange exchange)
             throws ParserConfigurationException, IOException, SAXException {
         InputSource source = new InputSource(is);
@@ -498,13 +498,13 @@ public class XmlConverter {
         return new DOMSource(document, systemId);
     }
 
-    @Converter
+    @Converter(order = 33)
     public DOMSource toDOMSource(File file, Exchange exchange) throws ParserConfigurationException, IOException, SAXException {
         InputStream is = IOHelper.buffered(new FileInputStream(file));
         return toDOMSource(is, exchange);
     }
 
-    @Converter
+    @Converter(order = 34)
     public DOMSource toDOMSourceFromStream(StreamSource source, Exchange exchange)
             throws ParserConfigurationException, IOException, SAXException {
         Document document;
@@ -527,33 +527,33 @@ public class XmlConverter {
         return new DOMSource(document, systemId);
     }
 
-    @Converter
+    @Converter(order = 35)
     public SAXSource toSAXSourceFromDOM(DOMSource source, Exchange exchange) throws TransformerException {
         String str = toString(source, exchange);
         StringReader reader = new StringReader(str);
         return new SAXSource(new InputSource(reader));
     }
 
-    @Converter
+    @Converter(order = 36)
     public SAXSource toSAXSourceFromStAX(StAXSource source, Exchange exchange) throws TransformerException {
         String str = toString(source, exchange);
         StringReader reader = new StringReader(str);
         return new SAXSource(new InputSource(reader));
     }
 
-    @Converter
+    @Converter(order = 37)
     public DOMSource toDOMSourceFromSAX(SAXSource source)
             throws IOException, SAXException, ParserConfigurationException, TransformerException {
         return new DOMSource(toDOMNodeFromSAX(source));
     }
 
-    @Converter
+    @Converter(order = 38)
     public DOMSource toDOMSourceFromStAX(StAXSource source)
             throws IOException, SAXException, ParserConfigurationException, TransformerException {
         return new DOMSource(toDOMNodeFromStAX(source));
     }
 
-    @Converter
+    @Converter(order = 39)
     public Node toDOMNodeFromSAX(SAXSource source)
             throws TransformerException {
         DOMResult result = new DOMResult();
@@ -561,7 +561,7 @@ public class XmlConverter {
         return result.getNode();
     }
 
-    @Converter
+    @Converter(order = 40)
     public Node toDOMNodeFromStAX(StAXSource source)
             throws TransformerException {
         DOMResult result = new DOMResult();
@@ -575,7 +575,7 @@ public class XmlConverter {
      * @param  nl the NodeList
      * @return    the DOM Node
      */
-    @Converter(allowNull = true)
+    @Converter(order = 41, allowNull = true)
     public Node toDOMNodeFromSingleNodeList(NodeList nl) {
         return nl.getLength() == 1 ? nl.item(0) : null;
     }
@@ -587,7 +587,7 @@ public class XmlConverter {
      * @param  nl the NodeList
      * @return    the DOM Document
      */
-    @Converter(allowNull = true)
+    @Converter(order = 42, allowNull = true)
     public Document toDOMDocumentFromSingleNodeList(NodeList nl) throws ParserConfigurationException, TransformerException {
         if (nl.getLength() == 1) {
             return toDOMDocument(nl.item(0));
@@ -603,7 +603,7 @@ public class XmlConverter {
     /**
      * Converts the given TRaX Source into a W3C DOM node
      */
-    @Converter(allowNull = true)
+    @Converter(order = 43, allowNull = true)
     public Node toDOMNode(Source source) throws TransformerException, ParserConfigurationException, IOException, SAXException {
         DOMSource domSrc = toDOMSource(source, null);
         return domSrc != null ? domSrc.getNode() : null;
@@ -612,7 +612,7 @@ public class XmlConverter {
     /**
      * Create a DOM element from the given source.
      */
-    @Converter
+    @Converter(order = 44)
     public Element toDOMElement(Source source)
             throws TransformerException, ParserConfigurationException, IOException, SAXException {
         Node node = toDOMNode(source);
@@ -623,7 +623,7 @@ public class XmlConverter {
      * 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.
      */
-    @Converter
+    @Converter(order = 45)
     public Element toDOMElement(Node node) throws TransformerException {
         // If the node is an document, return the root element
         if (node instanceof Document) {
@@ -644,7 +644,7 @@ public class XmlConverter {
      * @param  exchange is the exchange to be used when calling the converter
      * @return          the parsed document
      */
-    @Converter
+    @Converter(order = 46)
     public Document toDOMDocument(byte[] data, Exchange exchange)
             throws IOException, SAXException, ParserConfigurationException {
         DocumentBuilder documentBuilder = createDocumentBuilder(getDocumentBuilderFactory(exchange));
@@ -658,7 +658,7 @@ public class XmlConverter {
      * @param  exchange is the exchange to be used when calling the converter
      * @return          the parsed document
      */
-    @Converter
+    @Converter(order = 47)
     public Document toDOMDocument(InputStream in, Exchange exchange)
             throws IOException, SAXException, ParserConfigurationException {
         DocumentBuilder documentBuilder = createDocumentBuilder(getDocumentBuilderFactory(exchange));
@@ -679,7 +679,7 @@ public class XmlConverter {
      * @param  exchange is the exchange to be used when calling the converter
      * @return          the parsed document
      */
-    @Converter
+    @Converter(order = 48)
     public Document toDOMDocument(Reader in, Exchange exchange) throws IOException, SAXException, ParserConfigurationException {
         return toDOMDocument(new InputSource(in), exchange);
     }
@@ -691,7 +691,7 @@ public class XmlConverter {
      * @param  exchange is the exchange to be used when calling the converter
      * @return          the parsed document
      */
-    @Converter
+    @Converter(order = 49)
     public Document toDOMDocument(InputSource in, Exchange exchange)
             throws IOException, SAXException, ParserConfigurationException {
         DocumentBuilder documentBuilder = createDocumentBuilder(getDocumentBuilderFactory(exchange));
@@ -705,7 +705,7 @@ public class XmlConverter {
      * @param  exchange is the exchange to be used when calling the converter
      * @return          the parsed document
      */
-    @Converter
+    @Converter(order = 50)
     public Document toDOMDocument(String text, Exchange exchange)
             throws IOException, SAXException, ParserConfigurationException {
         return toDOMDocument(new StringReader(text), exchange);
@@ -718,7 +718,7 @@ public class XmlConverter {
      * @param  exchange is the exchange to be used when calling the converter
      * @return          the parsed document
      */
-    @Converter
+    @Converter(order = 51)
     public Document toDOMDocument(File file, Exchange exchange) throws IOException, SAXException, ParserConfigurationException {
         DocumentBuilder documentBuilder = createDocumentBuilder(getDocumentBuilderFactory(exchange));
         return documentBuilder.parse(file);
@@ -727,7 +727,7 @@ public class XmlConverter {
     /**
      * Create a DOM document from the given source.
      */
-    @Converter
+    @Converter(order = 52)
     public Document toDOMDocument(Source source)
             throws TransformerException, ParserConfigurationException, IOException, SAXException {
         Node node = toDOMNode(source);
@@ -740,7 +740,7 @@ public class XmlConverter {
      * 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.
      */
-    @Converter
+    @Converter(order = 53)
     public Document toDOMDocument(final Node node) throws ParserConfigurationException, TransformerException {
         ObjectHelper.notNull(node, "node");
 
@@ -769,22 +769,22 @@ public class XmlConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 54)
     public InputStream toInputStream(DOMSource source, Exchange exchange) throws TransformerException {
         return new ByteArrayInputStream(toByteArray(source, exchange));
     }
 
-    @Converter
+    @Converter(order = 55)
     public InputStream toInputStream(Document dom, Exchange exchange) throws TransformerException {
         return toInputStream(new DOMSource(dom), exchange);
     }
 
-    @Converter
+    @Converter(order = 56)
     public InputSource toInputSource(InputStream is, Exchange exchange) {
         return new InputSource(is);
     }
 
-    @Converter
+    @Converter(order = 57)
     public InputSource toInputSource(File file, Exchange exchange) throws FileNotFoundException {
         InputStream is = IOHelper.buffered(new FileInputStream(file));
         return new InputSource(is);
@@ -794,7 +794,7 @@ public class XmlConverter {
      * 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
+    @Converter(order = 58)
     public DOMSource toDOMSource(Source source, Exchange exchange)
             throws ParserConfigurationException, IOException, SAXException, TransformerException {
         if (source instanceof DOMSource) {
@@ -814,7 +814,7 @@ public class XmlConverter {
      * 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
+    @Converter(order = 59)
     public SAXSource toSAXSource(Source source, Exchange exchange) throws IOException, SAXException, TransformerException {
         if (source instanceof SAXSource) {
             return (SAXSource) source;
@@ -829,7 +829,7 @@ public class XmlConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 60)
     public StreamSource toStreamSource(Source source, Exchange exchange) throws TransformerException {
         if (source instanceof StreamSource) {
             return (StreamSource) source;
@@ -844,7 +844,7 @@ public class XmlConverter {
         }
     }
 
-    @Converter
+    @Converter(order = 61)
     public InputStream toInputStream(StreamSource source) throws IOException {
         InputStream is = source.getInputStream();
         if (is == null) {
diff --git a/core/camel-xml-jaxp/src/main/java/org/apache/camel/util/xml/StreamSourceConverter.java b/core/camel-xml-jaxp/src/main/java/org/apache/camel/util/xml/StreamSourceConverter.java
index 994e1db..2b3fb90 100644
--- a/core/camel-xml-jaxp/src/main/java/org/apache/camel/util/xml/StreamSourceConverter.java
+++ b/core/camel-xml-jaxp/src/main/java/org/apache/camel/util/xml/StreamSourceConverter.java
@@ -42,24 +42,24 @@ public final class StreamSourceConverter {
     private StreamSourceConverter() {
     }
 
-    @Converter
+    @Converter(order = 1)
     public static StreamCache convertToStreamCache(BytesSource source) {
         //no need to do stream caching for a BytesSource
         return null;
     }
 
-    @Converter
+    @Converter(order = 2)
     public static StreamCache convertToStreamCache(StreamSource source, Exchange exchange) throws IOException {
         return new StreamSourceCache(source, exchange);
     }
 
-    @Converter
+    @Converter(order = 3)
     public static StreamCache convertToStreamCache(SAXSource source, Exchange exchange) throws TransformerException {
         String data = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, source);
         return new SourceCache(data);
     }
 
-    @Converter
+    @Converter(order = 4)
     public static Serializable convertToSerializable(StreamCache cache, Exchange exchange) throws IOException {
         byte[] data = convertToByteArray(cache, exchange);
         return new BytesSource(data);


[camel] 03/05: CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 92099d3d8e21ec7519e28109514cfd6109130584
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Oct 31 09:56:21 2020 +0100

    CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order
---
 .../packaging/TypeConverterLoaderGeneratorMojo.java | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/TypeConverterLoaderGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/TypeConverterLoaderGeneratorMojo.java
index 857b121..6e93fef 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/TypeConverterLoaderGeneratorMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/TypeConverterLoaderGeneratorMojo.java
@@ -166,18 +166,10 @@ public class TypeConverterLoaderGeneratorMojo extends AbstractGeneratorMojo {
         converters.sort((o1, o2) -> {
             int sort = o1.returnType().name().compareTo(o2.returnType().name());
             if (sort == 0) {
-                // special sort when converting from predicate, which we want to be last
-                if ("Predicate".equals(o1.parameters().get(0).name().local())) {
-                    return 1;
-                } else if ("Predicate".equals(o2.parameters().get(0).name().local())) {
-                    return -1;
-                }
-                // special sort when converting xml Node vs NodeList, where we want NodeList last
-                if ("NodeList".equals(o1.parameters().get(0).name().local())) {
-                    return 1;
-                } else if ("NodeList".equals(o2.parameters().get(0).name().local())) {
-                    return -1;
-                }
+                // same group then sort by order
+                Integer order1 = asInteger(o1.annotation(CONVERTER_ANNOTATION), "order");
+                Integer order2 = asInteger(o2.annotation(CONVERTER_ANNOTATION), "order");
+                return order1.compareTo(order2);
             }
             return sort;
         });
@@ -520,6 +512,11 @@ public class TypeConverterLoaderGeneratorMojo extends AbstractGeneratorMojo {
         return av != null && av.asBoolean();
     }
 
+    private static int asInteger(AnnotationInstance ai, String name) {
+        AnnotationValue av = ai.value(name);
+        return av != null ? av.asInt() : 0;
+    }
+
     public static final class ClassConverters {
 
         private final Comparator<Type> comparator;


[camel] 05/05: CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 94866806284b4e0f3af251f15733299c6d685f81
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Oct 31 10:25:20 2020 +0100

    CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order
---
 .../jaxp/CamelXmlJaxpBulkConverterLoader.java      | 22 +++---
 .../apache/camel/converter/jaxp/XmlConverter.java  | 84 +++++++++++-----------
 2 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/core/camel-xml-jaxp/src/generated/java/org/apache/camel/converter/jaxp/CamelXmlJaxpBulkConverterLoader.java b/core/camel-xml-jaxp/src/generated/java/org/apache/camel/converter/jaxp/CamelXmlJaxpBulkConverterLoader.java
index def85f1..6020b67 100644
--- a/core/camel-xml-jaxp/src/generated/java/org/apache/camel/converter/jaxp/CamelXmlJaxpBulkConverterLoader.java
+++ b/core/camel-xml-jaxp/src/generated/java/org/apache/camel/converter/jaxp/CamelXmlJaxpBulkConverterLoader.java
@@ -288,13 +288,8 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
                 return getXmlConverter().toStringSource((java.lang.String) value);
             }
         } else if (to == org.w3c.dom.Document.class) {
-            if (value instanceof org.w3c.dom.NodeList) {
-                Object obj = getXmlConverter().toDOMDocumentFromSingleNodeList((org.w3c.dom.NodeList) value);
-                if (obj == null) {
-                    return Void.class;
-                } else {
-                    return obj;
-                }
+            if (value instanceof org.w3c.dom.Node) {
+                return getXmlConverter().toDOMDocument((org.w3c.dom.Node) value);
             }
             if (value instanceof byte[]) {
                 return getXmlConverter().toDOMDocument((byte[]) value, exchange);
@@ -317,8 +312,13 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
             if (value instanceof javax.xml.transform.Source) {
                 return getXmlConverter().toDOMDocument((javax.xml.transform.Source) value);
             }
-            if (value instanceof org.w3c.dom.Node) {
-                return getXmlConverter().toDOMDocument((org.w3c.dom.Node) value);
+            if (value instanceof org.w3c.dom.NodeList) {
+                Object obj = getXmlConverter().toDOMDocumentFromSingleNodeList((org.w3c.dom.NodeList) value);
+                if (obj == null) {
+                    return Void.class;
+                } else {
+                    return obj;
+                }
             }
         } else if (to == org.w3c.dom.Element.class) {
             if (value instanceof javax.xml.transform.Source) {
@@ -604,7 +604,7 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
                 return this;
             }
         } else if (to == org.w3c.dom.Document.class) {
-            if (from == org.w3c.dom.NodeList.class) {
+            if (from == org.w3c.dom.Node.class) {
                 return this;
             }
             if (from == byte[].class) {
@@ -628,7 +628,7 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
             if (from == javax.xml.transform.Source.class) {
                 return this;
             }
-            if (from == org.w3c.dom.Node.class) {
+            if (from == org.w3c.dom.NodeList.class) {
                 return this;
             }
         } else if (to == org.w3c.dom.Element.class) {
diff --git a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
index 6b9e7c7..8cee45b 100644
--- a/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
+++ b/core/camel-xml-jaxp/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
@@ -581,22 +581,37 @@ public class XmlConverter {
     }
 
     /**
-     * Convert a NodeList consisting of just 1 node to a DOM Document. Cannot convert NodeList with length > 1 because
-     * they require a root node.
-     * 
-     * @param  nl the NodeList
-     * @return    the DOM Document
+     * 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.
      */
-    @Converter(order = 42, allowNull = true)
-    public Document toDOMDocumentFromSingleNodeList(NodeList nl) throws ParserConfigurationException, TransformerException {
-        if (nl.getLength() == 1) {
-            return toDOMDocument(nl.item(0));
-        } else if (nl instanceof Node) {
-            // as XML parsers may often have nodes that implement both Node and NodeList then the type converter lookup
-            // may lookup either a type converter from NodeList or Node. So let's fallback and try with Node
-            return toDOMDocument((Node) nl);
+    @Converter(order = 42)
+    public Document toDOMDocument(final Node node) throws ParserConfigurationException, TransformerException {
+        ObjectHelper.notNull(node, "node");
+
+        // 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();
+                // import node must not occur concurrent on the same node (must be its owner)
+                // so we need to synchronize on it
+                synchronized (node.getOwnerDocument()) {
+                    doc.appendChild(doc.importNode(node, true));
+                }
+                return doc;
+            }
+            // other element types are not handled
         } else {
-            return null;
+            throw new TransformerException("Unable to convert DOM node to a Document: " + node);
         }
     }
 
@@ -735,37 +750,22 @@ public class XmlConverter {
     }
 
     /**
-     * Create a DOM document from the given Node.
+     * Convert a NodeList consisting of just 1 node to a DOM Document. Cannot convert NodeList with length > 1 because
+     * they require a root 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  nl the NodeList
+     * @return    the DOM Document
      */
-    @Converter(order = 53)
-    public Document toDOMDocument(final Node node) throws ParserConfigurationException, TransformerException {
-        ObjectHelper.notNull(node, "node");
-
-        // 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();
-                // import node must not occur concurrent on the same node (must be its owner)
-                // so we need to synchronize on it
-                synchronized (node.getOwnerDocument()) {
-                    doc.appendChild(doc.importNode(node, true));
-                }
-                return doc;
-            }
-            // other element types are not handled
+    @Converter(order = 53, allowNull = true)
+    public Document toDOMDocumentFromSingleNodeList(NodeList nl) throws ParserConfigurationException, TransformerException {
+        if (nl.getLength() == 1) {
+            return toDOMDocument(nl.item(0));
+        } else if (nl instanceof Node) {
+            // as XML parsers may often have nodes that implement both Node and NodeList then the type converter lookup
+            // may lookup either a type converter from NodeList or Node. So let's fallback and try with Node
+            return toDOMDocument((Node) nl);
         } else {
-            throw new TransformerException("Unable to convert DOM node to a Document: " + node);
+            return null;
         }
     }
 


[camel] 02/05: CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 6495703dd6ec0f200fb57645a6114648776c650c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Oct 31 09:56:15 2020 +0100

    CAMEL-15783: camel-core - Add order to @Converter so we can generate in hardcoded order
---
 .../src/main/java/org/apache/camel/Converter.java  |   4 +-
 .../converter/CamelBaseBulkConverterLoader.java    | 120 ++++++++++-----------
 .../org/apache/camel/converter/IOConverter.java    |   4 +-
 .../jaxp/CamelXmlJaxpBulkConverterLoader.java      |  78 +++++++-------
 4 files changed, 102 insertions(+), 104 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/Converter.java b/core/camel-api/src/main/java/org/apache/camel/Converter.java
index fef34e4..92907cb 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Converter.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Converter.java
@@ -81,8 +81,8 @@ public @interface Converter {
     boolean generateBulkLoader() default false;
 
     /**
-     * To be used for ordering converter methods when source code generating bulk loaders.
-     * The order is lowest to highest, eg 1, 2, 3.
+     * To be used for ordering converter methods when source code generating bulk loaders. The order is lowest to
+     * highest, eg 1, 2, 3.
      */
     int order() default 0;
 
diff --git a/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java b/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java
index 1758c61..f4e3038 100644
--- a/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java
+++ b/core/camel-base/src/generated/java/org/apache/camel/converter/CamelBaseBulkConverterLoader.java
@@ -52,6 +52,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
 
     private Object doConvertTo(Class<?> from, Class<?> to, Exchange exchange, Object value) throws Exception {
         if (to == byte[].class) {
+            if (value instanceof java.nio.ByteBuffer) {
+                return org.apache.camel.converter.NIOConverter.toByteArray((java.nio.ByteBuffer) value);
+            }
             if (value instanceof java.io.File) {
                 return org.apache.camel.converter.IOConverter.toByteArray((java.io.File) value);
             }
@@ -70,9 +73,6 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (value instanceof java.io.ByteArrayOutputStream) {
                 return org.apache.camel.converter.IOConverter.toByteArray((java.io.ByteArrayOutputStream) value);
             }
-            if (value instanceof java.nio.ByteBuffer) {
-                return org.apache.camel.converter.NIOConverter.toByteArray((java.nio.ByteBuffer) value);
-            }
         } else if (to == char[].class) {
             if (value instanceof java.lang.String) {
                 return org.apache.camel.converter.ObjectConverter.toCharArray((java.lang.String) value);
@@ -114,6 +114,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (value instanceof java.lang.String) {
                 return org.apache.camel.converter.IOConverter.toInputStream((java.lang.String) value, exchange);
             }
+            if (value instanceof java.nio.ByteBuffer) {
+                return org.apache.camel.converter.NIOConverter.toInputStream((java.nio.ByteBuffer) value);
+            }
             if (value instanceof java.lang.StringBuffer) {
                 return org.apache.camel.converter.IOConverter.toInputStream((java.lang.StringBuffer) value, exchange);
             }
@@ -129,9 +132,6 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (value instanceof java.io.ByteArrayOutputStream) {
                 return org.apache.camel.converter.IOConverter.toInputStream((java.io.ByteArrayOutputStream) value);
             }
-            if (value instanceof java.nio.ByteBuffer) {
-                return org.apache.camel.converter.NIOConverter.toInputStream((java.nio.ByteBuffer) value);
-            }
         } else if (to == java.io.ObjectInput.class) {
             if (value instanceof java.io.InputStream) {
                 return org.apache.camel.converter.IOConverter.toObjectInput((java.io.InputStream) value, exchange);
@@ -177,10 +177,6 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (value instanceof java.lang.String) {
                 return org.apache.camel.converter.ObjectConverter.toByte((java.lang.String) value);
             }
-        } else if (to == java.lang.CharSequence.class) {
-            if (value instanceof java.net.URI) {
-                return org.apache.camel.converter.UriTypeConverter.toString((java.net.URI) value);
-            }
         } else if (to == java.lang.Character.class || to == char.class) {
             if (value instanceof java.lang.String) {
                 return org.apache.camel.converter.ObjectConverter.toCharacter((java.lang.String) value);
@@ -220,15 +216,15 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
                 return org.apache.camel.converter.ObjectConverter.iterable(value);
             }
         } else if (to == java.lang.Long.class || to == long.class) {
+            if (value instanceof java.time.Duration) {
+                return org.apache.camel.converter.DurationConverter.toMilliSeconds((java.time.Duration) value);
+            }
             if (value instanceof java.sql.Timestamp) {
                 return org.apache.camel.converter.SQLConverter.toLong((java.sql.Timestamp) value);
             }
             if (value instanceof java.util.Date) {
                 return org.apache.camel.converter.DateTimeConverter.toLong((java.util.Date) value);
             }
-            if (value instanceof java.time.Duration) {
-                return org.apache.camel.converter.DurationConverter.toMilliSeconds((java.time.Duration) value);
-            }
             if (value instanceof java.lang.Number) {
                 Object obj = org.apache.camel.converter.ObjectConverter.toLong((java.lang.Number) value);
                 if (obj == null) {
@@ -257,6 +253,18 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
                 return org.apache.camel.converter.ObjectConverter.toShort((java.lang.String) value);
             }
         } else if (to == java.lang.String.class) {
+            if (value instanceof java.net.URI) {
+                return org.apache.camel.converter.UriTypeConverter.toString((java.net.URI) value);
+            }
+            if (value instanceof java.nio.ByteBuffer) {
+                return org.apache.camel.converter.NIOConverter.toString((java.nio.ByteBuffer) value, exchange);
+            }
+            if (value instanceof java.time.Duration) {
+                return org.apache.camel.converter.DurationConverter.toString((java.time.Duration) value);
+            }
+            if (value instanceof char[]) {
+                return org.apache.camel.converter.ObjectConverter.fromCharArray((char[]) value);
+            }
             if (value instanceof byte[]) {
                 return org.apache.camel.converter.IOConverter.toString((byte[]) value, exchange);
             }
@@ -266,26 +274,11 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (value instanceof java.net.URL) {
                 return org.apache.camel.converter.IOConverter.toString((java.net.URL) value, exchange);
             }
-            if (value instanceof java.io.Reader) {
-                return org.apache.camel.converter.IOConverter.toString((java.io.Reader) value);
-            }
             if (value instanceof java.io.BufferedReader) {
                 return org.apache.camel.converter.IOConverter.toString((java.io.BufferedReader) value);
             }
-            if (value instanceof java.io.InputStream) {
-                return org.apache.camel.converter.IOConverter.toString((java.io.InputStream) value, exchange);
-            }
-            if (value instanceof java.io.ByteArrayOutputStream) {
-                return org.apache.camel.converter.IOConverter.toString((java.io.ByteArrayOutputStream) value, exchange);
-            }
-            if (value instanceof java.nio.ByteBuffer) {
-                return org.apache.camel.converter.NIOConverter.toString((java.nio.ByteBuffer) value, exchange);
-            }
-            if (value instanceof java.time.Duration) {
-                return org.apache.camel.converter.DurationConverter.toString((java.time.Duration) value);
-            }
-            if (value instanceof char[]) {
-                return org.apache.camel.converter.ObjectConverter.fromCharArray((char[]) value);
+            if (value instanceof java.io.Reader) {
+                return org.apache.camel.converter.IOConverter.toString((java.io.Reader) value);
             }
             if (value instanceof java.lang.Integer) {
                 return org.apache.camel.converter.ObjectConverter.toString((java.lang.Integer) value);
@@ -293,6 +286,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (value instanceof java.lang.Long) {
                 return org.apache.camel.converter.ObjectConverter.toString((java.lang.Long) value);
             }
+            if (value instanceof java.io.InputStream) {
+                return org.apache.camel.converter.IOConverter.toString((java.io.InputStream) value, exchange);
+            }
             if (value instanceof java.lang.Boolean) {
                 return org.apache.camel.converter.ObjectConverter.toString((java.lang.Boolean) value);
             }
@@ -302,6 +298,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (value instanceof java.lang.StringBuilder) {
                 return org.apache.camel.converter.ObjectConverter.toString((java.lang.StringBuilder) value);
             }
+            if (value instanceof java.io.ByteArrayOutputStream) {
+                return org.apache.camel.converter.IOConverter.toString((java.io.ByteArrayOutputStream) value, exchange);
+            }
         } else if (to == java.math.BigInteger.class) {
             if (value instanceof java.lang.Object) {
                 Object obj = org.apache.camel.converter.ObjectConverter.toBigInteger(value);
@@ -316,9 +315,6 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
                 return org.apache.camel.converter.UriTypeConverter.toUri((java.lang.CharSequence) value);
             }
         } else if (to == java.nio.ByteBuffer.class) {
-            if (value instanceof java.io.InputStream) {
-                return org.apache.camel.converter.IOConverter.covertToByteBuffer((java.io.InputStream) value);
-            }
             if (value instanceof byte[]) {
                 return org.apache.camel.converter.NIOConverter.toByteBuffer((byte[]) value);
             }
@@ -346,6 +342,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (value instanceof java.lang.Double) {
                 return org.apache.camel.converter.NIOConverter.toByteBuffer((java.lang.Double) value);
             }
+            if (value instanceof java.io.InputStream) {
+                return org.apache.camel.converter.IOConverter.covertToByteBuffer((java.io.InputStream) value);
+            }
         } else if (to == java.sql.Timestamp.class) {
             if (value instanceof java.lang.Long) {
                 return org.apache.camel.converter.SQLConverter.toTimestamp((java.lang.Long) value);
@@ -433,6 +432,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
 
     public TypeConverter lookup(Class<?> to, Class<?> from) {
         if (to == byte[].class) {
+            if (from == java.nio.ByteBuffer.class) {
+                return this;
+            }
             if (from == java.io.File.class) {
                 return this;
             }
@@ -451,9 +453,6 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (from == java.io.ByteArrayOutputStream.class) {
                 return this;
             }
-            if (from == java.nio.ByteBuffer.class) {
-                return this;
-            }
         } else if (to == char[].class) {
             if (from == java.lang.String.class) {
                 return this;
@@ -495,6 +494,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (from == java.lang.String.class) {
                 return this;
             }
+            if (from == java.nio.ByteBuffer.class) {
+                return this;
+            }
             if (from == java.lang.StringBuffer.class) {
                 return this;
             }
@@ -510,9 +512,6 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (from == java.io.ByteArrayOutputStream.class) {
                 return this;
             }
-            if (from == java.nio.ByteBuffer.class) {
-                return this;
-            }
         } else if (to == java.io.ObjectInput.class) {
             if (from == java.io.InputStream.class) {
                 return this;
@@ -553,10 +552,6 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (from == java.lang.String.class) {
                 return this;
             }
-        } else if (to == java.lang.CharSequence.class) {
-            if (from == java.net.URI.class) {
-                return this;
-            }
         } else if (to == java.lang.Character.class || to == char.class) {
             if (from == java.lang.String.class) {
                 return this;
@@ -591,13 +586,13 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
                 return this;
             }
         } else if (to == java.lang.Long.class || to == long.class) {
-            if (from == java.sql.Timestamp.class) {
+            if (from == java.time.Duration.class) {
                 return this;
             }
-            if (from == java.util.Date.class) {
+            if (from == java.sql.Timestamp.class) {
                 return this;
             }
-            if (from == java.time.Duration.class) {
+            if (from == java.util.Date.class) {
                 return this;
             }
             if (from == java.lang.Number.class) {
@@ -618,34 +613,31 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
                 return this;
             }
         } else if (to == java.lang.String.class) {
-            if (from == byte[].class) {
-                return this;
-            }
-            if (from == java.io.File.class) {
+            if (from == java.net.URI.class) {
                 return this;
             }
-            if (from == java.net.URL.class) {
+            if (from == java.nio.ByteBuffer.class) {
                 return this;
             }
-            if (from == java.io.Reader.class) {
+            if (from == java.time.Duration.class) {
                 return this;
             }
-            if (from == java.io.BufferedReader.class) {
+            if (from == char[].class) {
                 return this;
             }
-            if (from == java.io.InputStream.class) {
+            if (from == byte[].class) {
                 return this;
             }
-            if (from == java.io.ByteArrayOutputStream.class) {
+            if (from == java.io.File.class) {
                 return this;
             }
-            if (from == java.nio.ByteBuffer.class) {
+            if (from == java.net.URL.class) {
                 return this;
             }
-            if (from == java.time.Duration.class) {
+            if (from == java.io.BufferedReader.class) {
                 return this;
             }
-            if (from == char[].class) {
+            if (from == java.io.Reader.class) {
                 return this;
             }
             if (from == java.lang.Integer.class) {
@@ -654,6 +646,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (from == java.lang.Long.class) {
                 return this;
             }
+            if (from == java.io.InputStream.class) {
+                return this;
+            }
             if (from == java.lang.Boolean.class) {
                 return this;
             }
@@ -663,6 +658,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (from == java.lang.StringBuilder.class) {
                 return this;
             }
+            if (from == java.io.ByteArrayOutputStream.class) {
+                return this;
+            }
         } else if (to == java.math.BigInteger.class) {
             if (from == java.lang.Object.class) {
                 return this;
@@ -672,9 +670,6 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
                 return this;
             }
         } else if (to == java.nio.ByteBuffer.class) {
-            if (from == java.io.InputStream.class) {
-                return this;
-            }
             if (from == byte[].class) {
                 return this;
             }
@@ -702,6 +697,9 @@ public final class CamelBaseBulkConverterLoader implements TypeConverterLoader,
             if (from == java.lang.Double.class) {
                 return this;
             }
+            if (from == java.io.InputStream.class) {
+                return this;
+            }
         } else if (to == java.sql.Timestamp.class) {
             if (from == java.lang.Long.class) {
                 return this;
diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java
index 6833dc7..54f4986 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/IOConverter.java
@@ -180,12 +180,12 @@ public final class IOConverter {
     }
 
     @Converter(order = 21)
-    public static String toString(Reader reader) throws IOException {
+    public static String toString(BufferedReader reader) throws IOException {
         return IOHelper.toString(reader);
     }
 
     @Converter(order = 22)
-    public static String toString(BufferedReader reader) throws IOException {
+    public static String toString(Reader reader) throws IOException {
         return IOHelper.toString(reader);
     }
 
diff --git a/core/camel-xml-jaxp/src/generated/java/org/apache/camel/converter/jaxp/CamelXmlJaxpBulkConverterLoader.java b/core/camel-xml-jaxp/src/generated/java/org/apache/camel/converter/jaxp/CamelXmlJaxpBulkConverterLoader.java
index 38026a8..def85f1 100644
--- a/core/camel-xml-jaxp/src/generated/java/org/apache/camel/converter/jaxp/CamelXmlJaxpBulkConverterLoader.java
+++ b/core/camel-xml-jaxp/src/generated/java/org/apache/camel/converter/jaxp/CamelXmlJaxpBulkConverterLoader.java
@@ -47,13 +47,16 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
 
     private Object doConvertTo(Class<?> from, Class<?> to, Exchange exchange, Object value) throws Exception {
         if (to == byte[].class) {
+            if (value instanceof org.w3c.dom.NodeList) {
+                return getDomConverter().toByteArray((org.w3c.dom.NodeList) value, exchange);
+            }
             if (value instanceof javax.xml.transform.Source) {
                 return getXmlConverter().toByteArray((javax.xml.transform.Source) value, exchange);
             }
+        } else if (to == java.io.InputStream.class) {
             if (value instanceof org.w3c.dom.NodeList) {
-                return getDomConverter().toByteArray((org.w3c.dom.NodeList) value, exchange);
+                return getDomConverter().toInputStream((org.w3c.dom.NodeList) value, exchange);
             }
-        } else if (to == java.io.InputStream.class) {
             if (value instanceof javax.xml.stream.XMLStreamReader) {
                 return getStaxConverter().createInputStream((javax.xml.stream.XMLStreamReader) value, exchange);
             }
@@ -66,9 +69,6 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
             if (value instanceof javax.xml.transform.stream.StreamSource) {
                 return getXmlConverter().toInputStream((javax.xml.transform.stream.StreamSource) value);
             }
-            if (value instanceof org.w3c.dom.NodeList) {
-                return getDomConverter().toInputStream((org.w3c.dom.NodeList) value, exchange);
-            }
         } else if (to == java.io.Reader.class) {
             if (value instanceof javax.xml.stream.XMLStreamReader) {
                 return getStaxConverter().createReader((javax.xml.stream.XMLStreamReader) value, exchange);
@@ -96,15 +96,15 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
                 return org.apache.camel.converter.jaxp.DomConverter.toLong((org.w3c.dom.NodeList) value);
             }
         } else if (to == java.lang.String.class) {
+            if (value instanceof org.w3c.dom.NodeList) {
+                return getDomConverter().toString((org.w3c.dom.NodeList) value, exchange);
+            }
             if (value instanceof org.w3c.dom.Node) {
                 return getDomConverter().toString((org.w3c.dom.Node) value, exchange);
             }
             if (value instanceof javax.xml.transform.Source) {
                 return getXmlConverter().toString((javax.xml.transform.Source) value, exchange);
             }
-            if (value instanceof org.w3c.dom.NodeList) {
-                return getDomConverter().toString((org.w3c.dom.NodeList) value, exchange);
-            }
         } else if (to == java.util.List.class) {
             if (value instanceof org.w3c.dom.NodeList) {
                 return org.apache.camel.converter.jaxp.DomConverter.toList((org.w3c.dom.NodeList) value);
@@ -288,6 +288,14 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
                 return getXmlConverter().toStringSource((java.lang.String) value);
             }
         } else if (to == org.w3c.dom.Document.class) {
+            if (value instanceof org.w3c.dom.NodeList) {
+                Object obj = getXmlConverter().toDOMDocumentFromSingleNodeList((org.w3c.dom.NodeList) value);
+                if (obj == null) {
+                    return Void.class;
+                } else {
+                    return obj;
+                }
+            }
             if (value instanceof byte[]) {
                 return getXmlConverter().toDOMDocument((byte[]) value, exchange);
             }
@@ -312,14 +320,6 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
             if (value instanceof org.w3c.dom.Node) {
                 return getXmlConverter().toDOMDocument((org.w3c.dom.Node) value);
             }
-            if (value instanceof org.w3c.dom.NodeList) {
-                Object obj = getXmlConverter().toDOMDocumentFromSingleNodeList((org.w3c.dom.NodeList) value);
-                if (obj == null) {
-                    return Void.class;
-                } else {
-                    return obj;
-                }
-            }
         } else if (to == org.w3c.dom.Element.class) {
             if (value instanceof javax.xml.transform.Source) {
                 return getXmlConverter().toDOMElement((javax.xml.transform.Source) value);
@@ -334,16 +334,16 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
             if (value instanceof javax.xml.transform.stax.StAXSource) {
                 return getXmlConverter().toDOMNodeFromStAX((javax.xml.transform.stax.StAXSource) value);
             }
-            if (value instanceof javax.xml.transform.Source) {
-                Object obj = getXmlConverter().toDOMNode((javax.xml.transform.Source) value);
+            if (value instanceof org.w3c.dom.NodeList) {
+                Object obj = getXmlConverter().toDOMNodeFromSingleNodeList((org.w3c.dom.NodeList) value);
                 if (obj == null) {
                     return Void.class;
                 } else {
                     return obj;
                 }
             }
-            if (value instanceof org.w3c.dom.NodeList) {
-                Object obj = getXmlConverter().toDOMNodeFromSingleNodeList((org.w3c.dom.NodeList) value);
+            if (value instanceof javax.xml.transform.Source) {
+                Object obj = getXmlConverter().toDOMNode((javax.xml.transform.Source) value);
                 if (obj == null) {
                     return Void.class;
                 } else {
@@ -363,13 +363,16 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
 
     public TypeConverter lookup(Class<?> to, Class<?> from) {
         if (to == byte[].class) {
+            if (from == org.w3c.dom.NodeList.class) {
+                return this;
+            }
             if (from == javax.xml.transform.Source.class) {
                 return this;
             }
+        } else if (to == java.io.InputStream.class) {
             if (from == org.w3c.dom.NodeList.class) {
                 return this;
             }
-        } else if (to == java.io.InputStream.class) {
             if (from == javax.xml.stream.XMLStreamReader.class) {
                 return this;
             }
@@ -382,9 +385,6 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
             if (from == javax.xml.transform.stream.StreamSource.class) {
                 return this;
             }
-            if (from == org.w3c.dom.NodeList.class) {
-                return this;
-            }
         } else if (to == java.io.Reader.class) {
             if (from == javax.xml.stream.XMLStreamReader.class) {
                 return this;
@@ -412,13 +412,13 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
                 return this;
             }
         } else if (to == java.lang.String.class) {
-            if (from == org.w3c.dom.Node.class) {
+            if (from == org.w3c.dom.NodeList.class) {
                 return this;
             }
-            if (from == javax.xml.transform.Source.class) {
+            if (from == org.w3c.dom.Node.class) {
                 return this;
             }
-            if (from == org.w3c.dom.NodeList.class) {
+            if (from == javax.xml.transform.Source.class) {
                 return this;
             }
         } else if (to == java.util.List.class) {
@@ -604,6 +604,9 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
                 return this;
             }
         } else if (to == org.w3c.dom.Document.class) {
+            if (from == org.w3c.dom.NodeList.class) {
+                return this;
+            }
             if (from == byte[].class) {
                 return this;
             }
@@ -628,9 +631,6 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
             if (from == org.w3c.dom.Node.class) {
                 return this;
             }
-            if (from == org.w3c.dom.NodeList.class) {
-                return this;
-            }
         } else if (to == org.w3c.dom.Element.class) {
             if (from == javax.xml.transform.Source.class) {
                 return this;
@@ -645,10 +645,10 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
             if (from == javax.xml.transform.stax.StAXSource.class) {
                 return this;
             }
-            if (from == javax.xml.transform.Source.class) {
+            if (from == org.w3c.dom.NodeList.class) {
                 return this;
             }
-            if (from == org.w3c.dom.NodeList.class) {
+            if (from == javax.xml.transform.Source.class) {
                 return this;
             }
         } else if (to == org.xml.sax.InputSource.class) {
@@ -662,13 +662,6 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
         return null;
     }
 
-    private volatile org.apache.camel.converter.jaxp.XmlConverter xmlConverter;
-    private org.apache.camel.converter.jaxp.XmlConverter getXmlConverter() {
-        if (xmlConverter == null) {
-            xmlConverter = new org.apache.camel.converter.jaxp.XmlConverter();
-        }
-        return xmlConverter;
-    }
     private volatile org.apache.camel.converter.jaxp.DomConverter domConverter;
     private org.apache.camel.converter.jaxp.DomConverter getDomConverter() {
         if (domConverter == null) {
@@ -676,6 +669,13 @@ public final class CamelXmlJaxpBulkConverterLoader implements TypeConverterLoade
         }
         return domConverter;
     }
+    private volatile org.apache.camel.converter.jaxp.XmlConverter xmlConverter;
+    private org.apache.camel.converter.jaxp.XmlConverter getXmlConverter() {
+        if (xmlConverter == null) {
+            xmlConverter = new org.apache.camel.converter.jaxp.XmlConverter();
+        }
+        return xmlConverter;
+    }
     private volatile org.apache.camel.converter.jaxp.StaxConverter staxConverter;
     private org.apache.camel.converter.jaxp.StaxConverter getStaxConverter() {
         if (staxConverter == null) {


[camel] 04/05: CAMEL-15778: camel-core - Optimize to allow to clear bootstrap configurer.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ade99f73df3370fed53083ee9b8cfa90c9af23c2
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Oct 31 09:59:37 2020 +0100

    CAMEL-15778: camel-core - Optimize to allow to clear bootstrap configurer.
---
 .../java/org/apache/camel/impl/engine/AbstractCamelContext.java     | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 505889e..e6d7fb5 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -2706,14 +2706,12 @@ public abstract class AbstractCamelContext extends BaseService
             }
             LOG.info("Apache Camel {} ({}) started in {}", getVersion(), getName(), TimeUtils.printDuration(stopWatch.taken()));
 
-            // we can always clear the bootstrap configurers (such as camel-main) after we have started
-            ConfigurerStrategy.clearBootstrapConfigurers();
-
             if (isLightweight()) {
                 LOG.info(
-                        "Clearing Camel bootstrap services to free memory."
+                        "Lightweight enabled. Clearing services to free memory."
                          + " Danger this impacts the CamelContext not being able to add new routes or use reflection-free configuration, etc.");
                 ReifierStrategy.clearReifiers();
+                ConfigurerStrategy.clearBootstrapConfigurers();
                 ConfigurerStrategy.clearConfigurers();
             }
         }