Sorry for the delayed reply.

Stephen McConnell wrote:

Antti Koivunen wrote:

<snip/>

Object logger = context.get(LOGGER);
if (logger instanceof avalon.Logger) {
m_logger = (avalon.Logger) logger;
} else if (logger instanceof commons.Log) {
m_logger = new Commons2AvalonLogger((commons.Log) logger);
}

This would of course also work the other way round, i.e. you could put an instance of VeryNiceLogger2AvalonLogger to the context of VeryNiceService. However, if VeryNiceCompany had never heard of Avalon (or IoC), and used static factories for accessing the loggers, there'd be little we could do without changing the code.


Burrrrk!
(i.e. I don;t like the approach)

:-)
(figured as much ;)

I suppose it does rather look like a hack :) And actually it would be possible to also hack around the static factory thing by using custom classloaders.


Component declares a logging strategy to the container:

<type>
<loggers>
<attributes>
<attribute key="urn:assembly:lifecycle.logging.strategy"
value="org.somwhere.MyPreferredLoggingInterface"/>
</attributes>
</loggers>
</type>

Cantainer reolves a logging handler and uses this during the logging stage of the deployment lifecycle.
Yes, this is a nice feature.


Take a look in avalon-sandbox/merlin/src/test/org/apache/avalon/playground/
You will find the file: StandardComponent.xinfo. This component is doing exactly the same thing except its declaring that it wants to use a custom context interface. If you run the merlin demo you will see it working:

$ merlin -profile config/demo.xml
I get the following error:


commencing block construction phase

[ERROR ] (sys): Message: Block installation phase failure.
===================================================================

Exception: java.lang.ClassCastException
null

===================================================================
java.lang.ClassCastException
at org.apache.excalibur.source.impl.SourceResolverImpl.service(SourceResolverImpl.java:173)
at org.apache.avalon.merlin.block.impl.DefaultBlockLoader.initialize(DefaultBlockLoader.java:280)
at org.apache.avalon.merlin.kernel.impl.DefaultKernel.initialize(DefaultKernel.java:387)
at org.apache.avalon.merlin.kernel.impl.KernelLoader.<init>(KernelLoader.java:108)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at Merlin.main(Merlin.java:284)
===================================================================

(: A ;)
--
Antti Koivunen (Mr.) <[EMAIL PROTECTED]>


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

Reply via email to