KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > ebasic > SimpleEC2


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SimpleEC2.java,v 1.7 2004/11/30 15:29:14 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.ebasic;
27
28 import java.rmi.RemoteException JavaDoc;
29 import javax.ejb.CreateException JavaDoc;
30 import javax.ejb.EntityBean JavaDoc;
31 import javax.ejb.EntityContext JavaDoc;
32 import javax.ejb.RemoveException JavaDoc;
33
34 import org.objectweb.jonas.common.Log;
35 import org.objectweb.util.monolog.api.BasicLevel;
36 import org.objectweb.util.monolog.api.Logger;
37
38
39 /**
40  * This is an entity bean with "container managed persistence version 2.x".
41  * The state of an instance is stored into a relational database.
42  * The following table should exist :
43  * ebasicSimpleEC2
44  * c_testname varchar(30) primarey key
45  * c_info integer
46  * c_numtest integer
47  * @author Philippe Coq, Philippe Durieux, Helene Joanin
48  */

49
50 public abstract class SimpleEC2 implements EntityBean JavaDoc {
51
52     static protected Logger logger = null;
53
54     protected EntityContext JavaDoc entityContext;
55
56
57     // Get and Set accessor methods of the bean's abstract schema
58
public abstract int getInfo();
59     public abstract void setInfo(int info);
60
61     public abstract int getNumTest();
62     public abstract void setNumTest(int numtest);
63
64     public abstract String JavaDoc getTestName();
65     public abstract void setTestName(String JavaDoc testname);
66
67
68     public void ejbActivate() {
69         logger.log(BasicLevel.DEBUG, "");
70     }
71
72     public void ejbPassivate() {
73         logger.log(BasicLevel.DEBUG, "");
74     }
75
76     public void ejbLoad() {
77         logger.log(BasicLevel.DEBUG, "");
78     }
79
80     public void ejbStore() {
81         logger.log(BasicLevel.DEBUG, "");
82     }
83   
84     public void ejbRemove() throws RemoveException JavaDoc {
85         logger.log(BasicLevel.DEBUG, "");
86     }
87
88     public void setEntityContext(EntityContext JavaDoc ctx) {
89         if (logger == null)
90             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
91         logger.log(BasicLevel.DEBUG, "");
92         entityContext = ctx;
93     
94     }
95
96     public void unsetEntityContext() {
97         logger.log(BasicLevel.DEBUG, "");
98     }
99
100     public String JavaDoc ejbCreate(String JavaDoc name, int info, int num) throws CreateException JavaDoc {
101         logger.log(BasicLevel.DEBUG, "create"+info+","+name+","+num);
102         setInfo(info);
103         setNumTest(num);
104         setTestName(name);
105         return(null);
106     }
107
108     public void ejbPostCreate(String JavaDoc name, int info, int num) {
109         logger.log(BasicLevel.DEBUG, "");
110     }
111
112     /**
113      * loop back on the same bean instance.
114      * This is forbidden when bean is non reentrant.
115      * @return true if test passed.
116      * @throws RemoteException
117      */

118     public boolean loopBack() throws RemoteException JavaDoc {
119         logger.log(BasicLevel.DEBUG, "");
120         boolean pass = false;
121         Simple myref = (Simple) entityContext.getEJBObject();
122         try {
123             myref.getNumTest();
124         } catch (RemoteException JavaDoc e) {
125             logger.log(BasicLevel.DEBUG, "expected exception:" + e);
126             pass = true;
127         }
128         return pass;
129     }
130
131     /**
132      * loop back on the same bean instance.
133      * This is forbidden when bean is non reentrant.
134      * @return true if test passed.
135      * @throws RemoteException
136      */

137     public boolean loopBackTx() throws RemoteException JavaDoc {
138         logger.log(BasicLevel.DEBUG, "");
139         boolean pass = false;
140         Simple myref = (Simple) entityContext.getEJBObject();
141         try {
142             myref.getNumTest();
143         } catch (RemoteException JavaDoc e) {
144             logger.log(BasicLevel.DEBUG, "expected exception:" + e);
145             pass = true;
146         }
147         return pass;
148     }
149     
150     /**
151      * Check the set of allowed operations
152      * See EJB 2.1 spec - 12.1.6
153      */

154     public void ejbHomeGlobalOpe() throws RemoteException JavaDoc {
155         logger.log(BasicLevel.DEBUG, "");
156         if (entityContext == null) {
157             throw new RemoteException JavaDoc("null entityContext");
158         }
159         entityContext.getEJBHome();
160         // This bean has no local interface
161
try {
162             entityContext.getEJBLocalHome();
163         } catch (IllegalStateException JavaDoc e) {
164         }
165         entityContext.getCallerPrincipal();
166         entityContext.getRollbackOnly();
167         entityContext.isCallerInRole("role");
168         entityContext.getTimerService();
169     }
170 }
171
Popular Tags