• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to identify the current running context?  RSS feed

 
Boopathi Ramasamy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a class file that needs to identify the context it is currently running in. Based on its context my logic will differ.
For ex: my class can be instantiated by a servlet or a session bean. How do i find out at runtime, the code is getting called from servlet or ejb?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36446
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boopathi,
Can you pass this information to your class when you instantiate it?
 
Camilo Morales
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

There is a class called: SessionContext, that you can inject with EJB 3.0, or, I guess, lookup in EJB 2.x.


SessionContext extends the javax.ejb.EJBContext class. EJBContext defines several methods that provide useful information to a bean at runtime.



There is a lot of information about this class in the Enterprise JavaBeans, 3.0 By Bill Burke, Richard Monson-Haefel, (O'Reilly).


Hope this helps,

Camilo Morales
SCJP 5
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is usually an indication of poor design if you need to know in what context you class exists. It makes your class non portable...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!