龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

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

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
package com.elink.util; /* * pCompany: 凌科软件 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

  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
  
精彩图集

赞助商链接