1 /*
2 * jDTAUS Banking SPI
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.spi;
22
23 import java.util.Date;
24 import java.util.Locale;
25 import org.jdtaus.core.container.ContainerFactory;
26
27 /**
28 * Gets thrown for illegal currencies.
29 *
30 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
31 * @version $JDTAUS: UnsupportedCurrencyException.java 8865 2014-01-10 17:13:42Z schulte $
32 */
33 public class UnsupportedCurrencyException extends IllegalArgumentException
34 {
35
36 /** Serial version UID for backwards compatibility with 1.1.x classes. */
37 private static final long serialVersionUID = -4268651061144430651L;
38
39 /**
40 * Currency code causing an {@code UnsupportedCurrencyException}.
41 * @serial
42 */
43 private String currencyCode;
44
45 /**
46 * Date for which the currency is not supported.
47 * @serial
48 */
49 private Date date;
50
51 /**
52 * Creates a new {@code UnsupportedCurrencyException} taking the unsupported currency code together with the date
53 * for which it was requested.
54 *
55 * @param currencyCode The ISO currency code which is not supported at {@code date}.
56 * @param date the date for which {@code currencyCode} is illegal.
57 */
58 public UnsupportedCurrencyException( final String currencyCode, final Date date )
59 {
60 super();
61 this.currencyCode = currencyCode;
62 this.date = (Date) ( date == null ? null : date.clone() );
63 }
64
65 /**
66 * Gets the currency code causing this exception to be thrown.
67 *
68 * @return The currency code causing this exception to be thrown or {@code null}.
69 */
70 public String getCurrencyCode()
71 {
72 return this.currencyCode;
73 }
74
75 /**
76 * Gets the date for which {@code getCurrencyCode()} is not supported.
77 *
78 * @return The date for which {@code getCurrencyCode()} is not supported or {@code null}.
79 */
80 public Date getDate()
81 {
82 return (Date) ( this.date == null ? null : this.date.clone() );
83 }
84
85 /**
86 * Returns the message of the exception.
87 *
88 * @return The message of the exception.
89 */
90 public String getMessage()
91 {
92 return this.getUnsupportedCurrencyMessage( this.getLocale(), this.currencyCode, this.date );
93 }
94
95 //--Dependencies------------------------------------------------------------
96
97 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies
98 // This section is managed by jdtaus-container-mojo.
99
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 }