pbwest      02/05/07 08:16:53

  Modified:    src/org/apache/fop/configuration Tag: FOP_0-20-0_Alt-Design
                        Configuration.java
  Log:
  Vector->ArrayList, Hashtable->HashMap, Enumerator->Iterator
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.6.4.1   +132 -88   xml-fop/src/org/apache/fop/configuration/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/configuration/Configuration.java,v
  retrieving revision 1.6
  retrieving revision 1.6.4.1
  diff -u -r1.6 -r1.6.4.1
  --- Configuration.java        30 Jul 2001 20:29:18 -0000      1.6
  +++ Configuration.java        7 May 2002 15:16:53 -0000       1.6.4.1
  @@ -1,5 +1,5 @@
   /*
  - * $Id: Configuration.java,v 1.6 2001/07/30 20:29:18 tore Exp $
  + * $Id: Configuration.java,v 1.6.4.1 2002/05/07 15:16:53 pbwest Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -7,16 +7,16 @@
   
   package org.apache.fop.configuration;
   
  -import java.util.Vector;
  -import java.util.Hashtable;
  -import java.util.Enumeration;
  +import java.util.ArrayList;
  +import java.util.HashMap;
  +import java.util.Iterator;
   import org.apache.fop.messaging.MessageHandler;
   
   /**
    * a configuration class for all general configuration aspects except those
  - * related to specific renderers. All configuration is stored
  - * in key / value pairs. The value can be a String, a list of Strings
  - * or a map, containing a list of key / value pairs.
  + * related to specific renderers. All configuration is stored in
  + * key.value pairs. The value can be a String, a Boolean, an Integer,
  + * or a list of Strings or a map, containing a list of key.value pairs.
    *
    */
   public class Configuration {
  @@ -31,18 +31,18 @@
       /**
        * stores the configuration information
        */
  -    private static Hashtable standardConfiguration = new Hashtable(30);
  +    private static HashMap standardConfiguration = new HashMap(30);
       ;
  -    private static Hashtable pdfConfiguration = new Hashtable(20);
  -    private static Hashtable awtConfiguration = new Hashtable(20);
  +    private static HashMap pdfConfiguration = new HashMap(20);
  +    private static HashMap awtConfiguration = new HashMap(20);
   
       /**
  -     * contains a Hashtable of existing Hashtables
  +     * contains a HashMap of existing HashMaps
        */
  -    private static Hashtable configuration = new Hashtable(3);
  +    private static HashMap configuration = new HashMap(3);
   
       /**
  -     * loads the configuration types into the configuration Hashtable
  +     * loads the configuration types into the configuration HashMap
        */
       static {
           configuration.put("standard", standardConfiguration);
  @@ -50,15 +50,15 @@
           configuration.put("awt", awtConfiguration);
       }
   
  -    public static Hashtable getConfiguration() {
  +    public static HashMap getConfiguration() {
           return configuration;
       }
   
       /**
        * general access method
        *
  -     * @param key a string containing the key value for the configuration value
  -     * role detemines the configuration target
  +     * @param key a string containing the key for the configuration value
  +     * role determines the configuration target
        * @return Object containing the value; normally you would use one of the
        * convenience methods, which return the correct form.
        * null   if the key is not defined.
  @@ -76,12 +76,11 @@
           }
       }
   
  -    ;
   
       /**
        * convenience methods to access strings values in the configuration
  -     * @param key a string containing the key value for the configuration value
  -     * role detemines the configuration target
  +     * @param key a string containing the key for the configuration value
  +     * role determines the configuration target
        * @return String a string containing the value
        * null   if the key is not defined.
        */
  @@ -94,12 +93,11 @@
           }
       }
   
  -    ;
   
       /**
        * convenience methods to access int values in the configuration
  -     * @param key a string containing the key value for the configuration value
  -     * role detemines the configuration target
  +     * @param key a string containing the key for the configuration value
  +     * role determines the configuration target
        * @return int a int containing the value
        * -1   if the key is not defined.
        */
  @@ -107,17 +105,18 @@
           Object obj = Configuration.getValue(key, role);
           if (obj instanceof String) {
               return Integer.parseInt((String)obj);
  +        } else if (obj instanceof Integer) {
  +            return ((Integer)obj).intValue();
           } else {
               return -1;
           }
       }
   
  -    ;
   
       /**
        * convenience methods to access boolean values in the configuration
  -     * @param key a string containing the key value for the configuration value
  -     * role detemines the configuration target
  +     * @param key a string containing the key for the configuration value
  +     * role determines the configuration target
        * @return Boolean true or false as value
        * null   if the key is not defined.
        */
  @@ -132,50 +131,69 @@
           }
       }
   
  -    ;
   
       /**
        * convenience methods to access list values in the configuration
  -     * @param key a string containing the key value for the configuration value
  -     * role detemines the configuration target
  -     * @return Vector a Vector containing the values
  +     * @param key a string containing the key for the configuration value
  +     * role determines the configuration target
  +     * @return ArrayList a ArrayList containing the values
        * null   if the key is not defined.
        */
  -    public static Vector getListValue(String key, int role) {
  +    public static ArrayList getListValue(String key, int role) {
           Object obj = Configuration.getValue(key, role);
  -        if (obj instanceof Vector) {
  -            return (Vector)obj;
  +        if (obj instanceof ArrayList) {
  +            return (ArrayList)obj;
           } else {
               return null;
           }
       }
   
  -    ;
   
       /**
        * convenience methods to access map/hashtable values in the configuration
  -     * @param key a string containing the key value for the configuration value
  -     * role detemines the configuration target
  -     * @return Hashtable a Hashtable containing the values
  +     * @param key a string containing the key for the configuration value
  +     * role determines the configuration target
  +     * @return HashMap a HashMap containing the values
        * null   if the key is not defined.
        */
  -    public static Hashtable getHashtableValue(String key, int role) {
  +    public static HashMap getHashMapValue(String key, int role) {
           Object obj = Configuration.getValue(key, role);
  -        if (obj instanceof Hashtable) {
  -            return (Hashtable)obj;
  +        if (obj instanceof HashMap) {
  +            return (HashMap)obj;
           } else {
               return null;
           }
       }
   
  -    ;
  +
  +    /**
  +     * Convenience method to access values in HashMap entries in the
  +     * configuration.
  +     * @param map a string containing the key for the configuration value.
  +     * <i>N.B.</i> this is the key of the <tt>HashMap</tt> itself.
  +     * @param key an object containing the key for an entry in the
  +     * <tt>HashMap</tt> indexed by <i>map</i>.
  +     * @param role determines the configuration target
  +     * @return an <tt>Object</tt> containing the value associated with
  +     * <i>key</i>, or <tt>null</tt>
  +     * if the map is not defined, the <i>key</i>entry is not defined,
  +     * or the <i>key</i>entry is itself <tt>null</tt>.
  +     */
  +    public static Object getHashMapEntry(String map, Object key, int role) {
  +        Object obj = getValue(map, role);
  +        if (obj instanceof HashMap) {
  +            return ((HashMap)obj).get(key);
  +        } else {
  +            return null;
  +        }
  +    }
   
   
       /**
        * convenience method which retrieves some configuration information
        * from the standard configuration
        *
  -     * @param key a string containing the key value for the configuration value
  +     * @param key a string containing the key for the configuration value
        * @return Object containing the value; normally you would use one of the
        * convenience methods, which return the correct form.
        * null   if the key is not defined.
  @@ -185,9 +203,10 @@
       }
   
       /**
  -     * convenience methods to access strings values in the standard configuration
  +     * convenience methods to access strings values in the standard
  +     * configuration
        *
  -     * @param key a string containing the key value for the configuration value
  +     * @param key a string containing the key for the configuration value
        * @return String a string containing the value
        * null   if the key is not defined.
        */
  @@ -198,7 +217,7 @@
       /**
        * convenience methods to access int values in the standard configuration
        *
  -     * @param key a string containing the key value for the configuration value
  +     * @param key a string containing the key for the configuration value
        * @return int a int containing the value
        * -1   if the key is not defined.
        */
  @@ -209,7 +228,7 @@
       /**
        * convenience methods to access boolean values in the configuration
        *
  -     * @param key a string containing the key value for the configuration value
  +     * @param key a string containing the key for the configuration value
        * @return boolean true or false as value
        * null   if the key is not defined.
        */
  @@ -220,35 +239,53 @@
       /**
        * convenience methods to access list values in the standard configuration
        *
  -     * @param key a string containing the key value for the configuration value
  -     * @return Vector a Vector containing the values
  +     * @param key a string containing the key for the configuration value
  +     * @return ArrayList a ArrayList containing the values
        * null   if the key is not defined.
        */
  -    public static Vector getListValue(String key) {
  +    public static ArrayList getListValue(String key) {
           return Configuration.getListValue(key, Configuration.STANDARD);
       }
   
       /**
  -     * convenience methods to access map/hashtable values in the standard 
configuration
  +     * convenience methods to access map/hashtable values in the standard
  +     * configuration
        *
  -     * @param key a string containing the key value for the configuration value
  -     * @return Hashtable a Hashtable containing the values
  +     * @param key a string containing the key for the configuration value
  +     * @return HashMap a HashMap containing the values
        * null   if the key is not defined.
        */
  -    public static Hashtable getHashtableValue(String key) {
  -        return Configuration.getHashtableValue(key, Configuration.STANDARD);
  +    public static HashMap getHashMapValue(String key) {
  +        return Configuration.getHashMapValue(key, Configuration.STANDARD);
  +    }
  +
  +
  +    /**
  +     * Convenience method to access values in HashMap entries in the
  +     * standard configuration.
  +     * @param map a string containing the key for the configuration value.
  +     * <i>N.B.</i> this is the key of the <tt>HashMap</tt> itself.
  +     * @param key an object containing the key for an entry in the
  +     * <tt>HashMap</tt> indexed by <i>map</i>.
  +     * @return an <tt>Object</tt> containing the value associated with
  +     * <i>key</i>, or <tt>null</tt>
  +     * if the map is not defined, the <i>key</i>entry is not defined,
  +     * or the <i>key</i>entry is itself <tt>null</tt>.
  +     */
  +    public static Object getHashMapEntry(String map, Object key) {
  +        return Configuration.getHashMapEntry(map, key, STANDARD);
       }
   
   
       /**
        * method to access fonts values in the standard configuration
        *
  -     * @param key a string containing the key value for the configuration value
  -     * @return Hashtable a Hashtable containing the values
  +     * @param key a string containing the key for the configuration value
  +     * @return HashMap a HashMap containing the values
        * null   if the key is not defined.
        */
  -    public static Vector getFonts() {
  -        return (Vector)Configuration.getValue("fonts",
  +    public static ArrayList getFonts() {
  +        return (ArrayList)Configuration.getValue("fonts",
                                                 Configuration.STANDARD);
       }
   
  @@ -256,7 +293,7 @@
        * initializes this configuration
        * @param config contains the configuration information
        */
  -    public static void setup(int role, Hashtable config) {
  +    public static void setup(int role, HashMap config) {
           switch (role) {
           case Configuration.STANDARD:
               standardConfiguration = config;
  @@ -268,16 +305,19 @@
               awtConfiguration = config;
               break;
           default:
  -            MessageHandler.errorln("Can't setup configuration. Unknown 
configuration role/target");
  +            MessageHandler.errorln(
  +            "Can't setup configuration. Unknown configuration role/target"
  +            );
           }
       }
   
       /**
        * adds information to the configuration map/hashtable in key,value form
  -     * @param key a string containing the key value for the configuration value
  +     * @param key a string containing the key for the configuration value
        * value the configuration information
  -     * role detemines the configuration target
  -     * @param value an Object containing the value; can be a String, a Vector or a 
Hashtable
  +     * role determines the configuration target
  +     * @param value an Object containing the value;
  +     * can be a String, a Boolean, and Integer, an ArrayList or a HashMap
        */
       public static void put(String key, Object value, int role) {
           switch (role) {
  @@ -292,20 +332,20 @@
               break;
           default:
               standardConfiguration.put(key, value);
  -            MessageHandler.errorln("Unknown role for new configuration entry. "
  -                                   + "Putting key:" + key + " - value:"
  +            MessageHandler.errorln("Unknown role for new configuration entry."
  +                                   + " Putting key:" + key + " - value:"
                                      + value + " into standard configuration.");
           }
       }
   
  -    ;
   
       /**
  -     * adds information to the standard configuration map/hashtable in key,value 
form
  -     * @param key a string containing the key value for the configuration value
  +     * adds information to the standard configuration hashmap in key.value form
  +     * @param key a string containing the key for the configuration value
        * value the configuration information
  -     * role detemines the configuration target
  -     * @param value an Object containing the value; can be a String, a Vector or a 
Hashtable
  +     * role determines the configuration target
  +     * @param value an Object containing the value;
  +     * can be a String, a Boolean, an Integer, an ArrayList or a HashMap
        */
   
       public static void put(String key, Object value) {
  @@ -318,38 +358,44 @@
       public static void dumpConfiguration() {
           String key;
           Object value;
  -        Vector list;
  -        Hashtable map, configuration;
  -        Enumeration enum;
  +        ArrayList list;
  +        HashMap map, configuration;
  +        Iterator iterator;
           String tmp;
           System.out.println("Dumping configuration: ");
  -        Hashtable[] configs = {
  +        HashMap[] configs = {
               standardConfiguration, pdfConfiguration, awtConfiguration
           };
           for (int i = 0; i < configs.length; i++) {
               MessageHandler.logln("----------------------");
               configuration = configs[i];
  -            Enumeration enumeration = configuration.keys();
  -            while (enumeration.hasMoreElements()) {
  -                key = (String)enumeration.nextElement();
  +            Iterator iter = configuration.keySet().iterator();
  +            while (iter.hasNext()) {
  +                key = (String)iter.next();
                   MessageHandler.logln("key: " + key);
                   value = configuration.get(key);
                   if (value instanceof String) {
                       MessageHandler.logln("   value: " + value);
  -                } else if (value instanceof Vector) {
  -                    list = (Vector)value;
  -                    enum = list.elements();
  +                } else if (value instanceof Boolean) {
  +                    MessageHandler.logln
  +                            ("   value: " + ((Boolean)value).booleanValue());
  +                } else if (value instanceof Integer) {
  +                    MessageHandler.logln
  +                                ("   value: " + ((Integer)value).intValue());
  +                } else if (value instanceof ArrayList) {
  +                    list = (ArrayList)value;
  +                    iterator = list.iterator();
                       MessageHandler.log("   values: ");
  -                    while (enum.hasMoreElements()) {
  -                        MessageHandler.log(enum.nextElement() + " - ");
  +                    while (iterator.hasNext()) {
  +                        MessageHandler.log(iterator.next() + " - ");
                       }
                       MessageHandler.logln("");
  -                } else if (value instanceof Hashtable) {
  -                    map = (Hashtable)value;
  -                    enum = map.keys();
  +                } else if (value instanceof HashMap) {
  +                    map = (HashMap)value;
  +                    iterator = map.keySet().iterator();
                       MessageHandler.log("   values: ");
  -                    while (enum.hasMoreElements()) {
  -                        tmp = (String)enum.nextElement();
  +                    while (iterator.hasNext()) {
  +                        tmp = (String)iterator.next();
                           MessageHandler.log(" " + tmp + ":" + map.get(tmp));
                       }
                       MessageHandler.logln("");
  @@ -357,8 +403,6 @@
               }
           }
       }
  -
  -
   
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to