001/*
002 * Copyright (c) 2012, 2020, Anatole Tresch, Werner Keil and others by the @author tag.
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 */
016package org.javamoney.moneta.convert.ecb;
017
018import javax.money.convert.ConversionContext;
019import javax.money.convert.ProviderContext;
020import javax.money.convert.ProviderContextBuilder;
021import javax.money.convert.RateType;
022
023/**
024 * <p>
025 * This class implements an {@link javax.money.convert.ExchangeRateProvider}
026 * that loads data from the European Central Bank data feed (XML). It loads the
027 * current exchange rates, as well as historic rates for the past 1500 days. The
028 * provider loads all data up to 1999 into its historic data cache.
029 * </p>
030 * <p>The default date is yesterday or the most recent day of week. To uses exchange rate from a specific date, you can use this way:</p>
031 * <p><code>CurrencyUnit termCurrency = ...;</code></p>
032 * <p><code>LocalDate localDate = ...;</code></p>
033 * <p><code>ConversionQuery conversionQuery = ConversionQueryBuilder.of().setTermCurrency(euro).set(localDate).build();</code>
034 * <p><code>CurrencyConversion currencyConversion = provider.getCurrencyConversion(conversionQuery);</code></p>
035 * <p><code>MonetaryAmount money = ...;</code></p>
036 * <p><code>MonetaryAmount result = currencyConversion.apply(money);</code></p>
037 *
038 * @author Anatole Tresch
039 * @author Werner Keil
040 * @author otaviojava
041 */
042public class ECBHistoricRateProvider extends ECBAbstractRateProvider {
043
044    /**
045     * The data id used for the LoaderService.
046     */
047    private static final String DATA_ID = ECBHistoricRateProvider.class.getSimpleName();
048
049    /**
050     * The {@link ConversionContext} of this provider.
051     */
052    private static final ProviderContext CONTEXT =
053            ProviderContextBuilder.of("ECB-HIST", RateType.HISTORIC, RateType.DEFERRED)
054                    .set("providerDescription", "European Central Bank").set("days", 1500).build();
055
056
057    public ECBHistoricRateProvider() {
058        super(CONTEXT);
059    }
060
061    @Override
062    public String getDataId() {
063        return DATA_ID;
064    }
065
066
067}