001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.internal;
018
019import java.util.*;
020
021/**
022 * Class-related utility methods.
023 *
024 * <h5 class='section'>See Also:</h5><ul>
025
026 * </ul>
027 */
028public class ResourceBundleUtils {
029
030   private static final ResourceBundle EMPTY = new ResourceBundle() {
031      @Override
032      protected Object handleGetObject(String key) {
033         return null;
034      }
035      @Override
036      public Enumeration<String> getKeys() {
037         return Collections.emptyEnumeration();
038      }
039   };
040
041   /**
042    * Same as {@link ResourceBundle#getBundle(String, Locale, ClassLoader)} but never throws a {@link MissingResourceException}.
043    *
044    * @param baseName The base name of the resource bundle, a fully qualified class name.
045    * @param locale The locale for which a resource bundle is desired.
046    * @param loader The class loader from which to load the resource bundle.
047    * @return The matching resource bundle, or <jk>null</jk> if it could not be found.
048    */
049   public static ResourceBundle findBundle(String baseName, Locale locale, ClassLoader loader) {
050      try {
051         return ResourceBundle.getBundle(baseName, locale, loader);
052      } catch (MissingResourceException e) {}
053      return null;
054   }
055
056   /**
057    * Returns an empty resource bundle.
058    *
059    * @return An empty resource bundle.
060    */
061   public static ResourceBundle empty() {
062      return EMPTY;
063   }
064}