You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/04/18 01:31:37 UTC
svn commit: r394809 -
/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java
Author: ekoneil
Date: Mon Apr 17 16:31:36 2006
New Revision: 394809
URL: http://svn.apache.org/viewcvs?rev=394809&view=rev
Log:
Code cleanup in FlowControllerFactory. Adding some comments, moved @deprecated methods to the bottom, and put protected/package protected/private methods below that.
Rich, if any of this is greatly troubling, don't hesitate to call me on it. ;)
BB: self
Test: NetUI pass
Modified:
beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java
Modified: beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java?rev=394809&r1=394808&r2=394809&view=diff
==============================================================================
--- beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java (original)
+++ beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowControllerFactory.java Mon Apr 17 16:31:36 2006
@@ -76,7 +76,9 @@
factory = ( FlowControllerFactory ) FactoryUtils.getFactory( servletContext, fcFactoryBean, FlowControllerFactory.class );
}
- if ( factory == null ) factory = new FlowControllerFactory();
+ if ( factory == null )
+ factory = new FlowControllerFactory();
+
factory.reinit( servletContext );
servletContext.setAttribute( CONTEXT_ATTR, factory );
@@ -90,14 +92,15 @@
protected void reinit( ServletContext servletContext )
{
super.reinit( servletContext );
- if ( _rch == null ) _rch = Handlers.get( servletContext ).getReloadableClassHandler();
+ if ( _rch == null )
+ _rch = Handlers.get( servletContext ).getReloadableClassHandler();
}
/**
- * Get a FlowControllerFactory.
+ * Get a {@link FlowControllerFactory}. The instance returned may or may not have been cached.
*
- * @param servletContext the current ServletContext.
- * @return a FlowControllerFactory for the given ServletContext. It may or may not be a cached instance.
+ * @param servletContext the current {@link ServletContext}.
+ * @return a {@link FlowControllerFactory} for the given {@link ServletContext}.
*/
public static FlowControllerFactory get( ServletContext servletContext )
{
@@ -143,7 +146,8 @@
//
// Reinitialize transient data that may have been lost on session failover.
//
- if ( cur != null ) cur.reinitialize( request, response, getServletContext() );
+ if ( cur != null )
+ cur.reinitialize( request, response, getServletContext() );
//
// If there's no current PageFlow, or if the current PageFlowController has a module path that
@@ -151,14 +155,17 @@
//
if ( cur == null || ! PageFlowUtils.getModulePathForRelativeURI( cur.getURI() ).equals( parentDir ) )
{
+ String className = null;
try
{
- String className = InternalUtils.getFlowControllerClassName( parentDir, request, getServletContext() );
+ className = InternalUtils.getFlowControllerClassName( parentDir, request, getServletContext() );
return className != null ? createPageFlow( context, className ) : null;
}
catch ( ClassNotFoundException e )
{
- if ( LOG.isInfoEnabled() ) LOG.info( "No page flow exists for path " + path );
+ if ( LOG.isInfoEnabled() )
+ LOG.info("No page flow exists for path " + path +
+ ". Unable to load class \"" + className + "\". Cause: " + e, e);
return null;
}
}
@@ -167,9 +174,9 @@
}
/**
- * Create a {@link PageFlowController} of the given type. The PageFlowController stack (for
- * nesting) will be cleared or pushed, and the new instance will be stored as the current
- * PageFlowController.
+ * Create a {@link PageFlowController} of the given type. The {@link PageFlowController} stack used
+ * for nesting will be cleared or pushed, and the new instance will be stored as the current
+ * {@link PageFlowController}.
*
* @param context a {@link RequestContext} object which contains the current request and response.
* @param pageFlowClassName the type name of the desired page flow.
@@ -188,8 +195,8 @@
* PageFlowController.
*
* @param context a {@link RequestContext} object which contains the current request and response.
- * @param pageFlowClass the type of the desired PageFlowController.
- * @return the newly-created PageFlowController, or <code>null</code> if none was found.
+ * @param pageFlowClass the type of the desired {@link PageFlowController}.
+ * @return the newly-created {@link PageFlowController}, or <code>null</code> if none was found.
*/
public PageFlowController createPageFlow( RequestContext context, Class pageFlowClass )
throws InstantiationException, IllegalAccessException
@@ -198,6 +205,9 @@
// If this is an abstract controller class, don't use it.
if (Modifier.isAbstract(pageFlowClass.getModifiers())) {
+ if(LOG.isInfoEnabled())
+ LOG.info("Unable to create Page Flow for class \"" + pageFlowClass.getName() +
+ "\" because the class is abstract");
return null;
}
@@ -262,7 +272,10 @@
existing.persistInSession(request, response);
return existing;
} else {
- // If the feature is enabled, crawl back through the nesting history
+ //
+ // If the feature is enabled, crawl back through the nesting history.
+ // This is implemented below.
+ //
}
}
}
@@ -274,9 +287,7 @@
if ( retVal == null )
{
if ( LOG.isDebugEnabled() )
- {
LOG.debug( "Creating PageFlowController of type " + pageFlowClass.getName() );
- }
retVal = ( PageFlowController ) getFlowControllerInstance( pageFlowClass );
createdNew = true;
@@ -289,8 +300,8 @@
if ( isNestable )
{
//
- // Call create() on the newly-created page flow. Note, leaves the PageFlowController with the responsibility
- // of driving an appropriate Control lifecycle.
+ // Call create() on the newly-created page flow. Note, the PageFlowController is responsible for
+ // driving the appropriate Control lifecycle.
//
if ( createdNew )
retVal.create( request, response, servletContext );
@@ -300,9 +311,7 @@
if ( current != null )
{
if ( LOG.isDebugEnabled() )
- {
LOG.debug( "Pushing PageFlowController " + current + " onto the nesting stack" );
- }
if ( pfStack == null )
pfStack = PageFlowStack.get( request, getServletContext(), true );
@@ -312,33 +321,33 @@
retVal.reinitialize( request, response, servletContext );
retVal.persistInSession( request, response );
}
+ //
+ // New page flow is not nestable; behave accordingly
+ //
else
{
//
- // Going to a non-nested pageflow. Blow away the pageflow stack.
+ // A Page Flow nesting stack exists and needs to be destroyed.
//
if ( pfStack != null )
{
if ( LOG.isDebugEnabled() )
- {
LOG.debug( "Destroying the PageFlowController stack." );
- }
//
- // Start popping page flows until 1) there are none left on the stack, or 2) we find
- // one of the type we're returning. If (2), we'll use that one (this means that executing
- // an action on a nesting page flow while in a nested one will not destroy the nesting
- // page flow only to create a new instance of it).
+ // Start popping page flows until:
+ // 1) there are none left on the stack
+ // 2) we find one of the type we're returning.
+ // If (2), we'll use that one (this means that executing an action on a nesting page flow
+ // while in a nested one will not destroy the nesting page flow only to create a new instance of it).
//
PageFlowController onStackAlready = pfStack.popUntil( request, retVal.getClass(), false );
if ( onStackAlready != null )
{
if ( LOG.isDebugEnabled() )
- {
LOG.debug( "Found a page flow of type " + retVal.getClass() + " in the stack; "
+ "using that instance and stopping destruction of the nesting stack." );
- }
retVal = onStackAlready;
retVal.persistInSession( request, response );
@@ -355,6 +364,9 @@
retVal.create( request, response, servletContext );
}
}
+ //
+ // There is no nesting stack, so just persist the new page flow
+ //
else
{
//
@@ -417,7 +429,7 @@
if ( LOG.isDebugEnabled() )
{
- LOG.debug( "Storing " + retVal + " in the session..." );
+ LOG.debug( "Storing new shared flow " + retVal + " in the session" );
}
retVal.persistInSession( request, response );
@@ -427,7 +439,8 @@
/**
* Get the map of shared flows for the given request. The map is derived from the shared flows
* that are declared (through the <code>sharedFlowRefs</code> attribute of
- * {@link org.apache.beehive.netui.pageflow.annotations.Jpf#Controller @Jpf.Controller}) in the page flow for the request.
+ * {@link org.apache.beehive.netui.pageflow.annotations.Jpf#Controller @Jpf.Controller}) in the
+ * page flow for the request.
*
* @param context a {@link RequestContext} object which contains the current request and response.
* @return a Map of shared-flow-name (String) to {@link SharedFlowController}.
@@ -505,56 +518,6 @@
return sharedFlows;
}
- LinkedHashMap/*< String, SharedFlowController >*/ getDefaultSharedFlows( RequestContext context )
- throws ClassNotFoundException, InstantiationException, IllegalAccessException
- {
- SharedFlowRefConfig[] defaultRefs = ConfigUtil.getConfig().getSharedFlowRefs();
-
- if ( defaultRefs != null )
- {
- if ( defaultRefs.length > 0 )
- {
- LinkedHashMap/*< String, SharedFlowController >*/ sharedFlows = new LinkedHashMap();
-
- for ( int i = 0; i < defaultRefs.length; i++ )
- {
- SharedFlowRefConfig ref = defaultRefs[i];
- if ( LOG.isInfoEnabled() )
- {
- LOG.info( "Shared flow of type " + ref.getType() + " is a default shared flow reference "
- + "with name " + ref.getName() );
- }
- addSharedFlow( context, ref.getName(), ref.getType(), sharedFlows );
- }
-
- return sharedFlows;
- }
- }
-
- return null;
- }
-
- private void addSharedFlow( RequestContext context, String name, String type, LinkedHashMap sharedFlows )
- throws ClassNotFoundException, InstantiationException, IllegalAccessException
- {
- HttpServletRequest request = context.getHttpRequest();
- SharedFlowController sf = PageFlowUtils.getSharedFlow( type, request );
-
- //
- // Reinitialize transient data that may have been lost on session failover.
- //
- if ( sf != null )
- {
- sf.reinitialize( request, context.getHttpResponse(), getServletContext() );
- }
- else
- {
- sf = createSharedFlow( context, type );
- }
-
- if ( ! ( sf instanceof GlobalApp ) ) sharedFlows.put( name, sf );
- }
-
/**
* Get a FlowController class. By default, this loads the class using the thread context class loader.
*
@@ -582,6 +545,12 @@
return ( FlowController ) flowControllerClass.newInstance();
}
+ /* ------------------------------------------------------------------------------
+
+ Deprecated APIs
+
+ ------------------------------------------------------------------------------ */
+
/**
* Get the page flow instance that should be associated with the given request. If it doesn't exist, create it.
* If one is created, the page flow stack (for nesting) will be cleared or pushed, and the new instance will be
@@ -593,7 +562,8 @@
* @param servletContext the current ServletContext.
* @return the {@link PageFlowController} for the request, or <code>null</code> if none was found.
*/
- public static PageFlowController getPageFlowForRequest( HttpServletRequest request, HttpServletResponse response,
+ public static PageFlowController getPageFlowForRequest( HttpServletRequest request,
+ HttpServletResponse response,
ServletContext servletContext )
{
return getPageFlowForRelativeURI( request, response, InternalUtils.getDecodedServletPath( request ), servletContext );
@@ -612,8 +582,10 @@
* @param servletContext the current ServletContext.
* @return the {@link PageFlowController} for the given URI, or <code>null</code> if none was found.
*/
- public static PageFlowController getPageFlowForURI( HttpServletRequest request, HttpServletResponse response,
- String uri, ServletContext servletContext )
+ public static PageFlowController getPageFlowForURI( HttpServletRequest request,
+ HttpServletResponse response,
+ String uri,
+ ServletContext servletContext )
{
return getPageFlowForRelativeURI( request, response, PageFlowUtils.getRelativeURI( request, uri, null ),
servletContext );
@@ -632,7 +604,8 @@
* @return the {@link PageFlowController} for the given path, or <code>null</code> if none was found.
*/
public static PageFlowController getPageFlowForRelativeURI( HttpServletRequest request,
- HttpServletResponse response, String path,
+ HttpServletResponse response,
+ String path,
ServletContext servletContext )
{
try
@@ -662,8 +635,10 @@
* @param servletContext the current ServletContext.
* @return the newly-created {@link PageFlowController}, or <code>null</code> if none was found.
*/
- public static PageFlowController getPageFlow( String pageFlowClassName, HttpServletRequest request,
- HttpServletResponse response, ServletContext servletContext )
+ public static PageFlowController getPageFlow( String pageFlowClassName,
+ HttpServletRequest request,
+ HttpServletResponse response,
+ ServletContext servletContext )
{
try
{
@@ -695,7 +670,8 @@
* @return the current session's {@link GlobalApp} instance, or a new one (based on Global.app) if none is found.
* If Global.app does not exist in the current webapp, <code>null</code> is returned.
*/
- public static GlobalApp getGlobalApp( HttpServletRequest request, HttpServletResponse response,
+ public static GlobalApp getGlobalApp( HttpServletRequest request,
+ HttpServletResponse response,
ServletContext servletContext )
{
Boolean noGlobalApp = (Boolean)servletContext.getAttribute(NO_GLOBAL_APP_KEY);
@@ -762,8 +738,10 @@
* @param servletContext the current ServletContext.
* @return the newly-created {@link PageFlowController}, or <code>null</code> if none was found.
*/
- public static PageFlowController getPageFlow( Class pageFlowClass, HttpServletRequest request,
- HttpServletResponse response, ServletContext servletContext )
+ public static PageFlowController getPageFlow( Class pageFlowClass,
+ HttpServletRequest request,
+ HttpServletResponse response,
+ ServletContext servletContext )
{
try
{
@@ -780,5 +758,62 @@
LOG.error( "Could not instantiate PageFlowController of type " + pageFlowClass.getName(), e );
return null;
}
+ }
+
+ /* ------------------------------------------------------------------------------
+
+ Internal APIs
+
+ ------------------------------------------------------------------------------ */
+
+ LinkedHashMap/*< String, SharedFlowController >*/ getDefaultSharedFlows( RequestContext context )
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException
+ {
+ SharedFlowRefConfig[] defaultRefs = ConfigUtil.getConfig().getSharedFlowRefs();
+
+ if ( defaultRefs != null )
+ {
+ if ( defaultRefs.length > 0 )
+ {
+ LinkedHashMap/*< String, SharedFlowController >*/ sharedFlows = new LinkedHashMap();
+
+ for ( int i = 0; i < defaultRefs.length; i++ )
+ {
+ SharedFlowRefConfig ref = defaultRefs[i];
+ if ( LOG.isInfoEnabled() )
+ {
+ LOG.info( "Shared flow of type " + ref.getType() + " is a default shared flow reference "
+ + "with name " + ref.getName() );
+ }
+ addSharedFlow( context, ref.getName(), ref.getType(), sharedFlows );
+ }
+
+ return sharedFlows;
+ }
+ }
+
+ return null;
+ }
+
+ private void addSharedFlow( RequestContext context, String name, String type, LinkedHashMap sharedFlows )
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException
+ {
+ HttpServletRequest request = context.getHttpRequest();
+ SharedFlowController sf = PageFlowUtils.getSharedFlow( type, request );
+
+ //
+ // Reinitialize transient data that may have been lost on session failover.
+ //
+ if ( sf != null )
+ {
+ sf.reinitialize( request, context.getHttpResponse(), getServletContext() );
+ }
+ else
+ {
+ sf = createSharedFlow( context, type );
+ }
+
+ if ( ! ( sf instanceof GlobalApp ) )
+ sharedFlows.put( name, sf );
}
}