This project has retired. For details please refer to its Attic page.
Coverage Report
Coverage Report - org.apache.ws.scout.registry.infomodel.LocalizedStringImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
LocalizedStringImpl
81%
31/38
79%
19/24
2.818
 
 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  2
     {
 37  2
         this.locale = Locale.getDefault();
 38  2
         this.charsetName = LocalizedString.DEFAULT_CHARSET_NAME;
 39  2
     }
 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  925
     {
 50  925
         if (locale == null)
 51  
         {
 52  0
             throw new IllegalArgumentException("locale cannot be null");
 53  
         }
 54  925
         if (charsetName == null)
 55  
         {
 56  0
             throw new IllegalArgumentException("charsetName cannot be null");
 57  
         }
 58  925
         this.locale = locale;
 59  925
         this.value = value;
 60  925
         this.charsetName = charsetName;
 61  925
     }
 62  
 
 63  
     public String getCharsetName()
 64  
     {
 65  50
         return charsetName;
 66  
     }
 67  
 
 68  
     public Locale getLocale()
 69  
     {
 70  260
         return locale;
 71  
     }
 72  
 
 73  
     public String getValue()
 74  
     {
 75  410
         return value;
 76  
     }
 77  
 
 78  
     public void setCharsetName(String charsetName)
 79  
     {
 80  4
         if (charsetName == null)
 81  
         {
 82  2
             throw new IllegalArgumentException("charsetName cannot be null");
 83  
         }
 84  2
         this.charsetName = charsetName;
 85  2
     }
 86  
 
 87  
     public void setLocale(Locale locale)
 88  
     {
 89  4
         if (locale == null)
 90  
         {
 91  2
             throw new IllegalArgumentException("locale cannot be null");
 92  
         }
 93  2
         this.locale = locale;
 94  2
     }
 95  
 
 96  
     public void setValue(String value)
 97  
     {
 98  4
         this.value = value;
 99  4
     }
 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  56
         if (this == o) return true;
 112  54
         if (!(o instanceof LocalizedStringImpl)) return false;
 113  54
         final LocalizedStringImpl localizedString = (LocalizedStringImpl) o;
 114  54
         if (!charsetName.equals(localizedString.charsetName)) return false;
 115  46
         if (!locale.equals(localizedString.locale)) return false;
 116  26
         if (value != null ? !value.equals(localizedString.value) : localizedString.value != null) return false;
 117  18
         return true;
 118  
     }
 119  
 
 120  
     public int hashCode()
 121  
     {
 122  
         int result;
 123  0
         result = charsetName.hashCode();
 124  0
         result = 29 * result + locale.hashCode();
 125  0
         result = 29 * result + (value != null ? value.hashCode() : 0);
 126  0
         return result;
 127  
     }
 128  
 
 129  
     public String toString()
 130  
     {
 131  0
         return value;
 132  
     }
 133  
 }