Clover coverage report - [ini4j]
Coverage timestamp: Sze nov. 30 2005 08:31:05 CET
file stats: LOC: 380   Methods: 26
NCLOC: 129   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
IniPreferences.java 100% 100% 100% 100%
coverage
 1    /*
 2    * Copyright 2005 [ini4j] Development Team
 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.ini4j;
 18   
 19    import java.util.prefs.*;
 20    import java.io.*;
 21    import java.net.URL;
 22   
 23    public class IniPreferences extends AbstractPreferences
 24    {
 25    /** frequently used empty String array */
 26    private static final String[] EMPTY = {};
 27   
 28    /** underlaying <code>Ini</code> implementation */
 29    private Ini _ini;
 30   
 31    protected class SectionPreferences extends AbstractPreferences
 32    {
 33    /** underlaying <code>Section</code> implementation */
 34    private Ini.Section _section;
 35   
 36    /**
 37    * Constructs a new SectionPreferences instance on top of Ini.Section instance.
 38    *
 39    * @param parent parent preferences node
 40    * @parem section underlaying Ini.Section instance
 41    * @param isNew indicate is this a new node or already existing one
 42    */
 43  15 SectionPreferences(IniPreferences parent, Ini.Section section, boolean isNew)
 44    {
 45  15 super(parent, section.getName());
 46  15 _section = section;
 47  15 newNode = isNew;
 48    }
 49   
 50    /**
 51    * Implements the <CODE>childSpi</CODE> method as per the specification in
 52    * {@link java.util.prefs.AbstractPreferences#childSpi(String)}.
 53    *
 54    * This implementation doesn't support this operation.
 55    *
 56    * @throws UnsupportedOperationException this implementation allways throws this exception
 57    * @param name child name
 58    * @return child node
 59    */
 60  1 protected AbstractPreferences childSpi(String name) throws UnsupportedOperationException
 61    {
 62  1 throw new UnsupportedOperationException();
 63    }
 64   
 65    /**
 66    * Implements the <CODE>childrenNamesSpi</CODE> method as per the specification in
 67    * {@link java.util.prefs.AbstractPreferences#childrenNamesSpi()}.
 68    *
 69    * This implementation allways returns an empty array.
 70    *
 71    * @return an emty array.
 72    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 73    */
 74  4 protected String[] childrenNamesSpi() throws BackingStoreException
 75    {
 76  4 return EMPTY;
 77    }
 78   
 79    /**
 80    * Implements the <CODE>flushSpi</CODE> method as per the specification in
 81    * {@link java.util.prefs.AbstractPreferences#flushSpi()}.
 82    *
 83    * This implementation does nothing.
 84    *
 85    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 86    */
 87  10 protected void flushSpi() throws BackingStoreException
 88    {
 89    ;
 90    }
 91   
 92    /**
 93    * Implements the <CODE>getSpi</CODE> method as per the specification in
 94    * {@link java.util.prefs.AbstractPreferences#getSpi(String)}.
 95    * @return if the value associated with the specified key at this preference node, or null if there is no association for this key, or the association cannot be determined at this time.
 96    * @param key key to getvalue for
 97    */
 98  47 protected String getSpi(String key)
 99    {
 100  47 return _section.fetch(key);
 101    }
 102   
 103    /**
 104    * Implements the <CODE>keysSpi</CODE> method as per the specification in
 105    * {@link java.util.prefs.AbstractPreferences#keysSpi()}.
 106    *
 107    * @return an array of the keys that have an associated value in this preference node.
 108    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 109    */
 110  10 protected String[] keysSpi() throws BackingStoreException
 111    {
 112  10 return _section.keySet().toArray(EMPTY);
 113    }
 114   
 115    /**
 116    * Implements the <CODE>putSpi</CODE> method as per the specification in
 117    * {@link java.util.prefs.AbstractPreferences#putSpi(String,String)}.
 118    *
 119    * @param key key to set value for
 120    * @param value new value of key
 121    */
 122  14 protected void putSpi(String key, String value)
 123    {
 124  14 _section.put(key, value);
 125    }
 126   
 127    /**
 128    * Implements the <CODE>removeNodeSpi</CODE> method as per the specification in
 129    * {@link java.util.prefs.AbstractPreferences#removeNodeSpi()}.
 130    *
 131    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 132    */
 133  2 protected void removeNodeSpi() throws BackingStoreException
 134    {
 135  2 _ini.remove(_section);
 136    }
 137   
 138    /**
 139    * Implements the <CODE>removeSpi</CODE> method as per the specification in
 140    * {@link java.util.prefs.AbstractPreferences#removeSpi(String)}.
 141    * @param key key to remove
 142    */
 143  13 protected void removeSpi(String key)
 144    {
 145  13 _section.remove(key);
 146    }
 147   
 148    /**
 149    * Implements the <CODE>syncSpi</CODE> method as per the specification in
 150    * {@link java.util.prefs.AbstractPreferences#syncSpi()}.
 151    *
 152    * This implementation does nothing.
 153    *
 154    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 155    */
 156  5 protected void syncSpi() throws BackingStoreException
 157    {
 158    ;
 159    }
 160   
 161    /**
 162    * Implements the <CODE>sync</CODE> method as per the specification in
 163    * {@link java.util.prefs.Preferences#sync()}.
 164    *
 165    * This implementation just call parent's <code>sync()</code> method.
 166    *
 167    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 168    */
 169  1 public void sync() throws BackingStoreException
 170    {
 171  1 parent().sync();
 172    }
 173   
 174    /**
 175    * Implements the <CODE>flush</CODE> method as per the specification in
 176    * {@link java.util.prefs.Preferences#flush()}.
 177    *
 178    * This implementation just call parent's <code>flush()</code> method.
 179    *
 180    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 181    */
 182  3 public void flush() throws BackingStoreException
 183    {
 184  3 parent().flush();
 185    }
 186    }
 187   
 188    /**
 189    * Constructs a new preferences node on top of <code>Ini</code> instance.
 190    *
 191    * @param ini underlaying <code>Ini</code> instance
 192    */
 193  14 public IniPreferences(Ini ini)
 194    {
 195  14 super(null, "");
 196  14 _ini = ini;
 197    }
 198   
 199    /**
 200    * Constructs a new preferences node based on newly loaded <code>Ini</code> instance.
 201    *
 202    * This is just a helper constructor, to make simpler constructing <code>IniPreferences</code>
 203    * directly from <code>Reader</code>.
 204    *
 205    * @param input the <code>Reader</code> containing <code>Ini</code> data
 206    * @throws IOException if an I/O error occured
 207    * @throws InvalidIniFormatException if <code>Ini</code> parsing error occured
 208    */
 209  1 public IniPreferences(Reader input) throws IOException, InvalidIniFormatException
 210    {
 211  1 super(null, "");
 212  1 _ini = new Ini(input);
 213    }
 214   
 215    /**
 216    * Constructs a new preferences node based on newly loaded <code>Ini</code> instance.
 217    *
 218    * This is just a helper constructor, to make simpler constructing <code>IniPreferences</code>
 219    * directly from <code>InputStream</code>.
 220    *
 221    * @param input the <code>InputStream</code> containing <code>Ini</code> data
 222    * @throws IOException if an I/O error occured
 223    * @throws InvalidIniFormatException if <code>Ini</code> parsing error occured
 224    */
 225  1 public IniPreferences(InputStream input) throws IOException, InvalidIniFormatException
 226    {
 227  1 super(null, "");
 228  1 _ini = new Ini(input);
 229    }
 230   
 231    /**
 232    * Constructs a new preferences node based on newly loaded <code>Ini</code> instance.
 233    *
 234    * This is just a helper constructor, to make simpler constructing <code>IniPreferences</code>
 235    * directly from <code>URL</code>.
 236    *
 237    * @param input the <code>URL</code> containing <code>Ini</code> data
 238    * @throws IOException if an I/O error occured
 239    * @throws InvalidIniFormatException if <code>Ini</code> parsing error occured
 240    */
 241  1 public IniPreferences(URL input) throws IOException, InvalidIniFormatException
 242    {
 243  1 super(null, "");
 244  1 _ini = new Ini(input);
 245    }
 246   
 247    /**
 248    * Implements the <CODE>childSpi</CODE> method as per the specification in
 249    * {@link java.util.prefs.AbstractPreferences#childSpi(String)}.
 250    * @param name child name
 251    * @return child node
 252    */
 253  15 protected AbstractPreferences childSpi(String name)
 254    {
 255  15 Ini.Section sec = _ini.get(name);
 256  15 boolean isNew = sec == null;
 257   
 258  15 if ( isNew )
 259    {
 260  6 sec = _ini.add(name);
 261    }
 262   
 263  15 return new SectionPreferences(this, sec, isNew);
 264    }
 265   
 266    /**
 267    * Implements the <CODE>childrenNamesSpi</CODE> method as per the specification in
 268    * {@link java.util.prefs.AbstractPreferences#childrenNamesSpi()}.
 269    * @return an array containing the names of the children of this preference node.
 270    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 271    */
 272  6 protected String[] childrenNamesSpi() throws BackingStoreException
 273    {
 274  6 return _ini.keySet().toArray(EMPTY);
 275    }
 276   
 277    /**
 278    * Implements the <CODE>flushSpi</CODE> method as per the specification in
 279    * {@link java.util.prefs.AbstractPreferences#flushSpi()}.
 280    *
 281    * This implementation does nothing.
 282    *
 283    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 284    */
 285  6 protected void flushSpi() throws BackingStoreException
 286    {
 287    ;
 288    }
 289   
 290    /**
 291    * Implements the <CODE>getSpi</CODE> method as per the specification in
 292    * {@link java.util.prefs.AbstractPreferences#getSpi(String)}.
 293    *
 294    * This implementation doesn't support this operation, so allways throws UnsupportedOperationException.
 295    *
 296    * @return if the value associated with the specified key at this preference node, or null if there is no association for this key, or the association cannot be determined at this time.
 297    * @param key key to getvalue for
 298    * @throws UnsupportedOperationException this implementation allways throws this exception
 299    */
 300  1 protected String getSpi(String key) throws UnsupportedOperationException
 301    {
 302  1 throw new UnsupportedOperationException();
 303    }
 304   
 305    /**
 306    * Implements the <CODE>keysSpi</CODE> method as per the specification in
 307    * {@link java.util.prefs.AbstractPreferences#keysSpi()}.
 308    *
 309    * This implementation allways return an empty array.
 310    *
 311    * @return an empty array.
 312    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 313    */
 314  1 protected String[] keysSpi() throws BackingStoreException
 315    {
 316  1 return EMPTY;
 317    }
 318   
 319    /**
 320    * Implements the <CODE>putSpi</CODE> method as per the specification in
 321    * {@link java.util.prefs.AbstractPreferences#putSpi(String,String)}.
 322    *
 323    * This implementation doesn;t support this operation, so allways throws UnsupportedOperationException.
 324    *
 325    * @param key key to set value for
 326    * @param value new value for key
 327    * @throws UnsupportedOperationException this implementation allways throws this exception
 328    */
 329  1 protected void putSpi(String key, String value) throws UnsupportedOperationException
 330    {
 331  1 throw new UnsupportedOperationException();
 332    }
 333   
 334    /**
 335    * Implements the <CODE>removeNodeSpi</CODE> method as per the specification in
 336    * {@link java.util.prefs.AbstractPreferences#removeNodeSpi()}.
 337    *
 338    * This implementation doesn;t support this operation, so allways throws UnsupportedOperationException.
 339    * @throws UnsupportedOperationException this implementation allways throws this exception
 340    * @throws BackingStoreException this implementation never throws this exception
 341    */
 342  1 protected void removeNodeSpi() throws BackingStoreException, UnsupportedOperationException
 343    {
 344  1 throw new UnsupportedOperationException();
 345    }
 346   
 347    /**
 348    * Implements the <CODE>removeSpi</CODE> method as per the specification in
 349    * {@link java.util.prefs.AbstractPreferences#removeSpi(String)}.
 350    * @param key key to remove
 351    * @throws UnsupportedOperationException this implementation allways throws this exception
 352    */
 353  1 protected void removeSpi(String key) throws UnsupportedOperationException
 354    {
 355  1 throw new UnsupportedOperationException();
 356    }
 357   
 358    /**
 359    * Implements the <CODE>syncSpi</CODE> method as per the specification in
 360    * {@link java.util.prefs.AbstractPreferences#syncSpi()}.
 361    *
 362    * This implementation does nothing.
 363    *
 364    * @throws BackingStoreException if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
 365    */
 366  3 protected void syncSpi() throws BackingStoreException
 367    {
 368    ;
 369    }
 370   
 371    /**
 372    * Provide access to underlaying {@link org.ini4j.Ini} implementation.
 373    *
 374    * @return <code>Ini</code> implementation
 375    */
 376  8 protected Ini getIni()
 377    {
 378  8 return _ini;
 379    }
 380    }