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; 020 021import org.jpos.iso.validator.ISOVException; 022 023/** 024 * Validator for no zero-filled fields. 025 * <p>Title: jPOS</p> 026 * <p>Description: Java Framework for Financial Systems</p> 027 * <p>Copyright: Copyright (c) 2000 jPOS.org. All rights reserved.</p> 028 * <p>Company: www.jPOS.org</p> 029 * @author Jose Eduardo Leon 030 * @version 1.0 031 */ 032public class IVA_ALPHANUMNOZERO extends IVA_ALPHANUM { 033 034 public IVA_ALPHANUMNOZERO() { 035 super(); 036 } 037 038 public IVA_ALPHANUMNOZERO( String Description ) { 039 super( Description ); 040 } 041 042 public IVA_ALPHANUMNOZERO( int minLen, int maxLen, String Description ) { 043 super( minLen, maxLen, Description ); 044 } 045 046 public IVA_ALPHANUMNOZERO( int maxLen, String Description ) { 047 super( maxLen, Description ); 048 } 049 050 public IVA_ALPHANUMNOZERO( boolean breakOnError, String Description ) { 051 this( Description ); 052 this.breakOnError = breakOnError; 053 } 054 055 public IVA_ALPHANUMNOZERO( boolean breakOnError, int maxLen, String Description ) { 056 this( maxLen, Description ); 057 this.breakOnError = breakOnError; 058 } 059 060 public IVA_ALPHANUMNOZERO( boolean breakOnError, int minLen, int maxLen, String Description ) { 061 this( minLen, maxLen, Description ); 062 this.breakOnError = breakOnError; 063 } 064 065 /** 066 * Validate that the component is not zero-filled. 067 */ 068 public ISOComponent validate ( ISOComponent f ) throws ISOException { 069 ISOField c = (ISOField)f; 070 try { 071 /** alphanum validations **/ 072 c = (ISOField)super.validate( c ); 073 /** no zero... **/ 074 if ( ISOUtil.isZero( (String)c.getValue() ) ){ 075 ISOVError e = new ISOVError( "Invalid Value Error. It can not be zero-filled. (Current value: "+ 076 c.getValue() +") ", getRejCode( ISOVError.ERR_INVALID_VALUE ) ); 077 if ( c instanceof ISOVField ) 078 ((ISOVField)c).addISOVError( e ); 079 else 080 c = new ISOVField( c, e ); 081 if ( breakOnError ) 082 throw new ISOVException ( "Error on field " + c.getKey(), c ); 083 } 084 return c; 085 } 086 catch (Exception ex) { 087 if ( ex instanceof ISOVException ) throw (ISOVException) ex; 088 return c; 089 } 090 } 091}