001/*
002 *  jDTAUS Banking API
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.dtaus;
022
023import java.util.Locale;
024import org.jdtaus.core.container.ContainerFactory;
025import org.jdtaus.core.container.Implementation;
026import org.jdtaus.core.container.ImplementationException;
027
028/**
029 * Gets thrown for any unexpected defects detected at runtime.
030 * <p>Applications should not depend on this exception for theire correctness. It is thrown whenever an unexpected
031 * situation is encountered. <i>{@code CorruptedException} should be used only to detect bugs.</i></p>
032 *
033 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
034 * @version $JDTAUS: CorruptedException.java 8810 2012-12-04 00:45:37Z schulte $
035 *
036 * @see PhysicalFileFactory
037 * @see PhysicalFile
038 * @see LogicalFile
039 */
040public class CorruptedException extends ImplementationException
041{
042
043    /** Serial version UID for backwards compatibility with 1.0.x classes. */
044    private static final long serialVersionUID = 4974992290184417024L;
045
046    /**
047     * Absolute file position at which a {@code CorruptedException} is caused.
048     * @serial
049     */
050    private final long position;
051
052    /**
053     * Creates a new {@code CorruptedException} taking the absolute position to the defect.
054     *
055     * @param implementation meta-data describing the implementation causing the exception to be thrown.
056     * @param position absolute position at which the file is defect.
057     */
058    public CorruptedException( final Implementation implementation, final long position )
059    {
060        super( implementation );
061        this.position = position;
062    }
063
064    /**
065     * Gets the absolute file position causing this exception to be thrown.
066     *
067     * @return The absolute file position causing this exception to be thrown or {@code null}.
068     */
069    public long getPosition()
070    {
071        return this.position;
072    }
073
074    /**
075     * Returns the message of the exception.
076     *
077     * @return The message of the exception.
078     */
079    public String getMessage()
080    {
081        return this.getCorruptedExceptionMessage( this.getLocale(), new Long( this.position ) );
082    }
083
084    //--Dependencies------------------------------------------------------------
085
086// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies
087    // This section is managed by jdtaus-container-mojo.
088
089    /**
090     * Gets the configured <code>Locale</code> implementation.
091     *
092     * @return The configured <code>Locale</code> implementation.
093     */
094    private Locale getLocale()
095    {
096        return (Locale) ContainerFactory.getContainer().
097            getDependency( this, "Locale" );
098
099    }
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}