001/*
002 *  jDTAUS Banking Messages
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.banking.messages;
022
023import java.util.Locale;
024import org.jdtaus.banking.dtaus.Checksum;
025import org.jdtaus.core.container.ContainerFactory;
026import org.jdtaus.core.text.Message;
027
028/**
029 * Message stating that a checksum is incorrect.
030 *
031 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
032 * @version $JDTAUS: ChecksumErrorMessage.java 8810 2012-12-04 00:45:37Z schulte $
033 */
034public final class ChecksumErrorMessage extends Message
035{
036
037    /** Serial version UID for backwards compatibility with 1.0.x classes. */
038    private static final long serialVersionUID = 2983079946808628079L;
039
040    /**
041     * Absolute position of the file with the incorrect checksum.
042     * @serial
043     */
044    private final long position;
045
046    /**
047     * Stored checksum.
048     * @serial
049     */
050    private final Checksum storedChecksum;
051
052    /**
053     * Computed checksum.
054     * @serial
055     */
056    private final Checksum computedChecksum;
057
058    /**
059     * Creates a new {@code ChecksumErrorMessage} instance.
060     *
061     * @param storedChecksum The checksum stored in a file.
062     * @param computedChecksum The computed checksum from the same file.
063     * @param position Absolute position of the file with the incorrect checksum.
064     *
065     * @throws NullPointerException if either {@code storedChecksum} or {@code computedChecksum} is {@code null}.
066     * @throws IllegalArgumentException if {@code storedChecksum} is equal to {@code computedChecksum} or if
067     * {@code position} is negative.
068     */
069    public ChecksumErrorMessage( final Checksum storedChecksum, final Checksum computedChecksum, final long position )
070    {
071        if ( storedChecksum == null )
072        {
073            throw new NullPointerException( "storedChecksum" );
074        }
075        if ( computedChecksum == null )
076        {
077            throw new NullPointerException( "computedChecksum" );
078        }
079        if ( storedChecksum.equals( computedChecksum ) )
080        {
081            throw new IllegalArgumentException( computedChecksum.toString() );
082        }
083        if ( position < 0L )
084        {
085            throw new IllegalArgumentException( Long.toString( position ) );
086        }
087
088        this.storedChecksum = storedChecksum;
089        this.computedChecksum = computedChecksum;
090        this.position = position;
091    }
092
093    /**
094     * {@inheritDoc}
095     *
096     * @return Values of the properties of the stored and computed checksum.
097     * <ul>
098     * <li>[0]: value of property {@code sumAmount} of the stored checksum.</li>
099     * <li>[1]: value of property {@code sumTargetAccount} of the stored checksum.</li>
100     * <li>[2]: value of property {@code sumTargetBank} of the stored checksum.</li>
101     * <li>[3]: value of property {@code transactionCount} of the stored checksum.</li>
102     * <li>[4]: value of property {@code sumAmount} of the copmuted checksum.</li>
103     * <li>[5]: value of property {@code sumTargetAccount} of the copmuted checksum.</li>
104     * <li>[6]: value of property {@code sumTargetBank} of the copmuted checksum.</li>
105     * <li>[7]: value of property {@code transactionCount} of the copmuted checksum.</li>
106     * <li>[8]: absolute position of the file with the incorrect checksum.</li>
107     * </ul>
108     */
109    public Object[] getFormatArguments( final Locale locale )
110    {
111        return new Object[]
112            {
113                new Long( this.storedChecksum.getSumAmount() ),
114                new Long( this.storedChecksum.getSumTargetAccount() ),
115                new Long( this.storedChecksum.getSumTargetBank() ),
116                new Integer( this.storedChecksum.getTransactionCount() ),
117                new Long( this.computedChecksum.getSumAmount() ),
118                new Long( this.computedChecksum.getSumTargetAccount() ),
119                new Long( this.computedChecksum.getSumTargetBank() ),
120                new Integer( this.computedChecksum.getTransactionCount() ),
121                new Long( this.position )
122            };
123    }
124
125    /**
126     * {@inheritDoc}
127     *
128     * @return The corresponding text from the message's {@code ResourceBundle}
129     * <blockquote><pre>
130     * The checksum of the file beginning at position {0,number} is invalid.
131     * </pre></blockquote>
132     */
133    public String getText( final Locale locale )
134    {
135        return this.getChecksumErrorMessage( locale, new Long( this.position ) );
136    }
137
138    //--Messages----------------------------------------------------------------
139
140// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages
141    // This section is managed by jdtaus-container-mojo.
142
143    /**
144     * Gets the text of message <code>checksumError</code>.
145     * <blockquote><pre>Die Prüfsumme der an Position {0,number} beginnenden logischen Datei ist ungültig.</pre></blockquote>
146     * <blockquote><pre>The checksum of the logical file beginning at position {0,number} is invalid.</pre></blockquote>
147     *
148     * @param locale The locale of the message instance to return.
149     * @param pos format parameter.
150     *
151     * @return the text of message <code>checksumError</code>.
152     */
153    private String getChecksumErrorMessage( final Locale locale,
154            final java.lang.Number pos )
155    {
156        return ContainerFactory.getContainer().
157            getMessage( this, "checksumError", locale,
158                new Object[]
159                {
160                    pos
161                });
162
163    }
164
165// </editor-fold>//GEN-END:jdtausMessages
166
167    //----------------------------------------------------------------Messages--
168}