This project has retired. For details please refer to its Attic page.
LocalizedStringImpl xref
View Javadoc
1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
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, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.ws.scout.registry.infomodel;
18  
19  import java.util.Locale;
20  
21  import javax.xml.registry.infomodel.LocalizedString;
22  
23  /**
24   * Implements JAXR Interface.
25   * For futher details, look into the JAXR API Javadoc.
26   *
27   * @author Anil Saldhana  <anil@apache.org>
28   */
29  public class LocalizedStringImpl implements LocalizedString
30  {
31      private String charsetName;
32      private Locale locale;
33      private String value;
34  
35      public LocalizedStringImpl()
36      {
37          this.locale = Locale.getDefault();
38          this.charsetName = LocalizedString.DEFAULT_CHARSET_NAME;
39      }
40  
41      /**
42       * Constuctor for a LocalizedString.
43       *
44       * @param locale      the locale; must not be null
45       * @param value       the value; may be null
46       * @param charsetName the charset; must not be null
47       */
48      public LocalizedStringImpl(Locale locale, String value, String charsetName)
49      {
50          if (locale == null)
51          {
52              throw new IllegalArgumentException("locale cannot be null");
53          }
54          if (charsetName == null)
55          {
56              throw new IllegalArgumentException("charsetName cannot be null");
57          }
58          this.locale = locale;
59          this.value = value;
60          this.charsetName = charsetName;
61      }
62  
63      public String getCharsetName()
64      {
65          return charsetName;
66      }
67  
68      public Locale getLocale()
69      {
70          return locale;
71      }
72  
73      public String getValue()
74      {
75          return value;
76      }
77  
78      public void setCharsetName(String charsetName)
79      {
80          if (charsetName == null)
81          {
82              throw new IllegalArgumentException("charsetName cannot be null");
83          }
84          this.charsetName = charsetName;
85      }
86  
87      public void setLocale(Locale locale)
88      {
89          if (locale == null)
90          {
91              throw new IllegalArgumentException("locale cannot be null");
92          }
93          this.locale = locale;
94      }
95  
96      public void setValue(String value)
97      {
98          this.value = value;
99      }
100 
101     /**
102      * There is a spec ambiguity here as it does not define how equals is determined for LocalizedString
103      * but they are intended to be used in Collections.
104      * We define it as locale, charsetName and value being equal.
105      *
106      * @param o the other object
107      * @return true if they are equal
108      */
109     public boolean equals(Object o)
110     {
111         if (this == o) return true;
112         if (!(o instanceof LocalizedStringImpl)) return false;
113         final LocalizedStringImplapache/ws/scout/registry/infomodel/LocalizedStringImpl.html#LocalizedStringImpl">LocalizedStringImpl localizedString = (LocalizedStringImpl) o;
114         if (!charsetName.equals(localizedString.charsetName)) return false;
115         if (!locale.equals(localizedString.locale)) return false;
116         if (value != null ? !value.equals(localizedString.value) : localizedString.value != null) return false;
117         return true;
118     }
119 
120     public int hashCode()
121     {
122         int result;
123         result = charsetName.hashCode();
124         result = 29 * result + locale.hashCode();
125         result = 29 * result + (value != null ? value.hashCode() : 0);
126         return result;
127     }
128 
129     public String toString()
130     {
131         return value;
132     }
133 }