1 26 27 package com.caucho.ejb.protocol; 28 29 import com.caucho.ejb.AbstractContext; 30 import com.caucho.ejb.AbstractEJBObject; 31 import com.caucho.ejb.AbstractServer; 32 import com.caucho.ejb.NoSuchObjectExceptionWrapper; 33 import com.caucho.ejb.RemoteExceptionWrapper; 34 import com.caucho.util.L10N; 35 36 import javax.ejb.EJBHome ; 37 import javax.ejb.EJBObject ; 38 import javax.ejb.FinderException ; 39 import javax.ejb.Handle ; 40 import javax.ejb.RemoveException ; 41 import java.io.ObjectStreamException ; 42 import java.io.Serializable ; 43 import java.rmi.NoSuchObjectException ; 44 import java.rmi.RemoteException ; 45 46 49 public abstract class JVMObject extends AbstractEJBObject 50 implements EJBObject, Serializable { 51 protected static final L10N L = new L10N(JVMObject.class); 52 53 protected Object _primaryKey; 54 protected ObjectSkeletonWrapper _skeletonWrapper; 55 56 protected AbstractServer _server; 57 protected Object _object; 58 59 62 public void _init(AbstractServer server, Object primaryKey) 63 { 64 if (primaryKey == null) 65 throw new NullPointerException (); 66 67 _server = server; 68 _primaryKey = primaryKey; 69 } 70 71 74 public Class getAPIClass() 75 { 76 return getServer().getRemoteObjectClass(); 77 } 78 79 82 public String getURL(String protocol) 83 { 84 HandleEncoder encoder = getServer().getHandleEncoder(protocol); 85 86 return encoder.getURL(getServer().encodeId(_primaryKey)); 87 } 88 89 92 public Handle getHandle() 93 throws RemoteException 94 { 95 HandleEncoder encoder = getServer().getHandleEncoder(); 96 97 return encoder.createHandle(getServer().encodeId(_primaryKey)); 98 } 99 100 103 public EJBHome getEJBHome() 104 throws RemoteException 105 { 106 try { 107 return getServer().getEJBHome(); 108 } catch (Exception e) { 109 throw new RemoteExceptionWrapper(e); 110 } 111 } 112 113 116 protected Object _caucho_getObject() 117 throws RemoteException 118 { 119 if (_server == null || _server.isDead() || _object == null) { 120 try { 121 AbstractContext context; 122 context = getServer().getContext(_primaryKey); 123 124 if (context != null) 125 _object = context.getRemoteView(); 126 } catch (FinderException e) { 127 throw new NoSuchObjectExceptionWrapper(e); 128 } 129 130 if (_object == null) 131 throw new NoSuchObjectException (L.l("`{0}' is not a valid bean. The bean may have been deleted or the server moved.", _primaryKey)); 132 133 _caucho_init_methods(_object.getClass()); 134 } 135 136 return _object; 137 } 138 139 protected void _caucho_init_methods(Class cl) 140 { 141 } 142 143 146 protected ClassLoader _caucho_getClassLoader() 147 throws RemoteException 148 { 149 ClassLoader loader = getServer().getClassLoader(); 150 151 return loader; 152 } 153 154 158 private AbstractServer getServer() 159 { 160 if (_server.isDead()) { 161 String serverId = _server.getHandleServerId(); 162 _object = null; 163 _server = EjbProtocolManager.getJVMServer(serverId); 164 } 165 166 return _server; 167 } 168 169 174 public boolean isIdentical(EJBObject obj) 175 throws RemoteException 176 { 177 return getHandle().equals(obj.getHandle()); 178 } 179 180 public void remove() 181 throws RemoveException , RemoteException 182 { 183 } 184 185 public Object getPrimaryKey() 186 throws RemoteException 187 { 188 return _primaryKey; 189 } 190 191 196 public Object writeReplace() throws ObjectStreamException 197 { 198 if (_skeletonWrapper == null) { 199 try { 200 _skeletonWrapper = new ObjectSkeletonWrapper(getHandle()); 201 } catch (Exception e) { 202 } 203 } 204 205 return _skeletonWrapper; 206 } 207 208 212 215 public static boolean to_boolean(Object o) 216 { 217 if (o == null) 218 return false; 219 else 220 return ((Boolean ) o).booleanValue(); 221 } 222 223 226 public static byte to_byte(Object o) 227 { 228 if (o == null) 229 return 0; 230 else 231 return ((Byte ) o).byteValue(); 232 } 233 234 237 public static short to_short(Object o) 238 { 239 if (o == null) 240 return 0; 241 else 242 return ((Short ) o).shortValue(); 243 } 244 245 248 public static char to_char(Object o) 249 { 250 if (o == null) 251 return 0; 252 else 253 return ((Character ) o).charValue(); 254 } 255 256 259 public static int to_int(Object o) 260 { 261 if (o == null) 262 return 0; 263 else 264 return ((Integer ) o).intValue(); 265 } 266 267 270 public static long to_long(Object o) 271 { 272 if (o == null) 273 return 0; 274 else 275 return ((Long ) o).longValue(); 276 } 277 278 281 public static float to_float(Object o) 282 { 283 if (o == null) 284 return 0; 285 else 286 return ((Float ) o).floatValue(); 287 } 288 289 292 public static double to_double(Object o) 293 { 294 if (o == null) 295 return 0; 296 else 297 return ((Double ) o).doubleValue(); 298 } 299 } 300 | Popular Tags |