LibraryToggle FramesPrintFeedback

Figure 3.1 gives an overview of the type conversion process, showing the steps involved in converting a given data value, value, to a specified type, toType.

The type conversion mechanism proceeds as follows:

  1. The CamelContext object holds a reference to the master TypeConverter instance. The first step in the conversion process is to retrieve the master type converter by calling CamelContext.getTypeConverter().

  2. Type conversion is initiated by calling the convertTo() method on the master type converter. This method instructs the type converter to convert the data object, value, from its original type to the type specified by the toType argument.

  3. Because the master type converter is a front end for many different slave type converters, it looks up the appropriate slave type converter by checking a registry of type mappings The registry of type converters is keyed by a type mapping pair (toType, fromType). If a suitable type converter is found in the registry, the master type converter calls the slave's convertTo() method and returns the result.

  4. If a suitable type converter cannot be found in the registry, the master type converter loads a new type converter, using the type converter loader.

  5. The type converter loader searches the available JAR libraries on the classpath to find a suitable type converter. Currently, the loader strategy that is used is implemented by the annotation type converter loader, which attempts to load a class annotated by the org.apache.camel.Converter annotation. See Create a TypeConverter file.

  6. If the type converter loader is successful, a new slave type converter is loaded and entered into the type converter registry. This type converter is then used to convert the value argument to the toType type.

  7. If the data is successfully converted, the converted data value is returned. If the conversion does not succeed, null is returned.

Comments powered by Disqus