Return-Path: Delivered-To: apmail-jakarta-struts-user-archive@www.apache.org Received: (qmail 34751 invoked from network); 8 Dec 2003 13:16:09 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 8 Dec 2003 13:16:09 -0000 Received: (qmail 68598 invoked by uid 500); 8 Dec 2003 13:15:49 -0000 Delivered-To: apmail-jakarta-struts-user-archive@jakarta.apache.org Received: (qmail 68567 invoked by uid 500); 8 Dec 2003 13:15:49 -0000 Mailing-List: contact struts-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list struts-user@jakarta.apache.org Received: (qmail 68553 invoked from network); 8 Dec 2003 13:15:48 -0000 Received: from unknown (HELO main.gmane.org) (80.91.224.249) by daedalus.apache.org with SMTP; 8 Dec 2003 13:15:48 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1ATLEq-0002Dr-00 for ; Mon, 08 Dec 2003 14:15:48 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: struts-user@jakarta.apache.org Received: from sea.gmane.org ([80.91.224.252]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1ATLEp-0002Dj-00 for ; Mon, 08 Dec 2003 14:15:47 +0100 Received: from news by sea.gmane.org with local (Exim 3.35 #1 (Debian)) id 1ATLEp-00088h-00 for ; Mon, 08 Dec 2003 14:15:47 +0100 From: Vic Cekvenich Subject: Re: Struts and Commons Chain Date: Mon, 08 Dec 2003 08:15:47 -0500 Lines: 92 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114 X-Accept-Language: en-us, en In-Reply-To: Sender: news X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N > 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: struts-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: struts-user-help@jakarta.apache.org