001/* 002 * jDTAUS Banking SPI 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.spi; 022 023import java.util.Date; 024import java.util.Locale; 025import org.jdtaus.core.container.ContainerFactory; 026 027/** 028 * Gets thrown for illegal currencies. 029 * 030 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 031 * @version $JDTAUS: UnsupportedCurrencyException.java 8865 2014-01-10 17:13:42Z schulte $ 032 */ 033public class UnsupportedCurrencyException extends IllegalArgumentException 034{ 035 036 /** Serial version UID for backwards compatibility with 1.1.x classes. */ 037 private static final long serialVersionUID = -4268651061144430651L; 038 039 /** 040 * Currency code causing an {@code UnsupportedCurrencyException}. 041 * @serial 042 */ 043 private String currencyCode; 044 045 /** 046 * Date for which the currency is not supported. 047 * @serial 048 */ 049 private Date date; 050 051 /** 052 * Creates a new {@code UnsupportedCurrencyException} taking the unsupported currency code together with the date 053 * for which it was requested. 054 * 055 * @param currencyCode The ISO currency code which is not supported at {@code date}. 056 * @param date the date for which {@code currencyCode} is illegal. 057 */ 058 public UnsupportedCurrencyException( final String currencyCode, final Date date ) 059 { 060 super(); 061 this.currencyCode = currencyCode; 062 this.date = (Date) ( date == null ? null : date.clone() ); 063 } 064 065 /** 066 * Gets the currency code causing this exception to be thrown. 067 * 068 * @return The currency code causing this exception to be thrown or {@code null}. 069 */ 070 public String getCurrencyCode() 071 { 072 return this.currencyCode; 073 } 074 075 /** 076 * Gets the date for which {@code getCurrencyCode()} is not supported. 077 * 078 * @return The date for which {@code getCurrencyCode()} is not supported or {@code null}. 079 */ 080 public Date getDate() 081 { 082 return (Date) ( this.date == null ? null : this.date.clone() ); 083 } 084 085 /** 086 * Returns the message of the exception. 087 * 088 * @return The message of the exception. 089 */ 090 public String getMessage() 091 { 092 return this.getUnsupportedCurrencyMessage( this.getLocale(), this.currencyCode, this.date ); 093 } 094 095 //--Dependencies------------------------------------------------------------ 096 097// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies 098 // This section is managed by jdtaus-container-mojo. 099 100 /** 101 * Gets the configured <code>Locale</code> implementation. 102 * 103 * @return The configured <code>Locale</code> implementation. 104 */ 105 private Locale getLocale() 106 { 107 return (Locale) ContainerFactory.getContainer(). 108 getDependency( this, "Locale" ); 109 110 } 111 112// </editor-fold>//GEN-END:jdtausDependencies 113 114 //------------------------------------------------------------Dependencies-- 115 //--Messages---------------------------------------------------------------- 116 117// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages 118 // This section is managed by jdtaus-container-mojo. 119 120 /** 121 * Gets the text of message <code>unsupportedCurrency</code>. 122 * <blockquote><pre>Die {0} Währung steht am {1,date,long} nicht zur Verfügung.</pre></blockquote> 123 * <blockquote><pre>The currency {0} is not available at {1,date,long}.</pre></blockquote> 124 * 125 * @param locale The locale of the message instance to return. 126 * @param currency format parameter. 127 * @param date format parameter. 128 * 129 * @return the text of message <code>unsupportedCurrency</code>. 130 */ 131 private String getUnsupportedCurrencyMessage( final Locale locale, 132 final java.lang.String currency, 133 final java.util.Date date ) 134 { 135 return ContainerFactory.getContainer(). 136 getMessage( this, "unsupportedCurrency", locale, 137 new Object[] 138 { 139 currency, 140 date 141 }); 142 143 } 144 145// </editor-fold>//GEN-END:jdtausMessages 146 147 //----------------------------------------------------------------Messages-- 148}