You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by rs...@apache.org on 2002/09/20 22:12:26 UTC

cvs commit: xml-axis/java/src/org/apache/axis/i18n ProjectResourceBundle.java

rsitze      2002/09/20 13:12:25

  Modified:    java/src/org/apache/axis/i18n ProjectResourceBundle.java
  Log:
  - fixed handleGetObject, correctly returns null if key not found
  - fixed getKeys(), returns keys + parent keys
  
  Revision  Changes    Path
  1.3       +53 -7     xml-axis/java/src/org/apache/axis/i18n/ProjectResourceBundle.java
  
  Index: ProjectResourceBundle.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/i18n/ProjectResourceBundle.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProjectResourceBundle.java	20 Sep 2002 16:35:36 -0000	1.2
  +++ ProjectResourceBundle.java	20 Sep 2002 20:12:25 -0000	1.3
  @@ -56,7 +56,9 @@
   package org.apache.axis.i18n;
   
   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;
  @@ -105,11 +107,44 @@
       protected Object handleGetObject(String key)
           throws MissingResourceException
       {
  -        return resourceBundle.getObject(key);
  +        if (log.isDebugEnabled()) {
  +            log.debug(this.toString() + "::handleGetObject(" + key + ")");
  +        }
  +//            return resourceBundle.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() {
  -        return resourceBundle.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(); }
  +                };
  +        }
       }
       
   
  @@ -265,10 +300,10 @@
           throws MissingResourceException
       {
           if (log.isDebugEnabled()) {
  -            log.debug("ProjectResourceBundle::getBundle(" + projectName + ","
  -                                                          + packageName + ","
  -                                                          + resourceName + ","
  -                                                          + String.valueOf(locale) + ",...)");
  +            log.debug("getBundle(" + projectName + ","
  +                                   + packageName + ","
  +                                   + resourceName + ","
  +                                   + String.valueOf(locale) + ",...)");
           }
           
           Context context = new Context();
  @@ -318,6 +353,9 @@
               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) {
  @@ -325,6 +363,9 @@
                       } else {
                           prb = new ProjectResourceBundle(name, parent);
                       }
  +                    if (log.isDebugEnabled()) {
  +                        log.debug("Root package not found, cross link to " + parent);
  +                    }
                   }
               }
   
  @@ -362,6 +403,10 @@
       {
           bundleCache.clear();
       }
  +    
  +    public String toString() {
  +        return resourceName;
  +    }
   
   
       private static class Context {
  @@ -408,7 +453,8 @@
                                                   _locale,
                                                   _loader);
               } catch (MissingResourceException e) {
  -                log.debug("loadBundle: Ignoring MissingResourceException", e);
  +                // Deliberately surpressing print stack.. just the string for info.
  +                log.debug("loadBundle: Ignoring MissingResourceException: " + e.getMessage());
               }
               return null;
           }