001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * DefaultResourceBundleFactory.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report;
030:
031: import java.util.Locale;
032: import java.util.ResourceBundle;
033:
034: /**
035: * A default implementation of the ResourceBundleFactory, that creates resource bundles using the specified locale.
036: * <p/>
037: * If not defined otherwise, this implementation uses <code>Locale.getDefault()</code> as Locale.
038: *
039: * @author Thomas Morgner
040: */
041: public class DefaultResourceBundleFactory implements
042: ResourceBundleFactory {
043: /**
044: * The locale used by this factory.
045: */
046: private Locale locale;
047:
048: /**
049: * Creates a new DefaultResourceBundleFactory using the system's default locale as factory locale.
050: */
051: public DefaultResourceBundleFactory() {
052: this (Locale.getDefault());
053: }
054:
055: /**
056: * Creates a new DefaultResourceBundleFactory using the specified locale as factory locale.
057: *
058: * @param locale the Locale instance that should be used when creating ResourceBundles.
059: * @throws NullPointerException if the given Locale is null.
060: */
061: public DefaultResourceBundleFactory(final Locale locale) {
062: if (locale == null) {
063: throw new NullPointerException("Locale must not be null");
064: }
065: this .locale = locale;
066: }
067:
068: /**
069: * Returns the locale that will be used to create the resource bundle.
070: *
071: * @return the locale.
072: */
073: public Locale getLocale() {
074: return locale;
075: }
076:
077: /**
078: * Redefines the locale. The locale given must not be null.
079: *
080: * @param locale the new locale (never null).
081: * @throws NullPointerException if the given locale is null.
082: */
083: public void setLocale(final Locale locale) {
084: if (locale == null) {
085: throw new NullPointerException("Locale must not be null");
086: }
087: this .locale = locale;
088: }
089:
090: /**
091: * Creates a resource bundle named by the given key and using the factory's defined locale.
092: *
093: * @param key the name of the resourcebundle, never null.
094: * @return the created resource bundle
095: * @throws NullPointerException if <code>key</code> is <code>null</code>
096: * @throws java.util.MissingResourceException
097: * if no resource bundle for the specified base name can be found
098: * @see ResourceBundle#getBundle(String,Locale)
099: */
100: public ResourceBundle getResourceBundle(final String key) {
101: return ResourceBundle.getBundle(key, locale);
102: }
103: }
|