KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > folder > PaperEC


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: PaperEC.java,v 1.5 2004/12/17 15:08:35 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.folder;
27
28 import javax.ejb.EJBException JavaDoc;
29 import javax.ejb.EJBLocalHome JavaDoc;
30 import javax.ejb.EntityBean JavaDoc;
31 import javax.ejb.EntityContext JavaDoc;
32 import javax.ejb.CreateException JavaDoc;
33 import javax.ejb.RemoveException JavaDoc;
34 import javax.naming.Context JavaDoc;
35 import javax.naming.InitialContext JavaDoc;
36 import javax.naming.NamingException JavaDoc;
37 import javax.rmi.PortableRemoteObject JavaDoc;
38
39 import org.objectweb.jonas.common.Log;
40 import org.objectweb.util.monolog.api.Logger;
41 import org.objectweb.util.monolog.api.BasicLevel;
42
43 /**
44  * Implementation for the bean PaperEC.
45  * @author Philippe Durieux, Philippe Coq
46  */

47 public class PaperEC implements EntityBean JavaDoc {
48
49     static protected Logger logger = null;
50     EntityContext JavaDoc ejbContext;
51     InitialContext JavaDoc ictx;
52     Context JavaDoc myEnv;
53
54     // ------------------------------------------------------------------
55
// State of the bean.
56
// They must be public for Container Managed Persistance.
57
// ------------------------------------------------------------------
58
public String JavaDoc name;
59     public int value;
60
61     /**
62      * Check environment variables
63      */

64     void checkEnv(String JavaDoc method) {
65
66         // Check directly in my context
67
logger.log(BasicLevel.DEBUG, "Check directly in my context");
68         try {
69             String JavaDoc value = (String JavaDoc) myEnv.lookup("myname");
70             if (!value.equals("myentity")) {
71                 logger.log(BasicLevel.ERROR, ": myEnv.lookup failed: myname=" + value);
72                 throw new EJBException JavaDoc("FileEC 1: " + method);
73             }
74         } catch (NamingException JavaDoc e) {
75             logger.log(BasicLevel.ERROR, ": myEnv.lookup raised exception:\n" + e);
76             throw new EJBException JavaDoc("FileEC 2: " + method);
77         }
78         // Check from initial Context
79
logger.log(BasicLevel.DEBUG, "Check from initial Context");
80         try {
81             String JavaDoc value = (String JavaDoc) ictx.lookup("java:comp/env/myname");
82             if (!value.equals("myentity")) {
83                 logger.log(BasicLevel.ERROR, ": ictx.lookup failed: myname=" + value);
84                 throw new EJBException JavaDoc("FileEC 6: " + method);
85             }
86         } catch (NamingException JavaDoc e) {
87             logger.log(BasicLevel.ERROR, ": ictx.lookup raised exception:\n" + e);
88             throw new EJBException JavaDoc("FileEC 7: " + method);
89         }
90         logger.log(BasicLevel.DEBUG, ": checkEnv OK");
91     }
92
93     // ------------------------------------------------------------------
94
// EntityBean implementation
95
// ------------------------------------------------------------------
96

97     public void setEntityContext(EntityContext JavaDoc ctx) {
98         if (logger == null) {
99             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
100         }
101         logger.log(BasicLevel.DEBUG, "");
102         ejbContext = ctx;
103         try {
104             // Get initial Context
105
ictx = new InitialContext JavaDoc();
106             myEnv = (Context JavaDoc) ictx.lookup("java:comp/env");
107         } catch (NamingException JavaDoc e) {
108             throw new EJBException JavaDoc("PaperEC: Cannot get filehome:" + e);
109         }
110         checkEnv("setEntityContext");
111
112         // Check that we can do "getEJBLocalHome"
113
EJBLocalHome JavaDoc homel = ctx.getEJBLocalHome();
114         if (homel == null) {
115             throw new EJBException JavaDoc("PaperEC: setEntityContext cannot get EJBLocalHome");
116         }
117     }
118
119     public void unsetEntityContext() {
120         logger.log(BasicLevel.DEBUG, "");
121         ejbContext = null;
122     }
123
124     public void ejbActivate() {
125         logger.log(BasicLevel.DEBUG, "");
126     }
127
128     public void ejbPassivate() {
129         logger.log(BasicLevel.DEBUG, "");
130     }
131
132     public void ejbLoad() {
133         logger.log(BasicLevel.DEBUG, "");
134     }
135
136     public void ejbStore() {
137         logger.log(BasicLevel.DEBUG, "");
138     }
139   
140     public void ejbRemove() throws RemoveException JavaDoc {
141         logger.log(BasicLevel.DEBUG, "");
142     }
143
144     // ------------------------------------------------------------------
145
// ejbCreate methods
146
// ------------------------------------------------------------------
147

148     public String JavaDoc ejbCreate(String JavaDoc name) throws CreateException JavaDoc {
149         logger.log(BasicLevel.DEBUG, "");
150         this.name = name;
151         this.value = 0;
152         return null; // In CMP, should return null.
153
}
154
155     public String JavaDoc ejbPostCreate(String JavaDoc name) throws CreateException JavaDoc {
156         logger.log(BasicLevel.DEBUG, "");
157         return null; // In CMP, should return null.
158
}
159
160     // ------------------------------------------------------------------
161
// PaperLocal implementation
162
// ------------------------------------------------------------------
163

164     public String JavaDoc getName() {
165         logger.log(BasicLevel.DEBUG, "");
166         return this.name;
167     }
168
169     public int getValue() {
170         logger.log(BasicLevel.DEBUG, "");
171         return this.value;
172     }
173
174     public void setValue(int v) {
175         logger.log(BasicLevel.DEBUG, "");
176         this.value = v;
177     }
178 }
179
180
Popular Tags