All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.camel.TypeConverter Maven / Gradle / Ivy

There is a newer version: 4.6.0
Show 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.
 */
package org.apache.camel;


/**
 * A pluggable strategy to be able to convert objects to different
 * types such as to and from String, InputStream/OutputStream,
 * Reader/Writer, Document, byte[], ByteBuffer etc
 * 
 * @version 
 */
public interface TypeConverter {

    /**
     * Whether the type converter allows returning null as a valid response.
     * 

* By default null is not a valid response, returning false from this method. */ boolean allowNull(); /** * Converts the value to the specified type * * @param type the requested type * @param value the value to be converted * @return the converted value, or null if not possible to convert * @throws TypeConversionException is thrown if error during type conversion */ T convertTo(Class type, Object value) throws TypeConversionException; /** * Converts the value to the specified type in the context of an exchange *

* Used when conversion requires extra information from the current * exchange (such as encoding). * * @param type the requested type * @param exchange the current exchange * @param value the value to be converted * @return the converted value, or null if not possible to convert * @throws TypeConversionException is thrown if error during type conversion */ T convertTo(Class type, Exchange exchange, Object value) throws TypeConversionException; /** * Converts the value to the specified type * * @param type the requested type * @param value the value to be converted * @return the converted value, is never null * @throws TypeConversionException is thrown if error during type conversion * @throws NoTypeConversionAvailableException if no type converters exists to convert to the given type */ T mandatoryConvertTo(Class type, Object value) throws TypeConversionException, NoTypeConversionAvailableException; /** * Converts the value to the specified type in the context of an exchange *

* Used when conversion requires extra information from the current * exchange (such as encoding). * * @param type the requested type * @param exchange the current exchange * @param value the value to be converted * @return the converted value, is never null * @throws TypeConversionException is thrown if error during type conversion * @throws NoTypeConversionAvailableException if no type converters exists to convert to the given type */ T mandatoryConvertTo(Class type, Exchange exchange, Object value) throws TypeConversionException, NoTypeConversionAvailableException; /** * Tries to convert the value to the specified type, * returning null if not possible to convert. *

* This method will not throw an exception if an exception occurred during conversion. * * @param type the requested type * @param value the value to be converted * @return the converted value, or null if not possible to convert */ T tryConvertTo(Class type, Object value); /** * Tries to convert the value to the specified type in the context of an exchange, * returning null if not possible to convert. *

* This method will not throw an exception if an exception occurred during conversion. * Converts the value to the specified type in the context of an exchange *

* Used when conversion requires extra information from the current * exchange (such as encoding). * * @param type the requested type * @param exchange the current exchange * @param value the value to be converted * @return the converted value, or null if not possible to convert */ T tryConvertTo(Class type, Exchange exchange, Object value); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy