You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Leo Sutic <le...@inspireinfrastructure.com> on 2004/01/23 17:38:12 UTC

[RT] Auto-configuring components

All,

I think I have moaned about it a number of times, but I don't like
having to
write lots of:

    public void configure (Configuration config) 
        throws ConfigurationException {
        myField = configuration.getAttribute ("my-field");
        myOtherField = configuration.getAttributeAsInteger
("my-other-field");
        ...
    }

or:

    public MyClass (String _myField, int _myOtherField, ... ) {
        this.myField = _myField;
        this.myOtherField = _myOtherField;
        ...
    }

So I did some experimenting with commons-attributes, and ended up with
something like this:

    /**
     * @@ConfigurableField ("@my-field")
     */
    private String myField;

    /**
     * @@ConfigurableField ("@my-other-field")
     */
    private int myOtherField;

The container would then, before calling configure(), set all
ConfigurableFields
in the class. Then configure() would be called, allowing the component
to
do whatever special configuration processing required.

(Since this required changes to the container, I moved the functionality
into
an "AbstractConfigurable" class that would do the setting in the
configure() method.)

Anyway, just thought you'd like to know.

/LS


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


RE: [RT] Auto-configuring components

Posted by Leo Sutic <le...@inspireinfrastructure.com>.

> From: peter royal [mailto:proyal@apache.org] 
> 
> On Jan 23, 2004, at 11:38 AM, Leo Sutic wrote:
> > The container would then, before calling configure(), set all 
> > ConfigurableFields in the class. Then configure() would be called, 
> > allowing the component to
> > do whatever special configuration processing required.
> 
> You should see what Jason van Zyl did with Plexus ... he treats XML 
> configuration data as a serialized object and uses XStream 
> (http://xstream.codehaus.org) to de-serialize the configuration 
> directly onto the component instance. pretty neat!

That's pretty much what I want to do, except I want to decouple
the serialized form from the component implementation (field names,
etc.)
and provide defaults. (Although I suspect that defaults are provided
by XStream not overwriting fields that have no corresponding XML node.)

Also - see my "JavaBeans are even more evil than first thought" email
for
other reasons (in short - making consistency checks is difficult).

/LS


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Re: [RT] Auto-configuring components

Posted by peter royal <pr...@apache.org>.
On Jan 23, 2004, at 11:38 AM, Leo Sutic wrote:
> The container would then, before calling configure(), set all
> ConfigurableFields
> in the class. Then configure() would be called, allowing the component
> to
> do whatever special configuration processing required.

You should see what Jason van Zyl did with Plexus ... he treats XML 
configuration data as a serialized object and uses XStream 
(http://xstream.codehaus.org) to de-serialize the configuration 
directly onto the component instance. pretty neat!
-pete


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


RE: [RT] Auto-configuring components

Posted by Leo Sutic <le...@inspireinfrastructure.com>.

> From: news [mailto:news@sea.gmane.org] On Behalf Of Leo Simons
> 
> Leo Sutic wrote:
> > Anyway, just thought you'd like to know.
> 
> good read. Shame it is so completely not compatible with the way the 
> world currently works :D

Compatible enough for a WORKSFORME... But yes, language extension, 
magic, etc.

/LS


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Re: [RT] Auto-configuring components

Posted by Leo Simons <le...@apache.org>.
Leo Sutic wrote:
> Anyway, just thought you'd like to know.

good read. Shame it is so completely not compatible with the way the 
world currently works :D

- LSD



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org