KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > DefaultPageFlowEventReporter


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;
19
20 import org.apache.struts.action.ActionMapping;
21 import org.apache.struts.action.ActionForm;
22 import org.apache.struts.action.ActionForward;
23 import org.apache.beehive.netui.util.internal.InternalStringBuilder;
24 import org.apache.beehive.netui.util.logging.Logger;
25
26 import javax.servlet.ServletContext JavaDoc;
27 import javax.servlet.ServletRequest JavaDoc;
28 import javax.servlet.ServletResponse JavaDoc;
29
30 /**
31  * Default event reporter. Logs every event when the log level is set to "debug" or "trace".
32  */

33 public class DefaultPageFlowEventReporter
34     extends PageFlowEventReporter
35 {
36     private static final Logger _log = Logger.getInstance( DefaultPageFlowEventReporter.class );
37     
38     protected DefaultPageFlowEventReporter( ServletContext JavaDoc servletContext )
39     {
40         super( servletContext );
41     }
42
43     public void actionRaised( FlowController flowController, ActionMapping mapping, ActionForm form,
44                               ServletRequest JavaDoc request, ServletResponse JavaDoc response )
45     {
46         if ( _log.isDebugEnabled() )
47         {
48             LogMsg msg = new LogMsg( "actionRaised" );
49             msg.addParam( "FlowController", flowController );
50             msg.addParam( "ActionMapping", mapping );
51             msg.addParam( "ActionForm", form );
52             msg.addParam( "Request", request );
53             msg.addParam( "Response", response );
54             _log.debug( msg );
55         }
56     }
57
58     public void actionSuccess( FlowController flowController, ActionMapping mapping, ActionForm form,
59                                ServletRequest JavaDoc request, ServletResponse JavaDoc response, ActionForward result,
60                                long timeTakenMillis )
61     {
62         if ( _log.isDebugEnabled() )
63         {
64             LogMsg msg = new LogMsg( "actionSuccess" );
65             msg.addParam( "FlowController", flowController );
66             msg.addParam( "ActionMapping", mapping );
67             msg.addParam( "ActionForm", form );
68             msg.addParam( "Request", request );
69             msg.addParam( "Response", response );
70             msg.addParam( "ActionForward", result );
71             msg.addParam( "TimeTakenMillis", new Long JavaDoc( timeTakenMillis ) );
72             _log.debug( msg );
73         }
74     }
75
76     public void exceptionRaised( Throwable JavaDoc ex, ActionMapping actionMapping, ActionForm form,
77                                  FlowController flowController, ServletRequest JavaDoc request,
78                                  ServletResponse JavaDoc response )
79     {
80         if ( _log.isDebugEnabled() )
81         {
82             LogMsg msg = new LogMsg( "exceptionRaised" );
83             msg.addParam( "Throwable", ex );
84             msg.addParam( "ActionMapping", actionMapping );
85             msg.addParam( "ActionForm", form );
86             msg.addParam( "FlowController", flowController );
87             msg.addParam( "Request", request );
88             msg.addParam( "Response", response );
89             _log.debug( msg );
90         }
91     }
92
93     public void exceptionHandled( Throwable JavaDoc ex, ActionMapping actionMapping, ActionForm form,
94                                   FlowController flowController, ServletRequest JavaDoc request,
95                                   ServletResponse JavaDoc response, ActionForward result,
96                                   long timeTakenMillis )
97     {
98         if ( _log.isDebugEnabled() )
99         {
100             LogMsg msg = new LogMsg( "exceptionHandled" );
101             msg.addParam( "Throwable", ex );
102             msg.addParam( "ActionMapping", actionMapping );
103             msg.addParam( "ActionForm", form );
104             msg.addParam( "FlowController", flowController );
105             msg.addParam( "Request", request );
106             msg.addParam( "Response", response );
107             msg.addParam( "ActionForward", result );
108             msg.addParam( "TimeTakenMillis", new Long JavaDoc( timeTakenMillis ) );
109             _log.debug( msg );
110         }
111     }
112
113     public void flowControllerCreated( FlowController flowController, ServletRequest JavaDoc request,
114                                        ServletResponse JavaDoc response )
115     {
116         if ( _log.isDebugEnabled() )
117         {
118             LogMsg msg = new LogMsg( "flowControllerCreated" );
119             msg.addParam( "FlowController", flowController );
120             msg.addParam( "Request", request );
121             msg.addParam( "Response", response );
122             _log.debug( msg );
123         }
124     }
125
126     public void flowControllerDestroyed( FlowController flowController )
127     {
128         if ( _log.isDebugEnabled() )
129         {
130             LogMsg msg = new LogMsg( "flowControllerDestroyed" );
131             msg.addParam( "FlowController", flowController );
132             _log.debug( msg );
133         }
134     }
135
136     public void beginActionRequest( ServletRequest JavaDoc request, ServletResponse JavaDoc response )
137     {
138         if ( _log.isDebugEnabled() )
139         {
140             LogMsg msg = new LogMsg( "beginActionRequest" );
141             msg.addParam( "Request", request );
142             msg.addParam( "Response", response );
143             _log.debug( msg );
144         }
145     }
146
147     public void endActionRequest( ServletRequest JavaDoc request, ServletResponse JavaDoc response, long timeTakenMillis )
148     {
149         if ( _log.isDebugEnabled() )
150         {
151             LogMsg msg = new LogMsg( "endActionRequest" );
152             msg.addParam( "Request", request );
153             msg.addParam( "Response", response );
154             msg.addParam( "TimeTakenMillis", new Long JavaDoc( timeTakenMillis ) );
155             _log.debug( msg );
156         }
157     }
158
159     public void beginPageRequest( ServletRequest JavaDoc request, ServletResponse JavaDoc response )
160     {
161         if ( _log.isDebugEnabled() )
162         {
163             LogMsg msg = new LogMsg( "beginPageRequest" );
164             msg.addParam( "Request", request );
165             msg.addParam( "Response", response );
166             _log.debug( msg );
167         }
168     }
169
170     public void endPageRequest( ServletRequest JavaDoc request, ServletResponse JavaDoc response, long timeTakenMillis )
171     {
172         if ( _log.isDebugEnabled() )
173         {
174             LogMsg msg = new LogMsg( "endPageRequest" );
175             msg.addParam( "Request", request );
176             msg.addParam( "Response", response );
177             msg.addParam( "TimeTakenMillis", new Long JavaDoc( timeTakenMillis ) );
178             _log.debug( msg );
179         }
180     }
181         
182     protected static class LogMsg
183     {
184         private String JavaDoc _eventName;
185         private InternalStringBuilder _logMessage;
186             
187         public LogMsg( String JavaDoc eventName )
188         {
189             _eventName = eventName;
190         }
191             
192         public void addParam( String JavaDoc name, Object JavaDoc value )
193         {
194             if ( _logMessage == null )
195             {
196                 _logMessage = new InternalStringBuilder( _eventName ).append( ": " );
197             }
198             else
199             {
200                 _logMessage.append( ", " );
201             }
202                 
203             _logMessage.append( name ).append( '=' ).append( value );
204         }
205             
206         public String JavaDoc toString()
207         {
208             return _logMessage == null ? _eventName : _logMessage.toString();
209         }
210     }
211 }
212
Popular Tags