Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MessageInfo |
|
| 1.8;1.8 |
1 | /* | |
2 | * Copyright 2004-2009 the Seasar Foundation and the Others. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
15 | */ | |
16 | package org.seasar.cubby.action; | |
17 | ||
18 | import org.seasar.cubby.util.Messages; | |
19 | ||
20 | /** | |
21 | * メッセージ情報です。 | |
22 | * | |
23 | * @author baba | |
24 | */ | |
25 | 67 | public class MessageInfo { |
26 | ||
27 | /** {@link Messages} からメッセージを取得するためのキー。 */ | |
28 | private String key; | |
29 | ||
30 | /** メッセージの置換パターンを置き換えるオブジェクトからなる配列。 */ | |
31 | private Object[] arguments; | |
32 | ||
33 | /** | |
34 | * {@link Messages} からメッセージを取得するためのキーを取得します。 | |
35 | * | |
36 | * @return キー | |
37 | */ | |
38 | public String getKey() { | |
39 | 0 | return key; |
40 | } | |
41 | ||
42 | /** | |
43 | * {@link Messages} からメッセージを取得するためのキーを設定します。 | |
44 | * | |
45 | * @param key | |
46 | * キー | |
47 | */ | |
48 | public void setKey(final String key) { | |
49 | 67 | this.key = key; |
50 | 67 | } |
51 | ||
52 | /** | |
53 | * メッセージの置換パターンを置き換えるオブジェクトからなる配列を取得します。 | |
54 | * | |
55 | * @return 置換文字列の配列 | |
56 | */ | |
57 | public Object[] getArguments() { | |
58 | 0 | if (arguments == null) { |
59 | 0 | return null; |
60 | } | |
61 | 0 | return arguments.clone(); |
62 | } | |
63 | ||
64 | /** | |
65 | * メッセージの置換パターンを置き換えるオブジェクトからなる配列を取得します。 | |
66 | * | |
67 | * @param arguments | |
68 | * 置換文字列 | |
69 | */ | |
70 | public void setArguments(final Object... arguments) { | |
71 | 4 | final Object[] copyArguments = new Object[arguments.length]; |
72 | 4 | System.arraycopy(arguments, 0, copyArguments, 0, arguments.length); |
73 | 4 | this.arguments = copyArguments; |
74 | 4 | } |
75 | ||
76 | /** | |
77 | * メッセージ文字列に変換します。 | |
78 | * | |
79 | * @param fieldNameKey | |
80 | * フィールド名のリソースキー | |
81 | * @return メッセージ文字列 | |
82 | */ | |
83 | public String toMessage(final String fieldNameKey) { | |
84 | final Object[] args; | |
85 | 40 | if (fieldNameKey != null) { |
86 | 40 | if (this.arguments != null) { |
87 | 2 | args = new Object[this.arguments.length + 1]; |
88 | 2 | final String paramNameText = Messages.getText(fieldNameKey); |
89 | 2 | args[0] = paramNameText; |
90 | 2 | System.arraycopy(this.arguments, 0, args, 1, |
91 | this.arguments.length); | |
92 | 2 | } else { |
93 | 38 | args = new Object[] { Messages.getText(fieldNameKey) }; |
94 | } | |
95 | } else { | |
96 | 0 | args = this.arguments; |
97 | } | |
98 | 40 | return Messages.getText(key, args); |
99 | } | |
100 | ||
101 | } |