Author: rich
Date: Mon Aug 30 13:01:39 2004
New Revision: 37215

Added:
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/ControlFieldInitializationException.java
   (contents, props changed)
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObjectException.java
   (contents, props changed)
Modified:
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FacesBackingBean.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowException.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObject.java
   
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/netui.properties
Log:
- Fixed to avoid masking exceptions thrown when Control member fields are being 
automatically initialized at page flow creation time.  These errors were being 
logged, but are now fatal (causing a ControlFieldInitializationException) in 
order to prevent a page flow from existing in a partially-initialized state.

- Fixed to avoid writing multiple exception pages to the response when:
    - an exception occurs during page flow creation time, and
    - an exception occurs during a page flow action during the same request, and
    - there is no user-configured exception-handling for either of the 
exceptions.

DRT: netui (WinXP)
BB: self (linux)




Added: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/ControlFieldInitializationException.java
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/ControlFieldInitializationException.java
       Mon Aug 30 13:01:39 2004
@@ -0,0 +1,47 @@
+/*
+ * B E A   S Y S T E M S
+ * Copyright 2002-2004  BEA Systems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.pageflow;
+
+public class ControlFieldInitializationException
+        extends PageFlowManagedObjectException
+{
+    private String _fieldName;
+    
+    /**
+     * Construct with no error message.
+     */ 
+    public ControlFieldInitializationException( String fieldName, 
PageFlowManagedObject object, Throwable cause )
+    {
+        super( object, cause );
+        _fieldName = fieldName;
+    }
+
+    protected Object[] getMessageArgs()
+    {
+        return new Object[]{ _fieldName, getManagedObject().getDisplayName() };
+    }
+
+    public String[] getMessageParts()
+    {
+        return new String[]
+        {
+            "Exception occurred when initializing field ", " on page flow ", 
"."
+        };
+    }
+}

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FacesBackingBean.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FacesBackingBean.java
  (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FacesBackingBean.java
  Mon Aug 30 13:01:39 2004
@@ -47,4 +47,9 @@
     {
         request.setAttribute( InternalConstants.BACKING_CLASS_IMPLICIT_OBJECT, 
this );
     }
+
+    public String getDisplayName()
+    {
+        return getClass().getName();
+    }
 }

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
    (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
    Mon Aug 30 13:01:39 2004
@@ -71,6 +71,7 @@
     private static final int EXCEEDED_MAX_CONCURRENT_REQUESTS_ERRORCODE = 503;
     private static final String DEFAULT_SIMPLE_ACTION_FORWARD_NAME = 
"_defaultForward";
     private static final Locale DEFAULT_LOCALE = Locale.getDefault();
+    private static final ActionForward NULL_ACTION_FORWARD = new 
ActionForward();
     
     
     static class PerRequestState
@@ -310,7 +311,7 @@
         
         if ( onCreateFwd != null )
         {
-            return onCreateFwd;
+            return onCreateFwd == NULL_ACTION_FORWARD ? null : onCreateFwd;
         }
         
         
@@ -552,6 +553,7 @@
                 {
                     _log.info( "Handling exception in onCreate(), page flow " 
+ this, th );
                     ActionForward fwd = handleException( th, null, 
"[onCreate]", null, request, response );
+                    if ( fwd == null ) fwd = NULL_ACTION_FORWARD;
                     request.setAttribute( ONCREATE_EXCEPTION_FORWARD, fwd );
                 }
                 catch ( Exception e )
@@ -1189,8 +1191,6 @@
     protected void onRefresh()
     {
     }
-    
-    public abstract String getDisplayName();
     
     /**
      * Used by derived classes to store information on the most recent action 
executed.

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowException.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowException.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowException.java
 Mon Aug 30 13:01:39 2004
@@ -30,23 +30,27 @@
 /**
  * Base class for PageFlow-related Exceptions.
  */ 
-public abstract class PageFlowException extends RuntimeException
+public abstract class PageFlowException
+        extends PageFlowManagedObjectException
 {
-    private FlowController _flowController;
     private String _actionName;
-    private String _messageKeyPrefix;
     
     
-    public PageFlowException( String actionName, FlowController fc )
+    protected PageFlowException( String actionName, FlowController fc )
     {
-        super();
-        _flowController = fc;
-        _actionName = ( actionName.startsWith( "/" ) ? actionName.substring( 1 
) : actionName );
-        
-        String className = getClass().getName();
-        int lastDot = className.lastIndexOf( '.' );
-        assert lastDot != -1;
-        _messageKeyPrefix = "PageFlow_" + className.substring( lastDot + 1 );
+        super( fc );
+        init( actionName );
+    }
+    
+    protected PageFlowException( String actionName, FlowController fc, 
Throwable cause )
+    {
+        super( fc, cause );
+        init( actionName );
+    }
+    
+    protected void init( String actionName )
+    {
+        _actionName = actionName.startsWith( "/" ) ? actionName.substring( 1 ) 
: actionName;
     }
     
     /**
@@ -56,7 +60,7 @@
      */ 
     public FlowController getFlowController()
     {
-        return _flowController;
+        return ( FlowController ) getManagedObject();
     }
     
     /**
@@ -66,7 +70,8 @@
      */ 
     public String getFlowControllerURI()
     {
-        return _flowController != null ? _flowController.getDisplayName() : 
null;
+        FlowController flowController = getFlowController();
+        return flowController != null ? flowController.getDisplayName() : null;
     }
     
     /**
@@ -78,69 +83,4 @@
     {
         return _actionName;
     }
-
-    /**
-     * Handle the error by writing a message to the response.
-     * 
-     * @param request the current HttpServletRequest
-     * @param response the current HttpServletResponse
-     */    
-    void sendError( HttpServletRequest request, HttpServletResponse response, 
int productionTimeErrorCode )
-        throws IOException
-    {
-        InternalUtils.sendDevTimeError( _messageKeyPrefix, getMessageArgs(), 
request, response, null,
-                                        productionTimeErrorCode );
-    }
-    
-    /**
-     * Handle the error by writing a message to the response.
-     * 
-     * @param request the current HttpServletRequest
-     * @param response the current HttpServletResponse
-     */    
-    public void sendError( HttpServletRequest request, HttpServletResponse 
response )
-        throws IOException
-    {
-        InternalUtils.sendError( _messageKeyPrefix, getMessageArgs(), request, 
response, null );
-    }
-    
-    /**
-     * Print a formatted message.
-     * 
-     * @param writer a writer to which to print the formatted message.
-     */ 
-    public void printError( PrintWriter writer )
-    {
-        writer.println( Bundle.getString( _messageKeyPrefix + "_Page", 
getMessageArgs() ) );
-    }
-
-    public String getLocalizedMessage()
-    {
-        return Bundle.getString( _messageKeyPrefix + "_Message", 
getMessageArgs() );
-    }
-    
-    public String getMessage()
-    {
-        StringBuffer buf = new StringBuffer();
-        String[] parts = getMessageParts();
-        Object[] args = getMessageArgs();
-
-        assert parts.length > args.length : parts.length + ", " + args.length;
-        
-        for ( int i = 0; i < parts.length; ++i )
-        {
-            buf.append( parts[i] );
-            
-            if ( i < args.length )
-            {
-                buf.append( args[i] );
-            }
-        }
-        
-        return buf.toString();
-    }
-    
-    protected abstract Object[] getMessageArgs();
-    
-    protected abstract String[] getMessageParts();
 }

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObject.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObject.java
     (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObject.java
     Mon Aug 30 13:01:39 2004
@@ -38,7 +38,8 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 
-abstract class PageFlowManagedObject implements Serializable, 
HttpSessionBindingListener
+abstract class PageFlowManagedObject
+        implements Serializable, HttpSessionBindingListener
 {
     private static final Logger _log = Logger.getInstance( 
PageFlowManagedObject.class );
     
@@ -133,6 +134,7 @@
      * @param request the current HttpServletRequest.
      */ 
     private void initJavaControls( HttpServletRequest request, 
HttpServletResponse response )
+        throws ControlFieldInitializationException
     {
         Map controlFields = 
JavaControlUtils.getAccessibleControlFieldAnnotations( getClass() );
         if ( controlFields.isEmpty() ) return;
@@ -171,13 +173,10 @@
                     field.set( this, bean );
                 }
             }
-            catch ( JavaControlUtils.ControlInstantiationException e )
+            catch ( Exception e )
             {
-                _log.error( "Exception while initializing Java Control " + 
field.getName(), e );
-            }
-            catch ( IllegalAccessException e )
-            {
-                _log.error( "Exception while initializing Java Control " + 
field.getName(), e );
+                _log.error( "Exception occurred while initializing control 
field " + field.getName(), e );
+                throw new ControlFieldInitializationException( 
field.getName(), this, e );
             }
         }
     }
@@ -228,4 +227,6 @@
     }
 
     abstract void setImplicitObject( HttpServletRequest request );
+    
+    public abstract String getDisplayName();
 }

Added: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObjectException.java
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObjectException.java
    Mon Aug 30 13:01:39 2004
@@ -0,0 +1,136 @@
+/*
+ * B E A   S Y S T E M S
+ * Copyright 2002-2004  BEA Systems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.pageflow;
+
+import org.apache.beehive.netui.util.Bundle;
+import org.apache.beehive.netui.pageflow.internal.InternalUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+
+/**
+ * Base class for PageFlow-related Exceptions.
+ */ 
+public abstract class PageFlowManagedObjectException
+        extends RuntimeException
+{
+    private PageFlowManagedObject _managedObject;
+    private String _messageKeyPrefix;
+    
+    
+    protected PageFlowManagedObjectException( PageFlowManagedObject object )
+    {
+        super();
+        init( object );
+    }
+    
+    protected PageFlowManagedObjectException( PageFlowManagedObject object, 
Throwable cause )
+    {
+        super( cause );
+        init( object );
+    }
+    
+    protected void init( PageFlowManagedObject object )
+    {
+        _managedObject = object;
+        
+        String className = getClass().getName();
+        int lastDot = className.lastIndexOf( '.' );
+        assert lastDot != -1;
+        _messageKeyPrefix = "PageFlow_" + className.substring( lastDot + 1 );
+    }
+    
+    /**
+     * Get the related PageFlowManagedObject.
+     * 
+     * @return the [EMAIL PROTECTED] PageFlowManagedObject} associated with 
this exception.
+     */ 
+    public PageFlowManagedObject getManagedObject()
+    {
+        return _managedObject;
+    }
+    
+    /**
+     * Handle the error by writing a message to the response.
+     * 
+     * @param request the current HttpServletRequest
+     * @param response the current HttpServletResponse
+     */    
+    void sendError( HttpServletRequest request, HttpServletResponse response, 
int productionTimeErrorCode )
+        throws IOException
+    {
+        InternalUtils.sendDevTimeError( _messageKeyPrefix, getMessageArgs(), 
request, response, null,
+                                        productionTimeErrorCode );
+    }
+    
+    /**
+     * Handle the error by writing a message to the response.
+     * 
+     * @param request the current HttpServletRequest
+     * @param response the current HttpServletResponse
+     */    
+    public void sendError( HttpServletRequest request, HttpServletResponse 
response )
+        throws IOException
+    {
+        InternalUtils.sendError( _messageKeyPrefix, getMessageArgs(), request, 
response, null );
+    }
+    
+    /**
+     * Print a formatted message.
+     * 
+     * @param writer a writer to which to print the formatted message.
+     */ 
+    public void printError( PrintWriter writer )
+    {
+        writer.println( Bundle.getString( _messageKeyPrefix + "_Page", 
getMessageArgs() ) );
+    }
+
+    public String getLocalizedMessage()
+    {
+        return Bundle.getString( _messageKeyPrefix + "_Message", 
getMessageArgs() );
+    }
+    
+    public String getMessage()
+    {
+        StringBuffer buf = new StringBuffer();
+        String[] parts = getMessageParts();
+        Object[] args = getMessageArgs();
+
+        assert parts.length > args.length : parts.length + ", " + args.length;
+        
+        for ( int i = 0; i < parts.length; ++i )
+        {
+            buf.append( parts[i] );
+            
+            if ( i < args.length )
+            {
+                buf.append( args[i] );
+            }
+        }
+        
+        return buf.toString();
+    }
+    
+    protected abstract Object[] getMessageArgs();
+    
+    protected abstract String[] getMessageParts();
+}

Modified: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/netui.properties
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/netui.properties
       (original)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/netui.properties
       Mon Aug 30 13:01:39 2004
@@ -281,6 +281,20 @@
 PageFlow_NotLoggedInException_Message= \
 Action {0} in page flow {1} requires a current user, but there is no logged-in 
user.
 
+PageFlow_ControlFieldInitializationException_Page= \
+<html><head><title>Page Flow Error - Control Field 
Initialization</title></head>\n \
+<body>\n \
+<h1>Page Flow Error - Control Field Initialization</h1>\n \
+<table border="1" cellspacing="0">\n \
+<tr><td><b>Control Container:</b></td><td>{1}</td></tr>\n \
+<tr><td><b>Control Field:</b></td><td>{0}</td></tr>\n \
+</table><br />\n \
+<span style="color:red">Exception occurred while initializing control field 
<b>{0}</b>.</span>\n \
+</body></html>\n
+
+PageFlow_ControlFieldInitializationException_Message= \
+Exception occurred while initializing control field {0} in {1}.
+
 PageFlow_LoginExpiredException_Page= \
 <html><head><title>Page Flow Error - Login Expired</title></head>\n \
 <body>\n \

Reply via email to