001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.hivemind;
016
017 import java.net.URL;
018
019 /**
020 * An object which is used to resolve classes and class-path resources. This is needed because, in
021 * an application server, different class loaders may be involved in loading different HiveMind
022 * modules. For example, the HiveMind library may be on the system claasspath, and modules may
023 * include EJBs and WARs, each loaded by a different classloader.
024 * <p>
025 * The class loader for the framework needs to be able to see resources in the application, but the
026 * application's class loader is a descendent of the framework's class loader. To resolve this, we
027 * need a 'hook', an instance that provides access to the application's class loader.
028 *
029 * @author Howard Lewis Ship
030 */
031
032 public interface ClassResolver
033 {
034 /**
035 * Forwarded, unchanged, to the class loader. Returns null if the resource is not found.
036 */
037
038 public URL getResource(String name);
039
040 /**
041 * Forwarded, to the the method <code>Class.forName(String, boolean, ClassLoader)</code>,
042 * using the resolver's class loader.
043 * <p>
044 * Since 1.1, the type may include primitive types and arrays (of primitives or of objects).
045 *
046 * @throws ApplicationRuntimeException
047 * on any error.
048 */
049
050 public Class findClass(String type);
051
052 /**
053 * Like {@link #findClass(String)}, but simply returns null if the class does not exist (i.e.,
054 * if {@link ClassNotFoundException} is thrown). This is used in certain spots when (typically)
055 * the exact package for a class is not known.
056 */
057
058 public Class checkForClass(String type);
059
060 /**
061 * Returns a {@link java.lang.ClassLoader} that can see all the classes the resolver can access.
062 */
063
064 public ClassLoader getClassLoader();
065 }