## page was renamed from Cytoscape_3.0/Developer/AOP
## page was renamed from Cytoscape_3.0/AOP
= AOP on Spring DM =
== Intro ==
This is a quick introduction how to use Aspect Oriented Programming feature in Spring.
=== Setup ===
You need the following bundles to use AspectJ style AOP on Spring DM:
{{{
org.aspectj
com.springsource.org.aspectj.weaver
1.6.3.RELEASE
org.aspectj
com.springsource.org.aspectj.runtime
1.6.3.RELEASE
net.sourceforge.cglib
com.springsource.net.sf.cglib
2.1.3
}}}
Also, do not forget dependency for Spring AOP feature:
{{{
org.aopalliance
com.springsource.org.aopalliance
1.0.0
org.springframework
spring-aop
2.5.5
}}}
=== BND setting ===
AOP features call some of the classes implicitly. Even if you include the dependency above in your pom.xml, BND tool cannot create correct ''Import-Package'' section for your manifest file. You need to write the AOP dependency explicitly like the following:
{{{
Import-Package: *
DynamicImport-Package: org.aspectj.*, org.springframework.aop.*, net.sf.cglib.*, org.aopalliance.*
Private-Package: org.cytoscape.io.read.internal.*,org.cytoscape.io.write.internal.*, org.cytoscape.io.internal.*
}}}
Now you are ready to use AOP on Spring DM.
=== Example ===
First, write a very simple aspect:
{{{#!java
package org.cytoscape.io.internal.aspects;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class SimpleAspect {
long start;
@Before("execution(* read*(..))")
public void testAspect(JoinPoint joinPoint) {
System.out.println("=========== Performance test for "
+ joinPoint.getSignature().toLongString() + " ==============");
start = System.currentTimeMillis();
}
@After("execution(* read*(..))")
public void testAspect2(JoinPoint joinPoint) {
long time = System.currentTimeMillis() - start;
System.out.println("=========== Loading time = " + time
+ " msec. ==============");
}
}
}}}
This aspect means the two methods in the class will be called every time method begin with "read" are executed.
In the bean definition file, you need to define this aspect as a bean. Name for the aspect bean is optional.
{{{
...
}}}
=== Issues ===
(not finished yet)