1 28 29 package com.caucho.ejb; 30 31 import com.caucho.ejb.xa.TransactionContext; 32 import com.caucho.security.SecurityContext; 33 import com.caucho.security.SecurityContextException; 34 import com.caucho.util.L10N; 35 import com.caucho.util.Log; 36 37 import javax.ejb.*; 38 import javax.transaction.UserTransaction ; 39 import java.rmi.RemoteException ; 40 import java.security.Identity ; 41 import java.security.Principal ; 42 import java.util.Properties ; 43 import java.util.logging.Level ; 44 import java.util.logging.Logger ; 45 46 49 abstract public class AbstractContext implements EJBContext { 50 protected static final L10N L = new L10N(AbstractContext.class); 51 protected static final Logger log = Log.open(AbstractContext.class); 52 53 private boolean _isDead; 54 55 58 public boolean isDead() 59 { 60 return _isDead; 61 } 62 63 66 protected abstract AbstractServer getServer(); 67 68 71 public EJBMetaData getEJBMetaData() 72 { 73 return getServer().getEJBMetaData(); 74 } 75 76 79 public EJBHome getEJBHome() 80 { 81 try { 82 return getServer().getEJBHome(); 83 } catch (RuntimeException e) { 84 throw e; 85 } catch (Exception e) { 86 log.log(Level.WARNING, e.toString(), e); 87 88 return null; 89 } 90 } 91 92 95 public EJBLocalHome getEJBLocalHome() 96 { 97 try { 98 return getServer().getEJBLocalHome(); 99 } catch (RuntimeException e) { 100 throw e; 101 } catch (Exception e) { 102 return null; 103 } 104 } 105 106 109 public Handle getHandle() 110 { 111 throw new UnsupportedOperationException (); 112 } 113 114 117 public HomeHandle getHomeHandle() 118 { 119 return getServer().getHomeHandle(); 120 } 121 122 125 public EJBLocalObject getEJBLocalObject() 126 throws IllegalStateException 127 { 128 throw new IllegalStateException (L.l("`{0}' has no local interface. Local beans need a local-home and a local interface. Remote beans must be called with a remote context.", 129 getServer())); 130 } 131 132 135 public Object lookup(String name) 136 { 137 return getServer().lookup(name); 138 } 139 140 143 public EJBObject getEJBObject() 144 { 145 return getRemoteView(); 146 150 } 151 152 155 public EJBObject getRemoteView() 156 { 157 throw new IllegalStateException (L.l("`{0}' has no remote interface. Remote beans need a home and a remote interface. Local beans must be called with a local context.", 158 getServer())); 159 } 160 161 164 public EJBHome createRemoteHomeView() 165 { 166 return null; 167 171 } 172 173 176 public EJBLocalHome createLocalHome() 177 { 178 return null; 179 183 } 184 185 188 public Properties getEnvironment() 189 { 190 return new Properties (); 191 } 192 193 196 public Identity getCallerIdentity() 197 { 198 return null; 199 } 200 201 204 public Principal getCallerPrincipal() 205 { 206 try { 207 return SecurityContext.getUserPrincipal(); 208 } catch (SecurityContextException e) { 209 log.log(Level.WARNING, e.toString(), e); 210 211 return null; 212 } 213 } 214 215 218 public boolean isCallerInRole(Identity role) 219 { 220 return false; 221 } 222 223 226 public boolean isCallerInRole(String roleName) 227 { 228 return SecurityContext.isUserInRole(roleName); 229 } 230 231 public void remove() 232 throws RemoveException 233 { 234 EJBObject obj = null; 235 try { 236 obj = getEJBObject(); 237 } catch (Exception e) { 238 } 239 240 try { 241 if (obj != null) { 242 obj.remove(); 243 return; 244 } 245 } catch (RemoteException e) { 246 } 247 248 EJBLocalObject local = null; 249 try { 250 local = getEJBLocalObject(); 251 } catch (Exception e) { 252 } 253 254 if (local != null) { 255 local.remove(); 256 return; 257 } 258 } 259 260 264 public UserTransaction getUserTransaction() 265 throws IllegalStateException 266 { 267 return getServer().getUserTransaction(); 268 } 269 270 273 public TimerService getTimerService() 274 { 275 throw new UnsupportedOperationException (); 276 } 277 278 281 public void setRollbackOnly() 282 throws IllegalStateException 283 { 284 TransactionContext trans = getServer().getTransaction(); 285 286 if (trans != null) 287 trans.setRollbackOnly(); 288 else 289 throw new IllegalStateException ("invalid transaction"); 290 } 291 292 295 public boolean getRollbackOnly() 296 throws IllegalStateException 297 { 298 TransactionContext trans = getServer().getTransaction(); 299 300 if (trans != null) 301 return trans.getRollbackOnly(); 302 else 303 throw new IllegalStateException ("invalid transaction"); 304 } 305 306 309 public void destroy() throws Exception 310 { 311 _isDead = true; 312 } 313 } 314 315 316 | Popular Tags |