Coverage Report - org.apache.ws.scout.registry.infomodel.InternationalStringImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
InternationalStringImpl
0%
0/33
0%
0/6
0
InternationalStringImpl$MapKey
0%
0/20
0%
0/8
0
 
 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.Collection;
 20  
 import java.util.Collections;
 21  
 import java.util.HashMap;
 22  
 import java.util.Iterator;
 23  
 import java.util.Locale;
 24  
 import java.util.Map;
 25  
 
 26  
 import javax.xml.registry.JAXRException;
 27  
 import javax.xml.registry.infomodel.InternationalString;
 28  
 import javax.xml.registry.infomodel.LocalizedString;
 29  
 
 30  
 /**
 31  
  * For futher details, look into the JAXR API Javadoc.
 32  
  *
 33  
  * @author Anil Saldhana  <anil@apache.org>
 34  
  */
 35  
 public class InternationalStringImpl implements InternationalString
 36  
 {
 37  
     /**
 38  
      * Maintains an Hashmap of locale to string value
 39  
      */
 40  0
     private final Map<MapKey,LocalizedString> map = new HashMap<MapKey,LocalizedString>();
 41  
 
 42  
     public InternationalStringImpl()
 43  0
     {
 44  0
     }
 45  
 
 46  
     public InternationalStringImpl(String str)
 47  0
     {
 48  0
         Locale locale = Locale.getDefault();
 49  0
         map.put(new MapKey(locale, LocalizedString.DEFAULT_CHARSET_NAME), new LocalizedStringImpl(locale, str, LocalizedString.DEFAULT_CHARSET_NAME));
 50  
 
 51  0
     }
 52  
 
 53  
     public InternationalStringImpl(Locale locale, String str, String charsetName)
 54  0
     {
 55  0
         MapKey mapKey = new MapKey(locale, charsetName);
 56  0
         map.put(mapKey, new LocalizedStringImpl(locale, str, charsetName));
 57  0
     }
 58  
 
 59  
     public void addLocalizedString(LocalizedString localizedString) throws JAXRException
 60  
     {
 61  0
         MapKey mapKey = new MapKey(localizedString);
 62  0
         map.put(mapKey, localizedString);
 63  0
     }
 64  
 
 65  
     public void addLocalizedStrings(Collection collection) throws JAXRException
 66  
     {
 67  0
         for (Iterator i = collection.iterator(); i.hasNext();)
 68  
         {
 69  0
             LocalizedString localizedString = (LocalizedString) i.next();
 70  0
             map.put(new MapKey(localizedString), localizedString);
 71  0
         }
 72  0
     }
 73  
 
 74  
     public Collection<LocalizedString> getLocalizedStrings() throws JAXRException
 75  
     {
 76  0
         return Collections.unmodifiableCollection(map.values());
 77  
     }
 78  
 
 79  
     public String getValue() throws JAXRException
 80  
     {
 81  0
         return getValue(Locale.getDefault());
 82  
     }
 83  
 
 84  
     public void setValue(String str) throws JAXRException
 85  
     {
 86  0
         setValue(Locale.getDefault(), str);
 87  0
     }
 88  
 
 89  
     public String getValue(Locale locale) throws JAXRException
 90  
     {
 91  0
         LocalizedString localizedString = (LocalizedString) map.get(new MapKey(locale, LocalizedString.DEFAULT_CHARSET_NAME));
 92  0
         return localizedString != null ? localizedString.getValue() : null;
 93  
     }
 94  
 
 95  
     public void setValue(Locale locale, String value) throws JAXRException
 96  
     {
 97  0
         map.put(new MapKey(locale, LocalizedString.DEFAULT_CHARSET_NAME), new LocalizedStringImpl(locale, value, LocalizedString.DEFAULT_CHARSET_NAME));
 98  0
     }
 99  
 
 100  
     public void removeLocalizedString(LocalizedString localizedString) throws JAXRException
 101  
     {
 102  0
         map.remove(new MapKey(localizedString));
 103  0
     }
 104  
 
 105  
     public void removeLocalizedStrings(Collection collection) throws JAXRException
 106  
     {
 107  0
         for (Iterator i = collection.iterator(); i.hasNext();)
 108  
         {
 109  0
             removeLocalizedString((LocalizedString) i.next());
 110  
         }
 111  0
     }
 112  
 
 113  
     public LocalizedString getLocalizedString(Locale locale, String charset) throws JAXRException
 114  
     {
 115  0
         return (LocalizedString) map.get(new MapKey(locale, charset));
 116  
     }
 117  
 
 118  
     private static class MapKey
 119  
     {
 120  
         private final Locale locale;
 121  
         private final String charsetName;
 122  
 
 123  
         public MapKey(Locale locale, String charsetName)
 124  0
         {
 125  0
             this.locale = locale;
 126  0
             this.charsetName = charsetName;
 127  0
         }
 128  
 
 129  
         public MapKey(LocalizedString localizedString) throws JAXRException
 130  0
         {
 131  0
             this.locale = localizedString.getLocale();
 132  0
             this.charsetName = localizedString.getCharsetName();
 133  0
         }
 134  
 
 135  
         public boolean equals(Object o)
 136  
         {
 137  0
             if (this == o) return true;
 138  0
             if (!(o instanceof MapKey)) return false;
 139  0
             final MapKey mapKey = (MapKey) o;
 140  0
             if (!charsetName.equals(mapKey.charsetName)) return false;
 141  0
             if (!locale.equals(mapKey.locale)) return false;
 142  0
             return true;
 143  
         }
 144  
 
 145  
         public int hashCode()
 146  
         {
 147  
             int result;
 148  0
             result = locale.hashCode();
 149  0
             result = 29 * result + charsetName.hashCode();
 150  0
             return result;
 151  
         }
 152  
 
 153  
         public String toString()
 154  
         {
 155  0
             StringBuffer buf = new StringBuffer(32);
 156  0
             buf.append('[').append(locale).append(',').append(charsetName).append(']');
 157  0
             return buf.toString();
 158  
         }
 159  
     }
 160  
 }