📄 actiondef.java
字号:
/*****************************************************************************
* (C) Copyright 2004 。
* 保留对所有使用、复制、修改和发布整个软件和相关文档的权利。
* 本计算机程序受著作权法和国际公约的保护,未经授权擅自复制或
* 传播本程序的全部或部分,可能受到严厉的民事和刑事制裁,并
* 在法律允许的范围内受到最大可能的起诉。
*/
/*****************************************************************************
* @作者:Golden Peng
* @版本: 1.0
* @时间: 2002-10-08
*/
/*****************************************************************************
* 修改记录清单
* 修改人 :
* 修改记录:
* 修改时间:
* 修改描述:
*
*/
package com.corp.bisc.ebiz.base;
import java.util.*;
import org.w3c.dom.*;
import com.corp.bisc.ebiz.util.*;
import com.corp.bisc.ebiz.exception.*;
/**
* Insert the type's description here.
* Creation date: (2002-5-13 11:05:36)
* @author: Administrator
*/
public class ActionDef extends ObjectBase
{
final static public int REQUEST_TYPE_NORMAL = 1;
final static public int REQUEST_TYPE_BINARY = 2;
final static public int REQUEST_TYPE_XML = 3;
final static public int REQUEST_TYPE_SIGNED = 4;
final static public int REQUEST_TYPE_FREEPKI = 5;
final static public int REQUEST_TYPE_FREEPKI_BIN= 6;
final static public String PATTERN_HEADING_ALLOW= "allow:";
final static public String PATTERN_HEADING_DENY = "deny:";
private String actionName = null;
private String actionDesc = "";
private String principalNeed = "";
private int protocol = REQUEST_TYPE_NORMAL;
private int multistep = 0;
private boolean finalstep = true;
private String sessionkey;
private Vector commandMaps = null;
private Hashtable paramCheckers = null;
//private Vector invalidKeys = null;
//private boolean signed = false;
//private boolean encrypted = false;
private int position = 0;
private String filterIPs;
/**
* ActionDef constructor comment.
*/
public ActionDef() {
super();
}
protected ActionDef(ActionDef template)
{
this.actionDesc = template.actionDesc;
this.actionName = template.actionName;
this.commandMaps = (Vector)template.commandMaps.clone();
//this.encrypted = template.encrypted;
this.finalstep = template.finalstep;
this.multistep = template.multistep;
this.paramCheckers = template.paramCheckers;
this.position = template.position;
this.principalNeed = template.principalNeed;
this.protocol = template.protocol;
this.sessionkey = template.sessionkey;
//this.signed = template.signed;
this.filterIPs = template.filterIPs;
}
/**
* 此处插入方法描述。
* 创建日期:(2002-5-14 21:04:21)
* @return java.lang.String
*/
public java.lang.String getActionDesc() {
return actionDesc;
}
/**
* 此处插入方法描述。
* 创建日期:(2002-5-14 21:04:21)
* @return java.lang.String
*/
public java.lang.String getActionName()
{
return actionName;
}
public int getCommandCount()
{
return commandMaps == null ? 0 : commandMaps.size();
}
public CommandMap getCommandMap(int i)
{
return (CommandMap)commandMaps.elementAt(i);
}
public CommandMap getCurrentCommandMap() {
if(commandMaps.size() > position)
{
return (CommandMap)commandMaps.elementAt(position);
}
return null;
}
public String getFilterIPs()
{
return filterIPs;
}
public CommandMap getFirstCommandMap() {
if(commandMaps.size() > 0)
{
position = 0;
return (CommandMap)commandMaps.elementAt(0);
}
return null;
}
/**
* Insert the method's description here.
* Creation date: (2002-5-21 15:12:13)
* @return int
*/
public int getMultistep() {
return multistep;
}
/**
* Insert the method's description here.
* Creation date: (2002-5-13 11:15:07)
* @return java.util.Vector
*/
public CommandMap getNextCommandMap() {
position++;
if(commandMaps.size() > position)
{
return (CommandMap)commandMaps.elementAt(position);
}
else
position = commandMaps.size();
return null;
}
public ParamChecker getParamChecker(String key)
{
return (ParamChecker)paramCheckers.get(key);
}
public String getPrincipal()
{
return principalNeed;
}
/**
* Insert the method's description here.
* Creation date: (2002-5-13 11:15:07)
* @return int
*/
public int getProtocol() {
return protocol;
}
/**
* Insert the method's description here.
* Creation date: (2002-5-21 15:12:13)
* @return java.lang.String
*/
public java.lang.String getSessionkey() {
return sessionkey;
}
protected void init(Node aNode , Hashtable cmdDefMap) throws InvalidConfigException
{
enter("init(Node)");
NamedNodeMap attribs = aNode.getAttributes();
Node urlNode = attribs.getNamedItem("name");
Node descNode = attribs.getNamedItem("description");
Node prinNode = attribs.getNamedItem("principal");
Node procNode = attribs.getNamedItem("protocol");
Node safeNode = attribs.getNamedItem("safety");
Node sessionNode = attribs.getNamedItem("sessionkey");
Node multiNode = attribs.getNamedItem("multi-step");
Node finalNode = attribs.getNamedItem("finalstep");
Node filterNode = attribs.getNamedItem("filterIPs");
if(sessionNode != null)
sessionkey = sessionNode.getNodeValue();
if(multiNode != null)
multistep = Integer.parseInt(multiNode.getNodeValue());
if(finalNode != null)
finalstep = Integer.parseInt(finalNode.getNodeValue()) > 0 ;
if (urlNode == null)
throw new InvalidConfigException("action/@url");
else
actionName = urlNode.getNodeValue();
if (descNode != null)
actionDesc = descNode.getNodeValue();
if (prinNode != null){
String tmp = prinNode.getNodeValue();
if(tmp != null){
principalNeed =tmp.trim();
}
}
if (filterNode != null)
filterIPs = filterNode.getNodeValue();
if (procNode != null)
{
String protocolText = procNode.getNodeValue();
StringTokenizer tokens = new StringTokenizer(protocolText , "|");
int procCount = 0;
while(tokens.hasMoreTokens())
{
String token = tokens.nextToken();
//因为PKI的应用自己对binary,normal等协议进行了封装
//故Signed和FreePKI协议和Normal、Binary、XML等协议现在为平等的地位
//但应该考虑到以后可能有两种协议共同存在的情况
/*
if (token.equals("Signed"))
{
signed = true;
}
else if (token.equals("Encrypted"))
{
encrypted = true;
}
else
{
*/
if (procCount ++ == 0)
{
if (token.equalsIgnoreCase("Normal"))
protocol = ActionDef.REQUEST_TYPE_NORMAL;
else if (token.equalsIgnoreCase("Binary"))
protocol = ActionDef.REQUEST_TYPE_BINARY;
else if (token.equalsIgnoreCase("XML"))
protocol = ActionDef.REQUEST_TYPE_XML;
else if (token.equalsIgnoreCase("Signed"))
protocol = ActionDef.REQUEST_TYPE_SIGNED;
else if (token.equalsIgnoreCase("FreePKI"))
protocol = ActionDef.REQUEST_TYPE_FREEPKI;
else if (token.equalsIgnoreCase("FreePKI_BIN"))
protocol = ActionDef.REQUEST_TYPE_FREEPKI_BIN;
else
procCount ++;
}
else
{
procCount ++;
}
if (procCount > 1)
{
throw new InvalidConfigException("action/[@protocol=" + token + "]");
}
//}
}
}
Vector nodesCmd = XMLUtil.selectNodes2(aNode , "commands/command");
int cmdSize = nodesCmd.size();
commandMaps = new Vector(cmdSize);
for(int i = 0 ; i < cmdSize ; i ++)
commandMaps.add(null);
for(int i = 0 ; i < cmdSize ; i++)
{
CommandMap cmdMap = new CommandMap();
Node nodeCmd = (Node)nodesCmd.elementAt(i);
cmdMap.init(nodeCmd , cmdDefMap);
int cmdIndex = cmdMap.getIndex() - 1;
if (cmdIndex < 0 || cmdIndex >= cmdSize || commandMaps.get(cmdIndex) != null)
throw new InvalidConfigException("commands/command[@index=" + cmdIndex + ']');
commandMaps.setElementAt(cmdMap , cmdIndex);
}
for(int i = 0 ; i < cmdSize ; i ++)
{
CommandMap cmdMap = (CommandMap)commandMaps.get(i);
if (i != 0)
{
CommandMap prevMap = (CommandMap)commandMaps.elementAt(i-1);
prevMap.setNextTransId(cmdMap.getTransId());
}
if (i != cmdSize - 1)
{
CommandMap nextMap = (CommandMap)commandMaps.elementAt(i+1);
nextMap.setPrevTransId(cmdMap.getTransId());
}
}
Vector nodesParam = XMLUtil.selectNodes2(aNode , "parameters/param");
int checkSize = nodesParam.size();
paramCheckers = new Hashtable();
for(int i = 0 ; i < checkSize ; i ++)
{
ParamChecker checker = new ParamChecker();
Node nodeChecker = (Node)nodesParam.elementAt(i);
checker.init(nodeChecker);
paramCheckers.put(checker.getParamName() , checker);
}
leave("init(Node)");
}
/**
* Insert the method's description here.
* Creation date: (2002-5-21 15:12:13)
* @return boolean
*/
public boolean isFinalstep() {
return finalstep;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -