rsitze 2002/09/20 09:35:36 Modified: java/src/org/apache/axis/utils Messages.java java/src/org/apache/axis/i18n MessagesConstants.java ProjectResourceBundle.java Messages.java Added: java/src/org/apache/axis/i18n MessageBundle.java Removed: java/src/org/apache/axis/i18n ExtendMessages.java Log: Fix circular link :-( Revision Changes Path 1.5 +29 -31 xml-axis/java/src/org/apache/axis/utils/Messages.java Index: Messages.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/Messages.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Messages.java 20 Sep 2002 15:19:24 -0000 1.4 +++ Messages.java 20 Sep 2002 16:35:36 -0000 1.5 @@ -59,22 +59,17 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; +/** + * These two imports added to facilitate copying to different packages... + * + * import org.apache.axis.i18n.MessageBundle; + * import org.apache.axis.i18n.MessagesConstants; + */ +import org.apache.axis.i18n.MessageBundle; import org.apache.axis.i18n.MessagesConstants; -import org.apache.axis.i18n.ExtendMessages; /** - * Root Messages classes. - * - * Copy this template to your package, edit the following attributes - * as/if necessary: - * - * projectName - * packageName - * resourceName - * classLoader - * locale - * parent - The ROOT Messages resource bundle should not define this.. - * For all other bundles in AXIS, this should point to the root. + * @see org.apache.axis.i18n.Messages * * @author Richard A. Sitze ([EMAIL PROTECTED]) * @author Karl Moss ([EMAIL PROTECTED]) @@ -82,22 +77,21 @@ */ public class Messages { private static final Class thisClass = Messages.class; - private static final String projectName = MessagesConstants.projectName; + private static final String packageName = getPackage(thisClass.getName()); + private static final ClassLoader classLoader = thisClass.getClassLoader(); + + private static final String projectName = MessagesConstants.projectName; private static final String resourceName = MessagesConstants.resourceName; private static final Locale locale = MessagesConstants.locale; - private static final ClassLoader classLoader = thisClass.getClassLoader(); - private static final ResourceBundle parent = null; + private static final ResourceBundle parent = null; /***** NO NEED TO CHANGE ANYTHING BELOW *****/ - private static final ExtendMessages rb = new ExtendMessages(resourceName, parent) { - protected String getPackageName() { return packageName; } - protected String getProjectName() { return projectName; } - protected ClassLoader getClassLoader() { return classLoader; } - protected Locale getLocale() { return locale; } - }; + private static final MessageBundle messageBundle = + new MessageBundle(projectName, packageName, resourceName, + locale, classLoader, parent); /** * Get a message from resource.properties from the package of the given object. @@ -109,7 +103,7 @@ public static String getMessage(String key) throws MissingResourceException { - return rb.getMessage(key); + return messageBundle.getMessage(key); } /** @@ -123,7 +117,7 @@ public static String getMessage(String key, String arg0) throws MissingResourceException { - return rb.getMessage(key, arg0); + return messageBundle.getMessage(key, arg0); } /** @@ -138,7 +132,7 @@ public static String getMessage(String key, String arg0, String arg1) throws MissingResourceException { - return rb.getMessage(key, arg0, arg1); + return messageBundle.getMessage(key, arg0, arg1); } /** @@ -154,7 +148,7 @@ public static String getMessage(String key, String arg0, String arg1, String arg2) throws MissingResourceException { - return rb.getMessage(key, arg0, arg1, arg2); + return messageBundle.getMessage(key, arg0, arg1, arg2); } /** @@ -171,7 +165,7 @@ public static String getMessage(String key, String arg0, String arg1, String arg2, String arg3) throws MissingResourceException { - return rb.getMessage(key, arg0, arg1, arg2, arg3); + return messageBundle.getMessage(key, arg0, arg1, arg2, arg3); } /** @@ -189,7 +183,7 @@ public static String getMessage(String key, String arg0, String arg1, String arg2, String arg3, String arg4) throws MissingResourceException { - return rb.getMessage(key, arg0, arg1, arg2, arg3, arg4); + return messageBundle.getMessage(key, arg0, arg1, arg2, arg3, arg4); } /** @@ -203,11 +197,15 @@ public static String getMessage(String key, String[] args) throws MissingResourceException { - return rb.getMessage(key, args); + return messageBundle.getMessage(key, args); + } + + public static ResourceBundle getResourceBundle() { + return messageBundle.getResourceBundle(); } - public static ResourceBundle getMessageBundle() { - return rb.getMessageBundle(); + public static MessageBundle getMessageBundle() { + return messageBundle; } private static final String getPackage(String name) { 1.2 +6 -12 xml-axis/java/src/org/apache/axis/i18n/MessagesConstants.java Index: MessagesConstants.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/i18n/MessagesConstants.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MessagesConstants.java 20 Sep 2002 15:19:25 -0000 1.1 +++ MessagesConstants.java 20 Sep 2002 16:35:36 -0000 1.2 @@ -62,19 +62,13 @@ * @author Richard A. Sitze ([EMAIL PROTECTED]) */ public class MessagesConstants { - public static final String projectName = "org.apache.axis"; - public static final String resourceName = "axisNLS"; + public static final String projectName = "org.apache.axis".intern(); + public static final String resourceName = "axisNLS".intern(); public static final Locale locale = null; - - public static final String rootPackageName = "org.apache.axis.utils"; + + public static final String rootPackageName = "org.apache.axis.utils".intern(); public static final ResourceBundle rootBundle = - org.apache.axis.utils.Messages.getMessageBundle(); -// -// ProjectResourceBundle.getBundle(projectName, -// rootPackageName, -// resourceName, -// locale, -// MessagesConstants.class.getClassLoader(), -// null); + ResourceBundle.getBundle("org.apache.axis.utils.axisNLS"); +// org.apache.axis.utils.Messages.getResourceBundle();// } 1.2 +2 -1 xml-axis/java/src/org/apache/axis/i18n/ProjectResourceBundle.java Index: ProjectResourceBundle.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/i18n/ProjectResourceBundle.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ProjectResourceBundle.java 20 Sep 2002 15:19:25 -0000 1.1 +++ ProjectResourceBundle.java 20 Sep 2002 16:35:36 -0000 1.2 @@ -289,7 +289,8 @@ } if (bundle == null) { - throw new MissingResourceException("Cannot find resource " + resourceName, + throw new MissingResourceException("Cannot find resource '" + + packageName + '.' + resourceName + "'", resourceName, ""); } 1.2 +43 -23 xml-axis/java/src/org/apache/axis/i18n/Messages.java Index: Messages.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/i18n/Messages.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Messages.java 20 Sep 2002 15:19:25 -0000 1.1 +++ Messages.java 20 Sep 2002 16:35:36 -0000 1.2 @@ -60,18 +60,32 @@ import java.util.ResourceBundle; /** + * These two imports added to facilitate copying to different packages... + * + * import org.apache.axis.i18n.MessageBundle; + * import org.apache.axis.i18n.MessagesConstants; + */ +import org.apache.axis.i18n.MessageBundle; +import org.apache.axis.i18n.MessagesConstants; + + +/** + * @see org.apache.axis.i18n.Messages + * * FUNCTIONAL TEMPLATE for Messages classes. * - * Copy this template to your package, edit the following attributes + * Copy this template to your package. + * + * For AXIS, the following constants are set appropriately. + * To adapt this scheme to another project, edit these attributes * as/if necessary: * - * projectName * packageName - * resourceName * classLoader + * projectName + * resourceName * locale - * parent - The ROOT Messages resource bundle should not define this.. - * For all other bundles in AXIS, this should point to the root. + * parent * * @author Richard A. Sitze ([EMAIL PROTECTED]) * @author Karl Moss ([EMAIL PROTECTED]) @@ -79,22 +93,24 @@ */ public class Messages { private static final Class thisClass = Messages.class; - private static final String projectName = MessagesConstants.projectName; + private static final String packageName = getPackage(thisClass.getName()); + private static final ClassLoader classLoader = thisClass.getClassLoader(); + + private static final String projectName = MessagesConstants.projectName; private static final String resourceName = MessagesConstants.resourceName; private static final Locale locale = MessagesConstants.locale; - private static final ClassLoader classLoader = thisClass.getClassLoader(); - private static final ResourceBundle parent = MessagesConstants.rootBundle; + private static final ResourceBundle parent = + (MessagesConstants.rootPackageName == packageName) + ? null + : MessagesConstants.rootBundle; /***** NO NEED TO CHANGE ANYTHING BELOW *****/ - private static final ExtendMessages rb = new ExtendMessages(resourceName, parent) { - protected String getPackageName() { return packageName; } - protected String getProjectName() { return projectName; } - protected ClassLoader getClassLoader() { return classLoader; } - protected Locale getLocale() { return locale; } - }; + private static final MessageBundle messageBundle = + new MessageBundle(projectName, packageName, resourceName, + locale, classLoader, parent); /** * Get a message from resource.properties from the package of the given object. @@ -106,7 +122,7 @@ public static String getMessage(String key) throws MissingResourceException { - return rb.getMessage(key); + return messageBundle.getMessage(key); } /** @@ -120,7 +136,7 @@ public static String getMessage(String key, String arg0) throws MissingResourceException { - return rb.getMessage(key, arg0); + return messageBundle.getMessage(key, arg0); } /** @@ -135,7 +151,7 @@ public static String getMessage(String key, String arg0, String arg1) throws MissingResourceException { - return rb.getMessage(key, arg0, arg1); + return messageBundle.getMessage(key, arg0, arg1); } /** @@ -151,7 +167,7 @@ public static String getMessage(String key, String arg0, String arg1, String arg2) throws MissingResourceException { - return rb.getMessage(key, arg0, arg1, arg2); + return messageBundle.getMessage(key, arg0, arg1, arg2); } /** @@ -168,7 +184,7 @@ public static String getMessage(String key, String arg0, String arg1, String arg2, String arg3) throws MissingResourceException { - return rb.getMessage(key, arg0, arg1, arg2, arg3); + return messageBundle.getMessage(key, arg0, arg1, arg2, arg3); } /** @@ -186,7 +202,7 @@ public static String getMessage(String key, String arg0, String arg1, String arg2, String arg3, String arg4) throws MissingResourceException { - return rb.getMessage(key, arg0, arg1, arg2, arg3, arg4); + return messageBundle.getMessage(key, arg0, arg1, arg2, arg3, arg4); } /** @@ -200,11 +216,15 @@ public static String getMessage(String key, String[] args) throws MissingResourceException { - return rb.getMessage(key, args); + return messageBundle.getMessage(key, args); + } + + public static ResourceBundle getResourceBundle() { + return messageBundle.getResourceBundle(); } - public static ResourceBundle getMessageBundle() { - return rb.getMessageBundle(); + public static MessageBundle getMessageBundle() { + return messageBundle; } private static final String getPackage(String name) { 1.1 xml-axis/java/src/org/apache/axis/i18n/MessageBundle.java Index: MessageBundle.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.axis.i18n; import java.text.MessageFormat; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * Accept parameters for ProjectResourceBundle, * but defer object instantiation (and therefore * resource bundle loading) until required. * * @author Richard A. Sitze ([EMAIL PROTECTED]) * @author Karl Moss ([EMAIL PROTECTED]) * @author Glen Daniels ([EMAIL PROTECTED]) */ public class MessageBundle { private boolean loaded = false; private ProjectResourceBundle _resourceBundle = null; private final String projectName; private final String packageName; private final String resourceName; private final Locale locale; private final ClassLoader classLoader; private final ResourceBundle parent; public final ProjectResourceBundle getResourceBundle() { if (!loaded) { _resourceBundle = ProjectResourceBundle.getBundle(projectName, packageName, resourceName, locale, classLoader, parent); loaded = true; } return _resourceBundle; } /** * Construct a new ExtendMessages */ public MessageBundle(String projectName, String packageName, String resourceName, Locale locale, ClassLoader classLoader, ResourceBundle parent) throws MissingResourceException { this.projectName = projectName; this.packageName = packageName; this.resourceName = resourceName; this.locale = locale; this.classLoader = classLoader; this.parent = parent; } /** * Gets a string message from the resource bundle for the given key * @param key The resource key * @return The message */ public String getMessage(String key) throws MissingResourceException { return getMessage(key, (String[]) null); } /** * <p>Gets a string message from the resource bundle for the given key. The * message may contain variables that will be substituted with the given * arguments. Variables have the format:</p> * <dir> * This message has two variables: {0} and {1} * </dir> * @param key The resource key * @param arg0 The argument to place in variable {0} * @return The message */ public String getMessage(String key, String arg0) throws MissingResourceException { return getMessage(key, new String[] { arg0 }); } /** * <p>Gets a string message from the resource bundle for the given key. The * message may contain variables that will be substituted with the given * arguments. Variables have the format:</p> * <dir> * This message has two variables: {0} and {1} * </dir> * @param key The resource key * @param arg0 The argument to place in variable {0} * @param arg1 The argument to place in variable {1} * @return The message */ public String getMessage(String key, String arg0, String arg1) throws MissingResourceException { return getMessage(key, new String[] { arg0, arg1 }); } /** * <p>Gets a string message from the resource bundle for the given key. The * message may contain variables that will be substituted with the given * arguments. Variables have the format:</p> * <dir> * This message has two variables: {0} and {1} * </dir> * @param key The resource key * @param arg0 The argument to place in variable {0} * @param arg1 The argument to place in variable {1} * @param arg2 The argument to place in variable {2} * @return The message */ public String getMessage(String key, String arg0, String arg1, String arg2) throws MissingResourceException { return getMessage(key, new String[] { arg0, arg1, arg2 }); } /** * <p>Gets a string message from the resource bundle for the given key. The * message may contain variables that will be substituted with the given * arguments. Variables have the format:</p> * <dir> * This message has two variables: {0} and {1} * </dir> * @param key The resource key * @param arg0 The argument to place in variable {0} * @param arg1 The argument to place in variable {1} * @param arg2 The argument to place in variable {2} * @param arg3 The argument to place in variable {3} * @return The message */ public String getMessage(String key, String arg0, String arg1, String arg2, String arg3) throws MissingResourceException { return getMessage(key, new String[] { arg0, arg1, arg2, arg3 }); } /** * <p>Gets a string message from the resource bundle for the given key. The * message may contain variables that will be substituted with the given * arguments. Variables have the format:</p> * <dir> * This message has two variables: {0} and {1} * </dir> * @param key The resource key * @param arg0 The argument to place in variable {0} * @param arg1 The argument to place in variable {1} * @param arg2 The argument to place in variable {2} * @param arg3 The argument to place in variable {3} * @param arg4 The argument to place in variable {4} * @return The message */ public String getMessage(String key, String arg0, String arg1, String arg2, String arg3, String arg4) throws MissingResourceException { return getMessage(key, new String[] { arg0, arg1, arg2, arg3, arg4 }); } /** * <p>Gets a string message from the resource bundle for the given key. The * message may contain variables that will be substituted with the given * arguments. Variables have the format:</p> * <dir> * This message has two variables: {0} and {1} * </dir> * @param key The resource key * @param array An array of objects to place in corresponding variables * @return The message */ public String getMessage(String key, String[] array) throws MissingResourceException { String msg = null; if (getResourceBundle() != null) { msg = getResourceBundle().getString(key); } if (msg == null) { throw new MissingResourceException("Cannot find resource key \"" + key + "\" in base name " + getResourceBundle().getResourceName(), getResourceBundle().getResourceName(), key); } return MessageFormat.format(msg, array); } }