Coverage Report - net.wotonomy.web.WOComponentRequestHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
WOComponentRequestHandler
0% 
0% 
12
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2000 Blacksmith, Inc.
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, see http://www.gnu.org
 17  
 */
 18  
 
 19  
 package net.wotonomy.web;
 20  
 
 21  
 
 22  
 /**
 23  
 * An implementation of WORequestHandler that dispatches Component actions.
 24  
 *
 25  
 * @author michael@mpowers.net
 26  
 * @author $Author: cgruber $
 27  
 * @version $Revision: 905 $
 28  
 */
 29  0
 public class WOComponentRequestHandler
 30  
         extends WORequestHandler
 31  
 {
 32  
     public WOResponse handleRequest( WORequest aRequest )
 33  
     {
 34  0
         WOApplication application = aRequest.application();
 35  0
         WOContext context = WOContext.contextWithRequest( aRequest );
 36  0
         WOResponse response = null;
 37  
             
 38  
         // no concurrent access is allowed to a user's session:
 39  
         // a user/browser/machine with multiple requests will have to wait
 40  0
         synchronized ( aRequest.request.getSession() )
 41  
         {
 42  
             try
 43  
             {
 44  0
                 application.awake();
 45  
                 
 46  0
                 WOSession session = null;
 47  
     /*            
 48  
                 // the NeXT way
 49  
                 String sessionID = aRequest.sessionID();
 50  
                 if ( sessionID != null )
 51  
                 {
 52  
                     session = application.restoreSessionWithID( sessionID, context );
 53  
                     if ( session == null )
 54  
                     {
 55  
                         response = application.handleSessionRestorationErrorInContext( context );
 56  
                     }
 57  
                 }
 58  
                 else
 59  
                 {
 60  
                     session = application.createSessionForRequest( aRequest );
 61  
                     if ( session == null )
 62  
                     {
 63  
                         response = application.handleSessionCreationErrorInContext( context );
 64  
                     }
 65  
                     else
 66  
                     {
 67  
                         session.setContext( context );
 68  
                     }
 69  
                 }
 70  
     */
 71  
                 // the servlet way
 72  0
                 String sessionID = aRequest.sessionID();
 73  0
                 if ( sessionID != null )
 74  
                 {
 75  0
                     session = application.restoreSessionWithID( sessionID, context );
 76  
                 }
 77  
     
 78  0
                 if ( session == null )
 79  
                 {
 80  0
                     session = application.createSessionForRequest( aRequest );
 81  0
                     if ( session == null )
 82  
                     {
 83  0
                         response = application.handleSessionCreationErrorInContext( context );
 84  0
                     }
 85  
                     else
 86  
                     {
 87  0
                         session.setContext( context );
 88  
                     }
 89  
                 }
 90  
                 
 91  0
                 context.setSession( session );
 92  
                 
 93  0
                 session.awake();
 94  
                 
 95  0
                 if ( response == null )
 96  
                 {
 97  
                     
 98  
                     WOComponent page;
 99  0
                     String contextID = aRequest.contextID(); 
 100  
                     
 101  0
                     if ( contextID != null )
 102  
                     {
 103  0
                         page = session.restorePageForContextID( contextID );
 104  0
                     }
 105  
                     else
 106  
                     {
 107  0
                         page = application.pageWithName( aRequest.pageName(), context ); 
 108  
                     }
 109  
                     
 110  0
                     if ( page == null )
 111  
                     {
 112  
                         //FIXME: should we call this a restoration error, or do we
 113  
                         // allow a bookmark with an expired context id to resume gracefully?
 114  0
                         page = application.pageWithName( aRequest.pageName(), context ); 
 115  
                         //!response = application.handlePageRestorationErrorInContext( context );
 116  
                     }
 117  
                     //!else
 118  
                     {
 119  0
                         context.pushElement( page ); //? needed?
 120  0
                         page.ensureAwakeInContext( context ); //? shouldn't this be in WOApplication?
 121  
     
 122  
                         // only take values from request if there are values in the request
 123  0
                         System.out.println("should I takeValuesFromRequest ? " + ( aRequest.formValueKeys().count() > 0 ));
 124  0
                         if ( aRequest.formValueKeys().count() > 0 )
 125  
                         {
 126  0
                             application.takeValuesFromRequest( aRequest, context );
 127  
                         }
 128  
                         
 129  
                         // only invoke action if there is a sender id to invoke
 130  
                         WOActionResults result;
 131  0
                         System.out.println("senderID: " + aRequest.senderID());
 132  0
                         if ( aRequest.senderID() != null )
 133  
                         {
 134  0
                             result = application.invokeAction( aRequest, context );
 135  0
                         }
 136  
                         else
 137  
                         {
 138  0
                             result = null;
 139  
                         }
 140  
                         
 141  0
                         if ( result == null || result == page ) // same page is returned
 142  
                         {
 143  0
                             result = page;
 144  
                             
 145  
                             // generate response
 146  0
                             response = new WOResponse();
 147  0
                             application.appendToResponse( response, context );
 148  0
                             page.sleep();
 149  0
                         }
 150  
                         else // different page is returned
 151  0
                         if ( result instanceof WOComponent )
 152  
                         {
 153  0
                             page.sleep();
 154  0
                             page = (WOComponent) result;
 155  0
                             page.ensureAwakeInContext( context );
 156  0
                             context.popElement(); // removes page
 157  0
                             context.pushElement( page );
 158  
                             
 159  
                             // generate response
 160  0
                             response = new WOResponse();
 161  0
                             application.appendToResponse( response, context );
 162  0
                             page.sleep();
 163  0
                         }
 164  
                         else // WOResponse was returnd
 165  
                         {
 166  0
                             response = (WOResponse) result;
 167  
                         }
 168  
                         
 169  0
                         context.popElement();
 170  0
                         session.sleep();
 171  0
                         session.savePage( page );
 172  0
                         session.setContext( null );
 173  0
                         application.saveSessionForContext( context );
 174  
                     }
 175  
                 }
 176  
             }
 177  0
             catch ( Throwable t )
 178  
             {
 179  0
                 response = application.handleException( t, context );
 180  0
             }
 181  
     
 182  0
             application.sleep();
 183  0
         }
 184  0
         return response;
 185  
     }
 186  
 }
 187  
 
 188  
 /*
 189  
  * $Log$
 190  
  * Revision 1.2  2006/02/19 01:44:02  cgruber
 191  
  * Add xmlrpc files
 192  
  * Remove jclark and replace with dom4j and javax.xml.sax stuff
 193  
  * Re-work dependencies and imports so it all compiles.
 194  
  *
 195  
  * Revision 1.1  2006/02/16 13:22:22  cgruber
 196  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 197  
  *
 198  
  * Revision 1.8  2003/08/07 00:15:15  chochos
 199  
  * general cleanup (mostly removing unused imports)
 200  
  *
 201  
  * Revision 1.7  2003/01/17 20:34:57  mpowers
 202  
  * Better handling for components and parents in the context's element stack.
 203  
  *
 204  
  * Revision 1.6  2003/01/15 19:50:49  mpowers
 205  
  * Fixed issues with WOSession and Serializable.
 206  
  * Can now persist sessions between classloaders (hot swap of class impls).
 207  
  *
 208  
  * Revision 1.4  2003/01/14 15:51:09  mpowers
 209  
  * No longer calling takeValues or invokeAction if there are no request params
 210  
  *
 211  
  * Revision 1.3  2003/01/13 22:24:34  mpowers
 212  
  * Request-response cycle is working with session and page persistence.
 213  
  *
 214  
  * Revision 1.1  2003/01/09 16:13:59  mpowers
 215  
  * Implemented WOComponentRequestHandler:
 216  
  * Bringing the request-response cycle more into conformance.
 217  
  *
 218  
  * Revision 1.2  2002/12/17 14:57:44  mpowers
 219  
  * Minor corrections to WORequests's parsing, and updated javadocs.
 220  
  *
 221  
  * Revision 1.1.1.1  2000/12/21 15:53:19  mpowers
 222  
  * Contributing wotonomy.
 223  
  *
 224  
  * Revision 1.2  2000/12/20 16:25:50  michael
 225  
  * Added log to all files.
 226  
  *
 227  
  *
 228  
  */
 229