001: //////////////////////////////////////////////////////////////////////////////
002: // Clirr: compares two versions of a java library for binary compatibility
003: // Copyright (C) 2003 - 2005 Lars Kühne
004: //
005: // This library is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU Lesser General Public
007: // License as published by the Free Software Foundation; either
008: // version 2.1 of the License, or (at your option) any later version.
009: //
010: // This library is distributed in the hope that it will be useful,
011: // but WITHOUT ANY WARRANTY; without even the implied warranty of
012: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: // Lesser General Public License for more details.
014: //
015: // You should have received a copy of the GNU Lesser General Public
016: // License along with this library; if not, write to the Free Software
017: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: //////////////////////////////////////////////////////////////////////////////
019:
020: package net.sf.clirr.core;
021:
022: import java.util.ResourceBundle;
023: import java.util.Locale;
024: import java.util.Enumeration;
025:
026: /**
027: * ResourceBundle that implements the default locale by delegating to the english bundle.
028: * This solves the bug described in
029: * https://sourceforge.net/tracker/index.php?func=detail&aid=594469&group_id=29721&atid=397078
030: * without having to duplicate any resource bundles, leading to a simpler build and a smaller jar.
031: *
032: * @author lkuehne
033: */
034: public class EventMessages extends ResourceBundle {
035: /**
036: * The base name of the resource bundle from which message descriptions
037: * are read.
038: */
039: public static final String RESOURCE_NAME = EventMessages.class
040: .getName();
041:
042: private ResourceBundle delegate = null;
043:
044: /**
045: * Control variable used in synchronized blocks that delegate to the {@link #delegate} bundle.
046: * The delegate bundle has "this" as it's parent.
047: * To prevent infinite loops in the lookup process when searching for
048: * non-existent keys we set isUsingDelegate to true to break out of the loop.
049: */
050: private boolean isUsingDelegate = false;
051:
052: /**
053: * Constructor.
054: * @deprecated Typical user code never calls this directly but uses
055: * {@link java.util.ResourceBundle#getBundle(java.lang.String)} or one of it's variants instead.
056: */
057: public EventMessages() {
058: }
059:
060: private ResourceBundle getDelegate() {
061: if (delegate == null) {
062: delegate = ResourceBundle.getBundle(RESOURCE_NAME,
063: Locale.ENGLISH);
064: }
065: return delegate;
066: }
067:
068: /** @see java.util.ResourceBundle#handleGetObject */
069: protected final synchronized Object handleGetObject(String key) {
070: try {
071: if (isUsingDelegate) {
072: // the underlying bundle is delegating the call back to us
073: // this means that the key is unknown, so we return null
074: return null;
075: } else {
076: isUsingDelegate = true;
077: return getDelegate().getObject(key);
078: }
079: } finally {
080: isUsingDelegate = false;
081: }
082: }
083:
084: /** @see java.util.ResourceBundle#getKeys */
085: public final synchronized Enumeration getKeys() {
086: try {
087: if (isUsingDelegate) {
088: // the underlying bundle is delegating the call back to us
089: // this means that the key is unknown, so we return null
090: return null;
091: } else {
092: isUsingDelegate = true;
093: return getDelegate().getKeys();
094: }
095: } finally {
096: isUsingDelegate = false;
097: }
098: }
099:
100: /** @see java.util.ResourceBundle#getLocale */
101: public final Locale getLocale() {
102: return getDelegate().getLocale();
103: }
104:
105: }
|