001/* 002 * jDTAUS Core Messages 003 * Copyright (C) 2005 Christian Schulte 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library; if not, write to the Free Software 017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 018 * 019 * $JDTAUS: IllegalNumberMessage.java 8525 2012-05-07 08:32:23Z schulte2005 $ 020 */ 021package org.jdtaus.core.messages; 022 023import java.util.Locale; 024import org.jdtaus.core.container.ContainerFactory; 025import org.jdtaus.core.text.Message; 026 027/** 028 * Message stating that an illegal number was specified. 029 * 030 * @author Christian Schulte 031 * @version $JDTAUS: IllegalNumberMessage.java 8525 2012-05-07 08:32:23Z schulte2005 $ 032 * @since 1.10 033 */ 034public final class IllegalNumberMessage extends Message 035{ 036 //--IllegalNumberMessage---------------------------------------------------- 037 038 /** Serial version UID for backwards compatibility with 1.0.x classes. */ 039 private static final long serialVersionUID = 6578496762473822182L; 040 041 /** 042 * The invalid number. 043 * @serial 044 */ 045 private Number invalidNumber; 046 047 /** 048 * The minimum required value. 049 * @serial 050 */ 051 private Number minimum; 052 053 /** 054 * The maximum allowed value. 055 * @serial 056 */ 057 private Number maximum; 058 059 /** 060 * Creates a new {@code IllegalNumberMessage} instance taking an invalid number, a minimum required value and a 061 * maximum allowed value. 062 * 063 * @param invalidNumber The invalid number or {@code null} if no such number is known. 064 * @param minimum The minimum required value or {@code null} if no such requirement exists. 065 * @param maximum The maximum allowed value or {@code null} if no such limit exists. 066 */ 067 public IllegalNumberMessage( final Number invalidNumber, final Number minimum, final Number maximum ) 068 { 069 super(); 070 this.invalidNumber = invalidNumber; 071 this.minimum = minimum; 072 this.maximum = maximum; 073 } 074 075 //----------------------------------------------------IllegalNumberMessage-- 076 //--Message----------------------------------------------------------------- 077 078 /** 079 * {@inheritDoc} 080 * <ul> 081 * <li>[0]: The invalid number or {@code null} if no such number is known.</li> 082 * <li>[1]: The minimum required value or {@code null} if no such requirement exists.</li> 083 * <li>[2]: The maximum allowed value or {@code null} if no such limit exists.</li> 084 * </ul> 085 */ 086 public Object[] getFormatArguments( final Locale locale ) 087 { 088 return new Object[] 089 { 090 this.invalidNumber, this.minimum, this.maximum 091 }; 092 093 } 094 095 public String getText( final Locale locale ) 096 { 097 final StringBuffer b = new StringBuffer( 128 ); 098 099 if ( this.invalidNumber != null ) 100 { 101 b.append( this.getIllegalValueMessage( locale, this.invalidNumber ) ).append( " " ); 102 } 103 104 if ( this.minimum != null ) 105 { 106 b.append( this.getIllegalMinimumValueMessage( locale, this.minimum ) ).append( " " ); 107 } 108 109 if ( this.maximum != null ) 110 { 111 b.append( this.getIllegalMaximumValueMessage( locale, this.maximum ) ).append( " " ); 112 } 113 114 115 if ( b.length() > 0 ) 116 { 117 b.setLength( b.length() - 1 ); 118 } 119 120 return b.toString(); 121 } 122 123 //-----------------------------------------------------------------Message-- 124 //--Messages---------------------------------------------------------------- 125 126// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages 127 // This section is managed by jdtaus-container-mojo. 128 129 /** 130 * Gets the text of message <code>illegalValue</code>. 131 * <blockquote><pre>Ungültiger Wert {0,number}.</pre></blockquote> 132 * <blockquote><pre>Illegal value {0,number}.</pre></blockquote> 133 * 134 * @param locale The locale of the message instance to return. 135 * @param value Illegal value. 136 * 137 * @return Information about an illegal value. 138 */ 139 private String getIllegalValueMessage( final Locale locale, 140 final java.lang.Number value ) 141 { 142 return ContainerFactory.getContainer(). 143 getMessage( this, "illegalValue", locale, 144 new Object[] 145 { 146 value 147 }); 148 149 } 150 151 /** 152 * Gets the text of message <code>illegalMaximumValue</code>. 153 * <blockquote><pre>Größer als {0,number}.</pre></blockquote> 154 * <blockquote><pre>Greater than {0,number}.</pre></blockquote> 155 * 156 * @param locale The locale of the message instance to return. 157 * @param maximum Maximum allowed value. 158 * 159 * @return Information about an illegal maximum value. 160 */ 161 private String getIllegalMaximumValueMessage( final Locale locale, 162 final java.lang.Number maximum ) 163 { 164 return ContainerFactory.getContainer(). 165 getMessage( this, "illegalMaximumValue", locale, 166 new Object[] 167 { 168 maximum 169 }); 170 171 } 172 173 /** 174 * Gets the text of message <code>illegalMinimumValue</code>. 175 * <blockquote><pre>Kleiner als {0,number}.</pre></blockquote> 176 * <blockquote><pre>Less than {0,number}.</pre></blockquote> 177 * 178 * @param locale The locale of the message instance to return. 179 * @param minimum Minimum required value. 180 * 181 * @return Information about an illegal minimum value. 182 */ 183 private String getIllegalMinimumValueMessage( final Locale locale, 184 final java.lang.Number minimum ) 185 { 186 return ContainerFactory.getContainer(). 187 getMessage( this, "illegalMinimumValue", locale, 188 new Object[] 189 { 190 minimum 191 }); 192 193 } 194 195// </editor-fold>//GEN-END:jdtausMessages 196 197 //----------------------------------------------------------------Messages-- 198}