KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > session > AbstractSessionObject


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.ejb.session;
30
31 import com.caucho.ejb.AbstractEJBObject;
32 import com.caucho.ejb.AbstractServer;
33 import com.caucho.ejb.protocol.ObjectSkeletonWrapper;
34 import com.caucho.util.Log;
35
36 import javax.ejb.EJBHome JavaDoc;
37 import javax.ejb.EJBLocalHome JavaDoc;
38 import javax.ejb.EJBLocalObject JavaDoc;
39 import javax.ejb.EJBObject JavaDoc;
40 import javax.ejb.Handle JavaDoc;
41 import javax.ejb.SessionBean JavaDoc;
42 import java.io.ObjectStreamException JavaDoc;
43 import java.io.Serializable JavaDoc;
44 import java.rmi.RemoteException JavaDoc;
45 import java.util.logging.Level JavaDoc;
46 import java.util.logging.Logger JavaDoc;
47
48 /**
49  * Abstract base class for a session object
50  */

51 abstract public class AbstractSessionObject extends AbstractEJBObject
52   implements EJBObject, EJBLocalObject JavaDoc, Serializable JavaDoc
53 {
54   private static final Logger JavaDoc log = Log.open(AbstractSessionObject.class);
55   
56   public SessionBean JavaDoc _getObject()
57   {
58     throw new UnsupportedOperationException JavaDoc("_getObject is not implemented");
59   }
60
61   /**
62    * Returns the server.
63    */

64   abstract public AbstractServer getServer();
65
66   /**
67    * Returns the handle.
68    */

69   public Handle JavaDoc getHandle()
70   {
71     return getServer().getHandleEncoder().createHandle(__caucho_getId());
72   }
73   
74   /**
75    * Returns the EJBHome stub for the container.
76    */

77   public EJBHome JavaDoc getEJBHome()
78   {
79     try {
80       return getServer().getEJBHome();
81     } catch (Exception JavaDoc e) {
82       log.log(Level.FINE, e.toString(), e);
83       return null;
84     }
85   }
86   
87   /**
88    * Returns the EJBLocalHome stub for the container.
89    */

90   public EJBLocalHome JavaDoc getEJBLocalHome()
91   {
92     try {
93       return (EJBLocalHome JavaDoc) getServer().getEJBLocalHome();
94     } catch (Exception JavaDoc e) {
95       log.log(Level.FINE, e.toString(), e);
96       return null;
97     }
98   }
99
100   public Object JavaDoc getPrimaryKey()
101   {
102     throw new UnsupportedOperationException JavaDoc();
103   }
104
105   /**
106    * Returns the SessionBean's primary stub
107    */

108   public EJBObject getEJBObject()
109   {
110     return this;
111   }
112   
113   /**
114    * Returns the SessionBean's primary stub
115    */

116   public EJBLocalObject JavaDoc getEJBLocalObject()
117   {
118     return this;
119   }
120
121   /**
122    * Returns the server.
123    */

124   public AbstractServer __caucho_getServer()
125   {
126     return getServer();
127   }
128
129   /**
130    * The home id is null.
131    */

132   public String JavaDoc __caucho_getId()
133   {
134     return getServer().encodeId(getPrimaryKey());
135   }
136
137   /**
138    * Returns true if the two objects are identical.
139    */

140   public boolean isIdentical(EJBObject obj) throws RemoteException JavaDoc
141   {
142     System.out.println("GETH: " + getHandle() + " " + obj.getHandle());
143     
144     return getHandle().equals(obj.getHandle());
145   }
146
147   /**
148    * Returns true if the two objects are identical.
149    */

150   public boolean isIdentical(EJBLocalObject JavaDoc obj)
151   {
152     return this == obj;
153   }
154
155   /**
156    * Serialize the HomeSkeletonWrapper in place of this object.
157    *
158    * @return the matching skeleton wrapper.
159    */

160   public Object JavaDoc writeReplace() throws ObjectStreamException JavaDoc
161   {
162     return new ObjectSkeletonWrapper(getHandle());
163   }
164 }
165
Popular Tags