RSS feed still buggy?
My generator seems still to be buggy because the items are listed twice on javablogs.com. Sorry!
What's coming in JDK 1.4.2?
Read this article and you will know =)
How I have added IoC to Struts Actions
One of the cool features of WebWork2 is the use of the IoC (Inversion of Control) design pattern. I asked myself wether it would be possible to add IoC to Struts Actions as well and after some meditation I have ended up with a solution which I want to discuss now. The class who is responsible for creating Action instances is RequestProcessor or TilesRequestProcessor if you are using Tiles. If you look at RequestProcessor you will notice the method processActionCreate. As the name suggests this method is responsible for creating the Action instances. Therefore I decided to derive from TilesRequestProcessor and overwrite processActionCreate. Inside the method I use reflection in order to find out wether the action returned by super.processActionCreate(...) implements on of the registered awareable interfaces. In case the action does I call the setter method declared in the interface. The registered awareable interfaces are maintained by a class called ComponentRegistry. This class is designed as a singleton. At last I wrote a Struts plugin that performs the initial registration of the awareable interfaces and their corresponding object instances.
Here's a code snippet from my custom RequestProcessor:
[code]
protected Action processActionCreate(HttpServletRequest request, HttpServletResponse response,
ActionMapping mapping)
throws IOException
{
Action action = super.processActionCreate(request, response, mapping);
// Look for Awareable classes (IoC) and invoke the setters if present ComponentRegistry registry = ComponentRegistry.getSharedInstance(); Set classes = registry.getRegisteredClasses(); Iterator it = classes.iterator(); while (it.hasNext()) { Class awareableIf = (Class)it.next(); if (awareableIf.isAssignableFrom(action.getClass())) { Object instance = registry.findComponent(awareableIf); log.debug("instance for interface [" + awareableIf + "]: " + instance); if (instance != null) { Method[] methods = awareableIf.getMethods(); if (methods.length != 1) throw new IOException("The awareable interface must exactly contain one method"); try { log.debug("Invoking method: " + methods[0]); methods[0].invoke(action, new Object[]{instance}); } catch(Exception ex) { log.error("Could not invoke setter on awareable interface", ex); throw new IOException("Could not invoke setter on awareable interface"); } } } } return action } [/code]
As you can see currently the setter of the awareable interface will be called on every request because the action caching is handled inside super.processActionCreate(...) and there's no way to find out if an action was created or reused as far as I know. Therefore you might want to cache the name of the classes whose setter you called.
Now that I have IoC I am looking into Interceptors :-) ...
Minor JavaScript bug fixed
The comment link was broken on Mozilla. Thanks to JavaScript guru pulsar this nasty bug was easy to fix.
Thoughts about caching with Struts Actions, Tiles and JSP
Talking to the database on each request is not necessary because the content of my weblog does not change very often (for now =) ). So I like the idea of using a cache. Whenever I add a new entry I could send a notification to the cache and the cache would be flushed. So far so good. The tricky thing now is that I am using Tiles and putting a cache taglib into the tile would have no effect because the correspondig Action, which talks to the database, would still get called. Therefore I need a cache logic before the Action gets called. Currently I think the best solution would be to write a special filter. The filter would cache a defined URL, e.g. http://woeye.highteq.net/weblog/show.do?author=woeye and flush the cache on special events. Perhaps I should take a look at OSCache from OpenSymphony?
Any ideas or suggestions?