rsitze      2002/09/17 16:02:21

  Modified:    java/src/org/apache/axis/components/i18n Messages.java
  Added:       java/src/org/apache/axis/components/i18n
                        DefaultMessageBundle.java MessageBundle.java
                        MessageBundleFactory.java
  Log:
  Add message bundle factory.
  
  Revision  Changes    Path
  1.2       +13 -34    xml-axis/java/src/org/apache/axis/components/i18n/Messages.java
  
  Index: Messages.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/components/i18n/Messages.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Messages.java     17 Sep 2002 22:21:36 -0000      1.1
  +++ Messages.java     17 Sep 2002 23:02:21 -0000      1.2
  @@ -57,7 +57,6 @@
   
   import java.text.MessageFormat;
   import java.util.MissingResourceException;
  -import java.util.ResourceBundle;
   
   
   /**
  @@ -67,42 +66,34 @@
    * @author Richard A. Sitze
    * @author Glen Daniels ([EMAIL PROTECTED])
    */
  -public class Messages {
  -    private static final String DEFAULT_PROPERTIES_RESOURCE_NAME =
  -        "org.apache.axis.utils.axisNLS";
  -
  +public final class Messages {
       // Message resource bundle.
  -    private static ResourceBundle messageBundle = null;
  +    private static MessageBundle messageBundle = null;
  +
   
  -    
       /**
  -     * Get the resource bundle that contains all
  -     * of the AXIS translatable messages.
  -     * 
  -     * This is currently ONLY used by TestMessages... which verifies
  -     * axisNLS.properties.  So, it will return the first in the message
  -     * list (axisNLS.properties)... name changed to reflect.
  +     * Load the message service.
  +     * This is ONLY done when it is needed.  If no messages are
  +     * printed (for example, only Wsdl2java is being run in non-
  +     * verbose mode) then there is no need to locate
  +     * service or for service to load resources.
        */
  -    public static ResourceBundle getMessageResourceBundle() {
  +    private static MessageBundle getMessageBundle() {
           if (messageBundle == null) {
  -            initializeMessageBundle();
  +            messageBundle = MessageBundleFactory.getMessageBundle();
           }
           return messageBundle;
  -    } // getMessageResourceBundle
  -
  +    } // initializeMessageBundle
   
   
  +    
       /**
        * Get the message with the given key.
        * There are no arguments for this message.
        */
       public static String getMessage(String key)
               throws MissingResourceException {
  -        if (messageBundle == null) {
  -            initializeMessageBundle();
  -        }
  -        
  -        return messageBundle.getString(key);
  +        return getMessageBundle().getMessage(key);
       } // getMessage
   
   
  @@ -156,16 +147,4 @@
               throws MissingResourceException {
           return MessageFormat.format(getMessage(key), vars);
       } // getMessage
  -
  -
  -
  -    /**
  -     * Load the resource bundle messages from the properties file.
  -     * This is ONLY done when it is needed.  If no messages are
  -     * printed (for example, only Wsdl2java is being run in non-
  -     * verbose mode) then there is no need to read the properties file.
  -     */
  -    private static void initializeMessageBundle() {
  -        messageBundle = ResourceBundle.getBundle(DEFAULT_PROPERTIES_RESOURCE_NAME);
  -    } // initializeMessageBundle
   }
  
  
  
  1.1                  
xml-axis/java/src/org/apache/axis/components/i18n/DefaultMessageBundle.java
  
  Index: DefaultMessageBundle.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.components.i18n;
  
  import java.util.MissingResourceException;
  import java.util.ResourceBundle;
  
  
  /**
   * Class to facilitate i18n (NLS) message translation for
   * axis components.
   *
   * @author Richard A. Sitze
   * @author Glen Daniels ([EMAIL PROTECTED])
   */
  public class DefaultMessageBundle implements MessageBundle {
      public static final String DEFAULT_PROPERTIES_RESOURCE_NAME =
          "org.apache.axis.utils.axisNLS";
  
      // Message resource bundle.
      private static ResourceBundle messageBundle = null;
  
  
      /**
       * Get the message with the given key.
       * There are no arguments for this message.
       */
      public String getMessage(String key)
              throws MissingResourceException {
          if (messageBundle == null) {
              initializeMessageBundle();
          }
          
          return messageBundle.getString(key);
      } // getMessage
      
      /**
       * Get the resource bundle that contains all
       * of the AXIS translatable messages.
       * 
       * This is currently ONLY used by TestMessages... which verifies
       * axisNLS.properties.  So, it will return the first in the message
       * list (axisNLS.properties)... name changed to reflect.
       */
      public static ResourceBundle getMessageResourceBundle() {
          if (messageBundle == null) {
              initializeMessageBundle();
          }
          return messageBundle;
      } // getMessageResourceBundle
  
      /**
       * Load the resource bundle messages from the properties file.
       * This is ONLY done when it is needed.  If no messages are
       * printed (for example, only Wsdl2java is being run in non-
       * verbose mode) then there is no need to read the properties file.
       */
      private static void initializeMessageBundle() {
          messageBundle = ResourceBundle.getBundle(DEFAULT_PROPERTIES_RESOURCE_NAME);
      } // initializeMessageBundle
  }
  
  
  
  1.1                  
xml-axis/java/src/org/apache/axis/components/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.components.i18n;
  
  import java.util.MissingResourceException;
  
  
  /**
   * Class to facilitate i18n (NLS) message translation for
   * axis components.
   *
   * @author Richard A. Sitze
   * @author Glen Daniels ([EMAIL PROTECTED])
   */
  public interface MessageBundle {
      /**
       * Get the (raw) message with the given key.
       */
      String getMessage(String key) throws MissingResourceException;
  }
  
  
  
  1.1                  
xml-axis/java/src/org/apache/axis/components/i18n/MessageBundleFactory.java
  
  Index: MessageBundleFactory.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.components.i18n;
  
  import org.apache.axis.AxisProperties;
  import org.apache.axis.components.logger.LogFactory;
  import org.apache.commons.discovery.tools.SPInterface;
  import org.apache.commons.logging.Log;
  
  
  /**
   * Class to facilitate i18n (NLS) message translation for
   * axis components.
   *
   * @author Richard A. Sitze
   * @author Glen Daniels ([EMAIL PROTECTED])
   */
  public class MessageBundleFactory {
      protected static Log log =
          LogFactory.getLog(MessageBundleFactory.class.getName());
  
      /**
       * Load the message service.
       */
      public static MessageBundle getMessageBundle() {
          MessageBundle bundle =
              (MessageBundle)AxisProperties.newInstance(
                           new SPInterface(MessageBundle.class, "axis.MessageBundle"),
                           DefaultMessageBundle.class);
          
          if (bundle == null) {
              log.fatal("Unable to load messages!");
          }
  
          log.debug("axis.MessageBundle: " + bundle.getClass().getName());
  
          return bundle;
      } // getMessageBundle
  }
  
  
  


Reply via email to