cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <lgaw...@mobilebox.pl>
Subject ApplesProcessor - a little crazy idea
Date Thu, 13 Oct 2005 15:22:51 GMT
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.


-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Mime
View raw message