WEB开发网
开发学院WEB开发Jsp Java Class 映射及实用工具类完整源代码 阅读

Java Class 映射及实用工具类完整源代码

 2008-01-05 19:10:54 来源:WEB开发网   
核心提示:package com.elink.util;/* * <p>Company: 凌科软件 www.elingke.com </p> * @author liubaojun * @version 1.0 * Created on 2004-11-29 * 来源于 elinkBSP 部分源代码 */

  package com.elink.util;

/*
* <p>Company: 凌科软件 www.elingke.com </p>
* @author liubaojun
* @version 1.0
* Created on 2004-11-29
* 来源于 elinkBSP 部分源代码
*/

import java.lang.reflect.*;
import java.net.*;

public class ClassUtil
{
/**
@param strClassName
@param argsType
@param args
@return Object
@throws java.lang.NoSUChMethodException
@throws java.lang.SecurityException
@throws java.lang.ClassNotFoundException
@throws java.lang.InstantiationException
@throws java.lang.IllegalaccessException
@throws java.lang.IllegalArgumentException
@throws java.lang.reflect.InvocationTargetException
*/
public static Object loadClass(String strClassName, Class[] argsType,
Object[] args)
throws NoSuchMethodException, SecurityException, ClassNotFoundException,
InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException
{
Object returnObj = null;
Class className = null;
Constructor constructor = null;
className = Class.forName(strClassName);
constructor = className.getConstructor(argsType);
returnObj = constructor.newInstance(args);
return returnObj;
}

/**
@param strClassName
@return Object
@throws java.lang.NoSuchMethodException
@throws java.lang.SecurityException
@throws java.lang.ClassNotFoundException
@throws java.lang.InstantiationException
@throws java.lang.IllegalAccessException
@throws java.lang.IllegalArgumentException
@throws java.lang.reflect.InvocationTargetException
*/
public static Object loadClass(String strClassName)
throws NoSuchMethodException, SecurityException, ClassNotFoundException,
InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException
{
return loadClass(strClassName, null, null);
}

public static Object loadClass(String strClassName, Object defObj)
{
try
{
return loadClass(strClassName, null, null);
}
catch( Throwable ex )
{
LogUtil.logException( ex );
}
return defObj;
}

/**
@param classObject
@param strMethodName

Tags:Java Class 映射

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接