001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.ejb.session;
030:
031: import com.caucho.ejb.AbstractEJBObject;
032: import com.caucho.ejb.AbstractServer;
033: import com.caucho.ejb.protocol.ObjectSkeletonWrapper;
034:
035: import javax.ejb.Handle;
036: import java.io.ObjectStreamException;
037: import java.io.Serializable;
038: import java.rmi.RemoteException;
039: import javax.ejb.*;
040:
041: /**
042: * Abstract base class for a stateful session object
043: */
044: abstract public class StatefulObject extends AbstractEJBObject
045: implements Serializable {
046: private String _primaryKey;
047:
048: /**
049: * Returns the server.
050: */
051: public AbstractServer getServer() {
052: return getStatefulServer();
053: }
054:
055: /**
056: * Returns the server which owns this bean.
057: */
058: @Override
059: public AbstractServer __caucho_getServer() {
060: return getStatefulServer();
061: }
062:
063: public abstract StatefulServer getStatefulServer();
064:
065: public String __caucho_getId() {
066: if (_primaryKey == null)
067: _primaryKey = getStatefulServer().createSessionKey(this );
068:
069: return _primaryKey;
070: }
071:
072: //
073: // EJB 2.1 methods
074: //
075:
076: /**
077: * Returns the primary key
078: */
079: public Object getPrimaryKey() {
080: return __caucho_getId();
081: }
082:
083: /**
084: * Returns the EJBHome
085: */
086: public EJBHome getEJBHome() {
087: return getServer().getEJBHome();
088: }
089:
090: /**
091: * Returns the EJBLocalHome
092: */
093: public EJBLocalHome getEJBLocalHome() {
094: return getServer().getEJBLocalHome();
095: }
096:
097: /**
098: * Returns the handle.
099: */
100: public Handle getHandle() {
101: return getServer().getHandleEncoder().createHandle(
102: __caucho_getId());
103: }
104:
105: /**
106: * Returns true if the two objects are identical.
107: */
108: public boolean isIdentical(EJBObject obj) throws RemoteException {
109: return getHandle().equals(obj.getHandle());
110: }
111:
112: /**
113: * Returns true if the two objects are identical.
114: */
115: public boolean isIdentical(EJBLocalObject obj) {
116: return this == obj;
117: }
118:
119: public void remove() throws javax.ejb.RemoveException {
120: }
121:
122: /**
123: * Serialize the HomeSkeletonWrapper in place of this object.
124: *
125: * @return the matching skeleton wrapper.
126: */
127: public Object writeReplace() throws ObjectStreamException {
128: return new ObjectSkeletonWrapper(getHandle());
129: }
130: }
|