KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > bean > CallingPOJO


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.bean;
23
24 import org.jboss.aop.Advised;
25
26 /**
27  *
28  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
29  * @version $Revision: 37406 $
30  */

31 public class CallingPOJO
32 {
33    POJO pojo;
34    NonadvisedPOJO nonpojo;
35
36    public CallingPOJO()
37    {
38       CallerInterceptor.called = false;
39       pojo = new POJO();
40       if (!CallerInterceptor.called)
41       {
42          throw new RuntimeException JavaDoc("constructor caller interceptor didn't work from within constructor");
43       }
44       CallerInterceptor.called = false;
45       pojo.someMethod();
46       if (!CallerInterceptor.called)
47       {
48          throw new RuntimeException JavaDoc("caller interceptor didn't work");
49       }
50       CallerInterceptor.called = false;
51       nonpojo = new NonadvisedPOJO("helloworld");
52       if (!CallerInterceptor.called)
53       {
54          throw new RuntimeException JavaDoc("constructor caller interceptor didn't work");
55       }
56       CallerInterceptor.called = false;
57       nonpojo.remoteTest();
58       if (!CallerInterceptor.called)
59       {
60          throw new RuntimeException JavaDoc("caller interceptor didn't work");
61       }
62       if (nonpojo instanceof Advised)
63       {
64          throw new RuntimeException JavaDoc("nonpojo is Advised when it shouldn't be");
65       }
66    }
67
68   /**
69    * This method should be a caller pointcut
70    */

71    public void callSomeMethod()
72    {
73       CallerInterceptor.called = false;
74       pojo = new POJO();
75       if (!CallerInterceptor.called)
76       {
77          throw new RuntimeException JavaDoc("constructor caller interceptor didn't work within method");
78       }
79       CallerInterceptor.called = false;
80       pojo.someMethod();
81       if (!CallerInterceptor.called)
82       {
83          throw new RuntimeException JavaDoc("caller interceptor didn't work");
84       }
85    }
86
87    /**
88     * This method should not be a caller pointcut
89     */

90    public void nocallSomeMethod()
91    {
92       CallerInterceptor.called = false;
93       pojo = new POJO();
94       if (CallerInterceptor.called)
95       {
96          throw new RuntimeException JavaDoc("constructor caller interceptor didn't work, interceptor was invoked when it shouldn't have been");
97       }
98       pojo.someMethod();
99       if (CallerInterceptor.called)
100       {
101          throw new RuntimeException JavaDoc("caller interceptor didn't work, caller interceptor was invoked when it shouldn't have been");
102       }
103    }
104
105    public void callUnadvised()
106    {
107       CallerInterceptor.called = false;
108       nonpojo = new NonadvisedPOJO("helloworld");
109       if (!CallerInterceptor.called)
110       {
111          throw new RuntimeException JavaDoc("consturctor caller interceptor didn't work");
112       }
113       CallerInterceptor.called = false;
114       nonpojo.remoteTest();
115       if (!CallerInterceptor.called)
116       {
117          throw new RuntimeException JavaDoc("caller interceptor didn't work");
118       }
119       if (nonpojo instanceof Advised)
120       {
121          throw new RuntimeException JavaDoc("nonpojo is Advised when it shouldn't be");
122       }
123    }
124
125 }
126
127
Popular Tags