package xin.glue.ui.B.common; import javax.crypto.spec.PSource; import com.posdata.glue.biz.activity.PosActivity; import com.posdata.glue.biz.constants.PosBizControlConstants; import com.posdata.glue.context.PosContext; import com.posdata.glue.dao.PosDaoException; import com.posdata.glue.dao.PosGenericDao; import com.posdata.glue.dao.vo.PosParameter; import com.posdata.glue.dao.vo.PosRowSet; /** * * @Description 页面初始化 * @author 梅贵平{meiguiping} * @date 2008-10-30 下午08:42:42 * @JDK Version jdk1.4.2 */ public class XgSimpleInit extends PosActivity { public XgSimpleInit(){} public String runActivity(PosContext context) { try { if(context.get("success")==null)//若触发的非success事件,则不进行初始化查询 { return PosBizControlConstants.SUCCESS; } String sCount = this.getProperty("sqlCount"); //判断页面是否需要初始化 if(sCount != null) { PosGenericDao posDao =this.getDao("mesdao"); //this.getDao(this.getProperty("mesdao"));//获得数据访问对象 String[] rkl = (String[])context.get("ResultKeyList"); int rklLength = 0; if(rkl !=null) { rklLength = rkl.length; } int iCount = Integer.parseInt(sCount.trim());//获取所对应的sql语句的个数 String[] arrSql = new String[iCount];//定义存放sqllist的数组 String[] nodeList = new String[iCount];//定义存放各sql语句参数的数组 int arrCount = iCount+rklLength; String[] arr = new String[arrCount];//各查询结果对象(PosRowSet)放入该数组, arr将存放到ResultKeyList中 String[] findResult = this.getProperty("FindKeyList").split("\\|");//分割resultkey //循环中存放参数及执行相应的SQL语句 for(int i=0; i < iCount; i++) { PosParameter posParam = new PosParameter(); arrSql[i] = this.getProperty("sqlkey"+i);//获得各条sql语句 nodeList[i] = this.getProperty("param"+i);//获得各条sql语句的参数 如:"ID|NAME|CHARGE_NO|XIN_DATE" arr[i] = findResult[i]; //获得各具体的PosRowSet存放对象,如:EmpListResult if(nodeList[i] !=null) { String[] nodeName = nodeList[i].split("\\|");//获取各个具体的参数,即节点名称 //sql预处理 for(int j=0; j < nodeName.length; j++) { posParam.setWhereClauseParameter(j, ((String[])context.get(nodeName[j]))[0]); } }//if(isNull) end PosRowSet rowset = posDao.find(arrSql[i], posParam); context.put(arr[i], rowset);//将结果集放入相应的resultkey中 }//for(iCount) end if(rkl!=null) { System.arraycopy(rkl, 0, arr, iCount, rklLength);//数组copy 将initResult初始化结果集也放到ResultKeyList中 }//if(rkl) end context.put("ResultKeyList", arr); }//if(sCount)end } catch(Exception ex) { throw new PosDaoException((new StringBuffer(400).append("Parameters initialize failed. detailMessage = ")).append(ex.toString()).toString() , ex); // System.out.println(ex.toString()); } return PosBizControlConstants.SUCCESS; } }