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.core.Configuration; 022import org.jpos.core.ConfigurationException; 023import org.jpos.core.Configurable; 024import org.jpos.util.LogSource; 025import org.jpos.util.Logger; 026 027/** 028 * Base Validator class for jPOS composed ISOComponents (ISOMsg). 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 */ 036public class ISOBaseValidator implements ISOValidator, LogSource, Configurable { 037 038 /** Default constructor. */ 039 public ISOBaseValidator() { 040 super(); 041 } 042 043 /** 044 * Creates the validator. 045 * @param breakOnError flag indicating validation abort condition 046 */ 047 public ISOBaseValidator( boolean breakOnError ) { 048 this.breakOnError = breakOnError; 049 } 050 051 public void setConfiguration(Configuration cfg) throws ConfigurationException { 052 this.cfg = cfg; 053 } 054 055 /** 056 * Returns whether validation should stop on first error. 057 * 058 * @return true if break-on-error is set 059 */ 060 public boolean breakOnError(){ 061 return breakOnError; 062 } 063 064 /** 065 * Sets whether validation should stop on first error. 066 * 067 * @param breakOnErr if true, stop on first error 068 */ 069 public void setBreakOnError( boolean breakOnErr ){ 070 this.breakOnError = breakOnErr; 071 } 072 073 /** 074 * Validate field-interdependency. 075 * @param m Component to validate 076 * @return ISOComponent or ISOVComponent resulting of validation process. 077 * @throws ISOException if break-on-error is true and an error succedd. 078 */ 079 public ISOComponent validate( ISOComponent m ) throws ISOException{ 080 if ( m.getComposite() != m ) 081 throw new ISOException ( "Can't call validate on non Composite" ); 082 return m; 083 } 084 085 public void setLogger( Logger logger, String realm ){ 086 this.logger = logger; 087 this.realm = realm; 088 } 089 090 public Logger getLogger(){ 091 return logger; 092 } 093 094 public String getRealm() { 095 return realm; 096 } 097 098 /** The logger for this validator. */ 099 protected Logger logger = null; 100 /** The realm string for this validator. */ 101 protected String realm = null; 102 /** Flag used to indicate if validat process break 103 * on first error or keep an error set **/ 104 protected boolean breakOnError = false; 105 /** The configuration for this validator. */ 106 protected Configuration cfg; 107}