?? datafactory.java
字號(hào):
package com.base;
import java.util.Vector;
import java.util.HashMap;
import java.util.Iterator;
import java.lang.reflect.Method;
import com.base.SysException;
import com.erpbase.general.Log;
import com.erpbase.util.StringUtility;
//import com.waveful.cargoflow.bl.commonaudit.EventData;
//import com.waveful.cargoflow.bl.commonaudit.AuditEventData;
public class DataFactory
{
static HashMap hashFields;
/**
*功能:從jsp頁面中得到所有的AuditEventData對(duì)象
*說明:如果jsp中沒有定義審核流程,則此處會(huì)返回一個(gè)null
*/
/*
public static AuditEventData getAuditEvent(CommonData comData)
{
AuditEventData aevData = new AuditEventData();
String strHas_audit_event = comData.getValue("has_audit_event");//是否有審核流程
if(!StringUtility.isNull(strHas_audit_event) && strHas_audit_event.equals("Y"))//有審核流程
{
aevData.setMenuCode(comData.getMenuCode());
aevData.setCorporation(comData.getCor_id());
aevData.setTableName(comData.getValue("audit_event_table"));//審核事件需要記錄的表
String strAuditEvent = comData.getValue("audit_event_id");
aevData.setEventId(strAuditEvent);//用戶選擇的審核事件號(hào)
aevData.setNotneedAudit(comData.getValue("no_audit"));//用戶是否設(shè)置為無需審核
String[] strRlt_order = comData.getValues("rlt_order:"+strAuditEvent);//審核流水順序
String[] strAuthRole = comData.getValues("auth_role:"+strAuditEvent); //得到接收方的角色編碼(審核/核定)
String[] strRoleName = comData.getValues("role_name:"+strAuditEvent); //得到接收方的角色名稱(審核/核定)
String[] strAuditerName = comData.getValues("s_type:"+strAuditEvent); //得到接收方名稱(人/職務(wù)的名稱)
String[] strAuditerCode = comData.getValues("toid:"+strAuditEvent); //得到接收方編碼(人或職務(wù)的編碼)
String[] strDayArray = comData.getValues("day:"+strAuditEvent); //得到轉(zhuǎn)發(fā)的天數(shù)
String[] strHourArray = comData.getValues("hour:"+strAuditEvent); //得到轉(zhuǎn)發(fā)的小時(shí)數(shù)
String[] strTransferCode = comData.getValues("fwtoid:"+strAuditEvent); //得到轉(zhuǎn)發(fā)的接收人編碼
String[] strTransferName = comData.getValues("fwtoname:"+strAuditEvent); //得到轉(zhuǎn)發(fā)的接收人姓名
Vector vctEventData = new Vector();
for (int loop=0; loop<strRlt_order.length; loop++)
{
EventData eventData = new EventData();
eventData.setRlt_order(strRlt_order[loop]);
eventData.setAuthRole(strAuthRole[loop]);
eventData.setRoleName(strRoleName[loop]);
eventData.setDayArray(strDayArray[loop]);
eventData.setHourArray(strHourArray[loop]);
eventData.setTransferCode(strTransferCode[loop]);
eventData.setTransferName(strTransferName[loop]);
eventData.setAuditerName(strAuditerName[loop]);
eventData.setAuditerCode(strAuditerCode[loop]);
vctEventData.addElement(eventData);
}
aevData.setEventData(vctEventData);
}
else aevData.setNotneedAudit("N");
return aevData;
}*/
/**
*功能:從前臺(tái)得到所有的輸入數(shù)據(jù),并且保存在Ojbect中,并且返回此Object
*說明:如果要從頁面中一個(gè)input對(duì)象,name="object_id"的對(duì)象存放物品名稱
*則Object中必須要有一個(gè)setObject_id(String str)的方法,否則將不能保存
*相關(guān)數(shù)據(jù),在保存時(shí),會(huì)自動(dòng)查找所有的set方法,并且會(huì)在前臺(tái)的jsp頁面中
*定義了相關(guān)的對(duì)象才會(huì)把數(shù)據(jù)保存進(jìn)來
*/
public static Object getData(CommonData comData, Object obj)throws SysException
{
try
{
HashMap mapFields = comData.getFieldMap();
HashMap mapMethods = getMapMethod(mapFields, obj);
Iterator iterKeys = (mapMethods.keySet()).iterator();
while(iterKeys.hasNext())
{
String strKey = (String)iterKeys.next();
String strFieldName = (String)mapFields.get(strKey);
String strValue = comData.getValue(strFieldName);
Method theMethod = (Method)mapMethods.get(strKey);
Object[] objValue = {strValue};
theMethod.invoke(obj, objValue);
}
}
catch(Exception ex)
{
Log.printDebug("ssssssssssssssss Exception(getData) sssssssssssssss");
Log.printException(ex);
throw new SysException("throw Exception caused by<br>執(zhí)行方法getData()時(shí)發(fā)生系統(tǒng)錯(cuò)誤!"+ex.getCause().getMessage());
}
return obj;
}
/**
*功能:從前臺(tái)得到所有的輸入數(shù)據(jù),并且保存在Ojbect中,并且返回此Object
*說明:如果要從頁面中一個(gè)input對(duì)象,name="object_id"的對(duì)象存放物品名稱
*則Object中必須要有一個(gè)setObject_id(String str)的方法,否則將不能保存
*相關(guān)數(shù)據(jù),在保存時(shí),會(huì)自動(dòng)查找所有的set方法,并且會(huì)在前臺(tái)的jsp頁面中
*定義了相關(guān)的對(duì)象才會(huì)把數(shù)據(jù)保存進(jìn)來
@param strExceptObjects 指不包含的對(duì)象,就是不包含的對(duì)象,如jsp中有一個(gè)對(duì)象
abc_code,如果不想把此值通過obj中的方法setAbc_code()保存到對(duì)象中
*/
public static Object getData(CommonData comData, Object obj, String strExceptObjects)
throws SysException
{
try
{
if(StringUtility.isNull(strExceptObjects)) strExceptObjects = "";
HashMap mapFields = comData.getFieldMap();
HashMap mapMethods = getMapMethod(mapFields, obj);
Iterator iterKeys = (mapMethods.keySet()).iterator();
while(iterKeys.hasNext())
{
String strKey = (String)iterKeys.next();
String strFieldName = (String)mapFields.get(strKey);
if(strExceptObjects.indexOf(strFieldName)>=0) continue;
String strValue = comData.getValue(strFieldName);
Method theMethod = (Method)mapMethods.get(strKey);
Object[] objValue = {strValue};
theMethod.invoke(obj, objValue);
}
}
catch(Exception ex)
{
Log.printDebug("ssssssssssssssss Exception(getData) sssssssssssssss");
Log.printException(ex);
throw new SysException("throw Exception caused by<br>執(zhí)行方法getData()時(shí)發(fā)生系統(tǒng)錯(cuò)誤!"+ex.getCause().getMessage());
}
return obj;
}
/**
@function:
*說明:如前臺(tái)的jsp頁面中定義多個(gè)名為object_id的對(duì)象,Object中的有一個(gè)setObject_id()
*的方法
@return 返回的Vector中的每一個(gè)元素都是一個(gè)Object對(duì)象,并且已經(jīng)把頁面中的值存放
在此對(duì)象中
*/
public static Vector getDatas(CommonData comData, Object obj)throws SysException
{
Vector vctData = new Vector();
try
{
//得到所有需要存放值的方法
HashMap mapMethods = getMapMethod(comData.getFieldMap(), obj);
//從前臺(tái)得到所有的值
HashMap mapValues = comData.getValues(hashFields);
int iValuesLength = comData.getValuesLength();
for(int loop=0; loop<iValuesLength; loop++)
{
Object oneObj = obj.getClass().newInstance();
Iterator iterKeyMap = (mapValues.keySet()).iterator();
while(iterKeyMap.hasNext())
{
String strKey = (String)iterKeyMap.next();
String[] strValues = (String[])mapValues.get(strKey);
if( strValues.length>loop)
{
Method theMethod = (Method)mapMethods.get(strKey);
String strValue = strValues[loop];
//Log.printDebug("在getDatas方法中strKey="+strKey+" || strValue="+strValue);
Object[] objValue = {strValue};
theMethod.invoke(oneObj, objValue);
}
}
vctData.addElement(oneObj);
}
}
catch(Exception ex)
{
Log.printDebug("ssssssssssssss Exception(getDatas) sssssssssssssss");
Log.printException(ex);
throw new SysException("throw Exception caused by<br>執(zhí)行方法getDatas()時(shí)發(fā)生系統(tǒng)錯(cuò)誤!"+ex.getCause().getMessage());
}
return vctData;
}
/**
@function:
*說明:如前臺(tái)的jsp頁面中定義多個(gè)名為object_id的對(duì)象,Object中的有一個(gè)setObject_id()
*的方法
@return 返回的Vector中的每一個(gè)元素都是一個(gè)Object對(duì)象,并且已經(jīng)把頁面中的值存放
在此對(duì)象中
*/
public static Vector getDatas(CommonData comData, Object obj, String strExceptObjects)
throws SysException
{
Vector vctData = new Vector();
if(StringUtility.isNull(strExceptObjects)) strExceptObjects = "";
try
{
//得到所有需要存放值的方法
HashMap mapMethods = getMapMethod(comData.getFieldMap(), obj);
//從前臺(tái)得到所有的值
HashMap mapValues = comData.getValues(hashFields);
int iValuesLength = comData.getValuesLength();
for(int loop=0; loop<iValuesLength; loop++)
{
Object oneObj = obj.getClass().newInstance();
Iterator iterKeyMap = (mapValues.keySet()).iterator();
while(iterKeyMap.hasNext())
{
String strKey = (String)iterKeyMap.next();
if(strExceptObjects.indexOf(strKey)>=0) continue;
String[] strValues = (String[])mapValues.get(strKey);
if( strValues.length>loop)
{
Method theMethod = (Method)mapMethods.get(strKey);
String strValue = strValues[loop];
//Log.printDebug("在getDatas方法中strKey="+strKey+" || strValue="+strValue);
Object[] objValue = {strValue};
theMethod.invoke(oneObj, objValue);
}
}
vctData.addElement(oneObj);
}
}
catch(Exception ex)
{
Log.printDebug("ssssssssssssss Exception(getDatas) sssssssssssssss");
Log.printException(ex);
throw new SysException("throw Exception caused by<br>執(zhí)行方法getDatas()時(shí)發(fā)生系統(tǒng)錯(cuò)誤!"+ex.getCause().getMessage());
}
return vctData;
}
/**
*功能:得到所有前臺(tái)jsp頁面中有request field對(duì)應(yīng)的所有的方法
@param mapFields中存放所有前臺(tái)的input對(duì)象,包括通過url進(jìn)行的參數(shù)傳遞
*/
private static HashMap getMapMethod(HashMap mapFields, Object obj)
{
hashFields = new HashMap();
HashMap mapMethods = new HashMap();
Class thisClass = obj.getClass();
getClassMethod( mapFields,thisClass,mapMethods);
Class superClass1 = thisClass.getSuperclass();
if( superClass1!=null && !superClass1.getName().equals("java.lang.Object"))
{
getClassMethod( mapFields,superClass1,mapMethods);
Class superClass2 = superClass1.getSuperclass();
if( superClass2!=null && !superClass2.getName().equals("java.lang.Object"))
getClassMethod( mapFields,superClass2,mapMethods);
}
return mapMethods;
}
/**
* 功能:獲得類對(duì)象中的與前臺(tái)jsp頁面字段對(duì)應(yīng)的set方法
*
*/
private static void getClassMethod( HashMap mapFields, Class cla,HashMap mapMethods)
{
Method[] classMethod = cla.getDeclaredMethods();
for(int outLoop=0; outLoop< classMethod.length; outLoop++)
{
String strMethodName = ( classMethod[outLoop]).getName();
if(strMethodName.startsWith("set"))
{
strMethodName = strMethodName.substring(3).toLowerCase();
String strMethodNameLower = strMethodName;
strMethodNameLower = strMethodNameLower.toLowerCase();
if(mapFields.containsKey(strMethodNameLower))
{
mapMethods.put(strMethodNameLower, classMethod[outLoop]);
hashFields.put(strMethodNameLower, (String)mapFields.get(strMethodNameLower));
}
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -