📄 jactionexceptionparser.java.bak
字号:
}else{
defaultMessage="";
}
}
}
return defaultMessage;
}
/**
* 得到默认的异常信息说明
* @return 默认的异常信息的说明
* @throws Exception
*/
public static String getDefaultExceptionDeclaration() throws Exception{
Node isNode=null;
String defaultDeclaration=null;
NodeList nodeList=getDefaultExceptionNode().getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
isNode=nodeList.item(i);
if(isNode.getNodeName().equals(EXCEPTION_DECLARATION)){
if(nodeList.item(i).hasChildNodes()){
defaultDeclaration = nodeList.item(i).getFirstChild().getNodeValue();
}else{
defaultDeclaration="";
}
}
}
return defaultDeclaration;
}
/**
* 得到默认异常类型节点
* @return 默认异常类型的节点
* @throws Exception
*/
private static Node getDefaultExceptionTypeNode() throws Exception{
Node isNode=null;
NodeList nodeList=getDefaultNode().getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
isNode=nodeList.item(i);
if(isNode.getNodeName().equals(EXCEPTION_TYPE)){
break;
}else{
continue;
}
}
return isNode;
}
/**
* 得到默认异常的类型名称
* @return 默认异常的类型名称
* @throws Exception
*/
public static String getDefaultExceptionTypeName() throws Exception{
Node isNode=null;
String defaultTypeName=null;
NodeList nodeList=getDefaultExceptionTypeNode().getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
isNode=nodeList.item(i);
if(isNode.getNodeName().equals(DEFAULT_EXCEPTION_TYPE_NAME)){
if(nodeList.item(i).hasChildNodes()){
defaultTypeName = nodeList.item(i).getFirstChild().getNodeValue();
}else{
defaultTypeName="";
}
}
}
return defaultTypeName;
}
/**
* 根据节点和节点的名称得到该节点中值
* @param node 节点
* @param nodeName 节点的名称
* @return
*/
private static String getNodeValue(Node node,String nodeName){
if(node.getNodeName().equals(nodeName)){
return node.getFirstChild().getNodeValue();
}else{
return "";
}
}
/**
* 根据节点和节点的名称得到该节点的属性中的值
* @param node 节点
* @param nodeName 节点名称
* @return
*/
private static String getNodeAttribute(Node node,String nodeName){
if(node.hasAttributes()){
NamedNodeMap nodeMap = node.getAttributes();
Node nodeValue = nodeMap.getNamedItem(nodeName);
return nodeValue.getNodeValue();
}else{
return "";
}
}
/**
* 根据异常信息,得到该异常信息所对应的异常的集合
* @param strMessage 异常信息
* @return 异常的集合
* @throws Exception
*/
public static ArrayList getExceptionCodeValue(String strMessage) throws Exception{
ArrayList arrayList=new ArrayList();
String childMessage="";
NodeList nodeList = getExceptionListNode().getChildNodes();//得到exceptionlist的子节点的集合
for(int i=0;i<nodeList.getLength();i++){
NodeList childNodeList=nodeList.item(i).getChildNodes();//得到exception的子节点的集合
for(int j=0;j<childNodeList.getLength();j++){
Node childNode = childNodeList.item(j);
//根据得到的message查出所对应的code,并放入ArrayList中
childMessage=getNodeValue(childNode,EXCEPTION_MESSAGE);
if(!childMessage.equals("")){
if (strMessage == null || strMessage.equals("") || (childMessage.indexOf(strMessage) != -1)) {
Node parentNode = childNode.getParentNode();
arrayList.add(getNodeAttribute(parentNode, JACTION_CODE));
}
}
}
}
return arrayList;
}
/**
* 显示异常信息的类别
* @param code 异常类型
* @return 异常类型的集合
* @throws Exception
*/
public static ArrayList getExceptionTypeValue(String code) throws Exception{
ArrayList arrayList=new ArrayList();
String typeCode="";
NodeList nodeList=getExceptionTypeNode().getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
typeCode=getNodeAttribute(nodeList.item(i),JACTION_CODE);
if(!typeCode.equals("")){
if (code == null || code.equals("") || (typeCode.indexOf(code) != -1)) {
arrayList.add(typeCode);
}
}
}
return arrayList;
}
/**
* 得到指定节点中的属性的值。
* @param node 节点
* @param attributeName 属性名称
* @return 指定节点中的属性的值
* @throws Exception
*/
static String getAttributeOfNode(Node node,String attributeName) throws Exception{
if(node.hasAttributes()){
NamedNodeMap namedNodeMap = node.getAttributes();
Node isNode = namedNodeMap.getNamedItem(attributeName);
return isNode.getNodeValue();
}else{
return "";
}
}
/**
* 根据codeValue判断是否有这个子节点,有返回true ,否则返回false
* @param node 节点
* @param codeValue code的标识
* @return 有返回true ,否则返回false
* @throws Exception
*/
private static boolean hasCode(Node node,String codeValue) throws Exception{
NodeList nodeList=node.getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
Node thisNode=nodeList.item(i);
if(getAttributeOfNode(thisNode,JACTION_CODE).equals(codeValue)){
return true;
}
}
return false;
}
/**
* 新增类型的节点和节点中的属性
* @param codeType 异常类型
* @param codeMessage 异常类型名称
* @return 新增的节点
* @throws Exception
*/
static Element addNewExceptionTypeElement(String codeType,String codeMessage) throws Exception{
//新增节点
Element newElement = document.createElement(JACTION_TYPE);
//设置属性
newElement.setAttribute(JACTION_CODE, codeType);
newElement.setAttribute(JACTION_NAME, codeMessage);
return newElement;
}
/**
* 对异常信息的类型进行新增和修改
* @param node 节点
* @param codeType code的value值
* @param codeMessage name的value值
* @throws Exception
*/
public static void setExceptionType(String codeType,String codeMessage) throws Exception{
Node node=getExceptionTypeNode();
if(hasCode(node,codeType)){//有子节点,进行更新
NodeList nodeList=node.getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
Node isNode=nodeList.item(i);
if(getAttributeOfNode(isNode,JACTION_CODE).equals(codeType)){
//得到新的节点
Element newExceptionType=addNewExceptionTypeElement(codeType,codeMessage);
//进行更新
node.replaceChild(newExceptionType,isNode);
}
}
}else{//没有,进行新增
Element newExceptionType=addNewExceptionTypeElement(codeType,codeMessage);
node.appendChild(newExceptionType);
}
writerToFile(document,EXCEPTION_FILE,"",true);
}
/**
* 判断是否有异常,有返回true,否则返回false
* @param node 节点
* @param exceptCode 异常类型的标识
* @return 有该异常返回true,否则返回false
* @throws Exception
*/
static boolean hasException(Node node,String exceptCode) throws Exception{
NodeList nodeList=node.getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
Node thisNode=nodeList.item(i);
if(getAttributeOfNode(thisNode,JACTION_CODE).equals(exceptCode)){
return true;
}
}
return false;
}
/**
* 新增异常的节点和节点中的属性
* @param exceptCode 异常标识
* @param exceptType 异常类型
* @param exceptMsg 异常信息
* @param exceptDecl 异常信息说明
* @return 新增异常类型的节点
* @throws Exception
*/
static Element addNewExceptionElement(String exceptCode, String exceptType,String exceptMsg,String exceptDecl) throws Exception {
//新增节点
Element newElement = document.createElement(EXCEPTION);
//设置属性
newElement.setAttribute(JACTION_CODE, exceptCode);
newElement.setAttribute(JACTION_TYPE, exceptType);
Element msgElement = document.createElement(EXCEPTION_MESSAGE);
msgElement.appendChild(document.createTextNode(exceptMsg));
Element declElement = document.createElement(EXCEPTION_DECLARATION);
declElement.appendChild(document.createTextNode(exceptDecl));
newElement.appendChild(msgElement);
newElement.appendChild(declElement);
return newElement;
}
/**
* 对异常信息进行新增和修改
* @param exceptCode 异常标识
* @param exceptType 异常类型
* @param exceptMsg 异常信息
* @param exceptDecl 异常信息说明
* @throws Exception
*/
public static void setException(String exceptCode,String exceptType,String exceptMsg,String exceptDecl) throws Exception{
Node node=getExceptionListNode();
if(hasException(node,exceptCode)){//修改
NodeList nodeList=node.getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
Node isNode=nodeList.item(i);
if(getAttributeOfNode(isNode,JACTION_CODE).equals(exceptCode)){
//得到新的节点
Element newException=addNewExceptionElement(exceptCode,exceptType,exceptMsg,exceptDecl);
//进行更新
node.replaceChild(newException,isNode);
}
}
}else{//新增
Element newException=addNewExceptionElement(exceptCode,exceptType,exceptMsg,exceptDecl);
node.appendChild(newException);
}
writerToFile(document,EXCEPTION_FILE,"",true);
}
/**
* 对默认异常信息进行新增和修改
* @param defaultType 异常类型
* @param defaultMsg 异常信息
* @param defaultDecl 异常信息说明
* @throws Exception
*/
public static void setDefaultException(String defaultType,String defaultMsg,String defaultDecl) throws Exception{
NodeList exNodeList=getDefaultExceptionNode().getChildNodes();
for(int i=0;i<exNodeList.getLength();i++){
Node exNode=exNodeList.item(i);
if(exNode.getNodeName().equals(EXCEPTION_MESSAGE)){
exNode.getFirstChild().setNodeValue(defaultMsg);
}
if(exNode.getNodeName().equals(EXCEPTION_DECLARATION)){
exNode.getFirstChild().setNodeValue(defaultDecl);
}
}
writerToFile(document,EXCEPTION_FILE,"",true);
NodeList typeNodeList=getDefaultExceptionTypeNode().getChildNodes();
for(int j=0;j<typeNodeList.getLength();j++){
Node typeNode=typeNodeList.item(j);
if(typeNode.getNodeName().equals(DEFAULT_EXCEPTION_TYPE_NAME)){
typeNode.getFirstChild().setNodeValue(defaultType);
}
}
writerToFile(document,EXCEPTION_FILE,"",true);
}
/******************************** main test *********************************/
public static void main(String args[]) throws Exception{
JactionExceptionParser jep = new JactionExceptionParser();
//Node isNode=jep.getExceptionListMessageNode();
//String nodeName=isNode.getNodeName();
//String nodeName=getExceptionTypeOfName("W");
//System.out.print("nodeName="+nodeName);
System.out.println("----------------");
//jep.init("02","E");
jep.init("002");
System.out.println("message=" + jep.getMessage());
System.out.println("declaration=" + jep.getDeclaration());
System.out.println("typeName=" + jep.getTypeName());
//Node node=jep.getExceptionTypeNode();
//setExceptionType(node,"v","fff");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -