add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / messages / MessageImpl.java
1 package org.apache.lucene.messages;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.util.Locale;
21
22 /**
23  * Default implementation of Message interface.
24  * For Native Language Support (NLS), system of software internationalization.
25  */
26 public class MessageImpl implements Message {
27
28   private static final long serialVersionUID = -3077643314630884523L;
29
30   private String key;
31
32   private Object[] arguments = new Object[0];
33
34   public MessageImpl(String key) {
35     this.key = key;
36
37   }
38
39   public MessageImpl(String key, Object... args) {
40     this(key);
41     this.arguments = args;
42   }
43
44   public Object[] getArguments() {
45     return this.arguments;
46   }
47
48   public String getKey() {
49     return this.key;
50   }
51
52   public String getLocalizedMessage() {
53     return getLocalizedMessage(Locale.getDefault());
54   }
55
56   public String getLocalizedMessage(Locale locale) {
57     return NLS.getLocalizedMessage(getKey(), locale, getArguments());
58   }
59
60   @Override
61   public String toString() {
62     Object[] args = getArguments();
63     StringBuilder sb = new StringBuilder(getKey());
64     if (args != null) {
65       for (int i = 0; i < args.length; i++) {
66         sb.append(i == 0 ? " " : ", ").append(args[i]);
67       }
68     }
69     return sb.toString();
70   }
71
72 }