You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ne...@apache.org on 2001/12/07 14:48:08 UTC

cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n DefaultBundleMatcher.java BundleSelector.java BundleInfo.java

neeme       01/12/07 05:48:08

  Modified:    src/scratchpad/org/apache/avalon/excalibur/i18n
                        DefaultBundleMatcher.java BundleSelector.java
                        BundleInfo.java
  Log:
  bundle matching rewrite
  
  Revision  Changes    Path
  1.3       +14 -27    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DefaultBundleMatcher.java
  
  Index: DefaultBundleMatcher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DefaultBundleMatcher.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultBundleMatcher.java	2001/11/19 12:09:17	1.2
  +++ DefaultBundleMatcher.java	2001/12/07 13:48:08	1.3
  @@ -19,7 +19,7 @@
    * to find the relevant bundle.
    *
    * @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/11/19 12:09:17 $ $Author: donaldp $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/12/07 13:48:08 $ $Author: neeme $
    */
   public class DefaultBundleMatcher implements BundleMatcher {
   
  @@ -32,11 +32,14 @@
        * @return      the string form
        */
       public String getType(BundleInfo bundleInfo) {
  -        for (int i = 0; i < bundleInfos.size(); i++) {
  -            if (((BundleInfo) bundleInfos.get(i)).matches(bundleInfo))
  -                return this.type;
  +        if (bundleInfos != null) {
  +            for (int i = 0; i < bundleInfos.size(); i++) {
  +                if (((BundleInfo) bundleInfos.get(i)).matches(bundleInfo))
  +                    return this.type;
  +            }
  +            return null;
           }
  -        return null;
  +        return this.type;
       }
   
       /**
  @@ -49,35 +52,19 @@
           Configuration[] bundleInfos = configuration.getChildren("bundle-info");
           for (int i = 0; i < bundleInfos.length; i++) {
   
  -            Locale locale = null;
  +            BundleInfo bundleInfo = null;
               try {
  -                Configuration localeConf = bundleInfos[i].getChild("locale");
  -                locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"));
  -                locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"),
  -                                    localeConf.getAttribute("variant"));
  +                bundleInfo = (BundleInfo) Class.forName(bundleInfos[i].getAttribute("class")).newInstance();
               }
               catch (ConfigurationException e) {
                   // ignore
               }
  -
  -            String bundleName = null;
  -            try {
  -                bundleName = bundleInfos[i].getAttribute("name");
  +            catch (Exception e) {
  +                throw new ConfigurationException("unable to load bundleinfo implementation", e);
               }
  -            catch (ConfigurationException e) {
  -                // ignore
  -            }
  -
  -            String ext = null;
  -            try {
  -                ext = bundleInfos[i].getAttribute("ext");
  -            }
  -            catch (ConfigurationException e) {
  -                // ignore
  -            }
  -            BundleInfo bundleInfo = new BundleInfo(bundleName, locale, ext);
  +            if (bundleInfo == null) bundleInfo = new BundleInfo();
  +            bundleInfo.configure(bundleInfos[i]);
               this.bundleInfos.add(bundleInfo);
           }
       }
  -
   }
  
  
  
  1.6       +8 -5      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleSelector.java
  
  Index: BundleSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleSelector.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BundleSelector.java	2001/11/01 08:45:04	1.5
  +++ BundleSelector.java	2001/12/07 13:48:08	1.6
  @@ -22,14 +22,13 @@
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.avalon.framework.logger.Loggable;
  -import org.apache.avalon.framework.logger.Logger;
   
   /**
    * This is the method for getting instances of ResourceBundles.
    *
    * @author <a href="mailto:neeme@one.lv">Neeme Praks</a>
    * @author <a href="mailto:mengelhart@earthtrip.com">Mike Engelhart</a>
  - * @version $Id: BundleSelector.java,v 1.5 2001/11/01 08:45:04 neeme Exp $
  + * @version $Id: BundleSelector.java,v 1.6 2001/12/07 13:48:08 neeme Exp $
    */
   
   public class BundleSelector
  @@ -84,7 +83,7 @@
           if (defaultLoader == null) throw new ConfigurationException("default loader not specified (matchers/@default-type)");
           Configuration[] matcherConfs = configuration.getChild("matchers").getChildren("matcher");
           for (int i = 0; i < matcherConfs.length; i++) {
  -            BundleMatcher matcher = (BundleMatcher) getInstance(configuration.getAttribute("class"));
  +            BundleMatcher matcher = (BundleMatcher) getInstance(matcherConfs[i].getAttribute("class"));
               matcher.configure(matcherConfs[i]);
               this.matchers.add(matcher);
           }
  @@ -95,7 +94,7 @@
               return Class.forName(className).newInstance();
           }
           catch (Exception e) {
  -            throw new ConfigurationException("unable to load object", e);
  +            throw new ConfigurationException("unable to load object: " + className, e);
           }
       }
   
  @@ -124,7 +123,11 @@
        * @exception ComponentException if a bundle is not found
        */
       public Component select(String name, String localeName) throws ComponentException {
  -        return select(new BundleInfo(name, new Locale(localeName, localeName)));
  +        BundleInfo bi = (BundleInfo) this.manager.lookup(BundleInfo.ROLE);
  +        bi.configure(name, new Locale(localeName, localeName));
  +        Component result = select(bi);
  +        this.manager.release(bi);
  +        return result;
       }
   
       /**
  
  
  
  1.4       +61 -9     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleInfo.java
  
  Index: BundleInfo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleInfo.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BundleInfo.java	2001/11/05 23:39:36	1.3
  +++ BundleInfo.java	2001/12/07 13:48:08	1.4
  @@ -9,36 +9,76 @@
   
   import java.util.Locale;
   
  +import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.excalibur.pool.Poolable;
  +import org.apache.avalon.excalibur.pool.Recyclable;
  +
   /**
    * Used to map locale information to URI space, to find the relevant bundle.
    *
    * @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
  - * @version CVS $Revision: 1.3 $ $Date: 2001/11/05 23:39:36 $ $Author: donaldp $
  + * @version CVS $Revision: 1.4 $ $Date: 2001/12/07 13:48:08 $ $Author: neeme $
    */
  -public class BundleInfo
  +public class BundleInfo implements Component, Poolable, Recyclable
   {
  +
  +    public static final String ROLE = "org.apache.avalon.excalibur.i18n.BundleInfo";
  +
       private String name;
       private Locale locale;
       private String ext;
   
  -    public BundleInfo(String name, Locale locale, String ext)
  +    public void configure(String name, Locale locale, String ext)
       {
           this.name = name;
           this.locale = locale;
           this.ext = ext;
       }
  +
  +    public void configure(String name, Locale locale)
  +    {
  +        configure(name, locale, null);
  +    }
   
  -    public BundleInfo(String name, Locale locale) 
  +    public void configure(Locale locale)
       {
  -        this(name, locale, null);
  +        configure(null, locale);
       }
   
  -    public BundleInfo(Locale locale) 
  +    public void configure(Configuration conf)
       {
  -        this(null, locale);
  +        Locale locale = null;
  +        try {
  +            Configuration localeConf = conf.getChild("locale");
  +            locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"));
  +            locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"),
  +                                localeConf.getAttribute("variant"));
  +        }
  +        catch (ConfigurationException e) {
  +            // ignore
  +        }
  +
  +        String bundleName = null;
  +        try {
  +            bundleName = conf.getAttribute("name");
  +        }
  +        catch (ConfigurationException e) {
  +            // ignore
  +        }
  +
  +        String ext = null;
  +        try {
  +            ext = conf.getAttribute("ext");
  +        }
  +        catch (ConfigurationException e) {
  +            // ignore
  +        }
  +        configure(bundleName, locale, ext);
       }
   
  -    public String getName() 
  +    public String getName()
       {
           return this.name;
       }
  @@ -61,7 +101,11 @@
       public BundleInfo getParent() 
       {
           if (this.locale != null && !this.locale.getLanguage().equals(""))
  -            return new BundleInfo(this.name, this.getParentLocale(), this.ext);
  +        {
  +            BundleInfo bi = new BundleInfo();
  +            bi.configure(this.name, this.getParentLocale(), this.ext);
  +            return bi;
  +        }
           else
               return null;
       }
  @@ -114,4 +158,12 @@
               match(locale.getCountry(), reference.getCountry()) &&
               match(locale.getVariant(), reference.getVariant());
       }
  +
  +    public void recycle()
  +    {
  +        this.name = null;
  +        this.locale = null;
  +        this.ext = null;
  +    }
  +
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>