velocity.type-converter-loader.vm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of camel-package-maven-plugin Show documentation
Show all versions of camel-package-maven-plugin Show documentation
Maven plugin to help package Camel components and plugins
The newest version!
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
/* Generated by camel build tools - do NOT edit this file! */
package ${package};
import javax.annotation.processing.Generated;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.DeferredContextBinding;
import org.apache.camel.Exchange;
import org.apache.camel.TypeConversionException;
import org.apache.camel.TypeConverterLoaderException;
import org.apache.camel.spi.TypeConverterLoader;
import org.apache.camel.spi.TypeConverterRegistry;
import org.apache.camel.support.SimpleTypeConverter;
import org.apache.camel.support.TypeConverterSupport;
import org.apache.camel.util.DoubleMap;
/**
* Generated by camel build tools - do NOT edit this file!
*/
@Generated("org.apache.camel.maven.packaging.TypeConverterLoaderGeneratorMojo")
@SuppressWarnings("unchecked")
@DeferredContextBinding
public final class ${className} implements TypeConverterLoader, CamelContextAware {
private CamelContext camelContext;
public ${className}() {
}
@Override
public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}
@Override
public CamelContext getCamelContext() {
return camelContext;
}
@Override
public void load(TypeConverterRegistry registry) throws TypeConverterLoaderException {
#if ( $converters.size() > 0 )
#if ( $converters.isIgnoreOnLoadError() )
try {
registerConverters(registry);
} catch (Throwable e) {
// ignore on load error
}
#else
registerConverters(registry);
#end
#end
#if ( $converters.sizeFallback() > 0 )
registerFallbackConverters(registry);
#end
}
#if ( $converters.size() > 0 )
private void registerConverters(TypeConverterRegistry registry) {
#foreach ( $to in $converters.getConverters().entrySet() )
#foreach ( $from in $to.getValue().entrySet() )
addTypeConverter(registry, ${to.getKey()}.class, ${mojo.toString($from.getKey())}.class, ${mojo.isAllowNull($from.getValue())},
(type, exchange, value) -> ${mojo.toJava($from.getValue(), $converterClasses)});
#end
#end
}
#end
private static void addTypeConverter(TypeConverterRegistry registry, Class> toType, Class> fromType, boolean allowNull, SimpleTypeConverter.ConversionMethod method) {
registry.addTypeConverter(toType, fromType, new SimpleTypeConverter(allowNull, method));
}
#if ( $converters.sizeFallback() > 0 )
private void registerFallbackConverters(TypeConverterRegistry registry) {
#foreach ( $ee in $converters.getFallbackConverters() )
addFallbackTypeConverter(registry, ${mojo.isAllowNull($ee)}, ${mojo.isFallbackCanPromote($ee)}, (type, exchange, value) -> ${mojo.toJavaFallback($ee, $converterClasses)});
#end
}
private static void addFallbackTypeConverter(TypeConverterRegistry registry, boolean allowNull, boolean canPromote, SimpleTypeConverter.ConversionMethod method) {
registry.addFallbackTypeConverter(new SimpleTypeConverter(allowNull, method), canPromote);
}
#end
#foreach ( $f in $converterClasses )
#set ( $s = $f.substring( $f.lastIndexOf('.') + 1 ) )
#set ( $v = $s.substring(0, 1).toLowerCase() + $s.substring(1) )
private volatile ${f} ${v};
private ${f} get${s}() {
if (${v} == null) {
${v} = new ${f}();
CamelContextAware.trySetCamelContext(${v}, camelContext);
}
return ${v};
}
#end
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy