1 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 ; 27 import javax.servlet.ServletRequest ; 28 import javax.servlet.ServletResponse ; 29 30 33 public class DefaultPageFlowEventReporter 34 extends PageFlowEventReporter 35 { 36 private static final Logger _log = Logger.getInstance( DefaultPageFlowEventReporter.class ); 37 38 protected DefaultPageFlowEventReporter( ServletContext servletContext ) 39 { 40 super( servletContext ); 41 } 42 43 public void actionRaised( FlowController flowController, ActionMapping mapping, ActionForm form, 44 ServletRequest request, ServletResponse 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 request, ServletResponse 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 ( timeTakenMillis ) ); 72 _log.debug( msg ); 73 } 74 } 75 76 public void exceptionRaised( Throwable ex, ActionMapping actionMapping, ActionForm form, 77 FlowController flowController, ServletRequest request, 78 ServletResponse 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 ex, ActionMapping actionMapping, ActionForm form, 94 FlowController flowController, ServletRequest request, 95 ServletResponse 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 ( timeTakenMillis ) ); 109 _log.debug( msg ); 110 } 111 } 112 113 public void flowControllerCreated( FlowController flowController, ServletRequest request, 114 ServletResponse 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 request, ServletResponse 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 request, ServletResponse 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 ( timeTakenMillis ) ); 155 _log.debug( msg ); 156 } 157 } 158 159 public void beginPageRequest( ServletRequest request, ServletResponse 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 request, ServletResponse 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 ( timeTakenMillis ) ); 178 _log.debug( msg ); 179 } 180 } 181 182 protected static class LogMsg 183 { 184 private String _eventName; 185 private InternalStringBuilder _logMessage; 186 187 public LogMsg( String eventName ) 188 { 189 _eventName = eventName; 190 } 191 192 public void addParam( String name, Object 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 toString() 207 { 208 return _logMessage == null ? _eventName : _logMessage.toString(); 209 } 210 } 211 } 212 | Popular Tags |