1 // Copyright 2004, 2005 The Apache Software Foundation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package org.apache.hivemind; 16 17 import java.net.URL; 18 19 /** 20 * An object which is used to resolve classes and class-path resources. This is needed because, in 21 * an application server, different class loaders may be involved in loading different HiveMind 22 * modules. For example, the HiveMind library may be on the system claasspath, and modules may 23 * include EJBs and WARs, each loaded by a different classloader. 24 * <p> 25 * The class loader for the framework needs to be able to see resources in the application, but the 26 * application's class loader is a descendent of the framework's class loader. To resolve this, we 27 * need a 'hook', an instance that provides access to the application's class loader. 28 * 29 * @author Howard Lewis Ship 30 */ 31 32 public interface ClassResolver 33 { 34 /** 35 * Forwarded, unchanged, to the class loader. Returns null if the resource is not found. 36 */ 37 38 public URL getResource(String name); 39 40 /** 41 * Forwarded, to the the method <code>Class.forName(String, boolean, ClassLoader)</code>, 42 * using the resolver's class loader. 43 * <p> 44 * Since 1.1, the type may include primitive types and arrays (of primitives or of objects). 45 * 46 * @throws ApplicationRuntimeException 47 * on any error. 48 */ 49 50 public Class findClass(String type); 51 52 /** 53 * Like {@link #findClass(String)}, but simply returns null if the class does not exist (i.e., 54 * if {@link ClassNotFoundException} is thrown). This is used in certain spots when (typically) 55 * the exact package for a class is not known. 56 */ 57 58 public Class checkForClass(String type); 59 60 /** 61 * Returns a {@link java.lang.ClassLoader} that can see all the classes the resolver can access. 62 */ 63 64 public ClassLoader getClassLoader(); 65 }