cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Green" <gree...@hotmail.com>
Subject Re: Question re: configurable Producers
Date Fri, 10 Nov 2000 21:13:56 GMT
Sunil.Kamath@razorfish.com wrote:
>I want to create a set of producers, each of which handle a different piece 
>of
>business functionality. Since these producers will need certain runtime
>parameters, they will implement the Configurable interface so that the
>ProducerFactory can init() them appropriately.
>Here is the problem:
>Since these producers are going to share some parameters, I want to create 
>an
>abstract Producer which will then be extended by the business specific
>Producers. Unfortunately, since the Configurations parameter which is 
>passed to
>the Producers on init() is based upon the Producer name, I will have to
>duplicate this parameters for each one of them.

I've just committed a simple patch to CVS to fix this problem. It isn't 
perfect (incidentally, my "day job" involves researching cleaner solutions 
to these kinds of "separations of concerns" problems) but it should work. 
Your superclass (or indeed _any_ supporting class) should call the new 
method as follows:

public abstract class BaseProducer implements Producer, Configurable {

  public void init (Configurations conf) {
    Configurations superConf = conf.getAnyConfig (BaseProducer.class,
      this);
    myBaseParam = superConf.get ("myBaseParam");
    // you can still use conf for common but varying parameters
    myVaryingParam = conf.get ("myVaryingParam");
    //...
    }
}

Then in cocoon.properties add

BaseProducer.baseParam = blah

and leave the other parameters as before.

Case is significant, and you must add the package name to the start of the 
line if you have put your classes in packages.

Is this acceptable?

>Examples:
>Abstract Class:
>public abstract class BaseProducer implements Producer, Configurable {
>      protected String myBaseParam;
>
>      public void init(Configurations conf) {
>           myBaseParam = conf.get("baseparam");
>           .....
>
>           childInit();
>      }
>
>      public abstract void childInit(Configurations conf);
>      ....
>}
>
>First Child Class:
>public class FirstProducer extends BaseProducer {
>      protected String myFirstParam;
>
>      public void childInit(Configurations conf) {
>           myFirstParam = conf.get("firstparam");
>           .....
>      }
>      ....
>}
>
>Second Child Class:
>public class SecondProducer extends BaseProducer {
>      protected String mySecondParam;
>
>      public void childInit(Configurations conf) {
>           mySecondParam = conf.get("secondparam");
>           .....
>      }
>      ....
>}
>
>cocoon.properties:
>....
>producers.type.first=FirstProducer
>producers.type.second=SecondProducer
>producers.first.baseparam="Base Param"
>producers.first.firstparam="First Param"
>producers.second.baseparam="Base Param"
>producers.second.secondparam="Second Param"
>
>
>As can be seen from the example, the baseparam property has to be specified
>twice in the properties file.
>Is there any way to avoid this duplication of effort and maintenance 
>hassle?
>---
>Thanks,
>Sunil
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: cocoon-users-help@xml.apache.org
>

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.


Mime
View raw message