axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r428104 - in /webservices/axis2/trunk/java/modules/jaxws: ./ src/org/apache/axis2/jaxws/i18n/ test/org/apache/axis2/jaxws/framework/ test/org/apache/axis2/jaxws/i18n/
Date Wed, 02 Aug 2006 19:26:07 GMT
Author: scheu
Date: Wed Aug  2 12:26:07 2006
New Revision: 428104

URL: http://svn.apache.org/viewvc?rev=428104&view=rev
Log:
AXIS2-964
I18N resource bundle and test
Contributor: Ming Cheung

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessageBundle.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/Messages.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessagesConstants.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/ProjectResourceBundle.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/RB.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/i18n/
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/i18n/JaxwsMessageBundleTests.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/maven.xml
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java

Modified: webservices/axis2/trunk/java/modules/jaxws/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/maven.xml?rev=428104&r1=428103&r2=428104&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/jaxws/maven.xml Wed Aug  2 12:26:07 2006
@@ -292,5 +292,16 @@
             </ant:sourcepath>
         </ant:javadoc>
     </goal>
+	
+	    <postGoal name="java:jar-resources">
+	      <tstamp>
+	        <format property="build.time" pattern="MMM dd, yyyy (hh:mm:ss z)" locale="en"/>
+	      </tstamp>
+	      <replace dir="${maven.build.dest}/org/apache/axis2/jaxws/i18n">
+	        <include name="resource*.properties"/>
+	        <replacefilter token="#today#" value="${build.time}"/>
+	        <replacefilter token="#axisVersion#" value="${pom.currentVersion}"/>
+	      </replace> 
+	    </postGoal>
 
 </project>

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessageBundle.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessageBundle.java?rev=428104&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessageBundle.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessageBundle.java Wed Aug  2 12:26:07 2006
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.jaxws.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.
+ */
+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, (Object[]) array);
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/Messages.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/Messages.java?rev=428104&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/Messages.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/Messages.java Wed Aug  2 12:26:07 2006
@@ -0,0 +1,291 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.jaxws.i18n;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+    private static final Class thisClass = Messages.class;
+
+    private static final String projectName = MessagesConstants.projectName;
+
+    private static final String resourceName = MessagesConstants.resourceName;
+    private static final Locale locale = MessagesConstants.locale;
+    
+    public static final String DEFAULT_MESSAGE_BUNDLE_KEY = "default";
+    private static final String NO_MESSAGE_BUNDLE = "Message Bundle is not available";
+
+    private static final String packageName = getPackage(thisClass.getName());
+    private static final ClassLoader classLoader = thisClass.getClassLoader();
+
+    private static final ResourceBundle parent =
+            (MessagesConstants.rootPackageName.equals(packageName))
+            ? null
+            : MessagesConstants.rootBundle;
+    
+    private static HashMap messageBundleMap = new HashMap ();
+
+    static {
+    	MessageBundle defaultMessageBundle =
+            new MessageBundle(projectName, packageName, resourceName,
+                    locale, classLoader, parent);
+    	addMessageBundle(DEFAULT_MESSAGE_BUNDLE_KEY,defaultMessageBundle);
+    }
+    
+    /**
+     * To add a new Message Bundle to the MessageBundle list.
+     * 
+     * @param messageBundleKey The key which will be used to refer to this message bundle later.
+     * @param messageBundle The message bundle.
+     */
+    public static void addMessageBundle (String messageBundleKey,MessageBundle messageBundle) {
+    	messageBundleMap.put(messageBundleKey,messageBundle);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param key The resource key
+     * @return The formatted message
+     */
+    public static String getMessage(String key)
+            throws MissingResourceException {
+    	MessageBundle messageBundle = getMessageBundle (DEFAULT_MESSAGE_BUNDLE_KEY);
+        return messageBundle.getMessage(key);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param key  The resource key
+     * @param arg0 The argument to place in variable {0}
+     * @return The formatted message
+     */
+    public static String getMessage(String key, String arg0)
+            throws MissingResourceException {
+    	MessageBundle messageBundle = getMessageBundle (DEFAULT_MESSAGE_BUNDLE_KEY);
+        return messageBundle.getMessage(key, arg0);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @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 formatted message
+     */
+    public static String getMessage(String key, String arg0, String arg1)
+            throws MissingResourceException {
+    	MessageBundle messageBundle = getMessageBundle (DEFAULT_MESSAGE_BUNDLE_KEY);
+        return messageBundle.getMessage(key, arg0, arg1);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @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 formatted message
+     */
+    public static String getMessage(String key, String arg0, String arg1, String arg2)
+            throws MissingResourceException {
+    	MessageBundle messageBundle = getMessageBundle (DEFAULT_MESSAGE_BUNDLE_KEY);
+        return messageBundle.getMessage(key, arg0, arg1, arg2);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @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 formatted message
+     */
+    public static String getMessage(String key, String arg0, String arg1, String arg2, String arg3)
+            throws MissingResourceException {
+    	MessageBundle messageBundle = getMessageBundle (DEFAULT_MESSAGE_BUNDLE_KEY);
+        return messageBundle.getMessage(key, arg0, arg1, arg2, arg3);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @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 formatted message
+     */
+    public static String getMessage(String key, String arg0, String arg1, String arg2, String arg3, String arg4)
+            throws MissingResourceException {
+    	MessageBundle messageBundle = getMessageBundle (DEFAULT_MESSAGE_BUNDLE_KEY);
+        return messageBundle.getMessage(key, arg0, arg1, arg2, arg3, arg4);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param key  The resource key
+     * @param args An array of objects to place in corresponding variables
+     * @return The formatted message
+     */
+    public static String getMessage(String key, String[] args)
+            throws MissingResourceException {
+    	MessageBundle messageBundle = getMessageBundle (DEFAULT_MESSAGE_BUNDLE_KEY);
+        return messageBundle.getMessage(key, args);
+    }
+
+    public static ResourceBundle getResourceBundle() {
+    	MessageBundle messageBundle = getMessageBundle (DEFAULT_MESSAGE_BUNDLE_KEY);
+        return messageBundle.getResourceBundle();
+    }
+
+    public static MessageBundle getMessageBundle() {
+    	MessageBundle messageBundle = getMessageBundle (DEFAULT_MESSAGE_BUNDLE_KEY);
+        return messageBundle;
+    }
+    
+    public static MessageBundle getMessageBundle(String messageBundleKey) {
+    	MessageBundle messageBundle = (MessageBundle) messageBundleMap.get (messageBundleKey);
+        return messageBundle;
+    }
+    
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param messageBundleKey The key for getting the correct message bundle.
+     * @param key The resource key
+     * @return The formatted message
+     */
+    public static String getMessageFromBundle(String messageBundleKey,String key)
+            throws MissingResourceException, Exception {
+    	MessageBundle messageBundle = getMessageBundle (messageBundleKey);
+    	if (messageBundle==null)
+    		throw new Exception (NO_MESSAGE_BUNDLE);
+    	
+        return messageBundle.getMessage(key);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param messageBundleKey The key for getting the correct message bundle.
+     * @param key  The resource key
+     * @param arg0 The argument to place in variable {0}
+     * @return The formatted message
+     */
+    public static String getMessageFromBundle(String messageBundleKey,String key, String arg0)
+            throws MissingResourceException, Exception {
+    	MessageBundle messageBundle = getMessageBundle (messageBundleKey);
+    	if (messageBundle==null)
+    		throw new Exception (NO_MESSAGE_BUNDLE);
+    	
+        return messageBundle.getMessage(key, arg0);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param messageBundleKey The key for getting the correct message bundle.
+     * @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 formatted message
+     */
+    public static String getMessageFromBundle(String messageBundleKey,String key, String arg0, String arg1)
+            throws MissingResourceException, Exception {
+    	MessageBundle messageBundle = getMessageBundle (messageBundleKey);
+    	if (messageBundle==null)
+    		throw new Exception (NO_MESSAGE_BUNDLE);
+    	
+        return messageBundle.getMessage(key, arg0, arg1);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param messageBundleKey The key for getting the correct message bundle.
+     * @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 formatted message
+     */
+    public static String getMessageFromBundle(String messageBundleKey,String key, String arg0, String arg1, String arg2)
+            throws MissingResourceException, Exception {
+    	MessageBundle messageBundle = getMessageBundle (messageBundleKey);
+    	if (messageBundle==null)
+    		throw new Exception (NO_MESSAGE_BUNDLE);
+    	
+        return messageBundle.getMessage(key, arg0, arg1, arg2);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param messageBundleKey The key for getting the correct message bundle.
+     * @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 formatted message
+     */
+    public static String getMessageFromBundle(String messageBundleKey,String key, String arg0, String arg1, String arg2, String arg3)
+            throws MissingResourceException, Exception {
+    	MessageBundle messageBundle = getMessageBundle (messageBundleKey);
+    	if (messageBundle==null)
+    		throw new Exception (NO_MESSAGE_BUNDLE);
+    	
+        return messageBundle.getMessage(key, arg0, arg1, arg2, arg3);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param messageBundleKey The key for getting the correct message bundle.
+     * @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 formatted message
+     */
+    public static String getMessageFromBundle(String messageBundleKey,String key, String arg0, String arg1, String arg2, String arg3, String arg4)
+            throws MissingResourceException, Exception {
+    	MessageBundle messageBundle = getMessageBundle (messageBundleKey);
+    	if (messageBundle==null)
+    		throw new Exception (NO_MESSAGE_BUNDLE);
+    	
+        return messageBundle.getMessage(key, arg0, arg1, arg2, arg3, arg4);
+    }
+
+    private static String getPackage(String name) {
+        return name.substring(0, name.lastIndexOf('.')).intern();
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessagesConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessagesConstants.java?rev=428104&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessagesConstants.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/MessagesConstants.java Wed Aug  2 12:26:07 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.jaxws.i18n;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+public class MessagesConstants {
+    public static final String projectName = "org.apache.axis2.jaxws".intern();
+    public static final String resourceName = "resource".intern();
+    public static final Locale locale = null;
+
+    public static final String rootPackageName = "org.apache.axis2.jaxws.i18n".intern();
+
+    public static final ResourceBundle rootBundle =
+            ProjectResourceBundle.getBundle(projectName,
+                    rootPackageName,
+                    resourceName,
+                    locale,
+                    MessagesConstants.class.getClassLoader(),
+                    null);
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/ProjectResourceBundle.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/ProjectResourceBundle.java?rev=428104&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/ProjectResourceBundle.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/ProjectResourceBundle.java Wed Aug  2 12:26:07 2006
@@ -0,0 +1,456 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.jaxws.i18n;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * <p>Wrapper class for resource bundles. Property files are used to store
+ * resource strings, which are the only types of resources available.
+ * Property files can inherit properties from other files so that
+ * a base property file can be used and a small number of properties
+ * can be over-ridden by another property file. For example you may
+ * create an english version of a resource file named "resource.properties".
+ * You then decide that the British English version of all of the properties
+ * except one are the same, so there is no need to redefine all of the
+ * properties in "resource_en_GB", just the one that is different.</p>
+ * <p>The basename is the name of the property file without the ".properties"
+ * extension.</p>
+ * <p>Properties will be cached for performance.<p>
+ * <p>Property values stored in the property files can also contain dynamic
+ * variables. Any dynamic variable defined in PropertiesUtil.getVariableValue()
+ * can be used (such as {date}), as well as arguments in the form {0}, {1}, etc.
+ * Argument values are specified in the various overloaded getString() methods.</p>
+ */
+public class ProjectResourceBundle extends ResourceBundle {
+	private static final Log log = LogFactory.getLog(ProjectResourceBundle.class);
+
+
+    // The static cache of ResourceBundles.
+    // The key is the 'basename + locale + default locale'
+    // The element is a ResourceBundle object
+    private static final Hashtable bundleCache = new Hashtable();
+
+    private static final Locale defaultLocale = Locale.getDefault();
+
+    private final ResourceBundle resourceBundle;
+    private final String resourceName;
+
+
+    protected Object handleGetObject(String key)
+            throws MissingResourceException {
+        if (log.isDebugEnabled()) {
+            log.debug(this.toString() + "::handleGetObject(" + key + ")");
+        }
+        Object obj;
+        try {
+            obj = resourceBundle.getObject(key);
+        } catch (MissingResourceException e) {
+            /* catch missing resource, ignore, & return null
+             * if this method doesn't return null, then parents
+             * are not searched
+             */
+            obj = null;
+        }
+        return obj;
+    }
+
+    public Enumeration getKeys() {
+        Enumeration myKeys = resourceBundle.getKeys();
+        if (parent == null) {
+            return myKeys;
+        } else {
+            final HashSet set = new HashSet();
+            while (myKeys.hasMoreElements()) {
+                set.add(myKeys.nextElement());
+            }
+
+            Enumeration pKeys = parent.getKeys();
+            while (pKeys.hasMoreElements()) {
+                set.add(pKeys.nextElement());
+            }
+
+            return new Enumeration() {
+                private Iterator it = set.iterator();
+
+                public boolean hasMoreElements() {
+                    return it.hasNext();
+                }
+
+                public Object nextElement() {
+                    return it.next();
+                }
+            };
+        }
+    }
+
+
+    /**
+     * Construct a new ProjectResourceBundle
+     *
+     * @param projectName  The name of the project to which the class belongs.
+     *                     It must be a proper prefix of the caller's package.
+     * @param packageName  The package name to further construct
+     *                     the basename.
+     * @param resourceName The name of the resource without the
+     *                     ".properties" extension
+     * @throws MissingResourceException if projectName is not a prefix of
+     *                                  the caller's package name, or if the resource could not be
+     *                                  found/loaded.
+     */
+    public static ProjectResourceBundle getBundle(String projectName,
+                                                  String packageName,
+                                                  String resourceName)
+            throws MissingResourceException {
+        return getBundle(projectName, packageName, resourceName, null, null, null);
+    }
+
+    /**
+     * Construct a new ProjectResourceBundle
+     *
+     * @param projectName  The name of the project to which the class belongs.
+     *                     It must be a proper prefix of the caller's package.
+     * @param caller       The calling class.
+     *                
+     * @param resourceName The name of the resource without the
+     *                     ".properties" extension
+     * @throws MissingResourceException if projectName is not a prefix of
+     *                                  the caller's package name, or if the resource could not be
+     *                                  found/loaded.
+     */
+    public static ProjectResourceBundle getBundle(String projectName,
+                                                  Class caller,
+                                                  String resourceName,
+                                                  Locale locale)
+            throws MissingResourceException {
+        return getBundle(projectName,
+                caller,
+                resourceName,
+                locale,
+                null);
+    }
+
+    /**
+     * Construct a new ProjectResourceBundle
+     *
+     * @param projectName  The name of the project to which the class belongs.
+     *                     It must be a proper prefix of the caller's package.
+     * @param packageName  The package name to construct base name.
+     *                     
+     * @param resourceName The name of the resource without the
+     *                     ".properties" extension
+     * @param locale       The locale
+     * @throws MissingResourceException if projectName is not a prefix of
+     *                                  the caller's package name, or if the resource could not be
+     *                                  found/loaded.
+     */
+    public static ProjectResourceBundle getBundle(String projectName,
+                                                  String packageName,
+                                                  String resourceName,
+                                                  Locale locale,
+                                                  ClassLoader loader)
+            throws MissingResourceException {
+        return getBundle(projectName, packageName, resourceName, locale, loader, null);
+    }
+
+    /**
+     * Construct a new ProjectResourceBundle
+     *
+     * @param projectName   The name of the project to which the class belongs.
+     *                      It must be a proper prefix of the caller's package.
+     * @param caller        The calling class.
+     *                      This is used to get the package name to further construct
+     *                      the basename as well as to get the proper ClassLoader.
+     * @param resourceName  The name of the resource without the
+     *                      ".properties" extension
+     * @param locale        The locale
+     * @param extendsBundle If non-null, then this ExtendMessages will
+     *                      default to extendsBundle.
+     * @throws MissingResourceException if projectName is not a prefix of
+     *                                  the caller's package name, or if the resource could not be
+     *                                  found/loaded.
+     */
+    public static ProjectResourceBundle getBundle(String projectName,
+                                                  Class caller,
+                                                  String resourceName,
+                                                  Locale locale,
+                                                  ResourceBundle extendsBundle)
+            throws MissingResourceException {
+        return getBundle(projectName,
+                getPackage(caller.getClass().getName()),
+                resourceName,
+                locale,
+                caller.getClass().getClassLoader(),
+                extendsBundle);
+    }
+
+    /**
+     * Construct a new ProjectResourceBundle
+     *
+     * @param projectName   The name of the project to which the class belongs.
+     *                      It must be a proper prefix of the caller's package.
+     * @param packageName  The package name to further construct
+     *                     the basename.
+     * @param resourceName  The name of the resource without the
+     *                      ".properties" extension
+     * @param locale        The locale
+     * @param extendsBundle If non-null, then this ExtendMessages will
+     *                      default to extendsBundle.
+     * @throws MissingResourceException if projectName is not a prefix of
+     *                                  the caller's package name, or if the resource could not be
+     *                                  found/loaded.
+     */
+    public static ProjectResourceBundle getBundle(String projectName,
+                                                  String packageName,
+                                                  String resourceName,
+                                                  Locale locale,
+                                                  ClassLoader loader,
+                                                  ResourceBundle extendsBundle)
+            throws MissingResourceException {
+        if (log.isDebugEnabled()) {
+            log.debug("getBundle(" + projectName + ","
+                    + packageName + ","
+                    + resourceName + ","
+                    + String.valueOf(locale) + ",...)");
+        }
+
+        Context context = new Context();
+        context.setLocale(locale);
+        context.setLoader(loader);
+        context.setProjectName(projectName);
+        context.setResourceName(resourceName);
+        context.setParentBundle(extendsBundle);
+
+        packageName = context.validate(packageName);
+
+        ProjectResourceBundle bundle = null;
+        try {
+            bundle = getBundle(context, packageName);
+        } catch (RuntimeException e) {
+            log.debug("Exception: ", e);
+            throw e;
+        }
+
+        if (bundle == null) {
+            throw new MissingResourceException("Cannot find resource '" +
+                    packageName + '.' + resourceName + "'",
+                    resourceName, "");
+        }
+
+        return bundle;
+    }
+
+    /**
+     * get bundle...
+     * - check cache
+     * - try up hierarchy
+     * - if at top of hierarchy, use (link to) context.getParentBundle()
+     */
+    private static synchronized ProjectResourceBundle getBundle(Context context, String packageName)
+            throws MissingResourceException {
+        String cacheKey = context.getCacheKey(packageName);
+
+        ProjectResourceBundle prb = (ProjectResourceBundle) bundleCache.get(cacheKey);
+
+        if (prb == null) {
+            String name = packageName + '.' + context.getResourceName();
+            ResourceBundle rb = context.loadBundle(packageName);
+            ResourceBundle parent = context.getParentBundle(packageName);
+
+            if (rb != null) {
+                prb = new ProjectResourceBundle(name, rb);
+                prb.setParent(parent);
+                if (log.isDebugEnabled()) {
+                    log.debug("Created " + prb + ", linked to parent " + String.valueOf(parent));
+                }
+            } else {
+                if (parent != null) {
+                    if (parent instanceof ProjectResourceBundle) {
+                        prb = (ProjectResourceBundle) parent;
+                    } else {
+                        prb = new ProjectResourceBundle(name, parent);
+                    }
+                    if (log.isDebugEnabled()) {
+                        log.debug("Root package not found, cross link to " + parent);
+                    }
+                }
+            }
+
+            if (prb != null) {
+                // Cache the resource
+                bundleCache.put(cacheKey, prb);
+            }
+        }
+
+        return prb;
+    }
+
+    private static String getPackage(String name) {
+        return name.substring(0, name.lastIndexOf('.')).intern();
+    }
+
+    /**
+     * Construct a new ProjectResourceBundle
+     */
+    private ProjectResourceBundle(String name, ResourceBundle bundle)
+            throws MissingResourceException {
+        this.resourceBundle = bundle;
+        this.resourceName = name;
+    }
+
+    public String getResourceName() {
+        return resourceName;
+    }
+
+    /**
+     * Clears the internal cache
+     */
+//    public static void clearCache() {
+//        bundleCache.clear();
+//    }
+
+    public String toString() {
+        return resourceName;
+    }
+
+
+    private static class Context {
+        private Locale _locale;
+        private ClassLoader _loader;
+        private String _projectName;
+        private String _resourceName;
+        private ResourceBundle _parent;
+
+        void setLocale(Locale l) {
+            /* 1. Docs indicate that if locale is not specified,
+             *    then the default local is used in it's place.
+             * 2. A null value for locale is invalid.
+             * 
+             * Therefore, default...
+             */
+            _locale = (l == null) ? defaultLocale : l;
+        }
+
+        void setLoader(ClassLoader l) {
+            _loader = (l != null) ? l : this.getClass().getClassLoader();
+            // START FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16868
+            if (_loader == null) {
+                _loader = ClassLoader.getSystemClassLoader();
+            }
+            // END FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16868
+        }
+
+        void setProjectName(String name) {
+            _projectName = name.intern();
+        }
+
+        void setResourceName(String name) {
+            _resourceName = name.intern();
+        }
+
+        void setParentBundle(ResourceBundle b) {
+            _parent = b;
+        }
+
+        Locale getLocale() {
+            return _locale;
+        }
+
+        ClassLoader getLoader() {
+            return _loader;
+        }
+
+        String getProjectName() {
+            return _projectName;
+        }
+
+        String getResourceName() {
+            return _resourceName;
+        }
+
+        ResourceBundle getParentBundle() {
+            return _parent;
+        }
+
+        String getCacheKey(String packageName) {
+            String loaderName = (_loader == null) ? "" : (":" + _loader.hashCode());
+            return packageName + "." + _resourceName + ":" + _locale + ":" + defaultLocale + loaderName;
+        }
+
+        ResourceBundle loadBundle(String packageName) {
+            try {
+                return ResourceBundle.getBundle(packageName + '.' + _resourceName,
+                        _locale,
+                        _loader);
+            } catch (MissingResourceException e) {
+                // Deliberately surpressing print stack.. just the string for info.
+                log.debug("loadBundle: Ignoring MissingResourceException: " + e.getMessage());
+            }
+            return null;
+        }
+
+        ResourceBundle getParentBundle(String packageName) {
+            ResourceBundle p;
+            if (!packageName.equals(_projectName)) {
+                p = getBundle(this, getPackage(packageName));
+            } else {
+                p = _parent;
+                _parent = null;
+            }
+            return p;
+        }
+
+        String validate(String packageName)
+                throws MissingResourceException {
+            if (_projectName == null || _projectName.length() == 0) {
+                log.debug("Project name not specified");
+                throw new MissingResourceException("Project name not specified",
+                        "", "");
+            }
+
+            if (packageName == null || packageName.length() == 0) {
+                log.debug("Package name not specified");
+                throw new MissingResourceException("Package not specified",
+                        packageName, "");
+            }
+            packageName = packageName.intern();
+    
+            /* Ensure that project is a proper prefix of class.
+             * Terminate project name with '.' to ensure proper match.
+             */
+            if (!packageName.equals(_projectName) && !packageName.startsWith(_projectName + '.')) {
+                log.debug("Project not a prefix of Package");
+                throw new MissingResourceException("Project '" + _projectName
+                        + "' must be a prefix of Package '"
+                        + packageName + "'",
+                        packageName + '.' + _resourceName, "");
+            }
+
+            return packageName;
+        }
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/RB.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/RB.java?rev=428104&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/RB.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/RB.java Wed Aug  2 12:26:07 2006
@@ -0,0 +1,718 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.jaxws.i18n;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.MessageFormat;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.Properties;
+
+/**
+ * CURRENTLY NOT USED
+ * KEEPING FOR REFERENCE  9/19/2002
+ * <p/>
+ * <p>Wrapper class for resource bundles. Property files are used to store
+ * resource strings, which are the only types of resources available.
+ * Property files can inherit properties from other files so that
+ * a base property file can be used and a small number of properties
+ * can be over-ridden by another property file. For example you may
+ * create an english version of a resource file named "resource.properties".
+ * You then decide that the British English version of all of the properties
+ * except one are the same, so there is no need to redefine all of the
+ * properties in "resource_en_GB", just the one that is different.</p>
+ * <p>The property file lookup searches for classes with various suffixes
+ * on the basis if the desired local and the current default local
+ * (as returned by Local.getDefault()). As property files are found the
+ * property values are merged so that inheritance is preserved.</p>
+ * <p>The order of searching is:</p>
+ * <dir>
+ * basename + "_" + langage + "_" + country + "_" + variant
+ * basename + "_" + langage + "_" + country
+ * basename + "_" + langage
+ * basename + "_" + defaultLanguage + "_" + defaultCountry + "_" + defaultVariant
+ * basename + "_" + defaultLanguage + "_" + defaultCountry
+ * basename + "_" + defaultLanguage
+ * basename
+ * </dir>
+ * <p>The basename is the name of the property file without the ".properties"
+ * extension.</p>
+ * <p>Properties will be cached for performance.<p>
+ * <p>Property values stored in the property files can also contain dynamic
+ * variables. Any dynamic variable defined in PropertiesUtil.getVariableValue()
+ * can be used (such as {date}), as well as arguments in the form {0}, {1}, etc.
+ * Argument values are specified in the various overloaded getString() methods.</p>
+ */
+public class RB {
+    // The static cache of properties. The key is the basename + the local +
+    // the default local and the element is the Properties object containing
+    // the resources
+    static Hashtable propertyCache = new Hashtable();
+
+    // The default base name
+    public static final String BASE_NAME = "resource";
+
+    // The property file extension
+    public static final String PROPERTY_EXT = ".properties";
+
+    // The name of the current base property file (with extension)
+    protected String basePropertyFileName;
+
+    // The properties for the current resource bundle
+    protected Properties resourceProperties;
+
+    /**
+     * Construct a new RB
+     *
+     * @param name The name of the property file without the ".properties" extension
+     */
+    public RB(String name) throws MissingResourceException {
+        this(null, name, null);
+    }
+
+    /**
+     * Construct a new RB
+     *
+     * @param caller The calling object. This is used to get the package name
+     *               to further construct the basename as well as to get the proper ClassLoader
+     * @param name   The name of the property file without the ".properties" extension
+     */
+    public RB(Object caller, String name) throws MissingResourceException {
+        this(caller, name, null);
+    }
+
+    /**
+     * Construct a new RB
+     *
+     * @param caller The calling object. This is used to get the package name
+     *               to further construct the basename as well as to get the proper ClassLoader
+     * @param name   The name of the property file without the ".properties" extension
+     * @param locale  The locale
+     */
+    public RB(Object caller, String name, Locale locale) throws MissingResourceException {
+        ClassLoader cl = null;
+
+        if (caller != null) {
+
+            Class c;
+            if (caller instanceof Class) {
+                c = (Class) caller;
+            } else {
+                c = caller.getClass();
+            }
+
+            // Get the appropriate class loader
+            cl = c.getClassLoader();
+
+            if (name.indexOf("/") == -1) {
+
+                // Create the full basename only if not given
+                String fullName = c.getName();
+
+                int pos = fullName.lastIndexOf(".");
+                if (pos > 0) {
+                    name = fullName.substring(0, pos + 1).replace('.', '/') + name;
+                }
+            }
+        } else {
+            // Try the shared default properties file...
+            if (name.indexOf("/") == -1) {
+                name = "org/apache/axis2/default-resource";
+            }
+        }
+
+        Locale defaultLocale = Locale.getDefault();
+
+        // If the locale given is the same as the default locale, ignore it
+        if (locale != null) {
+            if (locale.equals(defaultLocale)) {
+                locale = null;
+            }
+        }
+
+        // Load the properties. If no property files exist then a
+        // MissingResourceException will be thrown
+        loadProperties(name, cl, locale, defaultLocale);
+    }
+
+    /**
+     * Gets a string message from the resource bundle for the given key
+     *
+     * @param key The resource key
+     * @return The message
+     */
+    public String getString(String key) throws MissingResourceException {
+        return getString(key, (Object[]) 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 getString(String key, Object arg0) throws MissingResourceException {
+        Object[] o = new Object[1];
+        o[0] = arg0;
+        return getString(key, o);
+    }
+
+    /**
+     * <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 getString(String key, Object arg0, Object arg1) throws MissingResourceException {
+        Object[] o = new Object[2];
+        o[0] = arg0;
+        o[1] = arg1;
+        return getString(key, o);
+    }
+
+    /**
+     * <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 {1}
+     * @return The message
+     */
+    public String getString(String key, Object arg0, Object arg1, Object arg2) throws MissingResourceException {
+        Object[] o = new Object[3];
+        o[0] = arg0;
+        o[1] = arg1;
+        o[2] = arg2;
+        return getString(key, o);
+    }
+
+    /**
+     * <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 getString(String key, Object[] array) throws MissingResourceException {
+        String msg = null;
+        if (resourceProperties != null) {
+            msg = resourceProperties.getProperty(key);
+        }
+
+        if (msg == null) {
+            throw new MissingResourceException("Cannot find resource key \"" + key +
+                    "\" in base name " + basePropertyFileName,
+                    basePropertyFileName, key);
+        }
+
+        msg = MessageFormat.format(msg, array);
+        return msg;
+    }
+
+    protected void loadProperties(String basename, ClassLoader loader, Locale locale,
+                                  Locale defaultLocale)
+            throws MissingResourceException {
+        // Check the cache first
+        String loaderName = "";
+        if (loader != null) {
+            loaderName = ":" + loader.hashCode();
+        }
+        String cacheKey = basename + ":" + locale + ":" + defaultLocale + loaderName;
+        Properties p = (Properties) propertyCache.get(cacheKey);
+        basePropertyFileName = basename + PROPERTY_EXT;
+
+        if (p == null) {
+            // The properties were not found in the cache. Search the given locale
+            // first
+            if (locale != null) {
+                p = loadProperties(basename, loader, locale, p);
+            }
+
+            // Search the default locale
+            if (defaultLocale != null) {
+                p = loadProperties(basename, loader, defaultLocale, p);
+            }
+
+            // Search for the basename
+            p = merge(p, loadProperties(basePropertyFileName, loader));
+
+            if (p == null) {
+                throw new MissingResourceException("Cannot find resource for base name " +
+                        basePropertyFileName, basePropertyFileName, "");
+            }
+
+            // Cache the properties
+            propertyCache.put(cacheKey, p);
+
+        }
+
+        resourceProperties = p;
+    }
+
+    protected Properties loadProperties(String basename, ClassLoader loader, Locale locale,
+                                        Properties props) {
+
+        String language = locale.getLanguage();
+        String country = locale.getCountry();
+        String variant = locale.getVariant();
+        if (variant != null) {
+            if (variant.trim().length() == 0) {
+                variant = null;
+            }
+        }
+
+        if (language != null) {
+
+            if (country != null) {
+
+                if (variant != null) {
+                    props = merge(props, loadProperties(basename + "_" + language + "_" + country + "_" + variant +
+                            PROPERTY_EXT, loader));
+                }
+                props = merge(props, loadProperties(basename + "_" + language + "_" + country +
+                        PROPERTY_EXT, loader));
+            }
+            props = merge(props, loadProperties(basename + "_" + language + PROPERTY_EXT, loader));
+        }
+        return props;
+    }
+
+    protected Properties loadProperties(String resname, ClassLoader loader) {
+        Properties props = null;
+
+        // Attempt to open and load the properties
+        InputStream in = null;
+        try {
+            if (loader != null) {
+                in = loader.getResourceAsStream(resname);
+            }
+
+            // Either we're using the system class loader or we didn't find the
+            // resource using the given class loader
+            if (in == null) {
+                in = ClassLoader.getSystemResourceAsStream(resname);
+            }
+            if (in != null) {
+                props = new Properties();
+                try {
+                    props.load(in);
+                } catch (IOException ex) {
+                    // On error, clear the props
+                    props = null;
+                }
+            }
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (Exception ex) {
+                    // Ignore error on close
+                }
+            }
+        }
+        return props;
+    }
+
+    /**
+     * Merge two Properties objects
+     */
+    protected Properties merge(Properties p1, Properties p2) {
+        if ((p1 == null) &&
+                (p2 == null)) {
+            return null;
+        } else if (p1 == null) {
+            return p2;
+        } else if (p2 == null) {
+            return p1;
+        }
+
+        // Now merge. p1 takes precedence
+        Enumeration enumeration = p2.keys();
+        while (enumeration.hasMoreElements()) {
+            String key = (String) enumeration.nextElement();
+            if (p1.getProperty(key) == null) {
+                p1.put(key, p2.getProperty(key));
+            }
+        }
+
+        return p1;
+    }
+
+    /**
+     * Get the underlying properties
+     */
+    public Properties getProperties() {
+        return resourceProperties;
+    }
+
+    // STATIC ACCESSORS
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param key    The resource key
+     * @return The formatted message
+     */
+    public static String getString(Object caller, String key)
+            throws MissingResourceException {
+        return getMessage(caller, BASE_NAME, null, key, null);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param key    The resource key
+     * @param arg0   The argument to place in variable {0}
+     * @return The formatted message
+     */
+    public static String getString(Object caller, String key, Object arg0)
+            throws MissingResourceException {
+        Object[] o = new Object[1];
+        o[0] = arg0;
+        return getMessage(caller, BASE_NAME, null, key, o);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @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 formatted message
+     */
+    public static String getString(Object caller, String key, Object arg0, Object arg1)
+            throws MissingResourceException {
+        Object[] o = new Object[2];
+        o[0] = arg0;
+        o[1] = arg1;
+        return getMessage(caller, BASE_NAME, null, key, o);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @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 formatted message
+     */
+    public static String getString(Object caller, String key, Object arg0, Object arg1, Object arg2)
+            throws MissingResourceException {
+        Object[] o = new Object[3];
+        o[0] = arg0;
+        o[1] = arg1;
+        o[2] = arg2;
+        return getMessage(caller, BASE_NAME, null, key, o);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @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 formatted message
+     */
+    public static String getString(Object caller, String key, Object arg0, Object arg1, Object arg2, Object arg3)
+            throws MissingResourceException {
+        Object[] o = new Object[4];
+        o[0] = arg0;
+        o[1] = arg1;
+        o[2] = arg2;
+        o[3] = arg3;
+        return getMessage(caller, BASE_NAME, null, key, o);
+    }
+
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @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 Returns the formatted message.
+     */
+    public static String getString(Object caller, String key, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4)
+            throws MissingResourceException {
+        Object[] o = new Object[5];
+        o[0] = arg0;
+        o[1] = arg1;
+        o[2] = arg2;
+        o[3] = arg3;
+        o[4] = arg4;
+        return getMessage(caller, BASE_NAME, null, key, o);
+    }
+
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param key    The resource key
+     * @param args  An array of objects to place in corresponding variables
+     * @return Returns the formatted message.
+     */
+    public static String getString(Object caller, String key, Object[] args)
+            throws MissingResourceException {
+        return getMessage(caller, BASE_NAME, null, key, args);
+    }
+
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param locale The locale
+     * @param key    The resource key
+     * @return The formatted message
+     */
+    public static String getString(Object caller, Locale locale, String key)
+            throws MissingResourceException {
+        return getMessage(caller, BASE_NAME, locale, key, null);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param locale The locale
+     * @param key    The resource key
+     * @param arg0   The argument to place in variable {0}
+     * @return The formatted message
+     */
+    public static String getString(Object caller, Locale locale, String key, Object arg0)
+            throws MissingResourceException {
+        Object[] o = new Object[1];
+        o[0] = arg0;
+        return getMessage(caller, BASE_NAME, locale, key, o);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param locale The locale
+     * @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 formatted message
+     */
+    public static String getString(Object caller, Locale locale, String key, Object arg0, Object arg1)
+            throws MissingResourceException {
+        Object[] o = new Object[2];
+        o[0] = arg0;
+        o[1] = arg1;
+        return getMessage(caller, BASE_NAME, locale, key, o);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param locale The locale
+     * @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 formatted message
+     */
+    public static String getString(Object caller, Locale locale, String key, Object arg0, Object arg1, Object arg2)
+            throws MissingResourceException {
+        Object[] o = new Object[3];
+        o[0] = arg0;
+        o[1] = arg1;
+        o[2] = arg2;
+        return getMessage(caller, BASE_NAME, locale, key, o);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param locale The locale
+     * @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 formatted message
+     */
+    public static String getString(Object caller, Locale locale, String key, Object arg0, Object arg1, Object arg2, Object arg3)
+            throws MissingResourceException {
+        Object[] o = new Object[4];
+        o[0] = arg0;
+        o[1] = arg1;
+        o[2] = arg2;
+        o[3] = arg3;
+        return getMessage(caller, BASE_NAME, locale, key, o);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param locale The locale
+     * @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 Returns the formatted message.
+     */
+    public static String getString(Object caller, Locale locale, String key, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4)
+            throws MissingResourceException {
+        Object[] o = new Object[5];
+        o[0] = arg0;
+        o[1] = arg1;
+        o[2] = arg2;
+        o[3] = arg3;
+        o[4] = arg4;
+        return getMessage(caller, BASE_NAME, locale, key, o);
+    }
+
+    /**
+     * Get a message from resource.properties from the package of the given object.
+     *
+     * @param caller The calling object, used to get the package name and class loader
+     * @param locale The locale
+     * @param key    The resource key
+     * @param args  An array of objects to place in corresponding variables
+     * @return Returns the formatted message.
+     */
+    public static String getString(Object caller, Locale locale, String key, Object[] args)
+            throws MissingResourceException {
+        return getMessage(caller, BASE_NAME, locale, key, args);
+    }
+
+    // Workhorse that does the resource loading and key lookup
+    public static String getMessage(Object caller, String basename, Locale locale, String key,
+                                    Object[] args)
+            throws MissingResourceException {
+        String msg = null;
+        MissingResourceException firstEx = null;
+        String fullName = null;
+        Class curClass = null;
+        boolean didNull = false;
+
+        if (caller != null) {
+            if (caller instanceof Class)
+                curClass = (Class) caller;
+            else
+                curClass = caller.getClass();
+        }
+
+        while (msg == null) {
+
+            // Get the full name of the resource
+            if (curClass != null) {
+
+                // Create the full basename
+                String pkgName = curClass.getName();
+
+                int pos = pkgName.lastIndexOf(".");
+                if (pos > 0) {
+                    fullName = pkgName.substring(0, pos + 1).replace('.', '/') + basename;
+                } else {
+                    fullName = basename;
+                }
+            } else {
+                fullName = basename;
+            }
+
+            try {
+                RB rb = new RB(caller, fullName, locale);
+                msg = rb.getString(key, args);
+            } catch (MissingResourceException ex) {
+                if (curClass == null) {
+                    throw ex;
+                }
+
+                // Save the first exception
+                if (firstEx == null) {
+                    firstEx = ex;
+                }
+
+                // Get the superclass
+                curClass = curClass.getSuperclass();
+                if (curClass == null) {
+                    if (didNull)
+                        throw firstEx;
+                    didNull = true;
+                    caller = null;
+                } else {
+                    String cname = curClass.getName();
+                    if (cname.startsWith("java.") ||
+                            cname.startsWith("javax.")) {
+                        if (didNull)
+                            throw firstEx;
+                        didNull = true;
+                        caller = null;
+                        curClass = null;
+                    }
+                }
+            }
+
+        }
+        return msg;
+    }
+
+    /**
+     * Clears the internal cache.
+     */
+    public static void clearCache() {
+        propertyCache.clear();
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties?rev=428104&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties Wed Aug  2 12:26:07 2006
@@ -0,0 +1,25 @@
+# Translation instructions.
+# 1.  Each message line is of the form key=value.
+#     Translate the value, DO NOT translate the key.
+# 2.  The messages may contain arguments that will be filled in
+#     by the runtime.  These are of the form: {0}, {1}, etc.
+#     These must appear as is in the message, though the order
+#     may be changed to support proper language syntax.
+# 3.  If a single quote character is to appear in the resulting
+#     message, it must appear in this file as two consecutive
+#     single quote characters.
+# 4.  Lines beginning with "#" (like this one) are comment lines
+#     and may contain translation instructions.  They need not be
+#     translated unless your translated file, rather than this file,
+#     will serve as a base for other translators.
+
+#############################################################################
+# DO NOT TOUCH THESE PROPERTIES - THEY ARE AUTOMATICALLY UPDATED BY THE BUILD
+# PROCESS.
+axisVersion=Apache Axis2 version: #axisVersion#
+axisVersionRaw=#axisVersion#
+axisBuiltOnRaw=#today#
+axisUserAgent=Axis/#axisVersion#
+builtOn=Built on #today#
+#############################################################################
+test01=This is a test string 01

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?rev=428104&r1=428103&r2=428104&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Wed Aug  2 12:26:07 2006
@@ -27,6 +27,7 @@
 import org.apache.axis2.jaxws.description.WSDLTests;
 import org.apache.axis2.jaxws.exception.ExceptionFactoryTests;
 import org.apache.axis2.jaxws.handler.HandlerChainProcessorTests;
+import org.apache.axis2.jaxws.i18n.JaxwsMessageBundleTests;
 import org.apache.axis2.jaxws.message.BlockTests;
 import org.apache.axis2.jaxws.message.MessageTests;
 import org.apache.axis2.jaxws.message.SAAJConverterTests;
@@ -56,6 +57,7 @@
         suite.addTestSuite(WSDLDescriptionTests.class);
         
         suite.addTestSuite(HandlerChainProcessorTests.class);
+        suite.addTestSuite(JaxwsMessageBundleTests.class);
         
         suite.addTestSuite(StringProviderTests.class);
         suite.addTestSuite(SourceProviderTests.class);

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/i18n/JaxwsMessageBundleTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/i18n/JaxwsMessageBundleTests.java?rev=428104&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/i18n/JaxwsMessageBundleTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/i18n/JaxwsMessageBundleTests.java Wed Aug  2 12:26:07 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.i18n;
+
+import org.apache.axis2.jaxws.i18n.Messages;
+import junit.framework.TestCase;
+
+/**
+ * Tests basic function of the Message Bundle
+ *
+ */
+public class JaxwsMessageBundleTests extends TestCase {
+    
+    public JaxwsMessageBundleTests() { 
+        super();
+    }
+   
+    public JaxwsMessageBundleTests(String arg) {
+        super(arg);   
+    }
+    
+    /**
+     * @testStrategy: Test that the resource bundle
+     * is installed by obtaining a message
+     */
+    public void testMessages() throws Exception {
+        final String str = "This is a test string 01";
+        String tempStr = Messages.getMessage("test01");
+        // Check the String for accuracy
+        if (tempStr != null) {
+            System.out.println("tempStr is " + tempStr);
+            assertTrue(tempStr.equals(str));
+        } else {
+            System.out.println("String is NULL");
+        }
+        
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message