1 | /* |
2 | * jDTAUS Banking Messages |
3 | * Copyright (C) 2005 Christian Schulte |
4 | * <cs@schulte.it> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2.1 of the License, or any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this library; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * |
20 | */ |
21 | package org.jdtaus.banking.messages; |
22 | |
23 | import java.util.Date; |
24 | import java.util.Locale; |
25 | import org.jdtaus.core.container.ContainerFactory; |
26 | import org.jdtaus.core.text.Message; |
27 | |
28 | /** |
29 | * Message stating that a date is invalid. |
30 | * |
31 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
32 | * @version $JDTAUS: IllegalDateMessage.java 8865 2014-01-10 17:13:42Z schulte $ |
33 | */ |
34 | public final class IllegalDateMessage extends Message |
35 | { |
36 | |
37 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
38 | private static final long serialVersionUID = 4086935652662010927L; |
39 | |
40 | /** |
41 | * The illegal date. |
42 | * @serial |
43 | */ |
44 | private final Date date; |
45 | |
46 | /** |
47 | * The starting date of the range for valid dates. |
48 | * @serial |
49 | */ |
50 | private final Date dateRangeStart; |
51 | |
52 | /** |
53 | * The ending date of the range for valid dates. |
54 | * @serial |
55 | */ |
56 | private final Date dateRangeEnd; |
57 | |
58 | /** |
59 | * Creates a new {@code IllegalDateMessage} instance taking the illegal date and the range of dates for which a |
60 | * date is considered legal. |
61 | * |
62 | * @param date The illegal date. |
63 | * @param dateRangeStart The starting date of the range for valid dates. |
64 | * @param dateRangeEnd The ending date of the range for valid dates. |
65 | * |
66 | * @throws NullPointerException if either {@code date}, {@code dateRangeStart} or {@code dateRangeEnd} is |
67 | * {@code null}. |
68 | */ |
69 | public IllegalDateMessage( final Date date, final Date dateRangeStart, final Date dateRangeEnd ) |
70 | { |
71 | super(); |
72 | if ( date == null ) |
73 | { |
74 | throw new NullPointerException( "date" ); |
75 | } |
76 | if ( dateRangeStart == null ) |
77 | { |
78 | throw new NullPointerException( "dateRangeStart" ); |
79 | } |
80 | if ( dateRangeEnd == null ) |
81 | { |
82 | throw new NullPointerException( "dateRangeEnd" ); |
83 | } |
84 | |
85 | this.date = (Date) date.clone(); |
86 | this.dateRangeStart = (Date) dateRangeStart.clone(); |
87 | this.dateRangeEnd = (Date) dateRangeEnd.clone(); |
88 | } |
89 | |
90 | /** |
91 | * {@inheritDoc} |
92 | * |
93 | * @return The illegal date. |
94 | * <ul> |
95 | * <li>[0]: the illegal date.</li> |
96 | * <li>[1]: the starting date of the range for valid dates.</li> |
97 | * <li>[2]: the ending date of the range for valid dates.</li> |
98 | * </ul> |
99 | */ |
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 | } |