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 org.apache.camel.Service;
020    import org.apache.camel.TypeConverter;
021    
022    /**
023     * Registry for type converters.
024     *
025     * @version 
026     */
027    public interface TypeConverterRegistry extends Service {
028    
029        /**
030         * Utilization statistics of the this registry.
031         */
032        interface Statistics {
033    
034            /**
035             * Number of attempts
036             */
037            long getAttemptCounter();
038    
039            /**
040             * Number of successful conversions
041             */
042            long getHitCounter();
043    
044            /**
045             * Number of attempts which cannot be converted as no suitable type converter exists
046             */
047            long getMissCounter();
048    
049            /**
050             * Number of failed attempts during type conversion
051             */
052            long getFailedCounter();
053    
054            /**
055             * Reset the counters
056             */
057            void reset();
058        }
059    
060        /**
061         * Registers a new type converter
062         *
063         * @param toType        the type to convert to
064         * @param fromType      the type to convert from
065         * @param typeConverter the type converter to use
066         */
067        void addTypeConverter(Class<?> toType, Class<?> fromType, TypeConverter typeConverter);
068    
069        /**
070         * Registers a new fallback type converter
071         *
072         * @param typeConverter the type converter to use
073         * @param canPromote  whether or not the fallback type converter can be promoted to a first class type converter
074         */
075        void addFallbackTypeConverter(TypeConverter typeConverter, boolean canPromote);
076    
077        /**
078         * Performs a lookup for a given type converter.
079         *
080         * @param toType        the type to convert to
081         * @param fromType      the type to convert from
082         * @return the type converter or <tt>null</tt> if not found.
083         */
084        TypeConverter lookup(Class<?> toType, Class<?> fromType);
085    
086        /**
087         * Sets the injector to be used for creating new instances during type conversions.
088         *
089         * @param injector the injector
090         */
091        void setInjector(Injector injector);
092    
093        /**
094         * Gets the injector
095         *
096         * @return the injector
097         */
098        Injector getInjector();
099    
100        /**
101         * Gets the utilization statistics of this type converter registry
102         *
103         * @return the utilization statistics
104         */
105        Statistics getStatistics();
106    
107    }