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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.ejb.session;
031:
032: import com.caucho.ejb.*;
033: import com.caucho.ejb.protocol.*;
034:
035: import java.util.logging.*;
036: import java.io.*;
037: import java.rmi.*;
038: import javax.ejb.*;
039:
040: /**
041: * Abstract base class for a 3.0 session object
042: */
043: abstract public class StatelessObject extends AbstractEJBObject
044: implements EJBLocalObject, EJBObject {
045: private static final Logger log = Logger
046: .getLogger(StatelessObject.class.getName());
047:
048: protected final StatelessServer _server;
049: protected final Class _api;
050:
051: protected StatelessObject(StatelessServer server, Class api) {
052: _server = server;
053: _api = api;
054: }
055:
056: /**
057: * Returns the stateless server.
058: */
059: public StatelessServer getStatelessServer() {
060: return _server;
061: }
062:
063: /**
064: * Returns the stateless server.
065: */
066: public AbstractServer getServer() {
067: return _server;
068: }
069:
070: /*
071: * Returns the handle.
072: */
073: public Handle getHandle() {
074: return getServer().getHandleEncoder().createHandle(
075: __caucho_getId());
076: }
077:
078: /**
079: * Returns the EJBHome stub for the container.
080: */
081: public EJBHome getEJBHome() {
082: try {
083: return getServer().getEJBHome();
084: } catch (Exception e) {
085: log.log(Level.FINE, e.toString(), e);
086: return null;
087: }
088: }
089:
090: /**
091: * Returns the EJBLocalHome stub for the container.
092: */
093: public EJBLocalHome getEJBLocalHome() {
094: try {
095: return (EJBLocalHome) getServer().getEJBLocalHome();
096: } catch (Exception e) {
097: log.log(Level.FINE, e.toString(), e);
098: return null;
099: }
100: }
101:
102: public Object getPrimaryKey() {
103: throw new UnsupportedOperationException();
104: }
105:
106: /**
107: * Returns the SessionBean's primary stub
108: */
109: public EJBObject getEJBObject() {
110: return this ;
111: }
112:
113: /**
114: * Returns the SessionBean's primary stub
115: */
116: public EJBLocalObject getEJBLocalObject() {
117: return this ;
118: }
119:
120: /**
121: * Returns the server.
122: */
123: public AbstractServer __caucho_getServer() {
124: return getServer();
125: }
126:
127: /**
128: * The home id is null.
129: */
130: public String __caucho_getId() {
131: return "::ejb:stateless";
132: }
133:
134: //
135: // EJB 2.1 methods
136: //
137:
138: /**
139: * Returns true if the two objects are identical.
140: */
141: public boolean isIdentical(EJBObject obj) throws RemoteException {
142: return getHandle().equals(obj.getHandle());
143: }
144:
145: /**
146: * Returns true if the two objects are identical.
147: */
148: public boolean isIdentical(EJBLocalObject obj) {
149: return this == obj;
150: }
151:
152: /**
153: * Serialize the HomeSkeletonWrapper in place of this object.
154: *
155: * @return the matching skeleton wrapper.
156: */
157: public Object writeReplace() throws ObjectStreamException {
158: return _server.getObjectHandle(this , _api);
159: }
160:
161: public void remove() throws javax.ejb.RemoveException {
162: }
163: }
|