View Javadoc

1   /*   Copyright (C) 2004 Finalist IT Group
2    *
3    *   This file is part of JAG - the Java J2EE Application Generator
4    *
5    *   JAG is free software; you can redistribute it and/or modify
6    *   it under the terms of the GNU General Public License as published by
7    *   the Free Software Foundation; either version 2 of the License, or
8    *   (at your option) any later version.
9    *   JAG is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *   You should have received a copy of the GNU General Public License
14   *   along with JAG; if not, write to the Free Software
15   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   */
17  
18  package com.finalist.util.ejb.validation;
19  
20  
21  import java.io.Serializable;
22  
23  
24  /***
25   * An encapsulation of an individual error message returned by the
26   * <code>validate()</code> method of an <code>ActionForm</code>, consisting
27   * of a message key (to be used to look up message text in an appropriate
28   * message resources database) plus up to four placeholder objects that can
29   * be used for parametric replacement in the message text.
30   *
31   * The placeholder objects are referenced in the message text using the same
32   * syntax used by the JDK <code>MessageFormat</code> class. Thus, the first
33   * placeholder is '{0}', the second is '{1}', etc.
34   *
35   * @author Craig R. McClanahan
36   * @version $Revision: 1.1 $ $Date: 2004/03/01 19:29:18 $
37   */
38  
39  public class ModelError implements Serializable {
40  
41  
42     // ----------------------------------------------------------- Constructors
43  
44  
45     /***
46      * Construct an action error with no replacement values.
47      *
48      * @param key Message key for this error message
49      */
50     public ModelError(String key) {
51  
52        this(key, null, null, null, null);
53  
54     }
55  
56  
57     /***
58      * Construct an action error with the specified replacement values.
59      *
60      * @param key Message key for this error message
61      * @param value0 First replacement value
62      */
63     public ModelError(String key, Object value0) {
64  
65        this(key, value0, null, null, null);
66  
67     }
68  
69  
70     /***
71      * Construct an action error with the specified replacement values.
72      *
73      * @param key Message key for this error message
74      * @param value0 First replacement value
75      * @param value1 Second replacement value
76      */
77     public ModelError(String key, Object value0, Object value1) {
78  
79        this(key, value0, value1, null, null);
80  
81     }
82  
83  
84     /***
85      * Construct an action error with the specified replacement values.
86      *
87      * @param key Message key for this error message
88      * @param value0 First replacement value
89      * @param value1 Second replacement value
90      * @param value2 Third replacement value
91      */
92     public ModelError(String key, Object value0, Object value1,
93        Object value2) {
94  
95        this(key, value0, value1, value2, null);
96  
97     }
98  
99  
100    /***
101     * Construct an action error with the specified replacement values.
102     *
103     * @param key Message key for this error message
104     * @param value0 First replacement value
105     * @param value1 Second replacement value
106     * @param value2 Third replacement value
107     * @param value3 Fourth replacement value
108     */
109    public ModelError(String key, Object value0, Object value1,
110       Object value2, Object value3) {
111 
112       super();
113       this.key = key;
114       values[0] = value0;
115       values[1] = value1;
116       values[2] = value2;
117       values[3] = value3;
118 
119    }
120 
121 
122    // ----------------------------------------------------- Instance Variables
123 
124 
125    /***
126     * The message key for this error message.
127     */
128    private String key = null;
129 
130 
131    /***
132     * The replacement values for this error mesasge.
133     */
134    private Object values[] = {null, null, null, null};
135 
136 
137    // --------------------------------------------------------- Public Methods
138 
139 
140    /***
141     * Get the message key for this error message.
142     */
143    public String getKey() {
144 
145       return (this.key);
146 
147    }
148 
149 
150    /***
151     * Get the replacement values for this error message.
152     */
153    public Object[] getValues() {
154 
155       return (this.values);
156 
157    }
158 
159 
160 }