📄 classutility.java
字号:
/**
* $RCSfile: ClassUtility.java,v $
* $Revision: 1.1.1.1 $
* $Date: 2004/01/07 05:06:28 $
*
* Copyright (C) 2003 ICSS, Inc. All rights reserved.
*
* This software is the proprietary information of ICSS, Inc.
* Use is subject to license terms.
*/
package com.gctech.misc.util;
import java.io.InputStream;
/**
* <p>Title: OA系统</p>
* <p>Description:
* A utility class to assist with loading classes by name. Many application servers use
* custom classloaders, which will break uses of:
* <pre>
* Class.forName(className);
* </pre>
*
* This utility attempts to load the class using a number of different mechanisms to work
* around this problem.
</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: 中软远东国际</p>
*
* @author Andy
* @version 1.0
*/
public class ClassUtility {
private static ClassUtility instance = new ClassUtility();
/**
* Loads the class with the specified name.
*
* @param className the name of the class
* @return the resulting <code>Class</code> object
* @exception ClassNotFoundException if the class was not found
*/
public static Class forName(String className) throws ClassNotFoundException {
return instance.loadClass(className);
}
public static InputStream getResourceAsStream(String name) {
return instance.loadResource(name);
}
private ClassUtility() {}
public Class loadClass(String className) throws ClassNotFoundException {
Class theClass = null;
try {
theClass = Class.forName(className);
}
catch (ClassNotFoundException e1) {
try {
theClass = Thread.currentThread().getContextClassLoader().loadClass(className);
}
catch (ClassNotFoundException e2) {
theClass = getClass().getClassLoader().loadClass(className);
}
}
return theClass;
}
public InputStream loadResource(String name) {
InputStream in = getClass().getResourceAsStream(name);
if (in == null) {
in = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
if (in == null) {
in = getClass().getClassLoader().getResourceAsStream(name);
}
}
return in;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -