001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.iso.validator; 020 021import org.jpos.iso.*; 022import org.jpos.util.LogSource; 023import org.jpos.util.Loggeable; 024import org.jpos.util.Logger; 025 026import java.io.PrintStream; 027import java.util.Iterator; 028import java.util.Vector; 029import java.util.Map; 030 031/** 032 * Parse ISOComponents and put the errors into a list. 033 * <p>Title: jPOS</p> 034 * <p>Description: Java Framework for Financial Systems</p> 035 * <p>Copyright: Copyright (c) 2000 jPOS.org. All rights reserved.</p> 036 * <p>Company: www.jPOS.org</p> 037 * @author Jose Eduardo Leon 038 * @version 1.0 039 */ 040@SuppressWarnings("unchecked") 041public class VErrorParser implements LogSource, Loggeable { 042 043 /** 044 * Parse an ISOComponent and get an error vector. 045 * @param c Component to parse. 046 * @return error vector. 047 */ 048 public Vector getVErrors( ISOComponent c ) { 049 Vector v = new Vector(); 050 _getErr( c, v, "" ); 051 _errors = v; 052 return _errors; 053 } 054 055 public String parseXMLErrorList(){ 056 /** @todo !!!!!!!! */ 057 return ""; 058 } 059 060 public void setLogger(Logger logger, String realm) { 061 this.logger = logger; 062 this.realm = realm; 063 } 064 public String getRealm() { 065 return realm; 066 } 067 public Logger getLogger() { 068 return logger; 069 } 070 071 /** 072 * Parse error list, and get an dump 073 * the xml string representing the list. 074 * <pre> 075 * Ex: 076 * <isomsg> 077 * <field id="2"> 078 * <error description="Invalid Len Error" reject-code="101"/> 079 * </field> 080 * <field id="48"> 081 * <field id="0"> 082 * <field id="1"> 083 * <error description="Invalid Value Error" reject-code="102"/> 084 * </field> 085 * </field> 086 * </field> 087 * <error description="Field Expected Error" reject-code="999"> 088 * </isomsg> 089 * </pre> 090 * @param p output stream 091 * @param indent indent character 092 */ 093 public void dump(PrintStream p, String indent) { 094 /** @todo !!!!!!!!! */ 095 } 096 097 /** 098 * Free errors memory. 099 */ 100 public void resetErrors(){ 101 _errors = null; 102 } 103 104 /** 105 * Recursive method to get the errors. 106 */ 107 private void _getErr ( ISOComponent c, Vector list, String id ) { 108 if ( c instanceof ISOVField ){ 109 Iterator iter = ((ISOVField)c).errorListIterator(); 110 while (iter.hasNext()) { 111 ISOVError error = (ISOVError)iter.next(); 112 error.setId( id ); 113 list.add( error ); 114 } 115 } 116 else if ( c instanceof ISOMsg ){ 117 if ( c instanceof ISOVMsg ){ 118 /** Msg level error **/ 119 Iterator iter = ((ISOVMsg)c).errorListIterator(); 120 while (iter.hasNext()) { 121 ISOVError error = (ISOVError)iter.next(); 122 error.setId( id ); 123 list.add( error ); 124 } 125 } 126 /** recursively in childs **/ 127 Map fields = c.getChildren(); 128 int max = c.getMaxField(); 129 for (int i = 0; i <= max ; i++) 130 if ((c=(ISOComponent) fields.get (i)) != null ) 131 _getErr( c, list, id + Integer.toString(i) + " " ); 132 } 133 } 134 135 protected Logger logger = null; 136 protected String realm=null; 137 private Vector _errors = null; 138}