beehive-user@incubator.apache.org
[Top] [All Lists]

Re: question about inheritance

Subject: Re: question about inheritance
From: Adam Jenkins
Date: Sat, 21 May 2005 05:18:08 +1000
<explitative> awesome!

Wow, talk about spoilt for choice! :)  Each of those answers not only
help, but that's fantastic information to know for other uses.

A big well done to all the people that worked on this.  My entire team
(all fairly senior developers) are continually blown away by not just
the things that beehive does, but that lateral thinking that went into
it's creation.

It's good to see programming of this calibre.  Very inspiring to others
in the field.  Cheers for all the hard work and such a quick response to
my questions.

Thanks again
Adam

On Fri, 2005-05-20 at 13:10 -0600, Richard Feit wrote:
> Hi Adam,
> 
> These are great questions.  A few responses; hopefully one or more will 
> help you.
> 
>     - You can override beforeAction()/afterAction() on either the base 
> class or the derived class.  This is a brute-force way to run code 
> before/after every action.  In the beforeAction method, you could even 
> write code to read the action method's annotations through reflection, 
> and look for a custom annotation that you wrote to determine whether to 
> do the check and throw an exception if necessary.
> 
>     - We do have the idea of "action interceptors".  An action 
> interceptor is a class that can be configured to run before/after a 
> particular action, or all actions, or all actions in a particular page 
> flow.  It can do things like change/cancel the destination URI, throw an 
> exception, or "inject" an entire nested page flow to run before the 
> action.  These are registered in WEB-INF/beehive-netui-config.xml.  
> There's a bit of doc on this at 
> http://incubator.apache.org/beehive/pageflow/config/beehive-netui-config.html#pageflow-action-interceptors
>  
> .  But what you *really* want is a "named" action interceptor that you 
> can refer to in an annotation.  Short of that, you could write an 
> interceptor that would use the reflection/annotation-based approach I 
> mentioned above.  But read on...
> 
>     - In this specific case our annotations can help you do what you 
> want.  If you set the 'loginRequired' attribute on an action (or on the 
> page flow class, in @Jpf.Controller, which can be overridden on a 
> per-action basis), then a NotLoggedInException will be thrown if you hit 
> the action without being logged in.  By default, "being logged in" means 
> that getUserPrincipal() returns a non-null value on the request; 
> however, you can plug in your own login behavior.  To do this, you'd 
> implement org.apache.beehive.netui.pageflow.handler.LoginHandler, and 
> register your class under <login-handler> in 
> WEB-INF/beehive-netui-config.xml. 
> 
> Hope this helps -- let me know if you need more info on any of this.
> 
> Rich
> 
> Adam Jenkins wrote:
> 
> >Hi Rich,
> >
> >Thanks for the quick response.  That's excellent info, it answers about
> >3/4 of what I was after.  I have one more small question about executing
> >the assertion.
> >
> >Lets say I have a controller (and my syntax could be wrong here, I'm
> >still getting my head around beehive, but I think it get's what I'm
> >trying to achieve accross):
> >
> >@Jpf.Controller(
> >     simpleActions={
> >             @Jpf.Forward(name="not_authenticated" path="login.do")
> >     }       
> >     catches={
> >             @Jpf.Catch(type=UserNotLoggedInException.class 
> > method="forceLogin")
> >     }
> >)
> >public clas Base extends PageFlowController{
> >
> >     private void assertUserLoggedIn(...) throws UserNotLoggedInException{
> >             //do some stuff to make sure the user is validated.
> >     }
> >
> >     public Forward forceLogin(...){
> >             return new Forward("not_authenticated");
> >     }
> >}
> >
> >Now, I want to call assertUserLoggedIn before any action is executed and
> >I want it on almost every action in the system (except of course the
> >'login' action).  I would normally do this in a superclass of all the
> >struts actions I used.  That is, I would call assertUserLoggedIn in the
> >super class struts action and, if the exception was thrown it would be
> >handled by the global exception handling.  If no exception was thrown, I
> >would then call an abstract method that is implemented in the subclass
> >that actually does the processing and returns the forward.  That was my
> >way of enforcing that the first thing every action did was check and
> >make sure that the user was in fact logged in.  So, in a nut shell, is
> >there a way to call a common assertion or set of assertions (or set of
> >methods for that matter) from a whole set of actions without actually
> >specifying the assertions at the start of every action (think
> >crosscutting).  How would you recommend achieving something like that in
> >beehive?
> >
> >Cheers
> >Adam
> >
> >On Thu, 2005-05-19 at 17:14 -0600, Richard Feit wrote:
> >  
> >
> >>Hi Adam,
> >>
> >>Beehive does support inheritance in page flows (and in controls, for 
> >>that matter).  The important point for page flows is that the base and 
> >>derived @Jpf.Controller annotations are merged.   So if you have the 
> >>following hierarchy:
> >>
> >>    @Jpf.Controller(
> >>        nested=true,
> >>        catches={
> >>            @Jpf.Catch(type=Exception1.class, method="handleException1")
> >>        }
> >>    )
> >>    public class Base extends PageFlowController ...
> >>
> >>
> >>    @Jpf.Controller(
> >>        catches={
> >>            @Jpf.Catch(type=Exception2.class, method="handleException2")
> >>        }
> >>    )
> >>    public class Derived1 extends Base ...
> >>
> >>
> >>    @Jpf.Controller(
> >>        catches={
> >>            @Jpf.Catch(type=Exception3.class, method="handleException3")
> >>        }
> >>    )
> >>    public class Derived2 extends Derived1 ...
> >>
> >>...then the @Jpf.Controller annotation for Derived2 is virtually this:
> >>
> >>    @Jpf.Controller(
> >>        nested=true,
> >>        catches={
> >>            @Jpf.Catch(type=Exception1.class, method="handleException1")
> >>            @Jpf.Catch(type=Exception2.class, method="handleException2")
> >>            @Jpf.Catch(type=Exception3.class, method="handleException3")
> >>        }
> >>    )
> >>
> >>Additionally, action methods, exception handler methods, and annotated 
> >>control fields are all inherited as long as they're not private.
> >>
> >>Does this answer your question?
> >>
> >>Rich
> >>
> >>Adam Jenkins wrote:
> >>
> >>    
> >>
> >>>Hi All,
> >>>
> >>>I'm starting out with beehive and wondering about inheritance.  With
> >>>struts apps, I would put security assertions in a super class of all
> >>>actions and redirect any exceptions thrown to the appropriate page.  Is
> >>>there a way to do similar in beehive or do you have to use shared flows
> >>>for common stuff like that.
> >>>
> >>>Cheers
> >>>Adam
> >>>
> >>>
> >>>
> >>>
> >>> 
> >>>
> >>>      
> >>>
> >
> >
> >  
> >

<Prev in Thread] Current Thread [Next in Thread>