velocity.bulk-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.Ordered;
import org.apache.camel.TypeConversionException;
import org.apache.camel.TypeConverterLoaderException;
import org.apache.camel.TypeConverter;
import org.apache.camel.spi.TypeConvertible;
import org.apache.camel.spi.BulkTypeConverters;
import org.apache.camel.spi.TypeConverterLoader;
import org.apache.camel.spi.TypeConverterRegistry;
/**
* 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, BulkTypeConverters, CamelContextAware {
private CamelContext camelContext;
public ${className}() {
}
@Override
public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}
@Override
public CamelContext getCamelContext() {
return camelContext;
}
#if ( $base )
@Override
public int getOrder() {
return Ordered.HIGHEST;
}
#end
@Override
public int size() {
return ${converters.size()};
}
@Override
public void load(TypeConverterRegistry registry) throws TypeConverterLoaderException {
registry.addBulkTypeConverters(this);
doRegistration(registry);
}
@Override
public T convertTo(Class> from, Class to, Exchange exchange, Object value) throws TypeConversionException {
try {
Object obj = doConvertTo(from, to, exchange, value);
if (obj == Void.class) {;
return null;
} else {
return (T) obj;
}
} catch (TypeConversionException e) {
throw e;
} catch (Exception e) {
throw new TypeConversionException(value, to, e);
}
}
private Object doConvertTo(Class> from, Class> to, Exchange exchange, Object value) throws Exception {
#set ( $prevTo = false )
#foreach ( $method in $converters )
#set ( $to = $mojo.getToMethod($method) )
#set ( $from = $method.parameterTypes().get(0).toString() )
#if ( $to.indexOf('<') != -1 )
#set ( $to = $to.substring(0, $to.indexOf('<')) )
#end
#if ( $from.indexOf('<') != -1 )
#set ( $from = $from.substring(0, $from.indexOf('<')) )
#end
#set ( $newTo = false )
#set ( $primitiveTo = $mojo.asPrimitiveType($method) )
#set ( $firstPart = "to == ${to}.class" )
#set ( $secondPart = "" )
#if ( $mojo.asPrimitiveType($method) )
#set ( $secondPart = " || to == ${primitiveTo}.class" )
#end
#if ( ! $prevTo )
if (${firstPart}${secondPart}) {
#set ( $newTo = true )
#elseif ( !$prevTo.equals($to) )
} else if (${firstPart}${secondPart}) {
#set ( $newTo = true )
#end
if (value instanceof ${from}) {
#if ( $mojo.isAllowNull($method) )
Object obj = ${mojo.toJava($method, $converterClasses)};
if (obj == null) {
return Void.class;
} else {
return obj;
}
#else
return ${mojo.toJava($method, $converterClasses)};
#end
}
#set ( $prevTo = $to )
#end
}
return null;
}
private void doRegistration(TypeConverterRegistry registry) {
#foreach ( $method in $converters )
registry.addConverter(new TypeConvertible<>(${mojo.getGenericArgumentsForTypeConvertible($method)}), this);
#end
}
public TypeConverter lookup(Class> to, Class> from) {
#set ( $prevTo = false )
#foreach ( $method in $converters )
#set ( $to = $mojo.getToMethod($method) )
#set ( $from = $method.parameterTypes().get(0).toString() )
#if ( $to.indexOf('<') != -1 )
#set ( $to = $to.substring(0, $to.indexOf('<')) )
#end
#if ( $from.indexOf('<') != -1 )
#set ( $from = $from.substring(0, $from.indexOf('<')) )
#end
#set ( $newTo = false )
#set ( $primitiveTo = $mojo.asPrimitiveType($method) )
#set ( $firstPart = "to == ${to}.class" )
#set ( $secondPart = "" )
#if ( $mojo.asPrimitiveType($method) )
#set ( $secondPart = " || to == ${primitiveTo}.class" )
#end
#if ( ! $prevTo )
if (${firstPart}${secondPart}) {
#set ( $newTo = true )
#elseif ( ! $prevTo.equals($to) )
} else if (${firstPart}${secondPart}) {
#set ( $newTo = true )
#end
if (from == ${from}.class) {
return this;
}
#set ( $prevTo = $to )
#end
}
return null;
}
#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