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.core.Configuration; 022import org.jpos.core.ConfigurationException; 023import org.jpos.iso.*; 024import org.jpos.util.LogEvent; 025import org.jpos.util.Logger; 026 027/** 028 * ONLY TEST PURPOSE. 029 * <p>Title: jPOS</p> 030 * <p>Description: Java Framework for Financial Systems</p> 031 * <p>Copyright: Copyright (c) 2000 jPOS.org. All rights reserved.</p> 032 * <p>Company: www.jPOS.org</p> 033 * @author Jose Eduardo Leon 034 * @version 1.0 035 */ 036@SuppressWarnings("unchecked") 037public class TEST0100 extends ISOBaseValidator { 038 039 public TEST0100() { 040 super(); 041 } 042 043 public TEST0100( boolean breakOnError ) { 044 super( breakOnError ); 045 } 046 047 public void setConfiguration(Configuration cfg) throws ConfigurationException { 048 super.setConfiguration( cfg ); 049 java.util.StringTokenizer st = new java.util.StringTokenizer( cfg.get( "msg-type", ""), " " ); 050 while ( st.hasMoreTokens() ) 051 msgTypes.add( st.nextToken() ); 052 } 053 054 public ISOComponent validate(ISOComponent m) throws org.jpos.iso.ISOException { 055 if ( msgTypes.contains ( ((ISOMsg)m).getMTI() ) ){ 056 LogEvent evt = new LogEvent( this, "validate" ); 057 try { 058 super.validate ( m ); 059 ISOMsg msg = (ISOMsg)m; 060 int[] validFields = { 4,5,7,48 }; 061 if ( !msg.hasFields( validFields ) ){ 062 ISOVError e = new ISOVError( "Fields " + makeStrFromArray( validFields ) + " must appear in msg.", "001" ); 063 if ( msg instanceof ISOVMsg ) 064 ((ISOVMsg)msg).addISOVError( e ); 065 else 066 msg = new ISOVMsg( msg, e ); 067 if ( breakOnError ) 068 throw new ISOVException ( "Error on msg. " , msg ); 069 } 070 return msg; 071 } finally { 072 Logger.log( evt ); 073 } 074 } else return m; 075 } 076 077 private String makeStrFromArray( int[] validFields ){ 078 if ( validFields == null ) return null; 079 StringBuilder result = new StringBuilder(); 080 for (int validField : validFields) { 081 result.append(validField); 082 result.append(", "); 083 } 084 result.delete( result.length()-2, result.length()-1 ); 085 return result.toString( ); 086 } 087 088 private java.util.HashSet msgTypes=new java.util.HashSet(); 089}