All Kinds Of Pointcut : Pointcut « Spring « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Spring » Pointcut 




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");
  }
}




           
       














Spring-AllKindsOfPointcut.zip( 4,652 k)
Related examples in the same category
1.Use NameMatchMethodPointcutAdvisor
2.Use NameMatchMethodPointcut
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.