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.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Spring » PointcutScreenshots 
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.