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