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