← joda-money  /  src/main/java/org/joda/money/CurrencyUnitDataProvider.java

1
/*
2
 *  Copyright 2009-present, Stephen Colebourne
3
 *
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
 *  you may not use this file except in compliance with the License.
6
 *  You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *  Unless required by applicable law or agreed to in writing, software
11
 *  distributed under the License is distributed on an "AS IS" BASIS,
12
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *  See the License for the specific language governing permissions and
14
 *  limitations under the License.
15
 */
16
package org.joda.money;
17
18
/**
19
 * Provider for available currencies.
20
 */
21
public abstract class CurrencyUnitDataProvider {
22
23
    /**
24
     * Registers all the currencies known by this provider.
25
     *
26
     * @throws Exception if an error occurs
27
     */
28
    protected abstract void registerCurrencies() throws Exception;
29
30
    /**
31
     * Registers a currency allowing it to be used.
32
     * <p>
33
     * This method is called by {@link #registerCurrencies()} to perform the
34
     * actual creation of a currency.
35
     *
36
     * @param currencyCode  the currency code, not null
37
     * @param numericCurrencyCode  the numeric currency code, -1 if none
38
     * @param decimalPlaces  the number of decimal places that the currency
39
     *  normally has, from 0 to 3, or -1 for a pseudo-currency
40
     */
41
    protected final void registerCurrency(String currencyCode, int numericCurrencyCode, int decimalPlaces) {
42
        CurrencyUnit.registerCurrency(currencyCode, numericCurrencyCode, decimalPlaces, true);
43
    }
44
45
    /**
46
     * Registers a country allowing it to be used.
47
     * <p>
48
     * This method is called by {@link #registerCurrencies()} to perform the
49
     * actual creation of a country.
50
     *
51
     * @param countryCode  the country code, not null
52
     * @param currencyCode  the currency code, not null
53
     */
54
    protected final void registerCountry(String countryCode, String currencyCode) {
55
        CurrencyUnit.registerCountry(countryCode, CurrencyUnit.of(currencyCode));
56
    }
57
58
}
59