1 | /* |
2 | * jDTAUS Banking Messages |
3 | * Copyright (C) 2005 Christian Schulte |
4 | * <cs@schulte.it> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2.1 of the License, or any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this library; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * |
20 | */ |
21 | package org.jdtaus.banking.messages; |
22 | |
23 | import java.util.Locale; |
24 | import org.jdtaus.banking.dtaus.Checksum; |
25 | import org.jdtaus.core.container.ContainerFactory; |
26 | import org.jdtaus.core.text.Message; |
27 | |
28 | /** |
29 | * Message stating that a checksum is incorrect. |
30 | * |
31 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
32 | * @version $JDTAUS: ChecksumErrorMessage.java 8810 2012-12-04 00:45:37Z schulte $ |
33 | */ |
34 | public final class ChecksumErrorMessage extends Message |
35 | { |
36 | |
37 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
38 | private static final long serialVersionUID = 2983079946808628079L; |
39 | |
40 | /** |
41 | * Absolute position of the file with the incorrect checksum. |
42 | * @serial |
43 | */ |
44 | private final long position; |
45 | |
46 | /** |
47 | * Stored checksum. |
48 | * @serial |
49 | */ |
50 | private final Checksum storedChecksum; |
51 | |
52 | /** |
53 | * Computed checksum. |
54 | * @serial |
55 | */ |
56 | private final Checksum computedChecksum; |
57 | |
58 | /** |
59 | * Creates a new {@code ChecksumErrorMessage} instance. |
60 | * |
61 | * @param storedChecksum The checksum stored in a file. |
62 | * @param computedChecksum The computed checksum from the same file. |
63 | * @param position Absolute position of the file with the incorrect checksum. |
64 | * |
65 | * @throws NullPointerException if either {@code storedChecksum} or {@code computedChecksum} is {@code null}. |
66 | * @throws IllegalArgumentException if {@code storedChecksum} is equal to {@code computedChecksum} or if |
67 | * {@code position} is negative. |
68 | */ |
69 | public ChecksumErrorMessage( final Checksum storedChecksum, final Checksum computedChecksum, final long position ) |
70 | { |
71 | if ( storedChecksum == null ) |
72 | { |
73 | throw new NullPointerException( "storedChecksum" ); |
74 | } |
75 | if ( computedChecksum == null ) |
76 | { |
77 | throw new NullPointerException( "computedChecksum" ); |
78 | } |
79 | if ( storedChecksum.equals( computedChecksum ) ) |
80 | { |
81 | throw new IllegalArgumentException( computedChecksum.toString() ); |
82 | } |
83 | if ( position < 0L ) |
84 | { |
85 | throw new IllegalArgumentException( Long.toString( position ) ); |
86 | } |
87 | |
88 | this.storedChecksum = storedChecksum; |
89 | this.computedChecksum = computedChecksum; |
90 | this.position = position; |
91 | } |
92 | |
93 | /** |
94 | * {@inheritDoc} |
95 | * |
96 | * @return Values of the properties of the stored and computed checksum. |
97 | * <ul> |
98 | * <li>[0]: value of property {@code sumAmount} of the stored checksum.</li> |
99 | * <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 | } |