⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reflector.java

📁 基于数据库操作的封装
💻 JAVA
字号:
package org.shaoye.magic.reflector;

import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.Hashtable;
import java.util.Enumeration;

import org.shaoye.magic.oracle.Execute;

/**
 * @author zhangt
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class Reflector {

	//private Object obj;
	private String className;
	private Hashtable hashtable;

	public Reflector( String _className, Hashtable _hashtable) {
		//obj = _obj;
		className = _className;
		hashtable = _hashtable;
	}

	/**
	 * 
	 * 
	 */

	public Object runReflect() throws Exception, InvocationTargetException {

		Object newObj = Class.forName(className).newInstance();

		Method[] methods = Class.forName(className).getMethods();

		Enumeration hash_names = hashtable.keys();

		String value = null;

		while (hash_names.hasMoreElements()) 
		{
			value = (String)hash_names.nextElement();
			for (int j = 0; j < methods.length; j++) 
			{
				String meth_name = methods[j].getName();
				if (meth_name.startsWith("set")) 
				{
					meth_name = meth_name.substring(3, meth_name.length());
					if (meth_name.equalsIgnoreCase(value)) 
					{
						methods[j].invoke(newObj, new Object[] { hashtable.get(value) });
					}
				}
			}
		}
		return newObj;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -