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 java.util.LinkedList;
022import java.util.ListIterator;
023
024/**
025 * Wrapper class resulting from process of validating an ISOMsg
026 * instance. Contains details of the original msg and validation-error
027 * details too. Normally in validation process when an error is detected
028 * by validator in msg, then the msg is replaced by an instance
029 * of this class, containning error details.
030 * <p>Title: jPOS</p>
031 * <p>Description: Java Framework for Financial Systems</p>
032 * <p>Copyright: Copyright (c) 2000 jPOS.org.  All rights reserved.</p>
033 * <p>Company: www.jPOS.org</p>
034 * @author Jose Eduardo Leon
035 * @version 1.0
036 */
037@SuppressWarnings("unchecked")
038public class ISOVMsg extends ISOMsg implements ISOVErrorList {
039
040    private static final long serialVersionUID = 443461124206801037L;
041
042    /**
043     * Copy properties from parent.
044     * @param Source original instance.
045     */
046    private void copyFromParent( ISOMsg Source ){
047        this.packager = Source.packager;
048        this.fields = Source.fields;
049        this.dirty = Source.dirty;
050        this.maxFieldDirty = Source.maxFieldDirty;
051        this.header = Source.header;
052        this.fieldNumber = Source.fieldNumber;
053        this.maxField = Source.maxField;
054        this.direction = Source.direction;
055    }
056
057    /**
058     * Create a message from original instance adding error data.
059     * @param Source Original msg instance.
060     */
061    public ISOVMsg( ISOMsg Source ) {
062        /** @todo Try best strategy */
063        copyFromParent( Source );
064    }
065
066    public ISOVMsg( ISOMsg Source, ISOVError FirstError ) {
067        /** @todo Try best strategy */
068        copyFromParent( Source );
069        addISOVError( FirstError );
070    }
071
072    /**
073     * Add an error component to the list of errors.
074     * @param Error Error instance to add.
075     * @return True if the list of errors change after operation.
076     */
077    public boolean addISOVError(ISOVError Error) {
078        return errors.add( Error );
079    }
080
081    /**
082     * Get an error iterator instance.
083     * @return iterator.
084     */
085    public ListIterator errorListIterator() {
086        return errors.listIterator();
087    }
088
089    /** list of errors **/
090    protected LinkedList errors = new LinkedList(  );
091}