KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > ffolder > 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.3 2004/12/17 15:09:45 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.ffolder;
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
40 /**
41  * Implementation for the bean PaperEC.
42  * @author Philippe Durieux, Philippe Coq
43  */

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

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

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

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

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