001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: PaperEC.java 5996 2004-12-17 15:09:45Z joaninh $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.ffolder;
027:
028: import javax.ejb.EJBException;
029: import javax.ejb.EJBLocalHome;
030: import javax.ejb.EntityBean;
031: import javax.ejb.EntityContext;
032: import javax.ejb.CreateException;
033: import javax.ejb.RemoveException;
034: import javax.naming.Context;
035: import javax.naming.InitialContext;
036: import javax.naming.NamingException;
037: import javax.rmi.PortableRemoteObject;
038:
039: /**
040: * Implementation for the bean PaperEC.
041: * @author Philippe Durieux, Philippe Coq
042: */
043: public class PaperEC implements EntityBean {
044:
045: // static protected Logger logger = null;
046: EntityContext ejbContext;
047: InitialContext ictx;
048: Context myEnv;
049:
050: // ------------------------------------------------------------------
051: // State of the bean.
052: // They must be public for Container Managed Persistance.
053: // ------------------------------------------------------------------
054: public String name;
055: public int value;
056:
057: /**
058: * Check environment variables
059: */
060: void checkEnv(String method) {
061:
062: // Check directly in my context
063: // logger.log(BasicLevel.DEBUG, "Check directly in my context");
064: try {
065: String value = (String) myEnv.lookup("myname");
066: if (!value.equals("myentity")) {
067: //logger.log(BasicLevel.ERROR, ": myEnv.lookup failed: myname=" + value);
068: throw new EJBException("FileEC 1: " + method);
069: }
070: } catch (NamingException e) {
071: // logger.log(BasicLevel.ERROR, ": myEnv.lookup raised exception:\n" + e);
072: throw new EJBException("FileEC 2: " + method);
073: }
074: // Check from initial Context
075: //logger.log(BasicLevel.DEBUG, "Check from initial Context");
076: try {
077: String value = (String) ictx.lookup("java:comp/env/myname");
078: if (!value.equals("myentity")) {
079: //logger.log(BasicLevel.ERROR, ": ictx.lookup failed: myname=" + value);
080: throw new EJBException("FileEC 6: " + method);
081: }
082: } catch (NamingException e) {
083: //logger.log(BasicLevel.ERROR, ": ictx.lookup raised exception:\n" + e);
084: throw new EJBException("FileEC 7: " + method);
085: }
086: //logger.log(BasicLevel.DEBUG, ": checkEnv OK");
087: }
088:
089: // ------------------------------------------------------------------
090: // EntityBean implementation
091: // ------------------------------------------------------------------
092:
093: public void setEntityContext(EntityContext ctx) {
094: // if (logger == null) {
095: // logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
096: //}
097: //logger.log(BasicLevel.DEBUG, "");
098: ejbContext = ctx;
099: try {
100: // Get initial Context
101: ictx = new InitialContext();
102: myEnv = (Context) ictx.lookup("java:comp/env");
103: } catch (NamingException e) {
104: throw new EJBException("PaperEC: Cannot get filehome:" + e);
105: }
106: checkEnv("setEntityContext");
107:
108: // Check that we can do "getEJBLocalHome"
109: EJBLocalHome homel = ctx.getEJBLocalHome();
110: if (homel == null) {
111: throw new EJBException(
112: "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 {
138: // logger.log(BasicLevel.DEBUG, "");
139: }
140:
141: // ------------------------------------------------------------------
142: // ejbCreate methods
143: // ------------------------------------------------------------------
144:
145: public String ejbCreate(String name) throws CreateException {
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 ejbPostCreate(String name) throws CreateException {
153: //logger.log(BasicLevel.DEBUG, "");
154: return null; // In CMP, should return null.
155: }
156:
157: // ------------------------------------------------------------------
158: // PaperLocal implementation
159: // ------------------------------------------------------------------
160:
161: public String 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: }
|