Why not just declare handlers for *both* BaseException and Exception in
struts-config?

Quoting Ovidiu EFTIMIE <[EMAIL PROTECTED]>:

> I agree with you regarding the leading I ;
> I've implemented the setServlet method after sending the mail :)
> Yes you're right about GeneralImpl it must be final .
> I'm overiding execute just for BaseAction of course :), and I do it to
> catch
> exception that are not applicational
> Something like this
>     try{
> 
>         forward = executeAction(....);
>     }catch(BaseException bex){
>         log.error(bex);
>         //to be catched by the handlers declared in struts-config.xml
>         throw bex
>     }catch(Exception ex){
>         ex.printStackTrace();
>         log.fatal(e);
>     }
>     return forward;
> 
> Ovidiu
> 
> 
> ----- Original Message ----- 
> From: "Kris Schneider" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Thursday, November 20, 2003 2:13 PM
> Subject: Re: Simulating multiple inheritance for Action and DispatchAction
> 
> 
> The general approach is probably fine, although naming interfaces with a
> leading
> "I" makes me gag ;-). However, this seems like a bad idea:
> 
> public abstract class BaseAction extends Action implements IGeneral {
>   private static GeneralImpl general;
>   public BaseAction() {
>     general = new GeneralImpl(servlet);
>   }
> ...
> }
> 
> Every time an instance of BaseAction is created, the *static* field
> "general"
> gets reset. Also, where is BaseAction getting the "servlet" arg to pass to
> the
> GeneralImpl constructor? Instead, perhaps:
> 
> public abstract class BaseAction extends Action implements IGeneral {
>   private final IGeneral general;
>   public BaseAction() {
>     this.general = new GeneralImpl();
>   }
>   public void setServlet(ActionServlet servlet) {
>     super.setServlet(servlet);
>     this.general.setServlet(sevlet);
>   }
> ...
> }
> 
> Of course, that means adding a setServlet method to IGeneral and
> GeneralImpl.
> I'm also not sure why you'd override execute just to call executeAction.
> You
> certainly wouldn't want to override DispatchAction's execute method, right?
> 
> Quoting Ovidiu EFTIMIE <[EMAIL PROTECTED]>:
> 
> > Hi,
> > In my application I need to have my Actions and my DispatchActions.
> > Each one of this actions must have the same base class in which I have
> > common
> > methods to both of them.
> > My solution is to first declare an interface IGeneral in which I'm
> declaring
> > the
> > common methods, then create an implementation class,GeneralImpl.Next thind
> to
> > do
> > would be to create my base classes BaseAction and BaseDispatchAction and
> > this
> > two must implement IGeneral, and in their implementation they should
> delegate
> > to
> > a private static member of type GeneralImpl, which will handle this
> > methods.
> > Example:
> > <code>
> >     public interface IGeneral{
> >         public Connection getConnection() throws SQLException;
> >         ...........
> >         public User getUser(HttpServletRequest req);
> >     }
> > </code>
> >
> >
> > Then I'm creating the implementation for this methods:
> >
> >
> > <code>
> >     public class GeneralImpl implements IGeneral{
> >         private ActionServlet servlet;
> >         public GeneralImpl(ActionServlet srv){
> >             servlet = srv;
> >         }
> >         public Connection getConnection() throws SQLException{
> >             //code here
> >         }
> >         ...........
> >         public User getUser(HttpServletRequest req){
> >             //code here
> >         }
> >     }
> > </code>
> >
> > Now I create the base Actions
> >
> > <code>
> >     public abstract class BaseAction extends Action implements IGeneral {
> >             private static GeneralImpl general;
> >             public BaseAction (){
> >                 general = new GeneralImpl(servlet);
> >             }
> >             public ActionForward execute(ActionMapping mapping,ActionForm
> > form,HttpServletRequest request,HttpServletResponse response){
> >                 return executeAction(ActionMapping mapping,ActionForm
> > form,HttpServletRequest request,HttpServletResponse response)
> >             }
> >             public abstract executeAction(ActionMapping
> mapping,ActionForm
> > form,HttpServletRequest request,HttpServletResponse response);
> >             public Connection getConnection() throws SQLException{
> >                 return general.getConnection();
> >             }
> >             public User getUser(HttpServletRequest req){
> >                 return general.getUser(req);
> >             }
> >     }
> > </code>
> > The same for the DipatchAction.
> >
> > The question is anoybody has used something like this ? It this a good
> thing
> > to
> > do it ?
> >
> > Tanks in advance and sorry if  the text  it's too long
> > Ovidiu
> 
> -- 
> Kris Schneider <mailto:[EMAIL PROTECTED]>
> D.O.Tech       <http://www.dotech.com/>

-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to