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.core.container.ContainerFactory; 025import org.jdtaus.core.text.Message; 026 027/** 028 * Message stating that a file has an invalid length. 029 * 030 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 031 * @version $JDTAUS: IllegalFileLengthMessage.java 8810 2012-12-04 00:45:37Z schulte $ 032 */ 033public final class IllegalFileLengthMessage extends Message 034{ 035 036 /** Serial version UID for backwards compatibility with 1.0.x classes. */ 037 private static final long serialVersionUID = 961185282869701368L; 038 039 /** 040 * The length of a file incompatible to {@code blockSize}. 041 * @serial 042 */ 043 private final long fileLength; 044 045 /** 046 * The length of one block in byte. 047 * @serial 048 */ 049 private final int blockSize; 050 051 /** 052 * Creates a new {@code IllegalFileLengthMessage} instance taking the length of a file incompatible to a given block 053 * size. 054 * 055 * @param fileLength Length of a file incompatible to {@code blockSize}. 056 * @param blockSize Length of one block in byte. 057 * 058 * @throws IllegalArgumentException if either {@code fileLength} or {@code blockSize} is negative, or if 059 * {@code fileLength % blockSize} equals {@code 0}. 060 */ 061 public IllegalFileLengthMessage( final long fileLength, final int blockSize ) 062 { 063 if ( fileLength < 0 ) 064 { 065 throw new IllegalArgumentException( Long.toString( fileLength ) ); 066 } 067 if ( blockSize <= 0 ) 068 { 069 throw new IllegalArgumentException( Integer.toString( blockSize ) ); 070 } 071 if ( fileLength != 0 && fileLength % blockSize == 0 ) 072 { 073 throw new IllegalArgumentException( Long.toString( fileLength % blockSize ) ); 074 } 075 076 this.fileLength = fileLength; 077 this.blockSize = blockSize; 078 } 079 080 /** 081 * {@inheritDoc} 082 * 083 * @return the length of the file and the incompatible block size. 084 * <ul> 085 * <li>[0]: the length of the file incompatible to {@code blockSize}.</li> 086 * <li>[1]: the length of one block in byte.</li> 087 * </ul> 088 */ 089 public Object[] getFormatArguments( final Locale locale ) 090 { 091 return new Object[] 092 { 093 new Long( this.fileLength ), new Integer( this.blockSize ) 094 }; 095 } 096 097 /** 098 * {@inheritDoc} 099 * 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 parameter. 122 * @param blk format parameter. 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}