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 /** Default constructor. */ 035 public IVA_ALPHANUMNOZERO() { 036 super(); 037 } 038 039 /** 040 * Constructs a validator using only a description. 041 * 042 * @param Description human-readable field description 043 */ 044 public IVA_ALPHANUMNOZERO( String Description ) { 045 super( Description ); 046 } 047 048 /** 049 * Constructs a validator with explicit length bounds. 050 * 051 * @param minLen minimum acceptable length 052 * @param maxLen maximum acceptable length 053 * @param Description human-readable field description 054 */ 055 public IVA_ALPHANUMNOZERO( int minLen, int maxLen, String Description ) { 056 super( minLen, maxLen, Description ); 057 } 058 059 /** 060 * Constructs a validator with a maximum length. 061 * 062 * @param maxLen maximum acceptable length 063 * @param Description human-readable field description 064 */ 065 public IVA_ALPHANUMNOZERO( int maxLen, String Description ) { 066 super( maxLen, Description ); 067 } 068 069 /** 070 * Constructs a validator with a custom break-on-error flag. 071 * 072 * @param breakOnError if {@code true}, validation throws on the first error 073 * @param Description human-readable field description 074 */ 075 public IVA_ALPHANUMNOZERO( boolean breakOnError, String Description ) { 076 this( Description ); 077 this.breakOnError = breakOnError; 078 } 079 080 /** 081 * Constructs a validator with a custom break-on-error flag and a maximum length. 082 * 083 * @param breakOnError if {@code true}, validation throws on the first error 084 * @param maxLen maximum acceptable length 085 * @param Description human-readable field description 086 */ 087 public IVA_ALPHANUMNOZERO( boolean breakOnError, int maxLen, String Description ) { 088 this( maxLen, Description ); 089 this.breakOnError = breakOnError; 090 } 091 092 /** 093 * Constructs a validator with a custom break-on-error flag and explicit length bounds. 094 * 095 * @param breakOnError if {@code true}, validation throws on the first error 096 * @param minLen minimum acceptable length 097 * @param maxLen maximum acceptable length 098 * @param Description human-readable field description 099 */ 100 public IVA_ALPHANUMNOZERO( boolean breakOnError, int minLen, int maxLen, String Description ) { 101 this( minLen, maxLen, Description ); 102 this.breakOnError = breakOnError; 103 } 104 105 /** 106 * Validate that the component is not zero-filled. 107 * 108 * @param f component to validate 109 * @return the validated (possibly wrapped) component 110 * @throws ISOException if {@link #breakOnError} is set and the field is zero-filled or fails alphanumeric validation 111 */ 112 public ISOComponent validate ( ISOComponent f ) throws ISOException { 113 ISOField c = (ISOField)f; 114 try { 115 /** alphanum validations **/ 116 c = (ISOField)super.validate( c ); 117 /** no zero... **/ 118 if ( ISOUtil.isZero( (String)c.getValue() ) ){ 119 ISOVError e = new ISOVError( "Invalid Value Error. It can not be zero-filled. (Current value: "+ 120 c.getValue() +") ", getRejCode( ISOVError.ERR_INVALID_VALUE ) ); 121 if ( c instanceof ISOVField ) 122 ((ISOVField)c).addISOVError( e ); 123 else 124 c = new ISOVField( c, e ); 125 if ( breakOnError ) 126 throw new ISOVException ( "Error on field " + c.getKey(), c ); 127 } 128 return c; 129 } 130 catch (Exception ex) { 131 if ( ex instanceof ISOVException ) throw (ISOVException) ex; 132 return c; 133 } 134 } 135}