001/*
002 * Copyright (c) 2012, 2013, Credit Suisse (Anatole Tresch), Werner Keil.
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 * 
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 * 
016 * Contributors: Anatole Tresch - initial implementation Werner Keil -
017 * extensions and adaptions.
018 */
019package org.javamoney.moneta;
020
021import javax.money.MonetaryException;
022
023/**
024 * Exception thrown when the requested currency is unknown to the currency
025 * system in use.
026 * <p>
027 * For example, this exception would be thrown when trying to obtain a currency
028 * using an unrecognized currency code or locale.
029 * 
030 * @author Werner Keil
031 */
032public class UnknownCurrencyException extends MonetaryException {
033
034        private static final long serialVersionUID = 3277879391197687869L;
035        /** The requested currency code. */
036        private final String currencyCode;
037
038        /**
039         * Constructor.
040         * 
041         * @param currencyCode
042         *            the currencyCode, not {@code null}.
043         * @param message
044         *            the exception message, if null a default message will be
045         *            created.
046         */
047        public UnknownCurrencyException(String currencyCode) {
048                this(currencyCode, null);
049        }
050
051        /**
052         * Constructor.
053         * 
054         * @param currencyCode
055         *            the currencyCode, not {@code null}.
056         * @param message
057         *            the exception message, if null a default message will be
058         *            created.
059         */
060        public UnknownCurrencyException(String currencyCode,
061                        String message) {
062                super(message == null ? "Unknown currency - "
063                                + currencyCode : message);
064                if (currencyCode == null) {
065                        throw new IllegalArgumentException("currencyCode may not be null.");
066                }
067                this.currencyCode = currencyCode;
068        }
069
070        /**
071         * Access the currency code of the unknown currency.
072         * 
073         * @return the currency code of the unknown currency.
074         */
075        public String getCurrencyCode() {
076                return this.currencyCode;
077        }
078
079        /*
080         * (non-Javadoc)
081         * 
082         * @see java.lang.Object#toString()
083         */
084        @Override
085        public String toString() {
086                return "UnknownCurrencyException [currencyCode=" + currencyCode + "]";
087        }
088
089}