首页>代码>JBPM实例demo>/JbpmSource/src/com/ktvoa/process/action/MyBeanHelpers.java
package com.ktvoa.process.action;

import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.Serializable;
import java.lang.reflect.Method;


import com.ktv.lyk.bean.BeanHelper;
/**
 * 
* @类名: MyBeanHelpers
* @描述: TODO(反射帮助类)
* @作者 LYK
* @创建日期 2013-5-27 下午01:13:02
*
 */
public class MyBeanHelpers implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3669020648421624404L;

	/**
	 * 将实例化的对象赋给令一个对象
	 * 
	 * @param instanceObject
	 * @param instanceAtr
	 * @param clazz
	 * @param clazzAtr
	 */
	public static Object invokeBeanToAnthoer(Object instanceObject,
			String[] instanceAtr, Class<? extends Object> clazz,
			String[] clazzAtr) {
		
		Object newObject = null;
		if(null!=instanceObject)
			
		{

		/*
		 * if(instanceAtr.length!=clazzAtr.length) return;
		 */
		newObject = BeanHelper.newObject(clazz);
		int index = 0;
		PropertyDescriptor[] props = null;
		try {
			props = Introspector.getBeanInfo(instanceObject.getClass(),
					Object.class).getPropertyDescriptors();

			for (String instance : instanceAtr) {

				for (int i = 0, size = props.length; i < size; i++) {
					if (props[i].getName().equals(instance)) {
						 Object o= props[i].getReadMethod()
							.invoke(instanceObject);
						String value =(o==null)?"":o.toString();
						Class<?> type = props[i].getReadMethod()
								.getReturnType();
						Method set = newObject.getClass().getMethod(
								getSetMethodName(clazzAtr[index]), type);
						set.invoke(newObject, new Object[] { value });
						index++;

					}
				}

			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
}
		return newObject;

	}

	private static String getSetMethodName(String n) {
		String v = (n.charAt(0) + "").toUpperCase()
				+ n.substring(1, n.length());
		return "set" + v;
	}

}
最近下载更多
胜过这首歌  LV2 2023年6月27日
17852250910  LV2 2021年12月27日
157554513749  LV11 2020年8月1日
xuyongff  LV24 2020年3月3日
chaoy_nx  LV8 2020年2月25日
三生石sh1  LV13 2019年10月21日
逛逛逛  LV2 2019年8月13日
alreadyhome  LV10 2019年6月6日
hanl  LV12 2019年2月22日
wj024835  LV8 2019年1月25日
最近浏览更多
胜过这首歌  LV2 2023年6月27日
liuzejuncn  LV6 2022年3月27日
17852250910  LV2 2021年12月27日
qwqqwq123 2021年7月14日
暂无贡献等级
hollwomanc  LV1 2021年4月9日
pxqtsht  LV15 2021年4月1日
zhaoyu_2016  LV2 2021年1月12日
chenliuyang 2020年10月13日
暂无贡献等级
随便取个名字_哈哈  LV27 2020年10月5日
157554513749  LV11 2020年8月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友