All Kinds Of Pointcut : Pointcut « Spring « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Spring » Pointcut 
28. 56. 9. All Kinds Of Pointcut

File: context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx.xsd">

    <bean id="test" class="bean.TestBean2">
        <property name="simpleBean" ref="simple"/>
    </bean>
    <bean id="simple" class="bean.SimpleBean"/>
    <aop:config>
        <aop:advisor advice-ref="tx-advice"
                     pointcut="SystemPointcuts.testBeanExecution()"/>
    </aop:config>

    <bean id="transactionManager" class="NoopTransactionManager"/>

    <tx:advice id="tx-advice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED"/> 
        </tx:attributes>
    </tx:advice>
</beans>

File: Main.java

import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionStatus;

import bean.SimpleBean;
import bean.TestBean2;

public class Main {
  public static void main(String[] args) {
    ApplicationContext ac = new ClassPathXmlApplicationContext("context.xml");
    TestBean2 testBean = (TestBean2ac.getBean("test");
    SimpleBean simpleBean = (SimpleBeanac.getBean("simple");
    testBean.work();
    testBean.stop();
    simpleBean.sayHello();
    simpleBean.x("a""b");
  }
}
final class SystemPointcuts {
  private SystemPointcuts() {
  }

  @Pointcut("execution(* bean..*.*(..)) &&" +
          "!execution(* bean..*.set*(..)) &&" +
          "!execution(* bean..*.get*())")
  public void serviceExecution() { }

  @Pointcut("within(bean.TestBean2)")
  public void within1() { }

  @Pointcut("execution(* bean.TestBean2.*(..))")
  public void testBeanExecution() { }

  @Pointcut("execution(* bean.TestBean2.*(..))")
  private void testBeanExec() { }

  @Pointcut("execution(* bean..*.*(..))")
  public void inProsringPackage() { }

  @Pointcut("within(bean..*)")
  private void withinProSpringPackage() { }

  @Pointcut("execution(* bean.TestBean2.*(..)) &&" +
          "within(bean..*)")
  public void same1() { }

  @Pointcut("execution(* bean.TestBean2.*(..)) &&" +
          "withinProSpringPackage()")
  public void same2() { }

  @Pointcut("testBeanExec() && withinProSpringPackage()")
  public void same3() { }


  @Pointcut("within(bean.TestBean2)")
  public void fromTestBeanExecution() { }

  @Pointcut("this(bean.SimpleBean)")
  public void onlyFromSimpleBean() { }

  @Pointcut("target(bean.SimpleBean)")
  public void onlyToSimpleBean() { }

  @Pointcut("args(String, String)")
  public void onlyTwoStringArguments() { }

//  @Pointcut("bean(test)")
  public void beanName() { }
}
class NoopTransactionManager extends AbstractPlatformTransactionManager {

  protected Object doGetTransaction() throws TransactionException {
      return new Object();
  }

  protected void doBegin(Object object, TransactionDefinition transactionDefinitionthrows TransactionException {
      System.out.println("Begin");
  }

  protected void doCommit(DefaultTransactionStatus defaultTransactionStatusthrows TransactionException {
      System.out.println("Commit");
  }

  protected void doRollback(DefaultTransactionStatus defaultTransactionStatusthrows TransactionException {
      System.out.println("Rollback");
  }
}

File: SimpleBean.java

package bean;

public class SimpleBean {
  public void sayHello() {
    System.out.println("Hello");
  }

  public void x(CharSequence a, String b) {

  }

}

File: TestBean2.java

package bean;

public class TestBean2 {
  private SimpleBean simpleBean;

  public void work() {
    this.simpleBean.sayHello();
    System.out.println("work");
  }

  public void stop() {
    this.simpleBean.sayHello();
    System.out.println("stop");
  }

  public void setSimpleBean(SimpleBean simpleBean) {
    this.simpleBean = simpleBean;
  }
}
  Download:  Spring-AllKindsOfPointcut.zip( 4,652 k)
28. 56. Pointcut
28. 56. 1. Default Pointcut Advisor
28. 56. 2. Control Flow Pointcut
28. 56. 3. ComposablePointcut Union
28. 56. 4. ComposablePointcut Intersection
28. 56. 5. Class Filter In DynamicMethodMatcherPointcut
28. 56. 6. NameMatchMethodPointcutAdvisor
28. 56. 7. NameMatchMethodPointcut
28. 56. 8. Jdk Regexp based Method Pointcut
28. 56. 9. All Kinds Of Pointcut
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.