View Javadoc

1   package com.atlassian.xwork.interceptors;
2   
3   import com.opensymphony.xwork.interceptor.AroundInterceptor;
4   import com.opensymphony.xwork.ActionInvocation;
5   import com.opensymphony.xwork.ActionProxy;
6   import com.opensymphony.webwork.ServletActionContext;
7   import com.atlassian.util.profiling.UtilTimerStack;
8   import com.atlassian.util.profiling.ProfilingUtils;
9   
10  public class XWorkProfilingInterceptor extends AroundInterceptor
11  {
12      String location;
13  
14      protected void before(ActionInvocation actionInvocation) throws Exception
15      {
16          UtilTimerStack.push(makeStackKey(actionInvocation.getProxy()));
17          ServletActionContext.getRequest(); // needed to make sure the request is present (I think)
18      }
19  
20      protected void after(ActionInvocation actionInvocation, String string) throws Exception
21      {
22          UtilTimerStack.pop(makeStackKey(actionInvocation.getProxy()));
23      }
24  
25      private String makeStackKey(ActionProxy proxy)
26      {
27          String methodName = proxy.getConfig().getMethodName();
28  
29          if (methodName == null)
30              methodName = "execute";
31  
32          String actionClazz = ProfilingUtils.getJustClassName(proxy.getConfig().getClassName());
33  
34          return "XW Interceptor: " + (location != null ? location + ": " : "") + proxy.getNamespace() + "/" + proxy.getActionName() + ".action (" + actionClazz + "." + methodName + "())";
35      }
36  
37      public String getLocation()
38      {
39          return location;
40      }
41  
42      public void setLocation(String location)
43      {
44          this.location = location;
45      }
46  
47  }