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.util.Optional; 020 021/** 022 * Finder to find factories from the resource classpath, usually <b>META-INF/services/org/apache/camel/</b>. 023 */ 024public interface FactoryFinder { 025 026 /** 027 * Gets the resource classpath. 028 * 029 * @return the resource classpath. 030 */ 031 String getResourcePath(); 032 033 /** 034 * Creates a new class instance using the key to lookup 035 * 036 * @param key is the key to add to the path to find a text file containing the factory name 037 * @return a newly created instance (if exists) 038 */ 039 Optional<Object> newInstance(String key); 040 041 /** 042 * Creates a new class instance using the key to lookup 043 * 044 * @param key is the key to add to the path to find a text file containing the factory name 045 * @param type the class type 046 * @return a newly created instance (if exists) 047 */ 048 <T> Optional<T> newInstance(String key, Class<T> type); 049 050 /** 051 * Finds the given factory class using the key to lookup. 052 * 053 * @param key is the key to add to the path to find a text file containing the factory name 054 * @return the factory class 055 */ 056 Optional<Class<?>> findClass(String key); 057 058 /** 059 * Finds the given factory class using the key to lookup. 060 * 061 * @param key is the key to add to the path to find a text file containing the factory name 062 * @param propertyPrefix prefix on key 063 * @return the factory class 064 */ 065 Optional<Class<?>> findClass(String key, String propertyPrefix); 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 * @param clazz the class which is used for checking compatible 073 * @return the factory class 074 */ 075 Optional<Class<?>> findClass(String key, String propertyPrefix, Class<?> clazz); 076 077 /** 078 * Finds the optional factory class using the key to lookup. 079 * 080 * @param key is the key to add to the path to find a text file containing the factory name 081 * @param propertyPrefix prefix on key 082 * @return the factory class if found, or <tt>null</tt> if no class existed 083 */ 084 Optional<Class<?>> findOptionalClass(String key, String propertyPrefix); 085 086}