View Javadoc

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.core.container.ContainerFactory;
25  import org.jdtaus.core.text.Message;
26  
27  /**
28   * Message stating that a file has an invalid length.
29   *
30   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
31   * @version $JDTAUS: IllegalFileLengthMessage.java 8661 2012-09-27 11:29:58Z schulte $
32   */
33  public final class IllegalFileLengthMessage extends Message
34  {
35  
36      /** Serial version UID for backwards compatibility with 1.0.x classes. */
37      private static final long serialVersionUID = 961185282869701368L;
38  
39      /**
40       * The length of a file incompatible to {@code blockSize}.
41       * @serial
42       */
43      private final long fileLength;
44  
45      /**
46       * The length of one block in byte.
47       * @serial
48       */
49      private final int blockSize;
50  
51      /**
52       * Creates a new {@code IllegalFileLengthMessage} instance taking the length of a file incompatible to a given block
53       * size.
54       *
55       * @param fileLength Length of a file incompatible to {@code blockSize}.
56       * @param blockSize Length of one block in byte.
57       *
58       * @throws IllegalArgumentException if either {@code fileLength} or {@code blockSize} is negative, or if
59       * {@code fileLength % blockSize} equals {@code 0}.
60       */
61      public IllegalFileLengthMessage( final long fileLength, final int blockSize )
62      {
63          if ( fileLength < 0 )
64          {
65              throw new IllegalArgumentException( Long.toString( fileLength ) );
66          }
67          if ( blockSize <= 0 )
68          {
69              throw new IllegalArgumentException( Integer.toString( blockSize ) );
70          }
71          if ( fileLength != 0 && fileLength % blockSize == 0 )
72          {
73              throw new IllegalArgumentException( Long.toString( fileLength % blockSize ) );
74          }
75  
76          this.fileLength = fileLength;
77          this.blockSize = blockSize;
78      }
79  
80      /**
81       * {@inheritDoc}
82       *
83       * @return the length of the file and the incompatible block size.
84       * <ul>
85       * <li>[0]: the length of the file incompatible to {@code blockSize}.</li>
86       * <li>[1]: the length of one block in byte.</li>
87       * </ul>
88       */
89      public Object[] getFormatArguments( final Locale locale )
90      {
91          return new Object[]
92              {
93                  new Long( this.fileLength ), new Integer( this.blockSize )
94              };
95      }
96  
97      /**
98       * {@inheritDoc}
99       *
100      * @return The corresponding text from the message's {@code ResourceBundle}
101      * <blockquote><pre>
102      * The length of the file ({0, number}) is incompatible to the blocksize {1,number}.
103      * </pre></blockquote>
104      */
105     public String getText( final Locale locale )
106     {
107         return this.getIllegalFileLengthMessage( locale, new Long( this.fileLength ), new Long( this.blockSize ) );
108     }
109 
110     //--Messages----------------------------------------------------------------
111 
112 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages
113     // This section is managed by jdtaus-container-mojo.
114 
115     /**
116      * Gets the text of message <code>illegalFileLength</code>.
117      * <blockquote><pre>Die Datei-Länge {0,number} ist inkompatible zu einer Block-Größe von {1,number}.</pre></blockquote>
118      * <blockquote><pre>The length of the file ({0, number}) is incompatible to the blocksize {1,number}.</pre></blockquote>
119      *
120      * @param locale The locale of the message instance to return.
121      * @param len format argument.
122      * @param blk format argument.
123      *
124      * @return the text of message <code>illegalFileLength</code>.
125      */
126     private String getIllegalFileLengthMessage( final Locale locale,
127             final java.lang.Number len,
128             final java.lang.Number blk )
129     {
130         return ContainerFactory.getContainer().
131             getMessage( this, "illegalFileLength", locale,
132                 new Object[]
133                 {
134                     len,
135                     blk
136                 });
137 
138     }
139 
140 // </editor-fold>//GEN-END:jdtausMessages
141 
142     //----------------------------------------------------------------Messages--
143 }