KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > interceptor > action > OriginalForward


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.interceptor.action;
19
20 import org.apache.beehive.netui.util.logging.Logger;
21 import org.apache.beehive.netui.pageflow.Forward;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.io.Serializable JavaDoc;
29
30 class OriginalForward extends InterceptorForward
31 {
32     private Map JavaDoc _savedAttrs;
33     
34     private static final Logger _log = Logger.getInstance( OriginalForward.class );
35     
36     
37     OriginalForward( Forward fwd, HttpServletRequest JavaDoc request )
38     {
39         super( fwd );
40         saveRequestAttrs( request );
41     }
42     
43     OriginalForward( HttpServletRequest JavaDoc request )
44     {
45         super( request );
46         saveRequestAttrs( request );
47     }
48     
49     private void saveRequestAttrs( HttpServletRequest JavaDoc request )
50     {
51         _savedAttrs = new HashMap JavaDoc();
52         
53         for ( Enumeration JavaDoc e = request.getAttributeNames(); e.hasMoreElements(); )
54         {
55             String JavaDoc attrName = ( String JavaDoc ) e.nextElement();
56             Object JavaDoc attrVal = request.getAttribute( attrName );
57             
58             if ( attrVal instanceof Serializable JavaDoc )
59             {
60                 _savedAttrs.put( attrName, attrVal );
61             }
62             else
63             {
64                 if ( _log.isWarnEnabled() )
65                 {
66                     _log.warn( "Dropping non-serializable request attribute " + attrName + " (" + attrVal + ")." );
67                 }
68             }
69         }
70     }
71     
72     public void rehydrateRequest( HttpServletRequest JavaDoc request )
73     {
74         if ( _savedAttrs != null )
75         {
76             for ( Iterator JavaDoc i = _savedAttrs.entrySet().iterator(); i.hasNext(); )
77             {
78                 Map.Entry JavaDoc entry = ( Map.Entry JavaDoc ) i.next();
79                 
80                 String JavaDoc attrName = ( String JavaDoc ) entry.getKey();
81                 if ( request.getAttribute( attrName ) == null )
82                 {
83                     request.setAttribute( attrName, entry.getValue() );
84                 }
85             }
86         }
87     }
88 }
89
Popular Tags