001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.spi; 018 019 import java.util.Iterator; 020 import java.util.List; 021 022 import org.apache.camel.StaticService; 023 import org.apache.camel.TypeConverter; 024 import org.apache.camel.util.KeyValueHolder; 025 026 /** 027 * Registry for type converters. 028 * <p/> 029 * The utilization {@link Statistics} is by default disabled, as it has a slight performance impact under very high 030 * concurrent load. The statistics can be enabled using {@link Statistics#setStatisticsEnabled(boolean)} method. 031 * 032 * @version 033 */ 034 public interface TypeConverterRegistry extends StaticService { 035 036 /** 037 * Utilization statistics of the this registry. 038 */ 039 interface Statistics { 040 041 /** 042 * Number of attempts 043 */ 044 long getAttemptCounter(); 045 046 /** 047 * Number of successful conversions 048 */ 049 long getHitCounter(); 050 051 /** 052 * Number of attempts which cannot be converted as no suitable type converter exists 053 */ 054 long getMissCounter(); 055 056 /** 057 * Number of failed attempts during type conversion 058 */ 059 long getFailedCounter(); 060 061 /** 062 * Reset the counters 063 */ 064 void reset(); 065 066 /** 067 * Whether statistics is enabled. 068 */ 069 boolean isStatisticsEnabled(); 070 071 /** 072 * Sets whether statistics is enabled. 073 * 074 * @param statisticsEnabled <tt>true</tt> to enable 075 */ 076 void setStatisticsEnabled(boolean statisticsEnabled); 077 } 078 079 /** 080 * Registers a new type converter 081 * 082 * @param toType the type to convert to 083 * @param fromType the type to convert from 084 * @param typeConverter the type converter to use 085 */ 086 void addTypeConverter(Class<?> toType, Class<?> fromType, TypeConverter typeConverter); 087 088 /** 089 * Removes the type converter 090 * 091 * @param toType the type to convert to 092 * @param fromType the type to convert from 093 * @return <tt>true</tt> if removed, <tt>false</tt> if the type converter didn't exist 094 */ 095 boolean removeTypeConverter(Class<?> toType, Class<?> fromType); 096 097 /** 098 * Registers a new fallback type converter 099 * 100 * @param typeConverter the type converter to use 101 * @param canPromote whether or not the fallback type converter can be promoted to a first class type converter 102 */ 103 void addFallbackTypeConverter(TypeConverter typeConverter, boolean canPromote); 104 105 /** 106 * Performs a lookup for a given type converter. 107 * 108 * @param toType the type to convert to 109 * @param fromType the type to convert from 110 * @return the type converter or <tt>null</tt> if not found. 111 */ 112 TypeConverter lookup(Class<?> toType, Class<?> fromType); 113 114 /** 115 * Gets a read-only list of the type converter from / to classes 116 * 117 * @return a list containing fromType/toType class names 118 */ 119 List<Class[]> listAllTypeConvertersFromTo(); 120 121 /** 122 * Sets the injector to be used for creating new instances during type conversions. 123 * 124 * @param injector the injector 125 */ 126 void setInjector(Injector injector); 127 128 /** 129 * Gets the injector 130 * 131 * @return the injector 132 */ 133 Injector getInjector(); 134 135 /** 136 * Gets the utilization statistics of this type converter registry 137 * 138 * @return the utilization statistics 139 */ 140 Statistics getStatistics(); 141 142 /** 143 * Number of type converters in the registry. 144 * 145 * @return number of type converters in the registry. 146 */ 147 int size(); 148 149 }