KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > remon > MainEC2


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: MainEC2.java,v 1.3 2004/12/17 11:05:12 camillej Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.relation.remon;
27
28 import javax.ejb.CreateException JavaDoc;
29 import javax.ejb.DuplicateKeyException JavaDoc;
30 import javax.ejb.EJBException JavaDoc;
31 import javax.ejb.EntityContext JavaDoc;
32 import javax.ejb.FinderException 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.BasicLevel;
41 import org.objectweb.util.monolog.api.Logger;
42
43 /**
44  * @author Ph Durieux
45  */

46 public abstract class MainEC2 implements javax.ejb.EntityBean JavaDoc {
47
48     private AttributeHome attrhome = null;
49
50     // ------------------------------------------------------------------
51
// Get and Set accessor methods of the bean's abstract schema
52
// ------------------------------------------------------------------
53
public abstract String JavaDoc getId();
54     public abstract void setId(String JavaDoc id);
55     public abstract String JavaDoc getPf1();
56     public abstract void setPf1(String JavaDoc pf1);
57
58     public abstract Attribute getAttr();
59     public abstract void setAttr(Attribute a);
60
61     // ------------------------------------------------------------------
62
// EntityBean implementation
63
// ------------------------------------------------------------------
64

65     static protected Logger logger = null;
66     EntityContext JavaDoc ejbContext;
67
68     /**
69      * Create a new instance with:
70      * @param id the primary key
71      * @param pf1 value cmp field
72      * @param att foreign key attribute
73      * @throws CreateException Failure to create an entity EJB object.
74      * @throws DuplicateKeyException An object with the same key already exists.
75      */

76     public String JavaDoc ejbCreate(String JavaDoc id, String JavaDoc pf1, String JavaDoc att) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
77         logger.log(BasicLevel.DEBUG, "");
78
79         // Init here the bean fields
80
setId(id);
81         setPf1(pf1);
82
83         // In CMP, should return null.
84
return null;
85     }
86
87     /**
88      * Make here the relations between ejbs
89      * @throws CreateException Failure to create the attribute
90      */

91     public void ejbPostCreate(String JavaDoc id, String JavaDoc pf1, String JavaDoc aname) throws CreateException JavaDoc {
92         logger.log(BasicLevel.DEBUG, "id=" + id);
93         Attribute attr = attrhome.create(aname);
94         setAttr(attr);
95     }
96
97     /**
98      * Set the associated entity context. The container invokes this method
99      * on an instance after the instance has been created.
100      * This method is called in an unspecified transaction context.
101      *
102      * @param ctx - An EntityContext interface for the instance. The instance
103      * should store the reference to the context in an instance variable.
104      * @throws EJBException Thrown by the method to indicate a failure caused by a
105      * system-level error.
106      */

107     public void setEntityContext(EntityContext JavaDoc ctx) {
108         if (logger == null)
109             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
110         logger.log(BasicLevel.DEBUG, "");
111         ejbContext = ctx;
112         try {
113             Context JavaDoc ictx = new InitialContext JavaDoc();
114             attrhome = (AttributeHome) PortableRemoteObject.narrow(ictx.lookup("java:comp/env/ejb/attribute"), AttributeHome.class);
115         } catch (NamingException JavaDoc e) {
116             throw new EJBException JavaDoc("Impossible to get AttributeHome:", e);
117         }
118     }
119
120     /**
121      * Unset the associated entity context. The container calls this method
122      * before removing the instance.
123      * This is the last method that the container invokes on the instance.
124      * The Java garbage collector will eventually invoke the finalize() method
125      * on the instance.
126      * This method is called in an unspecified transaction context.
127      *
128      * @throws EJBException Thrown by the method to indicate a failure caused by a
129      * system-level error.
130      */

131     public void unsetEntityContext() {
132         logger.log(BasicLevel.DEBUG, "");
133         ejbContext = null;
134     }
135
136     /**
137      * A container invokes this method before it removes the EJB object
138      * that is currently associated with the instance. This method is
139      * invoked when a client invokes a remove operation on the enterprise Bean's
140      * home interface or the EJB object's remote interface. This method
141      * transitions the instance from the ready state to the pool of available
142      * instances.
143      *
144      * This method is called in the transaction context of the remove operation.
145      * @throws RemoveException The enterprise Bean does not allow destruction of the object.
146      * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
147      * error.
148      */

149     public void ejbRemove() throws RemoveException JavaDoc {
150         logger.log(BasicLevel.DEBUG, "");
151         getAttr().remove();
152     }
153
154     /**
155      * A container invokes this method to instruct the instance to synchronize
156      * its state by loading it state from the underlying database.
157      * This method always executes in the proper transaction context.
158      *
159      * @throws EJBException Thrown by the method to indicate a failure caused by
160      * a system-level error.
161      */

162     public void ejbLoad() {
163         logger.log(BasicLevel.DEBUG, "");
164     }
165
166     /**
167      * A container invokes this method to instruct the instance to synchronize
168      * its state by storing it to the underlying database.
169      * This method always executes in the proper transaction context.
170      *
171      * @throws EJBException Thrown by the method to indicate a failure caused by
172      * a system-level error.
173      */

174     public void ejbStore() {
175         logger.log(BasicLevel.DEBUG, "");
176     }
177
178     /**
179      * A container invokes this method on an instance before the instance
180      * becomes disassociated with a specific EJB object.
181      */

182     public void ejbPassivate() {
183         logger.log(BasicLevel.DEBUG, "");
184     }
185
186     /**
187      * A container invokes this method when the instance is taken out of
188      * the pool of available instances to become associated with a specific
189      * EJB object.
190      */

191     public void ejbActivate() {
192         logger.log(BasicLevel.DEBUG, "");
193     }
194
195 }
196
Popular Tags