001/**
002 * Copyright (c) 2012, 2014, Credit Suisse (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.internal.convert;
017
018import java.net.MalformedURLException;
019
020import javax.money.convert.ConversionContext;
021import javax.money.convert.ProviderContext;
022import javax.money.convert.ProviderContextBuilder;
023import javax.money.convert.RateType;
024
025/**
026 * <p>
027 * This class implements an {@link javax.money.convert.ExchangeRateProvider}
028 * that loads data from the European Central Bank data feed (XML). It loads the
029 * current exchange rates, as well as historic rates for the past 1500 days. The
030 * provider loads all data up to 1999 into its historic data cache.
031 * </p>
032 * <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>
033 * <p><code>CurrencyUnit termCurrency = ...;</code></p>
034 * <p><code>LocalDate localDate = ...;</code></p>
035 * <p><code>ConversionQuery conversionQuery = ConversionQueryBuilder.of().setTermCurrency(euro).setTimestamp(localDate).build();</code>v
036 * <p><code>CurrencyConversion currencyConversion = provider.getCurrencyConversion(conversionQuery);</code></p>
037 * <p><code>MonetaryAmount money = ...;</code></p>
038 * <p><code>MonetaryAmount result = currencyConversion.apply(money);</code></p>
039 *
040 * @author Anatole Tresch
041 * @author Werner Keil
042 * @author otaviojava
043 */
044public class ECBHistoricRateProvider extends AbstractECBRateProvider {
045
046    /**
047     * The data id used for the LoaderService.
048     */
049    private static final String DATA_ID = ECBHistoricRateProvider.class.getSimpleName();
050
051    /**
052     * The {@link ConversionContext} of this provider.
053     */
054    private static final ProviderContext CONTEXT =
055            ProviderContextBuilder.of("ECB-HIST", RateType.HISTORIC, RateType.DEFERRED)
056                    .set("providerDescription", "European Central Bank").set("days", 1500).build();
057
058
059    public ECBHistoricRateProvider() throws MalformedURLException {
060        super(CONTEXT);
061    }
062
063    @Override
064    public String getDataId() {
065        return DATA_ID;
066    }
067
068}