cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reinhard Poetz <reinh...@apache.org>
Subject Re: ApplesProcessor - a little crazy idea
Date Thu, 13 Oct 2005 16:17:50 GMT
Leszek Gawron wrote:
> I'd like to:
> 
> 1. make ApplesProcessor.instantiateController protected
> 
> 2. introduce SpringAwareApplesProcessor that would not create an apples 
> controller like the current one:
> 
> private AppleController instantiateController(String className)
>     throws Exception {
>     Class clazz = Thread.currentThread()
>         .getContextClassLoader().loadClass(className);
>     Object o = clazz.newInstance();
>     return (AppleController) o;
> }
> 
> but like this:
> 
> private AppleController instantiateController( String beanName )
>     throws Exception {
>     Object o = getSpringContext().getBean( beanName );
>     if ( !( o instanceof AppleController ) )
>        throw new SomeException( "cannot fetch an apple controller "
>                                 + "by name: " + beanName );
> }
> 
> Most of my apples look like this:
> public class RouteDefinitionsApple extends AbstractSpringApple {
>     public void process( AppleRequest request, AppleResponse response ){
>         ApplicationContext springContext = fetchContextFromSomewhere();
>         FooService foo = (FooService) springContext.
>                                              getBean( "fooService" );
>         String bar = foo.bar();
>         response.sendPage( "view/foo.jx", bar );
>     }
> 
> My change would allow to have automatic spring dependencies injected 
> because the apple itself would be spring managed.
> 
> We could make instantiateController either with bean name or bean class.
> 
> WDYT? If you don't like it I will do 2). only in my codebase.

I like it. I'm one of the Apples users Sylvain mentioned in his mail. I've also 
prototyped nearly the same code as you did :-)
Do you use the spring block or does getSpringContext() refer to a "usual" spring 
context? I'd prefer using the Spring block as the integration is _much_ more 
advanced, thanks to Carsten.

So please check in and then we can work on it.

(NB I hope that I can soon drop Apples in favor of JavaFlow as using a state 
machine is a PITA. The missing part is serialization support for Javaflow. It is 
itself already serializeable as Torsten showed me in Amsterdam, but needs some 
integration work in Cocoon to make use of it.)

-- 
Reinhard Pötz           Independent Consultant, Trainer & (IT)-Coach 

{Software Engineering, Open Source, Web Applications, Apache Cocoon}

                                        web(log): http://www.poetz.cc
----------------------------------------------
----------------------


Mime
View raw message