myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "TracingMyFacesUsingAspectJ" by JamesRichards
Date Wed, 07 Jun 2006 23:34:42 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by JamesRichards:
http://wiki.apache.org/myfaces/TracingMyFacesUsingAspectJ

------------------------------------------------------------------------------
  Here is the aspect upon which the discussion will be based:
  
  {{{
+ package com.dbz.lms.aspects;
+ 
  import java.io.BufferedWriter;
  import java.io.File;
  import java.io.FileWriter;
@@ -12, +14 @@

  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
+ import com.dbz.lms.faces.action.DealHandler;
- import org.apache.myfaces.taglib.html.ext.HtmlDataTableTag;
- import org.apache.myfaces.component.html.ext.HtmlDataTable;
- import org.apache.myfaces.custom.datascroller.HtmlDataScroller;
  import org.apache.myfaces.lifecycle.LifecycleImpl;
  import javax.faces.component.UIViewRoot;
  import javax.faces.component.UIComponent;
@@ -23, +23 @@

  import org.apache.myfaces.el.PropertyResolverImpl;
  import javax.faces.context.FacesContext;
  import org.apache.myfaces.context.servlet.ServletFacesContextImpl;
- 
+ import javax.faces.application.NavigationHandler;
+ import org.apache.myfaces.application.ApplicationImpl;
+ import org.apache.myfaces.application.ActionListenerImpl;
+ import javax.faces.event.ActionEvent;
+ import javax.faces.event.ActionListener;
+ import javax.faces.component.UICommand;
  import org.aspectj.lang.JoinPoint;
- import org.hibernate.impl.SessionImpl;
  
  aspect Trace {
  	private static final Log log = LogFactory.getLog(Trace.class);
@@ -38, +42 @@

  		}
  	}
  	
+ 	pointcut renderResponse(Object cmp) : this(cmp) && call(* FacesContext+.renderResponse());
+ 
+     Object around(Object cmp): renderResponse(cmp) {
+     	if (cmp instanceof UIComponentBase) {
+         	UIComponentBase uiCmp = (UIComponentBase)cmp;
+             traceEntry("UIComponent calling renderResponse():" + uiCmp.getId() + ":" + thisJoinPoint.getThis()
+ ":");
+     	} else {
+             traceEntry("Non-UIComponent calling renderResponse():" + cmp + ":" + thisJoinPoint.getThis()
+ ":");
+     	}
+         Object retVal = proceed(cmp);
+         traceExit(cmp.hashCode() + ":" + thisJoinPointStaticPart.getSignature() + " returning
" + retVal); 
+         return retVal;
+     }
+ 	
+ 	
      pointcut myClass(Object obj): this(obj) && 
      	(
+     	    within(ApplicationImpl)
+     	    || within(NavigationHandler)
-     		within(ServletFacesContextImpl)
+     		|| within(ServletFacesContextImpl)
      	    || within(LifecycleImpl)
      	    || within(UIViewRoot)
+     	    || within(UIComponentBase)
+     	    || within(UICommand)
+     	    || within(ActionListenerImpl)
      	)
+     	&& !execution(UIComponentBase.new(..))
      	&& !execution(* ServletFacesContextImpl.getApplication(..))
      	&& !execution(* ServletFacesContextImpl.getExternalContext(..))
      	&& !execution(* ServletFacesContextImpl.getM*(..))
@@ -66, +91 @@

      	&& !execution(* UIViewRoot.getRenderKitId())
      	&& !execution(* UIViewRoot.getLocale())
      	&& !execution(* UIViewRoot.create*())
+     	&& !execution(* ApplicationImpl.get*())
+     	&& !execution(* ApplicationImpl.set*(..))
+     	&& !within(com.dbz.lms.aspects.*)
      	&& !execution(String *.toString())
      	&& !execution(String *.hashCode());
  
@@ -145, +173 @@

      		buf.append(args[i] + "");
      	}
      	buf.append("]");
+     	Object thisObj = thisJoinPoint.getThis();
+     	String id = "";
+     	if (thisObj instanceof UIComponentBase) {
+     		id = ((UIComponentBase)thisObj).getId();
+     	}
-         traceEntry(obj.hashCode() + ":" + thisJoinPoint.getThis() + ":" + buf.toString());
+         traceEntry(obj.hashCode() + ":" + id + ":" + thisJoinPoint.getThis() + ":" + buf.toString());
          Object retVal = proceed(obj);
          traceExit(obj.hashCode() + ":" + thisJoinPointStaticPart.getSignature() + " returning
" + retVal); 
          return retVal;
      }
  }
+ 
  }}}
  
  The development environment for following this example is as follows:
@@ -168, +202 @@

  
  Once the AspectJ nature is added, you will want to add the myfaces libraries to the AspectJ
weaving path:
  
+ {{{
  1) Right click on your MyFaces project
  2) Choose "Properties" from the context menu
  3) In the properties dialog, select the "AspectJ InPath" screen
@@ -177, +212 @@

  6) The AspectJ compiler will now compile your source and will weave the trace into the MyFaces
classes
  7) Copy the ouput of the compilation to your web applications "WEB-INF/classes" directory
and restart your server
  7a) NOTE: if you are not using a web application, you must merely ensure that the woven
classes are first in the runtime classpath of your application
+ }}}
  
  Upon relaunching your application, once MyFaces actually runs, you should be able to "tail
-f c:\trace.out" to follow the execution of MyFaces.  Note that the file location should be
changed as appropriate for Unix.
  

Mime
View raw message