001/*
002 *  jDTAUS Banking Messages
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.banking.messages;
022
023import java.util.Date;
024import java.util.Locale;
025import org.jdtaus.core.container.ContainerFactory;
026import org.jdtaus.core.text.Message;
027
028/**
029 * Message stating that a currency is in use in combination with a date at which its use is invalid.
030 *
031 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
032 * @version $JDTAUS: CurrencyConstraintMessage.java 8865 2014-01-10 17:13:42Z schulte $
033 */
034public final class CurrencyConstraintMessage extends Message
035{
036
037    /** Serial version UID for backwards compatibility with 1.0.x classes. */
038    private static final long serialVersionUID = 3569739879822644273L;
039
040    /**
041     * The ISO currency code of the currency violating the constraint.
042     * @serial
043     */
044    private final String currencyCode;
045
046    /**
047     * The date at which {@code currencyCode} violates the constraint.
048     * @serial
049     */
050    private final Date date;
051
052    /**
053     * Creates a new {@code CurrencyConstraintMessage} taking a currency code of the currency violating the constraint
054     * at a given date.
055     *
056     * @param currencyCode The ISO currency code of the currency violating the constraint.
057     * @param date The date at which {@code currencyCode} violates the constraint.
058     *
059     * @throws NullPointerException if either {@code currencyCode} or {@code date} is {@code null}.
060     */
061    public CurrencyConstraintMessage( final String currencyCode, final Date date )
062    {
063        if ( currencyCode == null )
064        {
065            throw new NullPointerException( "currencyCode" );
066        }
067        if ( date == null )
068        {
069            throw new NullPointerException( "date" );
070        }
071
072        this.currencyCode = currencyCode;
073        this.date = (Date) date.clone();
074    }
075
076    /**
077     * {@inheritDoc}
078     *
079     * @return The ISO currency code of the currency violating the constraint with corresponding date.
080     * <ul>
081     * <li>[0]: ISO currency code.</li>
082     * <li>[1]: date.</li>
083     * </ul>
084     */
085    public Object[] getFormatArguments( final Locale locale )
086    {
087        return new Object[]
088            {
089                this.currencyCode, this.date
090            };
091    }
092
093    /**
094     * {@inheritDoc}
095     *
096     * @return The corresponding text from the message's {@code ResourceBundle}
097     * <blockquote><pre>
098     * The {0} currency is in use but not valid at {1,date,long}.
099     * </pre></blockquote>
100     */
101    public String getText( final Locale locale )
102    {
103        return this.getCurrencyConstraintMessage( locale, this.currencyCode, this.date );
104    }
105
106    //--Messages----------------------------------------------------------------
107
108// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages
109    // This section is managed by jdtaus-container-mojo.
110
111    /**
112     * Gets the text of message <code>currencyConstraint</code>.
113     * <blockquote><pre>Die {0} Währung befindet sich in Verwendung, ist am {1,date,long} jedoch ungültig.</pre></blockquote>
114     * <blockquote><pre>The {0} currency is in use but not valid at {1,date,long}.</pre></blockquote>
115     *
116     * @param locale The locale of the message instance to return.
117     * @param currency format parameter.
118     * @param constraintDate format parameter.
119     *
120     * @return the text of message <code>currencyConstraint</code>.
121     */
122    private String getCurrencyConstraintMessage( final Locale locale,
123            final java.lang.String currency,
124            final java.util.Date constraintDate )
125    {
126        return ContainerFactory.getContainer().
127            getMessage( this, "currencyConstraint", locale,
128                new Object[]
129                {
130                    currency,
131                    constraintDate
132                });
133
134    }
135
136// </editor-fold>//GEN-END:jdtausMessages
137
138    //----------------------------------------------------------------Messages--
139}