1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.cubby.validator; |
17 | |
|
18 | |
import org.seasar.cubby.util.Messages; |
19 | |
|
20 | 30 | public class MessageInfo { |
21 | |
|
22 | |
private String key; |
23 | |
|
24 | |
private Object[] arguments; |
25 | |
|
26 | |
public String getKey() { |
27 | 0 | return key; |
28 | |
} |
29 | |
|
30 | |
public void setKey(String key) { |
31 | 30 | this.key = key; |
32 | 30 | } |
33 | |
|
34 | |
public Object[] getArguments() { |
35 | 0 | if (arguments == null) { |
36 | 0 | return null; |
37 | |
} |
38 | 0 | return arguments.clone(); |
39 | |
} |
40 | |
|
41 | |
public void setArguments(Object... arguments) { |
42 | 30 | this.arguments = arguments; |
43 | 30 | } |
44 | |
|
45 | |
public MessageBuilder builder() { |
46 | 5 | MessageBuilder builder = new MessageBuilder(key, arguments); |
47 | 5 | return builder; |
48 | |
} |
49 | |
|
50 | 5 | public class MessageBuilder { |
51 | |
|
52 | |
private final String messageKey; |
53 | |
|
54 | |
private String fieldNameKey; |
55 | |
|
56 | |
public final Object[] arguments; |
57 | |
|
58 | 5 | private MessageBuilder(final String messageKey, final Object[] arguments) { |
59 | 5 | this.messageKey = messageKey; |
60 | 5 | this.arguments = arguments; |
61 | 5 | } |
62 | |
|
63 | |
public MessageBuilder fieldNameKey(final String fieldNameKey) { |
64 | 5 | this.fieldNameKey = fieldNameKey; |
65 | 5 | return this; |
66 | |
} |
67 | |
|
68 | |
public String toString() { |
69 | |
final Object[] args; |
70 | 5 | if (fieldNameKey != null) { |
71 | 5 | args = new Object[this.arguments.length + 1]; |
72 | 5 | final String paramNameText = Messages.getText(fieldNameKey); |
73 | 5 | args[0] = paramNameText; |
74 | 5 | System.arraycopy(this.arguments, 0, args, 1, this.arguments.length); |
75 | 5 | } else { |
76 | 0 | args = this.arguments; |
77 | |
} |
78 | 5 | return Messages.getText(messageKey, args); |
79 | |
} |
80 | |
} |
81 | |
} |