valueobject.java

来自「采用web2.0技术,采用动态标签,sql语句全部存储在数据库里面.开发速度快.」· Java 代码 · 共 261 行

JAVA
261
字号
package com.sztheater.framework.util;

import java.io.*;
import java.util.*;
/**
 * <p>Title:</p>
 * <p>Description:</p>
 * <p> </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author 王练军
 * @version 1.0
 */
public class ValueObject{
	protected HashMap      m_ResultSet   = null; /*结果集HashMap*/
	protected HashMap      m_ParamMap    = null; /*参数HashMap*/
	protected HashMap      m_UserInfo    = null; /*参数HashMap*/
	protected HashMap      m_LoginUser   = null; /*参数HashMap*/
	protected HashMap      m_PageMap     = null; /*分页HashMap*/
	protected String       m_func_id     = null; /*功能号*/
	protected String       m_action_id   = null; /*动作*/
	protected String       m_message     = null; /*返回信息*/
	protected String       m_exception   = null; /**业务功能调用返回的异常信息*/
	protected int          m_succ_flag   = 0   ; /*成功标志*/
	protected StringBuffer m_trace_msg   = null; /*跟踪信息*/
	
	public void free(){
		if(m_trace_msg!=null) {
			m_trace_msg.delete(0,m_trace_msg.length());
			m_trace_msg.setLength(0);
		}
			
		this.m_func_id = "";
		CommFunc.freeObj(m_ResultSet);
		CommFunc.freeObj(m_ParamMap );
		CommFunc.freeObj(m_PageMap  );
		m_ResultSet = null;
		m_ParamMap  = null;
		m_PageMap   = null;
		m_trace_msg = null;
	}
	public ValueObject(){
		free();
		m_ResultSet   = new HashMap();
		m_ParamMap    = new HashMap();
		m_PageMap     = new HashMap();
	}
	public void setTrace(boolean bTrace){
		if(m_trace_msg==null && bTrace) {
			m_trace_msg = new StringBuffer("");
			return ;
		}
		if(!bTrace){
			if(m_trace_msg!=null) {
				m_trace_msg.delete(0,m_trace_msg.length());
				m_trace_msg.setLength(0);
				m_trace_msg = null;
			}
		}		
	}
	public void addTrace(String s_trace){
		if(s_trace==null || m_trace_msg==null) return ;
		m_trace_msg.append("\n");
		m_trace_msg.append(s_trace);
	}
	public String getTrace(){
		String s_trace = "";
		if(m_trace_msg!=null) {
			s_trace = m_trace_msg.toString();
		}
		return s_trace;		
	}
	
	public StringBuffer getTraceBuffer(){
		return m_trace_msg;		
	}
	public void setFuncID(String func_id){
		if(func_id==null ) func_id = "";
		func_id = func_id.trim();
		this.m_func_id = func_id;
	}
	public void setActionID(String action_id){
		if(action_id==null) action_id = "";
		action_id = action_id.trim();
		this.m_action_id = action_id;
	}
	public String getFuncID(){
		if(this.m_func_id==null) this.m_func_id = "";
		this.m_func_id = this.m_func_id.trim();
		if(this.m_func_id.equals("")){
			this.m_func_id = CommFunc.getValue(m_ParamMap,"func","",true);
		}
		if(this.m_func_id.equals("")) {
			this.m_func_id = CommFunc.getValue(m_ParamMap,"FUNC_ID","",true);
		}
		if(this.m_func_id.equals("")) {
			this.m_func_id = CommFunc.getValue(m_ParamMap,"func_id","",true);
		}
		return this.m_func_id;
	}
	public String getActionID(){
		if(this.m_action_id==null) this.m_action_id = "";
		this.m_action_id = this.m_action_id.trim();
		if(this.m_action_id.equals("")){
			this.m_action_id = CommFunc.getValue(m_ParamMap,"action","",true);
		}
		if(this.m_action_id.equals("")) {
			this.m_action_id = CommFunc.getValue(m_ParamMap,"ACTION_ID","",true);
		}
		if(this.m_action_id.equals("")) {
			this.m_action_id = CommFunc.getValue(m_ParamMap,"action_id","",true);
		}
		return this.m_action_id;
	}
	public String getMessage(){
		if(this.m_message==null) return "";
		return this.m_message;
	}
	public int setErrMsg(int iFlag,String sMessage){
		if(sMessage==null || sMessage.trim().equals("")) sMessage = "";
		this.m_succ_flag = iFlag;
		this.m_message   = sMessage;
		return iFlag;
	}
	public int setErrMsg(String sMessage){
		int    iFlag = -1;
		int    iPos  = 0;
		String sErr  = "-1";
		if(sMessage==null) sMessage = "";
		
		iPos  = sMessage.indexOf(" ");
		if(iPos>0){
			sErr     = sMessage.substring(0,iPos);
			sMessage = sMessage.substring(iPos + 1);
		}
		sErr = sErr.trim();
		try{
			iFlag = Integer.parseInt(sErr);
		}catch(Exception e){
		
		}
		return setErrMsg(iFlag,sMessage);
	}
	public int getFlag(){
		return this.m_succ_flag;
	}
	/**从业务功能调用结果中取异常信息,可以用EL表达式${return.exception},其中return为本类的一个实例*/
	public String getException() {
		if(this.m_exception==null) return "";
		return this.m_exception;
	}
	public void setException(String s_exception){
		if(s_exception==null) s_exception = "" ;
		this.m_exception = s_exception;
	}
	public void setException(Exception e){
		this.m_exception = "";
		if(e!=null) this.m_exception =e.getMessage();
	}
	/*登录用户信息*/
	public HashMap getUser() {
		return this.m_UserInfo;
	}
	public HashMap getLoginUser() {
		return this.m_LoginUser;
	}
	public void setLoginUser(HashMap hashUser) {
		if(this.m_LoginUser==null) this.m_LoginUser = new HashMap();
		CommFunc.copyData(hashUser,this.m_LoginUser);
	}
	public void setUser(HashMap hashUser) {
		if(this.m_UserInfo==null) this.m_UserInfo = new HashMap();
		CommFunc.copyData(hashUser,this.m_UserInfo);
	}
	
	/**从业务功能调用结果中取返回参数,可以用EL表达式${return.param.testparam.}*/
	public HashMap getParam() {
		return this.m_ParamMap;
	}
	public String getParameter(String paraName) {
		if(this.m_ParamMap==null || paraName==null) return null;
		paraName = paraName.trim();
		return (String)this.m_ParamMap.get(paraName);
	}
	public String getParameter(String paraName,String strDef,boolean bTrim) {
		if(this.m_ParamMap==null || paraName==null) return null;
		paraName = paraName.trim();
		
		String paraValue = (String)this.m_ParamMap.get(paraName);
		if(paraValue==null) paraValue = strDef;
		if(bTrim) paraValue = paraValue.trim();
		return paraValue;
	}
	public void putParam(String paramName,Object paramValue){
		if(m_ParamMap==null) m_ParamMap = new HashMap();
		this.m_ParamMap.put(paramName,paramValue);
	}
	public void putParam(HashMap hashPara){
		if(m_ParamMap==null) m_ParamMap = new HashMap();
		CommFunc.freeObj(this.m_ParamMap);
		CommFunc.copyData(hashPara,this.m_ParamMap);
	}
	
	/**从业务功能调用结果中取某一结果集*/
	public HashMap getResultSet() {
		return this.m_ResultSet;
	}
	public ArrayList getDataSet(String rs_name) {
		if(this.m_ResultSet==null|| rs_name==null ||  rs_name.trim().equals("")) return null;
		rs_name = rs_name.trim();
		Object obj = this.m_ResultSet.get(rs_name);
		ArrayList aList = null;
		if(obj==null || !obj.getClass().getName().equals("java.util.ArrayList")) return null;
		aList = new ArrayList();
		CommFunc.copyData( (ArrayList) obj,aList);
		return aList;
	}
	public void putResultSet(String resultSetName,Object resultSetValue){
		if(m_ResultSet==null) m_ResultSet = new HashMap();
		this.m_ResultSet.put(resultSetName,resultSetValue);
	}
	/*分页HashMap*/
	public HashMap getPage() {
		return this.m_PageMap;
	}
	public int getPageInfo(String resultSetName,String pageField) {
		if(this.m_PageMap==null || resultSetName==null) return 0;
		resultSetName = resultSetName.trim();
		
		HashMap aHash  = (HashMap)this.m_PageMap.get(resultSetName);
		if(aHash==null) return 0;
		
		String  s_value= (String)aHash.get(pageField);
		return CommFunc.strToInt(s_value,0);
	}
	public void putPage(String resultSetName,String pageField,int pageValue){
		if(this.m_PageMap==null) this.m_PageMap = new HashMap();
		
		HashMap hashPage = null;
		hashPage = (HashMap)this.m_PageMap.get(resultSetName);
		if(hashPage==null){
			hashPage = new HashMap();
			this.m_PageMap.put(resultSetName,hashPage);
		}
		hashPage.put(pageField,String.valueOf(pageValue));
	}
	public String getXml() {
		String strXML = "";
		strXML += "<func_id>"    + m_func_id    + "</func_id>\n";
		strXML += "<action_id>"  + m_action_id  + "</action_id>\n";
		strXML += "<message>"    + getMessage() + "</message>\n";
		strXML += "<exception>"  + m_exception  + "</exception>\n";
		strXML += "<trace_msg>"  + getTrace()   + "</trace_msg>\n";
		strXML += "<用户>\n"  +CommFunc.toString(m_UserInfo  ,true)+"</用户>\n";
		strXML += "<结果集>\n"+CommFunc.toString(m_ResultSet ,true)+"</结果集>\n";
		strXML += "<参数>\n"  +CommFunc.toString(m_ParamMap  ,true)+"</参数>\n";
		strXML += "<分页>\n"  +CommFunc.toString(m_PageMap   ,true)+"</分页>\n";
		strXML += "<用户>\n"  +CommFunc.toString(m_UserInfo  ,true)+"</用户>\n";
		return strXML;
	}
}

⌨️ 快捷键说明

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