📄 classutil.java
字号:
/* JSPWiki - a JSP-based WikiWiki clone. Copyright (C) 2001-2003 Janne Jalkanen (Janne.Jalkanen@iki.fi) This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package com.ecyrd.jspwiki.util;import java.util.ArrayList;import java.util.Iterator;import java.util.List;/** * Contains useful utilities for class file manipulation. * * @author Janne Jalkanen * @since 2.1.29. */public class ClassUtil{ /** * Attempts to find a class from a collection of packages. This will first * attempt to find the class based on just the className parameter, but * should that fail, will iterate through the "packages" -list, prefixes * the package name to the className, and then tries to find the class * again. * * @param packages A List of Strings, containing different package names. * @param className The name of the class to find. * @return The class, if it was found. * @throws ClassNotFoundException if this particular class cannot be found * from the list. */ public static Class findClass( List packages, String className ) throws ClassNotFoundException { ClassLoader loader = ClassUtil.class.getClassLoader(); try { return loader.loadClass( className ); } catch( ClassNotFoundException e ) { for( Iterator i = packages.iterator(); i.hasNext(); ) { String packageName = (String)i.next(); try { return loader.loadClass( packageName + "." + className ); } catch( ClassNotFoundException ex ) { // This is okay, we go to the next package. } } } throw new ClassNotFoundException("Class not found in search path!"); } /** * A shortcut for findClass when you only have a singular package to search. * It will first attempt to instantiate the class directly from the className, * and will then try to prefix it with the packageName. * * @param packageName A package name (such as "com.ecyrd.jspwiki.plugins"). * @param className The class name to find. * @return The class, if it was found. * @throws ClassNotFoundException if this particular class cannot be found. */ public static Class findClass( String packageName, String className ) throws ClassNotFoundException { ArrayList list = new ArrayList(); list.add( packageName ); return findClass( list, className ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -