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