KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > annotated > AspectPerVM


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.aop.annotated;
23
24 import org.jboss.aop.joinpoint.ConstructorInvocation;
25 import org.jboss.aop.joinpoint.FieldReadInvocation;
26 import org.jboss.aop.joinpoint.FieldWriteInvocation;
27 import org.jboss.aop.joinpoint.Invocation;
28 import org.jboss.aop.joinpoint.MethodInvocation;
29 import org.jboss.aop.pointcut.Pointcut;
30
31 /**
32  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
33  * @version $Revision: 37406 $
34  * @@org.jboss.aop.Aspect (scope=org.jboss.aop.advice.Scope.PER_VM)
35  */

36 public class AspectPerVM
37 {
38    public int constructorCalled;
39    public int methodCalled;
40    public int fieldRead;
41    public int fieldWrite;
42    public int anotherPOJOAccess;
43    
44    /**
45     * @@org.jboss.aop.PointcutDef ("execution(org.jboss.test.aop.annotated.AnotherPOJO->new(..))")
46     */

47    public static Pointcut anotherPOJOConstructors;
48    
49    /**
50     * @@org.jboss.aop.PointcutDef ("get(* org.jboss.test.aop.annotated.AnotherPOJO->field)")
51     */

52    public static Pointcut anotherPOJOFieldReads;
53
54    /**
55     * @@org.jboss.aop.PointcutDef ("set(* org.jboss.test.aop.annotated.AnotherPOJO->field)")
56     */

57    public static Pointcut anotherPOJOFieldWrites;
58    
59    /**
60     * @@org.jboss.aop.PointcutDef ("execution(* org.jboss.test.aop.annotated.AnotherPOJO->*(..))")
61     */

62    public static Pointcut anotherPOJOPublicMethods;
63
64    /**
65     * @@org.jboss.aop.PointcutDef ("org.jboss.test.aop.annotated.AspectPerVM.anotherPOJOFieldWrites OR org.jboss.test.aop.annotated.AspectPerVM.anotherPOJOFieldReads")
66     */

67    public static Pointcut anotherPOJOFields;
68
69    /**
70     * @@org.jboss.aop.Prepare ("all(org.jboss.test.aop.annotated.PreparePOJO)")
71     */

72    public static Pointcut preparePOJO;
73    
74    /**
75     * @@org.jboss.aop.Bind (pointcut="execution(org.jboss.test.aop.annotated.POJO*->new())")
76     */

77    public Object JavaDoc constructorAdvice(ConstructorInvocation invocation) throws Throwable JavaDoc
78    {
79       System.out.println("AspectPerVM.constructorAdvice accessing: " + invocation.getConstructor().toString());
80       constructorCalled++;
81       return invocation.invokeNext();
82    }
83
84    /**
85     * @@org.jboss.aop.Bind (pointcut="execution(void org.jboss.test.aop.annotated.POJO*->someMethod())")
86     */

87    public Object JavaDoc methodAdvice(MethodInvocation invocation) throws Throwable JavaDoc
88    {
89       System.out.println("AspectPerVM.methodAdvice accessing: " + invocation.getMethod().toString());
90       methodCalled++;
91       return invocation.invokeNext();
92    }
93
94    /**
95     * @@org.jboss.aop.Bind (pointcut="set(* org.jboss.test.aop.annotated.POJO*->field)")
96     */

97    public Object JavaDoc fieldAdvice(FieldWriteInvocation invocation) throws Throwable JavaDoc
98    {
99       System.out.println("AspectPerVM.fieldAdvice writing to field: " + invocation.getField().getName());
100       fieldWrite++;
101       return invocation.invokeNext();
102    }
103
104    /**
105     * @@org.jboss.aop.Bind (pointcut="get(* org.jboss.test.aop.annotated.POJO*->field)")
106     */

107    public Object JavaDoc fieldAdvice(FieldReadInvocation invocation) throws Throwable JavaDoc
108    {
109       System.out.println("AspectPerVM.fieldAdvice reading field: " + invocation.getField().getName());
110       fieldRead++;
111       return invocation.invokeNext();
112    }
113
114    /**
115     * @@org.jboss.aop.Bind (pointcut = "org.jboss.test.aop.annotated.AspectPerVM.anotherPOJOFields OR org.jboss.test.aop.annotated.AspectPerVM.anotherPOJOConstructors OR org.jboss.test.aop.annotated.AspectPerVM.anotherPOJOPublicMethods")
116     */

117    public Object JavaDoc anotherPOJOAdvice(Invocation invocation) throws Throwable JavaDoc
118    {
119       System.out.println("AspectPerVM.anotherPOJOAdvice");
120       anotherPOJOAccess++;
121       return invocation.invokeNext();
122    }
123    
124    public void reset()
125    {
126       constructorCalled = 0;
127       methodCalled = 0;
128       fieldRead = 0;
129       fieldWrite = 0;
130       anotherPOJOAccess = 0;
131    }
132
133 }
134
Popular Tags