KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > exception > ExceptionTesterBean


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.exception;
23
24 import java.rmi.RemoteException JavaDoc;
25 import java.security.InvalidKeyException JavaDoc;
26 import javax.ejb.CreateException JavaDoc;
27 import javax.ejb.EJBException JavaDoc;
28 import javax.ejb.SessionBean JavaDoc;
29 import javax.ejb.SessionContext JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31 import javax.naming.NameNotFoundException JavaDoc;
32 import javax.naming.NamingException JavaDoc;
33
34 /** Tests of exception propagation via remote and local interfaces
35  *
36  * @author Scott.Stark@jboss.org
37  * @version $Revision: 41274 $
38  */

39 public class ExceptionTesterBean implements SessionBean JavaDoc
40 {
41    private SessionContext JavaDoc ctx;
42
43    public void ejbCreate() throws CreateException JavaDoc
44    {
45       try
46       {
47          InitialContext JavaDoc ic = new InitialContext JavaDoc();
48          Boolean JavaDoc failInEjbCreate = (Boolean JavaDoc) ic.lookup("java:comp/env/failInEjbCreate");
49          if( failInEjbCreate.booleanValue() )
50             throw new CreateException JavaDoc("Failed in ejbCreate as requested");
51       }
52       catch(NameNotFoundException JavaDoc ignore)
53       {
54          // Assume failInEjbCreate = false
55
}
56       catch(NamingException JavaDoc e)
57       {
58          throw new CreateException JavaDoc("Failed to access ENC, "+e.getMessage());
59       }
60    }
61
62    public void applicationExceptionInTx() throws ApplicationException
63    {
64       throw new ApplicationException("Application exception from within " +
65          " an inherited transaction");
66    }
67
68    public void applicationErrorInTx()
69    {
70       throw new ApplicationError("Application error from within " +
71          " an inherited transaction");
72    }
73
74    public void ejbExceptionInTx()
75    {
76       throw new EJBException JavaDoc("EJB exception from within " +
77          " an inherited transaction");
78    }
79
80    public void runtimeExceptionInTx()
81    {
82       throw new RuntimeException JavaDoc("Runtime exception from within " +
83          " an inherited transaction");
84    }
85
86    public void remoteExceptionInTx() throws RemoteException JavaDoc
87    {
88       throw new RemoteException JavaDoc("Remote exception from within " +
89          " an inherited transaction");
90    }
91
92    public void applicationExceptionNewTx() throws ApplicationException
93    {
94       throw new ApplicationException("Application exception from within " +
95          " a new container transaction");
96    }
97
98    public void applicationErrorNewTx()
99    {
100       throw new ApplicationError("Application error from within " +
101          " an inherited transaction");
102    }
103
104    public void ejbExceptionNewTx()
105    {
106       throw new EJBException JavaDoc("EJB exception from within " +
107          " a new container transaction");
108    }
109
110    public void runtimeExceptionNewTx()
111    {
112       throw new RuntimeException JavaDoc("Runtime exception from within " +
113          " a new container transaction");
114    }
115
116    public void remoteExceptionNewTx() throws RemoteException JavaDoc
117    {
118       throw new RemoteException JavaDoc("Remote exception from within " +
119          " a new container transaction");
120    }
121
122    public void applicationExceptionNoTx() throws ApplicationException
123    {
124       throw new ApplicationException("Application exception without " +
125          " a transaction");
126    }
127
128    public void applicationErrorNoTx()
129    {
130       throw new ApplicationError("Application error from within " +
131          " an inherited transaction");
132    }
133
134    public void ejbExceptionNoTx()
135    {
136       throw new EJBException JavaDoc("EJB exception without " +
137          " a transaction");
138    }
139
140    public void runtimeExceptionNoTx()
141    {
142       throw new RuntimeException JavaDoc("Runtime exception without " +
143          " a transaction");
144    }
145
146    public void remoteExceptionNoTx() throws RemoteException JavaDoc
147    {
148       throw new RemoteException JavaDoc("Remote exception without " +
149          " a transaction");
150    }
151
152    public void securityExceptionByAppNoTx()
153          throws InvalidKeyException JavaDoc
154    {
155       // This exception should be propagated as is
156
throw new InvalidKeyException JavaDoc("securityExceptionByAppNoTx");
157    }
158
159    public void securityExceptionNoTx()
160    {
161       // The method permissions should cause the security exception
162
}
163
164    public void setSessionContext(SessionContext JavaDoc ctx)
165    {
166       this.ctx = ctx;
167    }
168
169    public void ejbActivate()
170    {
171    }
172
173    public void ejbPassivate()
174    {
175    }
176
177    public void ejbRemove()
178    {
179    }
180 }
181
Popular Tags