1 /*
2 * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3 * the spring framework, http://el4j.sf.net
4 * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5 * 1000 Lausanne, Switzerland, http://www.elca.ch
6 *
7 * EL4J is published under the GNU Lesser General Public License (LGPL)
8 * Version 2.1. See http://www.gnu.org/licenses/
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 Lesser General Public License for more details.
14 *
15 * For alternative licensing, please contact info@elca.ch
16 */
17
18 package ch.elca.el4j.tests.services.exceptionhandler;
19
20 /**
21 * Sample bean class used for testing.
22 *
23 * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/exception_handling/src/test/java/ch/elca/el4j/tests/services/exceptionhandler/AImpl.java $
24 *
25 * @author Andreas Bur (ABU)
26 */
27 public class AImpl implements A {
28
29 /** Static int to count number of method invocations. */
30 public static int s_numberOfConcatCalls = 0;
31
32 /** Static field to set if the call should fail. */
33 public static boolean s_concatFails = true;
34
35 /** The adder to delegate calls to. */
36 private Adder m_adder;
37
38 /** Number of retires. */
39 // Checkstyle: MagicNumber off
40 private int m_retries = 4;
41 // Checkstyle: MagicNumber on
42
43 /** Resets the static counter. */
44 public static void reset() {
45 s_numberOfConcatCalls = 0;
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 public void setRetries(int retries) {
52 this.m_retries = retries;
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 public void setAdder(Adder adder) {
59 m_adder = adder;
60 s_concatFails = true;
61 }
62
63 /**
64 * {@inheritDoc}
65 */
66 public int div(int a, int b) {
67 return a / b;
68 }
69
70 /**
71 * {@inheritDoc}
72 */
73 public void throwException() throws ApplicationException {
74 throw new ApplicationException("Exception");
75 }
76
77 /**
78 * {@inheritDoc}
79 */
80 public void throwRTException() {
81 throw new RuntimeException();
82 }
83
84 /**
85 * {@inheritDoc}
86 */
87 public String concat(String a, String b) {
88 s_numberOfConcatCalls++;
89 if (s_concatFails) {
90 throw new UnsupportedOperationException();
91 } else {
92 return a.concat(b);
93 }
94 }
95
96 /**
97 * {@inheritDoc}
98 */
99 public int add(int a, int b) {
100 return m_adder.add(a, b);
101 }
102
103 /**
104 * {@inheritDoc}
105 */
106 public int sub(int a, int b) {
107 if (m_retries > 0) {
108 m_retries--;
109 throw new IllegalArgumentException();
110 }
111 return a - b;
112 }
113 }