cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gree...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/framework Configurations.java
Date Fri, 10 Nov 2000 21:12:33 GMT
greenrd     00/11/10 13:12:33

  Modified:    .        changes.xml
               src/org/apache/cocoon/framework Configurations.java
  Log:
  added ability to configure superclasses and support classes independently
  
  Revision  Changes    Path
  1.144     +4 -0      xml-cocoon/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/changes.xml,v
  retrieving revision 1.143
  retrieving revision 1.144
  diff -u -r1.143 -r1.144
  --- changes.xml	2000/11/09 15:35:56	1.143
  +++ changes.xml	2000/11/10 21:12:28	1.144
  @@ -4,7 +4,7 @@
   
   <!--
     History of Cocoon changes   
  -  $Id: changes.xml,v 1.143 2000/11/09 15:35:56 greenrd Exp $ 
  +  $Id: changes.xml,v 1.144 2000/11/10 21:12:28 greenrd Exp $ 
   -->
   
   <changes title="History of Changes">
  @@ -18,6 +18,10 @@
     </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="RDG" type="add">
  +   Added ability to get tailored Configurations for superclasses
  +   and support classes.
  +  </action>
     <action dev="RDG" type="fix" due-to="Claude Warren" 
      due-to-email="claude@histio.org">
      Fixed XInclude problem with local absolute URLs.
  
  
  
  1.10      +48 -18    xml-cocoon/src/org/apache/cocoon/framework/Configurations.java
  
  Index: Configurations.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/framework/Configurations.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Configurations.java	2000/07/21 23:54:08	1.9
  +++ Configurations.java	2000/11/10 21:12:29	1.10
  @@ -1,4 +1,4 @@
  -/*-- $Id: Configurations.java,v 1.9 2000/07/21 23:54:08 stefano Exp $ --
  +/*-- $Id: Configurations.java,v 1.10 2000/11/10 21:12:29 greenrd Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -58,16 +58,18 @@
    * class to work.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.9 $ $Date: 2000/07/21 23:54:08 $
  + * @version $Revision: 1.10 $ $Date: 2000/11/10 21:12:29 $
    */
   
   public class Configurations {
   
  +    protected Configurations root;
       protected String baseName;
       protected Properties properties;
   
       public Configurations() {
           properties = new Properties();
  +        root = this;
       }
   
       /**
  @@ -89,6 +91,7 @@
           InputStream input = new FileInputStream(file);
           properties.load(input);
           input.close();
  +        root = this;
       }
   
       /**                                                                  
  @@ -108,6 +111,7 @@
               properties = new Properties();
           }
           properties.load(stream);
  +        root = this;
       }
   
       /**
  @@ -115,8 +119,29 @@
        */
       public Configurations(Configurations c) {
           properties = new Properties(c.properties);
  +        root = this;
       }
   
  +    /** 
  +     * Create a subconfiguration starting from the base node.
  +     */
  +    public Configurations(Configurations parent, String base) {
  +        root = parent.root;
  +        setBasename((parent.baseName == null) ? base : parent.baseName + "." + base);
  +        String prefix = base + ".";
  +
  +        Enumeration keys = parent.properties.propertyNames();
  +        while (keys.hasMoreElements()) {
  +            String key = (String) keys.nextElement();
  +
  +            if (key.startsWith(prefix)) {
  +                set(key.substring(prefix.length()), parent.get(key));
  +            } else if (key.equals(base)) {
  +                set("", parent.get(key));
  +            }
  +        }
  +    }
  +
       /**
        * Set the configuration.
        */
  @@ -152,7 +177,8 @@
       public Object getNotNull(String key) {
           Object o = properties.get(key);
           if (o == null) {
  -            throw new RuntimeException("Cocoon configuration item '" + ((baseName == null)
? "" : baseName + "." + key) + "' is not set");
  +            throw new RuntimeException("Cocoon configuration item '" + 
  +              ((baseName == null) ? "" : baseName + "." + key) + "' is not set");
           } else {
               return o;
           }
  @@ -177,22 +203,26 @@
        * Create a subconfiguration starting from the base node.
        */
       public Configurations getConfigurations(String base) {
  -        Configurations c = new Configurations();
  -        c.setBasename((baseName == null) ? base : baseName + "." + base);
  -        String prefix = base + ".";
  -
  -        Enumeration keys = properties.propertyNames();
  -        while (keys.hasMoreElements()) {
  -            String key = (String) keys.nextElement();
  -
  -            if (key.startsWith(prefix)) {
  -                c.set(key.substring(prefix.length()), this.get(key));
  -            } else if (key.equals(base)) {
  -                c.set("", this.get(key));
  -            }
  -        }
  +        return new Configurations(this, base);
  +    }
   
  -        return c;
  +    /**
  +     * For use by superclasses and support classes.
  +     * Gets the configuration for the
  +     * specified class from the root configurations object.
  +     *
  +     * @param c - the superclass that is to be configured.
  +     * @param x - the object that is to be configured, for validation.
  +     * @throws IllegalAccessException if this object is not allowed
  +     * to access configuration information for the given class.
  +     */
  +    public Configurations getAnyConfig (Class c, Object x) 
  +    throws IllegalAccessException {
  +      if (!c.isInstance (x)) {
  +        throw new IllegalAccessException 
  +          (x + " cannot access configuration for " + c);
  +      }
  +      return root.getConfigurations (c.getName ());
       }
   
       /**
  
  
  

Mime
View raw message