The Intercepting filter concept is what JBoss uses I think with their interceptor stack with both pre and post processing.You can change the order in which the Interceptors are processed by changing it in the jboss.xml file.Since these interceptors are stateless, the values are stored in thread context.They use the Interceptor interface.
Vijay -----Original Message----- From: news [mailto:[EMAIL PROTECTED] Behalf Of Vic Cekvenich Sent: Monday, December 08, 2003 5:16 AM To: [EMAIL PROTECTED] Subject: Re: Struts and Commons Chain > This is very interesting I think. > .V > > Hookom, Jacob wrote: > >> I was looking at chain's implementation, instead of executing the >> commands >> with the visitor pattern, wouldn't a more powerful/flexible method be to >> implement it using a filter pattern? >> >> See: >> http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter. >> >> html >> >> >> Sample Chain: >> CommandServletStart >> CommandExceptionHandler >> CommandStoreState >> CommandExceptionThrower >> >> -- >> >> CommandStart.execute(Context ctx, Chain chain) throws Exception >> { >> ServletContext srvCtx = (ServletContext) ctx; >> String usrId = srvCtx.getRequestScope().getParameter("id")); >> String newName = srvCtx.getRequestScope().getParameter("name")); >> >> // get user and save state >> User user = SomeService.getUser(usrId); >> String oldName = user.getName(); >> >> // set new state and execute >> try >> { >> user.setName(newName); >> ctx.setAttribute("user", user); >> chain.executeNext(ctx); >> } >> catch (Exception e) >> { >> // on error, rollback change >> user.setName(oldName); >> throw e; >> } >> } >> >> -- >> >> CommandExceptionHandler.execute(Context ctx, Chain chain) throws >> Exception >> { >> try >> { >> chain.executeNext(ctx); >> } >> catch (SQLException e) >> { >> chain.executeNext(ctx); >> } >> // let unhandled exceptions go up >> } >> >> CommandExceptionThrower.execute(Context ctx, Chain chain) throws >> Exception >> { >> throw new SQLException(); >> } >> >> With this, you would not have to change your inheritance to add behavior >> (going from a command to a filter). The given command would already know >> best on how to handle itself and since it calls the next item in the >> chain, >> we can also wrap the context to take care of situations where we want to >> have listener type behavior. >> >> The chain could also allow for runtime manipulation by the commands, to >> insert additional commands to handle errors. >> >> chain.insert("SomeCommand").insert("AnotherCommand).executeNext(ctx); >> >> -------- >> Jacob Hookom >> Senior Programmer/Analyst >> McKesson Medical-Surgical >> Golden Valley, MN > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

