Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MessageInfo |
|
| 1.6666666666666667;1.667 |
1 | /* | |
2 | * Copyright 2004-2010 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 | ||
17 | package org.seasar.cubby.action; | |
18 | ||
19 | import java.util.Arrays; | |
20 | ||
21 | import org.seasar.cubby.util.Messages; | |
22 | ||
23 | /** | |
24 | * メッセージ情報です。 | |
25 | * | |
26 | * @author baba | |
27 | */ | |
28 | 67 | public class MessageInfo { |
29 | ||
30 | /** {@link Messages} からメッセージを取得するためのキー。 */ | |
31 | private String key; | |
32 | ||
33 | /** メッセージの置換パターンを置き換えるオブジェクトからなる配列。 */ | |
34 | private Object[] arguments; | |
35 | ||
36 | /** | |
37 | * {@link Messages} からメッセージを取得するためのキーを取得します。 | |
38 | * | |
39 | * @return キー | |
40 | */ | |
41 | public String getKey() { | |
42 | 0 | return key; |
43 | } | |
44 | ||
45 | /** | |
46 | * {@link Messages} からメッセージを取得するためのキーを設定します。 | |
47 | * | |
48 | * @param key | |
49 | * キー | |
50 | */ | |
51 | public void setKey(final String key) { | |
52 | 67 | this.key = key; |
53 | 67 | } |
54 | ||
55 | /** | |
56 | * メッセージの置換パターンを置き換えるオブジェクトからなる配列を取得します。 | |
57 | * | |
58 | * @return 置換文字列の配列 | |
59 | */ | |
60 | public Object[] getArguments() { | |
61 | 0 | if (arguments == null) { |
62 | 0 | return null; |
63 | } | |
64 | 0 | return arguments.clone(); |
65 | } | |
66 | ||
67 | /** | |
68 | * メッセージの置換パターンを置き換えるオブジェクトからなる配列を取得します。 | |
69 | * | |
70 | * @param arguments | |
71 | * 置換文字列 | |
72 | */ | |
73 | public void setArguments(final Object... arguments) { | |
74 | 4 | final Object[] copyArguments = new Object[arguments.length]; |
75 | 4 | System.arraycopy(arguments, 0, copyArguments, 0, arguments.length); |
76 | 4 | this.arguments = copyArguments; |
77 | 4 | } |
78 | ||
79 | /** | |
80 | * メッセージ文字列に変換します。 | |
81 | * | |
82 | * @param fieldNameKey | |
83 | * フィールド名のリソースキー | |
84 | * @return メッセージ文字列 | |
85 | */ | |
86 | public String toMessage(final String fieldNameKey) { | |
87 | final Object[] args; | |
88 | 40 | if (fieldNameKey != null) { |
89 | 40 | if (this.arguments != null) { |
90 | 2 | args = new Object[this.arguments.length + 1]; |
91 | 2 | final String paramNameText = Messages.getText(fieldNameKey); |
92 | 2 | args[0] = paramNameText; |
93 | 2 | System.arraycopy(this.arguments, 0, args, 1, |
94 | this.arguments.length); | |
95 | 2 | } else { |
96 | 38 | args = new Object[]{Messages.getText(fieldNameKey)}; |
97 | } | |
98 | } else { | |
99 | 0 | args = this.arguments; |
100 | } | |
101 | 40 | return Messages.getText(key, args); |
102 | } | |
103 | ||
104 | /** | |
105 | * {@inheritDoc} | |
106 | */ | |
107 | @Override | |
108 | public String toString() { | |
109 | 0 | final StringBuilder builder = new StringBuilder(); |
110 | 0 | builder.append(super.toString()); |
111 | 0 | builder.append("[key="); |
112 | 0 | builder.append(key); |
113 | 0 | builder.append(",arguments="); |
114 | 0 | builder.append(Arrays.deepToString(arguments)); |
115 | 0 | builder.append("]"); |
116 | 0 | return builder.toString(); |
117 | } | |
118 | ||
119 | } |