KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > args > Aspect


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

33 public class Aspect implements PojoInterface
34 {
35    public static boolean echoCalled = false;
36
37    public String JavaDoc echo(String JavaDoc arg)
38    {
39       echoCalled = true;
40
41       if (!arg.equals("hello")) throw new RuntimeException JavaDoc("Args don't match");
42
43       try
44       {
45          return (String JavaDoc) CurrentInvocation.proceed();
46       }
47       catch (Throwable JavaDoc throwable)
48       {
49          throw new RuntimeException JavaDoc(throwable);
50       }
51    }
52
53    public static boolean wrapped = false;
54
55    public Object JavaDoc wrap(MethodInvocation invocation) throws Throwable JavaDoc
56    {
57       wrapped = true;
58       return invocation.invokeNext();
59    }
60
61    public static boolean args = false;
62
63    public Object JavaDoc bunchArgs(int x, double y, float z, String JavaDoc str, int q) throws Throwable JavaDoc
64    {
65       args = true;
66       return CurrentInvocation.proceed();
67    }
68
69    public static boolean argsWithInvocation = false;
70
71    public Object JavaDoc bunchArgsWithInvocation(MethodInvocation invocation, int x, double y, float z, String JavaDoc str, int q) throws Throwable JavaDoc
72    {
73       argsWithInvocation = true;
74       return invocation.invokeNext();
75    }
76
77
78    public static boolean bunchCalled = false;
79
80    public int bunch(int x, double y, float z, String JavaDoc str, int q)
81    {
82       bunchCalled = true;
83
84       if (x != 1 && y != 2.2 && z != 3.3F && !str.equals("four") && q != 5)
85       {
86          throw new RuntimeException JavaDoc("Arguments don't match");
87       }
88       try
89       {
90          return ((Integer JavaDoc) CurrentInvocation.proceed()).intValue();
91       }
92       catch (Throwable JavaDoc throwable)
93       {
94          throw new RuntimeException JavaDoc(throwable);
95       }
96    }
97
98    public static boolean arg1Called = false;
99
100    public Object JavaDoc arg1(int x) throws Throwable JavaDoc
101    {
102       arg1Called = true;
103
104       if (x != 1) throw new RuntimeException JavaDoc("Args don't match");
105       return CurrentInvocation.proceed();
106    }
107
108    public static boolean arg2Called = false;
109
110    public Object JavaDoc arg2(double y) throws Throwable JavaDoc
111    {
112       arg2Called = true;
113
114       if (y != 2.2) throw new RuntimeException JavaDoc("Args don't match");
115       return CurrentInvocation.proceed();
116    }
117
118    public static boolean arg3Called = false;
119
120    public Object JavaDoc arg3(float z) throws Throwable JavaDoc
121    {
122       arg3Called = true;
123
124       if (z != 3.3F) throw new RuntimeException JavaDoc("Args don't match for arg3: " + z);
125       return CurrentInvocation.proceed();
126    }
127
128    public static boolean arg4Called = false;
129
130    public Object JavaDoc arg4(String JavaDoc str) throws Throwable JavaDoc
131    {
132       arg4Called = true;
133
134       if (!str.equals("four")) throw new RuntimeException JavaDoc("Args don't match");
135       return CurrentInvocation.proceed();
136    }
137
138    public static boolean arg15Called = false;
139
140    public Object JavaDoc arg15(int x, int q) throws Throwable JavaDoc
141    {
142       arg15Called = true;
143
144       if (x != 1 && q != 5) throw new RuntimeException JavaDoc("Args don't match");
145       return CurrentInvocation.proceed();
146    }
147
148    public static boolean arg24Called = false;
149
150    public Object JavaDoc arg24(double y, String JavaDoc str) throws Throwable JavaDoc
151    {
152       arg24Called = true;
153
154       if (y != 2.2 && !str.equals("four")) throw new RuntimeException JavaDoc("Args don't match");
155       return CurrentInvocation.proceed();
156    }
157 }
158
Popular Tags