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.io.IOException;
020    import java.util.List;
021    
022    import org.apache.camel.NoFactoryAvailableException;
023    
024    /**
025     * Finder to find factories from the resource classpath, usually <b>META-INF/services/org/apache/camel/</b>.
026     *
027     * @version 
028     */
029    public interface FactoryFinder {
030    
031        /**
032         * Gets the resource classpath.
033         *
034         * @return the resource classpath.
035         */
036        String getResourcePath();
037    
038        /**
039         * Creates a new class instance using the key to lookup
040         *
041         * @param key is the key to add to the path to find a text file containing the factory name
042         * @return a newly created instance
043         * @throws org.apache.camel.NoFactoryAvailableException is thrown if no factories exist for the given key
044         */
045        Object newInstance(String key) throws NoFactoryAvailableException;
046    
047        /**
048         * Creates a new class instance using the key to lookup
049         *
050         * @param key is the key to add to the path to find a text file containing the factory name
051         * @param injector injector to use
052         * @param type expected type
053         * @return a newly created instance as the expected type
054         * @throws ClassNotFoundException is thrown if not found
055         * @throws java.io.IOException is thrown if loading the class or META-INF file not found
056         */
057        <T> List<T> newInstances(String key, Injector injector, Class<T> type) throws ClassNotFoundException, IOException;
058    
059        /**
060         * Finds the given factory class using the the key to lookup.
061         *
062         * @param key is the key to add to the path to find a text file containing the factory name
063         * @return the factory class
064         * @throws ClassNotFoundException is thrown if class not found
065         * @throws java.io.IOException is thrown if loading the class or META-INF file not found
066         */
067        Class<?> findClass(String key) throws ClassNotFoundException, IOException;
068    
069        /**
070         * Finds the given factory class using the the key to lookup.
071         *
072         * @param key is the key to add to the path to find a text file containing the factory name
073         * @param propertyPrefix prefix on key
074         * @return the factory class
075         * @throws ClassNotFoundException is thrown if not found
076         * @throws java.io.IOException is thrown if loading the class or META-INF file not found
077         */
078        Class<?> findClass(String key, String propertyPrefix) throws ClassNotFoundException, IOException;
079    
080        /**
081         * Finds the given factory class using the the key to lookup.
082         *
083         * @param key is the key to add to the path to find a text file containing the factory name
084         * @param propertyPrefix prefix on key
085         * @param clazz the class which is used for checking compatible
086         * @return the factory class
087         * @throws ClassNotFoundException is thrown if not found
088         * @throws java.io.IOException is thrown if loading the class or META-INF file not found
089         */
090        Class<?> findClass(String key, String propertyPrefix, Class<?> clazz) throws ClassNotFoundException, IOException;
091    }