src/share/classes/sun/util/resources/OpenListResourceBundle.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  51 /**
  52  * Subclass of <code>ResourceBundle</code> which mimics
  53  * <code>ListResourceBundle</code>, but provides more hooks
  54  * for specialized subclass behavior. For general description,
  55  * see {@link java.util.ListResourceBundle}.
  56  * <p>
  57  * This class leaves handleGetObject non-final, and
  58  * adds a method createMap which allows subclasses to
  59  * use specialized Map implementations.
  60  */
  61 public abstract class OpenListResourceBundle extends ResourceBundle {
  62     /**
  63      * Sole constructor.  (For invocation by subclass constructors, typically
  64      * implicit.)
  65      */
  66     protected OpenListResourceBundle() {
  67     }
  68 
  69     // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
  70     @Override
  71     public Object handleGetObject(String key) {
  72         if (key == null) {
  73             throw new NullPointerException();
  74         }
  75 
  76         loadLookupTablesIfNecessary();
  77         return lookup.get(key); // this class ignores locales
  78     }
  79 
  80     /**
  81      * Implementation of ResourceBundle.getKeys.
  82      */
  83     @Override
  84     public Enumeration<String> getKeys() {
  85         ResourceBundle parent = this.parent;
  86         return new ResourceBundleEnumeration(handleGetKeys(),
  87                 (parent != null) ? parent.getKeys() : null);
  88     }
  89 
  90     /**
  91      * Returns a set of keys provided in this resource bundle,
  92      * including no parents.
  93      */
  94     public Set<String> handleGetKeys() {

  95         loadLookupTablesIfNecessary();
  96 
  97         return lookup.keySet();
  98     }
  99 
 100     @Override
 101     public Set<String> keySet() {
 102         if (keyset != null) {
 103             return keyset;
 104         }
 105         Set<String> ks = createSet();
 106         ks.addAll(handleGetKeys());
 107         if (parent != null) {
 108             ks.addAll(parent.keySet());
 109         }
 110         synchronized (this) {
 111             if (keyset == null) {
 112                 keyset = ks;
 113             }
 114         }
 115         return keyset;
 116     }
 117 
 118     /**
 119      * See ListResourceBundle class description.
 120      */
 121     abstract protected Object[][] getContents();
 122 
 123     /**
 124      * Load lookup tables if they haven't been loaded already.
 125      */
 126     void loadLookupTablesIfNecessary() {


   1 /*
   2  * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  51 /**
  52  * Subclass of <code>ResourceBundle</code> which mimics
  53  * <code>ListResourceBundle</code>, but provides more hooks
  54  * for specialized subclass behavior. For general description,
  55  * see {@link java.util.ListResourceBundle}.
  56  * <p>
  57  * This class leaves handleGetObject non-final, and
  58  * adds a method createMap which allows subclasses to
  59  * use specialized Map implementations.
  60  */
  61 public abstract class OpenListResourceBundle extends ResourceBundle {
  62     /**
  63      * Sole constructor.  (For invocation by subclass constructors, typically
  64      * implicit.)
  65      */
  66     protected OpenListResourceBundle() {
  67     }
  68 
  69     // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
  70     @Override
  71     protected Object handleGetObject(String key) {
  72         if (key == null) {
  73             throw new NullPointerException();
  74         }
  75 
  76         loadLookupTablesIfNecessary();
  77         return lookup.get(key); // this class ignores locales
  78     }
  79 
  80     /**
  81      * Implementation of ResourceBundle.getKeys.
  82      */
  83     @Override
  84     public Enumeration<String> getKeys() {
  85         ResourceBundle parentBundle = this.parent;
  86         return new ResourceBundleEnumeration(handleKeySet(),
  87                 (parentBundle != null) ? parentBundle.getKeys() : null);
  88      }
  89 
  90     /**
  91      * Returns a set of keys provided in this resource bundle,
  92      * including no parents.
  93      */
  94     @Override
  95     protected Set<String> handleKeySet() {
  96         loadLookupTablesIfNecessary();

  97         return lookup.keySet();
  98     }
  99 
 100     @Override
 101     public Set<String> keySet() {
 102         if (keyset != null) {
 103             return keyset;
 104         }
 105         Set<String> ks = createSet();
 106         ks.addAll(handleKeySet());
 107         if (parent != null) {
 108             ks.addAll(parent.keySet());
 109         }
 110         synchronized (this) {
 111             if (keyset == null) {
 112                 keyset = ks;
 113             }
 114         }
 115         return keyset;
 116     }
 117 
 118     /**
 119      * See ListResourceBundle class description.
 120      */
 121     abstract protected Object[][] getContents();
 122 
 123     /**
 124      * Load lookup tables if they haven't been loaded already.
 125      */
 126     void loadLookupTablesIfNecessary() {