001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.ws.scout.registry.infomodel;
018:
019: import java.util.Locale;
020:
021: import javax.xml.registry.infomodel.LocalizedString;
022:
023: /**
024: * Implements JAXR Interface.
025: * For futher details, look into the JAXR API Javadoc.
026: *
027: * @author Anil Saldhana <anil@apache.org>
028: */
029: public class LocalizedStringImpl implements LocalizedString {
030: private String charsetName;
031: private Locale locale;
032: private String value;
033:
034: public LocalizedStringImpl() {
035: this .locale = Locale.getDefault();
036: this .charsetName = LocalizedString.DEFAULT_CHARSET_NAME;
037: }
038:
039: /**
040: * Constuctor for a LocalizedString.
041: *
042: * @param locale the locale; must not be null
043: * @param value the value; may be null
044: * @param charsetName the charset; must not be null
045: */
046: public LocalizedStringImpl(Locale locale, String value,
047: String charsetName) {
048: if (locale == null) {
049: throw new IllegalArgumentException("locale cannot be null");
050: }
051: if (charsetName == null) {
052: throw new IllegalArgumentException(
053: "charsetName cannot be null");
054: }
055: this .locale = locale;
056: this .value = value;
057: this .charsetName = charsetName;
058: }
059:
060: public String getCharsetName() {
061: return charsetName;
062: }
063:
064: public Locale getLocale() {
065: return locale;
066: }
067:
068: public String getValue() {
069: return value;
070: }
071:
072: public void setCharsetName(String charsetName) {
073: if (charsetName == null) {
074: throw new IllegalArgumentException(
075: "charsetName cannot be null");
076: }
077: this .charsetName = charsetName;
078: }
079:
080: public void setLocale(Locale locale) {
081: if (locale == null) {
082: throw new IllegalArgumentException("locale cannot be null");
083: }
084: this .locale = locale;
085: }
086:
087: public void setValue(String value) {
088: this .value = value;
089: }
090:
091: /**
092: * There is a spec ambiguity here as it does not define how equals is determined for LocalizedString
093: * but they are intended to be used in Collections.
094: * We define it as locale, charsetName and value being equal.
095: *
096: * @param o the other object
097: * @return true if they are equal
098: */
099: public boolean equals(Object o) {
100: if (this == o)
101: return true;
102: if (!(o instanceof LocalizedStringImpl))
103: return false;
104: final LocalizedStringImpl localizedString = (LocalizedStringImpl) o;
105: if (!charsetName.equals(localizedString.charsetName))
106: return false;
107: if (!locale.equals(localizedString.locale))
108: return false;
109: if (value != null ? !value.equals(localizedString.value)
110: : localizedString.value != null)
111: return false;
112: return true;
113: }
114:
115: public int hashCode() {
116: int result;
117: result = charsetName.hashCode();
118: result = 29 * result + locale.hashCode();
119: result = 29 * result + (value != null ? value.hashCode() : 0);
120: return result;
121: }
122:
123: public String toString() {
124: return value;
125: }
126: }
|