1 | /* |
2 | * jDTAUS Banking API |
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.dtaus; |
22 | |
23 | import java.util.Locale; |
24 | import org.jdtaus.core.container.ContainerFactory; |
25 | import org.jdtaus.core.container.Implementation; |
26 | import org.jdtaus.core.container.ImplementationException; |
27 | |
28 | /** |
29 | * Gets thrown for any unexpected defects detected at runtime. |
30 | * <p>Applications should not depend on this exception for theire correctness. It is thrown whenever an unexpected |
31 | * situation is encountered. <i>{@code CorruptedException} should be used only to detect bugs.</i></p> |
32 | * |
33 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
34 | * @version $JDTAUS: CorruptedException.java 8810 2012-12-04 00:45:37Z schulte $ |
35 | * |
36 | * @see PhysicalFileFactory |
37 | * @see PhysicalFile |
38 | * @see LogicalFile |
39 | */ |
40 | public class CorruptedException extends ImplementationException |
41 | { |
42 | |
43 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
44 | private static final long serialVersionUID = 4974992290184417024L; |
45 | |
46 | /** |
47 | * Absolute file position at which a {@code CorruptedException} is caused. |
48 | * @serial |
49 | */ |
50 | private final long position; |
51 | |
52 | /** |
53 | * Creates a new {@code CorruptedException} taking the absolute position to the defect. |
54 | * |
55 | * @param implementation meta-data describing the implementation causing the exception to be thrown. |
56 | * @param position absolute position at which the file is defect. |
57 | */ |
58 | public CorruptedException( final Implementation implementation, final long position ) |
59 | { |
60 | super( implementation ); |
61 | this.position = position; |
62 | } |
63 | |
64 | /** |
65 | * Gets the absolute file position causing this exception to be thrown. |
66 | * |
67 | * @return The absolute file position causing this exception to be thrown or {@code null}. |
68 | */ |
69 | public long getPosition() |
70 | { |
71 | return this.position; |
72 | } |
73 | |
74 | /** |
75 | * Returns the message of the exception. |
76 | * |
77 | * @return The message of the exception. |
78 | */ |
79 | public String getMessage() |
80 | { |
81 | return this.getCorruptedExceptionMessage( this.getLocale(), new Long( this.position ) ); |
82 | } |
83 | |
84 | //--Dependencies------------------------------------------------------------ |
85 | |
86 | // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies |
87 | // This section is managed by jdtaus-container-mojo. |
88 | |
89 | /** |
90 | * Gets the configured <code>Locale</code> implementation. |
91 | * |
92 | * @return The configured <code>Locale</code> implementation. |
93 | */ |
94 | private Locale getLocale() |
95 | { |
96 | return (Locale) ContainerFactory.getContainer(). |
97 | getDependency( this, "Locale" ); |
98 | |
99 | } |
100 | |
101 | // </editor-fold>//GEN-END:jdtausDependencies |
102 | |
103 | //------------------------------------------------------------Dependencies-- |
104 | //--Messages---------------------------------------------------------------- |
105 | |
106 | // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages |
107 | // This section is managed by jdtaus-container-mojo. |
108 | |
109 | /** |
110 | * Gets the text of message <code>corruptedException</code>. |
111 | * <blockquote><pre>Die physikalische Datei ist ab Position {0,number} defekt.</pre></blockquote> |
112 | * <blockquote><pre>The physical file got corrupted at position {0,number}.</pre></blockquote> |
113 | * |
114 | * @param locale The locale of the message instance to return. |
115 | * @param pos format parameter. |
116 | * |
117 | * @return the text of message <code>corruptedException</code>. |
118 | */ |
119 | private String getCorruptedExceptionMessage( final Locale locale, |
120 | final java.lang.Number pos ) |
121 | { |
122 | return ContainerFactory.getContainer(). |
123 | getMessage( this, "corruptedException", locale, |
124 | new Object[] |
125 | { |
126 | pos |
127 | }); |
128 | |
129 | } |
130 | |
131 | // </editor-fold>//GEN-END:jdtausMessages |
132 | |
133 | //----------------------------------------------------------------Messages-- |
134 | } |