当前位置: 代码迷 >> ASP >> AspectJ(三)Examples
  详细解决方案

AspectJ(三)Examples

热度:1174   发布时间:2012-10-08 19:54:56.0
AspectJ(3)Examples
AspectJ(3)Examples

Chapter 3. Examples
3.1 Obtaining, Compiling and Running the Examples
I download the aspectj stable version with these URLs
http://mirror.neu.edu.cn/eclipse/tools/aspectj/aspectj-1.6.12-src.jar
http://download.actuatechina.com/eclipse/tools/aspectj/aspectj-1.6.12.jar

Double click aspectj-1.6.12.jar, install aspectj in my local machine. I install it in d:/tool directory.
And I add this location D:\tool\aspectj1.6.12\bin to my system PATH.
Add location D:\tool\aspectj1.6.12\lib\aspectjrt.jar to my system CLASSPATH

And all the example is in this directory D:\tool\aspectj1.6.12\doc\examples\.
>cd D:\tool\aspectj1.6.12\doc\examples\
>ajc -argfile telecom/billing.lst
>java telecom.BillingSimulation

3.2. Basic Techniques
Join Points and thisJoinPoint
(examples/tjp)
When using a pointcut that picks out join points of a single kind by name, typicaly the advice will know exactly what kind of join point it is associated with.
thisJoinPoint    JoinPoint
Object[] args = jp.getArgs();
String[] names = ((CodeSignature)jp.getSignature()).getParameterNames();
Class[] types = ((CodeSignature)jp.getSignature()).getParameterTypes();

cflow(this(Demo) && execution(void go()));
So that only executions made in the control flow of Demo.go are iintercepted. !execution(* go()) to exclude go itself.

Roles and Views
examples/introduction
Unlike advice, inter-type declarations affect not only the behavior of the application, but also the structural relationship between an application's classes.
The Point class -----> The CloneablePoint aspect
public aspect CloneablePoint{
...snip...
declare parents: Point implements Cloneable;
public Object Point.clone() throws CloneNotSupportedException{
makeRectangular();
makePolar();
return super.clone();
}
...snip...
}

The ComparablePoint aspect
The HashablePoint aspect

3.3. Development Aspects
Tracing using aspects
examples/tracing
Sometimes, tracing is one of those things that slows the system down, so these calls should often be pulled out of the system before the product is shipped.

3.4. Production Aspects
A Bean Aspect
examples/bean
The Point class ----> The BoundPoint aspect
...snip..
private PropertyChangeSupport Point.support = new PropertyChangeSupport(this);
...snip...
class Demo implements PropertyChangeListener
...snip...

The Subject/Observer Protocol
examples/observer

A Simple Telecom Simulation
examples/telecom

3.5. Reusable Aspects
Tracing using Aspects, Revisited

references:
http://www.eclipse.org/aspectj/doc/released/progguide/examples.html