Re: [loom] [dna] Properties in component configurations

Jason van Zyl <[email protected]>
Newsgroups gmane.comp.java.jcontainer.interest
Message-ID <[email protected]>
On Fri, 2003-11-14 at 01:37, Peter Donald wrote:
> On Fri, 14 Nov 2003 12:34 pm, Ryan Hoegg wrote:
> > Wanted to get your thoughts on using properties in component
> > configuration like in maven / jelly.
> >
> > My first thought is that it should be done transparently by the
> > container, but I don't know if that should somehow be mentioned in DNA.
> > Thoughts?
> 
> I definetly prefer this way. If I understand you correctly what you want to be 
> able to do is something like variable interpolation in configuration ala
> 
> <foo>
>   <dir>${loom.home}</dir>
> </foo>
> 
> If you look in the CLIMain class in Loom you will see that we actually do this 
> for kernel.xml. 
> 
> final Properties params = new Properties();
> params.setProperty( "loom.home", home.getAbsolutePath() );
> final Configuration root = ConfigUtil.expandValues( original, params );
> 
> So loom.home will be expanded in config xml. You could easily expand this to 
> work with all components aswell. Maybe expand a set of default properties + 
> any defined in SAR-INF/config.properties or something.
> 
> Alternatively you could use Jexl (http://jakarta.apache.org/commons/jexl) to 
> expand properties (which is what maven uses). Jexl is good in that you get to 
> do manipulation on objects (string caternating or cutting etc) and can invoke 
> methods etc on values.
> 
> The final method would be to treat the whole config.xml as a jelly script and 
> process it. 
> 
> The ConfigUtil post-processes the configuration after parsing but a far better 
> approach would be to write an XMLFilterImpl that expands the variables it 
> finds etc.

I guess I completely missed the boat on that one. I thought you were
talking about directly configuring components ... Wasn't paying
attention.

At any rate now that I actually know what you're talking about here's a
little Reader that does the trick:

http://cvs.codehaus.org/viewcvs.cgi/plexus/plexus-utils/src/java/org/codehaus/plexus/util/InterpolationFilterReader.java?rev=1.1&root=codehaus&view=auto

Just provide a Map of values, a Reader and begin/end token markers and
the values in the Map will be interpolated into the stream. In plexus I
use a an map adapter for the context and interpolate every configuration
that's processed.

-- 
jvz.

Jason van Zyl
[email protected]
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
  
  -- Jacques Ellul, The Technological Society
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.