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 given schedule is invalid.
030 *
031 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
032 * @version $JDTAUS: IllegalScheduleMessage.java 8865 2014-01-10 17:13:42Z schulte $
033 */
034public final class IllegalScheduleMessage extends Message
035{
036
037    /** Serial version UID for backwards compatibility with 1.0.x classes. */
038    private static final long serialVersionUID = -8689097743116031670L;
039
040    /**
041     * Create date of the illegal schedule.
042     * @serial
043     */
044    private final Date createDate;
045
046    /**
047     * Execution date of the illegal schedule.
048     * @serial
049     */
050    private final Date executionDate;
051
052    /**
053     * Maximum number of days allowed between {@code createDate} and
054     * {@code executionDate}.
055     * @serial
056     */
057    private final int maxDays;
058
059    /**
060     * Creates a new {@code IllegalScheduleMessage} instance taking the create date and the date of execution not
061     * forming a valid schedule for a maximum number of days between them.
062     *
063     * @param createDate The create date of the schedule.
064     * @param executionDate The execution date of the schedule.
065     * @param maxDays The maximum number of days allowed between {@code createDate} and {@code executionDate}.
066     *
067     * @throws NullPointerException if {@code createDate} is {@code null}.
068     * @throws IllegalArgumentException if {@code maxDays} is negative.
069     */
070    public IllegalScheduleMessage( final Date createDate, final Date executionDate, final int maxDays )
071    {
072        super();
073        if ( createDate == null )
074        {
075            throw new NullPointerException( "createDate" );
076        }
077        if ( maxDays < 0 )
078        {
079            throw new IllegalArgumentException( Integer.toString( maxDays ) );
080        }
081
082        this.createDate = (Date) createDate.clone();
083        this.executionDate = (Date) ( executionDate == null ? null : executionDate.clone() );
084        this.maxDays = maxDays;
085    }
086
087    /**
088     * {@inheritDoc}
089     *
090     * @return The create date and the date of execution.
091     * <ul>
092     * <li>[0]: the create date of the schedule.</li>
093     * <li>[1]: the date of execution of the invalid schedule.</li>
094     * <li>[2]: the maximum number of days allowed between create date and
095     * execution date.</li>
096     * </ul>
097     */
098    public Object[] getFormatArguments( final Locale locale )
099    {
100        return new Object[]
101            {
102                this.createDate, this.executionDate, new Integer( this.maxDays )
103            };
104    }
105
106    /**
107     * {@inheritDoc}
108     *
109     * @return The corresponding text from the message's {@code ResourceBundle}
110     * <blockquote><pre>
111     * The executiondate {1,date,long} is before create date {0,date,long} or more than {2,number} days thereafter.
112     * </pre></blockquote>
113     */
114    public String getText( final Locale locale )
115    {
116        return this.getIllegalScheduleMessage( locale, this.createDate, this.executionDate,
117                                               new Integer( this.maxDays ) );
118
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>illegalSchedule</code>.
128     * <blockquote><pre>Das Ausführungsdatum {1,date,long} liegt vor dem Dateierstellungsdatum {0,date,long} oder mehr als {2,number} Kalendertage dahinter.</pre></blockquote>
129     * <blockquote><pre>The executiondate {1,date,long} is before create date {0,date,long} or more than {2,number} days thereafter.</pre></blockquote>
130     *
131     * @param locale The locale of the message instance to return.
132     * @param cdat format parameter.
133     * @param edat format parameter.
134     * @param max format parameter.
135     *
136     * @return the text of message <code>illegalSchedule</code>.
137     */
138    private String getIllegalScheduleMessage( final Locale locale,
139            final java.util.Date cdat,
140            final java.util.Date edat,
141            final java.lang.Number max )
142    {
143        return ContainerFactory.getContainer().
144            getMessage( this, "illegalSchedule", locale,
145                new Object[]
146                {
147                    cdat,
148                    edat,
149                    max
150                });
151
152    }
153
154// </editor-fold>//GEN-END:jdtausMessages
155
156    //----------------------------------------------------------------Messages--
157}