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.InputStream;
020
021 /**
022 * A class resolver for loading classes in a loosly coupled manner to cater for different platforms such
023 * as standalone, web container, j2ee container and OSGi platforms.
024 */
025 public interface ClassResolver {
026
027 /**
028 * Resolves the given class by its name
029 *
030 * @param name full qualified name of class
031 * @return the class if resolved, <tt>null</tt> if not found.
032 */
033 Class resolveClass(String name);
034
035 /**
036 * Resolves the given class by its name
037 *
038 * @param name full qualified name of class
039 * @param type the expected type of the class
040 * @return the class if resolved, <tt>null</tt> if not found.
041 */
042 <T> Class<T> resolveClass(String name, Class<T> type);
043
044 /**
045 * Resolves the given class by its name
046 *
047 * @param name full qualified name of class
048 * @param loader use the provided class loader
049 * @return the class if resolved, <tt>null</tt> if not found.
050 */
051 Class resolveClass(String name, ClassLoader loader);
052
053 /**
054 * Resolves the given class by its name
055 *
056 * @param name full qualified name of class
057 * @param type the expected type of the class
058 * @param loader use the provided class loader
059 * @return the class if resolved, <tt>null</tt> if not found.
060 */
061 <T> Class<T> resolveClass(String name, Class<T> type, ClassLoader loader);
062
063 /**
064 * Resolves the given class by its name
065 *
066 * @param name full qualified name of class
067 * @return the class if resolved, <tt>null</tt> if not found.
068 * @throws ClassNotFoundException is thrown if class not found
069 */
070 Class resolveMandatoryClass(String name) throws ClassNotFoundException;
071
072 /**
073 * Resolves the given class by its name
074 *
075 * @param name full qualified name of class
076 * @param type the expected type of the class
077 * @return the class if resolved, <tt>null</tt> if not found.
078 * @throws ClassNotFoundException is thrown if class not found
079 */
080 <T> Class<T> resolveMandatoryClass(String name, Class<T> type) throws ClassNotFoundException;
081
082 /**
083 * Resolves the given class by its name
084 *
085 * @param name full qualified name of class
086 * @return the class if resolved, <tt>null</tt> if not found.
087 * @param loader use the provided class loader
088 * @throws ClassNotFoundException is thrown if class not found
089 */
090 Class resolveMandatoryClass(String name, ClassLoader loader) throws ClassNotFoundException;
091
092 /**
093 * Resolves the given class by its name
094 *
095 * @param name full qualified name of class
096 * @param type the expected type of the class
097 * @param loader use the provided class loader
098 * @return the class if resolved, <tt>null</tt> if not found.
099 * @throws ClassNotFoundException is thrown if class not found
100 */
101 <T> Class<T> resolveMandatoryClass(String name, Class<T> type, ClassLoader loader) throws ClassNotFoundException;
102
103 /**
104 * Loads the given resource as a stream
105 * @param uri the uri of the resource
106 * @return as a stream
107 */
108 InputStream loadResourceAsStream(String uri);
109
110 }