1   /*
2    * AspectJTest - Quick look at AspectJ
3    * Copyright (C) 2007 Christian Schenk
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    * 
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18   */
19  package org.christianschenk.aspectjtest.aspects;
20  
21  import org.apache.log4j.Logger;
22  import org.aspectj.lang.JoinPoint;
23  import org.aspectj.lang.annotation.After;
24  import org.aspectj.lang.annotation.Around;
25  import org.aspectj.lang.annotation.Aspect;
26  import org.aspectj.lang.annotation.Before;
27  import org.aspectj.lang.annotation.Pointcut;
28  
29  @Aspect
30  public class AspectJAnnotation {
31  
32  	private static final Logger log = Logger.getLogger(AspectJAnnotation.class);
33  
34  	@Pointcut("execution(* org.christianschenk.*.Main.helloWorld())")
35  	public void helloWorld() {}
36  
37  	@Before("helloWorld()")
38  	public void beforeHelloWorld(final JoinPoint thisJoinPoint) {
39  		log.debug("Before: " + thisJoinPoint.getStaticPart().getSignature().getName());
40  	}
41  
42  	@After("helloWorld()")
43  	public void afterHelloWorld(final JoinPoint thisJoinPoint) {
44  		log.debug("After: " + thisJoinPoint.getStaticPart().getSignature().getName());
45  	}
46  
47  	@Around("execution(org.christianschenk.*.Main.new())")
48  	public void aroundMainConstructor(final JoinPoint thisJoinPoint) {
49  		log.debug("Around : " + thisJoinPoint.getStaticPart().getSignature().getName());
50  	}
51  }