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 date is invalid.
030 *
031 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
032 * @version $JDTAUS: IllegalDateMessage.java 8865 2014-01-10 17:13:42Z schulte $
033 */
034public final class IllegalDateMessage extends Message
035{
036
037    /** Serial version UID for backwards compatibility with 1.0.x classes. */
038    private static final long serialVersionUID = 4086935652662010927L;
039
040    /**
041     * The illegal date.
042     * @serial
043     */
044    private final Date date;
045
046    /**
047     * The starting date of the range for valid dates.
048     * @serial
049     */
050    private final Date dateRangeStart;
051
052    /**
053     * The ending date of the range for valid dates.
054     * @serial
055     */
056    private final Date dateRangeEnd;
057
058    /**
059     * Creates a new {@code IllegalDateMessage} instance taking the illegal date and the range of dates for which a
060     * date is considered legal.
061     *
062     * @param date The illegal date.
063     * @param dateRangeStart The starting date of the range for valid dates.
064     * @param dateRangeEnd The ending date of the range for valid dates.
065     *
066     * @throws NullPointerException if either {@code date}, {@code dateRangeStart} or {@code dateRangeEnd} is
067     * {@code null}.
068     */
069    public IllegalDateMessage( final Date date, final Date dateRangeStart, final Date dateRangeEnd )
070    {
071        super();
072        if ( date == null )
073        {
074            throw new NullPointerException( "date" );
075        }
076        if ( dateRangeStart == null )
077        {
078            throw new NullPointerException( "dateRangeStart" );
079        }
080        if ( dateRangeEnd == null )
081        {
082            throw new NullPointerException( "dateRangeEnd" );
083        }
084
085        this.date = (Date) date.clone();
086        this.dateRangeStart = (Date) dateRangeStart.clone();
087        this.dateRangeEnd = (Date) dateRangeEnd.clone();
088    }
089
090    /**
091     * {@inheritDoc}
092     *
093     * @return The illegal date.
094     * <ul>
095     * <li>[0]: the illegal date.</li>
096     * <li>[1]: the starting date of the range for valid dates.</li>
097     * <li>[2]: the ending date of the range for valid dates.</li>
098     * </ul>
099     */
100    public Object[] getFormatArguments( final Locale locale )
101    {
102        return new Object[]
103            {
104                this.date, this.dateRangeStart, this.dateRangeEnd
105            };
106    }
107
108    /**
109     * {@inheritDoc}
110     *
111     * @return The corresponding text from the message's {@code ResourceBundle}
112     * <blockquote><pre>
113     * The date {0,date,long} is either before {1,date,long} or after {2,date,long}.
114     * </pre></blockquote>
115     */
116    public String getText( final Locale locale )
117    {
118        return this.getIllegalDateMessage( locale, this.date, this.dateRangeStart, this.dateRangeEnd );
119    }
120
121    //--Messages----------------------------------------------------------------
122
123// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages
124    // This section is managed by jdtaus-container-mojo.
125
126    /**
127     * Gets the text of message <code>illegalDate</code>.
128     * <blockquote><pre>Das Datum {0,date,long} liegt entweder vor {1,date,long} oder hinter {2,date,long}.</pre></blockquote>
129     * <blockquote><pre>The date {0,date,long} is either before {1,date,long} or after {2,date,long}.</pre></blockquote>
130     *
131     * @param locale The locale of the message instance to return.
132     * @param dat format parameter.
133     * @param start format parameter.
134     * @param end format parameter.
135     *
136     * @return the text of message <code>illegalDate</code>.
137     */
138    private String getIllegalDateMessage( final Locale locale,
139            final java.util.Date dat,
140            final java.util.Date start,
141            final java.util.Date end )
142    {
143        return ContainerFactory.getContainer().
144            getMessage( this, "illegalDate", locale,
145                new Object[]
146                {
147                    dat,
148                    start,
149                    end
150                });
151
152    }
153
154// </editor-fold>//GEN-END:jdtausMessages
155
156    //----------------------------------------------------------------Messages--
157}