01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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: * Initial developer(s): Sebastien Chassande
22: * Contributor(s):
23: *
24: * --------------------------------------------------------------------------
25: * $Id: JEntityContext.java 4408 2004-03-19 14:31:54Z sauthieg $
26: * --------------------------------------------------------------------------
27: */
28:
29: package org.objectweb.jonas_ejb.container.jorm;
30:
31: import javax.ejb.EntityBean;
32:
33: import org.objectweb.jonas_ejb.container.JEntityFactory;
34: import org.objectweb.jorm.naming.api.PName;
35:
36: /**
37: * This class extends the JEntityContext of the JOnAS container in order to take
38: * in consideration the fact that the container manages PName instances and not
39: * primary keys. This is the reason why the getPrimaryKey method is overriden.
40: *
41: * @author Sebastien Chassande-Barrioz
42: */
43: public class JEntityContext extends
44: org.objectweb.jonas_ejb.container.JEntityContext {
45:
46: public JEntityContext(JEntityFactory bf, EntityBean eb) {
47: super (bf, eb);
48: }
49:
50: /**
51: * Obtains the primary key of the EJB object that is currently associated
52: * with this instance.
53: * @return The EJB object currently associated with the instance.
54: * @exception IllegalStateException Thrown if the instance invokes this
55: * method while the instance is in a state that does not allow
56: * the instance to invoke this method.
57: */
58: public Object getPrimaryKey() throws IllegalStateException {
59: PName pn = (PName) super .getPrimaryKey();
60: Coder c = (Coder) bf.getLocalHome();
61: if (c == null) {
62: c = (Coder) bf.getHome();
63: }
64: try {
65: return c.encode(pn);
66: } catch (Exception e) {
67: throw new IllegalStateException("Inner: Encoding error:"
68: + e.getMessage());
69: }
70: }
71: }
|