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 /** Default constructor. */ 040 public TEST0100() { 041 super(); 042 } 043 044 /** 045 * Constructs the validator with the requested error behaviour. 046 * 047 * @param breakOnError when {@code true}, validation throws on the first error 048 */ 049 public TEST0100( boolean breakOnError ) { 050 super( breakOnError ); 051 } 052 053 public void setConfiguration(Configuration cfg) throws ConfigurationException { 054 super.setConfiguration( cfg ); 055 java.util.StringTokenizer st = new java.util.StringTokenizer( cfg.get( "msg-type", ""), " " ); 056 while ( st.hasMoreTokens() ) 057 msgTypes.add( st.nextToken() ); 058 } 059 060 public ISOComponent validate(ISOComponent m) throws org.jpos.iso.ISOException { 061 if ( msgTypes.contains ( ((ISOMsg)m).getMTI() ) ){ 062 LogEvent evt = new LogEvent( this, "validate" ); 063 try { 064 super.validate ( m ); 065 ISOMsg msg = (ISOMsg)m; 066 int[] validFields = { 4,5,7,48 }; 067 if ( !msg.hasFields( validFields ) ){ 068 ISOVError e = new ISOVError( "Fields " + makeStrFromArray( validFields ) + " must appear in msg.", "001" ); 069 if ( msg instanceof ISOVMsg ) 070 ((ISOVMsg)msg).addISOVError( e ); 071 else 072 msg = new ISOVMsg( msg, e ); 073 if ( breakOnError ) 074 throw new ISOVException ( "Error on msg. " , msg ); 075 } 076 return msg; 077 } finally { 078 Logger.log( evt ); 079 } 080 } else return m; 081 } 082 083 private String makeStrFromArray( int[] validFields ){ 084 if ( validFields == null ) return null; 085 StringBuilder result = new StringBuilder(); 086 for (int validField : validFields) { 087 result.append(validField); 088 result.append(", "); 089 } 090 result.delete( result.length()-2, result.length()-1 ); 091 return result.toString( ); 092 } 093 094 private java.util.HashSet msgTypes=new java.util.HashSet(); 095}