📄 processinfo.java
字号:
package com.base;
import java.sql.*;
import java.util.Vector;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import com.erpbase.general.Log;
import com.erpbase.util.StringUtility;
import com.erpbase.entity.base.CommonItem;
import com.erpbase.entity.base.CommonList;
import com.erpbase.entity.base.ConnectionFactory;
public class ProcessInfo
{
//获得一个数据库连接
private static Connection _conn;
//控制器编码
private static String _strProcessId;
//通用查询结果集
private static CommonItem _item;
/**
* 功能:初始化类方法,设置控制器编码信息。
* @param strProcessId:控制器编码
*/
public static void init( String strProcessId) throws Exception
{
_strProcessId = strProcessId;
if( _conn==null)
_conn = ConnectionFactory.getConnection();
CommonList list = new CommonList();
list.setConnection( _conn);
list.setQuerySQL( getQuerySQL());
Vector vctItem = list.getData();
if( vctItem==null)
{
throw new SysException("没有指定如何处理请求!");
}
if( vctItem.size()==1)
{
_item = ( CommonItem)vctItem.elementAt(0);
}
else
{
throw new SysException("得到的processInfo信息不正确!");
}
}
/**
* 功能:设置控制器编码,此编码唯一确定了CONTROLLERMAPPING表的一条记录
* @param strProcessId:控制器编码
*/
private static void setProcessId( String strProcessId)
{
_strProcessId = strProcessId;
}
/**
* 功能:获得CONTROLLERMAPPING信息的查询语句
*/
private static String getQuerySQL()
{
return "select cm_classpath, cm_methodname, cm_successjsppath, cm_operationnote, cm_isdirectturnto from controllermapping where cm_code='"+_strProcessId+"'";
}
/**
* 功能:获得请求页面的处理类
*/
public static String getProcessClass()
{
String strClass = _item.getValueByIndexOf(0);
return strClass;
}
/**
* 功能:获得请求页面的处理方法
*/
public static String getClassMethod()
{
String strMethod = _item.getValueByIndexOf(1);
return strMethod;
}
/**
* 功能:获得请求处理成功后的转向页面,如果得不到
* 该页面,则主控制器转向一默认得成功页面。
*/
public static String getSuccessPath()
{
String strSuccessPath = _item.getValueByIndexOf(2);
return strSuccessPath;
}
/**
* 功能:获得请求处理成功后转向页面时的业务说明
* 如:入库单修改成功。
*/
public static String getOperationNote()
{
String strOperationNote = _item.getValueByIndexOf(3);
return strOperationNote;
}
/**
* 功能:获得请求处理成功后是否直接转向指定页面,如果是(Y)则主控制器执行完成后
* 直接转向指定页面,如果否(N)则主控制器执行完成后先转向到操作结果提示页,
* 用户通过点击结果提示页"返回"按钮返回到指定页面。如果没有指定操作后转向
* 页面,则此字段不起作用,主控制器执行完成后直接转向操作结果提示页。
*/
public static String getIsDirectTurnTo()
{
String strIsDirectTurnTo = _item.getValueByIndexOf(4);
return strIsDirectTurnTo;
}
/**
* 功能:执行请求的处理。通过查询controllermapping获得用户提交请求
* 信息的处理方法。
* @param CommonData data:用户提交的请求处理信息对象。对象那封装了
* request和session 对象。通过调用此对象的相关方法,可获得页
* 面的请求信息。 throws Exception
*/
public static void execute( CommonData data,HttpServletRequest request)throws ClassNotFoundException,InstantiationException,NoSuchMethodException,IllegalAccessException,Exception
{
try
{
String strClass = getProcessClass();
String strMethod = getClassMethod();
Object obj = Class.forName( strClass).newInstance();
Class[] arrClass = {data.getClass()};
Object[] arrObject = {data};
Method mtd = obj.getClass().getMethod( strMethod,arrClass);
mtd.invoke( obj,arrObject);
HttpServletRequest req = data.getRequest();
Enumeration era = req.getAttributeNames();
while( era.hasMoreElements())
{
String strAttributeName = ( String)era.nextElement();
request.setAttribute( strAttributeName,req.getAttribute( strAttributeName));
}
}
catch( ClassNotFoundException cfe)
{
Log.printException( cfe);
throw new SysException("系统错误:得到处理该请求的类信息错误!",cfe);
}
catch( InstantiationException ite)
{
Log.printException( ite);
throw new SysException( "系统错误:指定类可能为抽象类或接口,无法实例化!",ite);
}
catch( NoSuchMethodException nme)
{
Log.printException( nme);
throw new SysException( "系统错误:得到处理该请求的方法错误!",nme);
}
catch( IllegalAccessException iae)
{
Log.printException( iae);
throw new SysException( "系统错误:无法进入指定类进行请求处理!",iae);
}
catch( InvocationTargetException ite)
{
Log.printException(ite);
Log.printDebug("----------throw Exception caused by----------");
Log.printDebug(ite.getCause().getMessage());
Log.printDebug("---------------------------------------------");
throw new Exception("throw Exception caused by<br>"+ite.getCause().getMessage());
}
catch( Exception e)
{
Log.printException( e);
throw e;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -