In AWT event handling, an event handling class can implement WindowListener
(lot's of work) or extend WindowAdpater(less work). In swing, a table model
can implement TableModel (lot's of work) or extend AbtractTableModel (less
work). I have been using this same idea with ejb-classes for a few years now
(See DefaultSessionBean class shown below). However, I never see it in any
books or sample code and wonder why.
I am posting the class for two reasons:
1. Does anyone see any problem with using this class?
2. If not, feel free to use it.
Note: I am already aware of a few issues:
1. You must be careful not to pass "this"
2. You are precluded from inheriting from some other class (due to Java's
single inheritance)
3. If you misspell a SessionBean call-back method, it won't be caught by the
compiler.
These are all fairly minor.
Below is the class:
==========================================================
/* This class provides default implementations of the
SessionBean interface and no-op implementations of
EJBObject's methods. This helper class provides two benefits:
1. No need to mindlessly type-in SessionBeans's
methods, which are almost always no-op or boiler-plate.
IMO, inheriting these default implementations is more
elegant than using code-generation. This class is similar
in concept to AWT's adapter classes
(i.e. WindowAdapter,MouseAdapter) or swing's "default"
classes (i.e. DefaultTableModel, DefaultTreeModel).
2. The ejb-class can now implement the remote interface.
This way, if you don't properly implement the interface,
you receive a compile-time error rather than a deploy-time
error (which can be cryptic at times).
See Section 9.2.2 of the EJB 1.1 Spec.
Note: when passing a self reference to another class,
be sure to use:
someOtherClass.foo(ejbContext.getEJBObject())
rather than:
someOtherClass.foo(this)
Dave Ford
http://www.smart-soft.com */
package ss.util;
import javax.ejb.*;
import javax.naming.*;
public class DefaultSessionBean implements EJBObject,SessionBean{
protected SessionContext ejbContext;
protected Context namingContext;
protected boolean debug = true;
/* methods from EJBObject */
public EJBHome getEJBHome(){ return null; }
public Handle getHandle(){return null;}
public Object getPrimaryKey(){return null;}
public boolean isIdentical(EJBObject obj){return false;}
public void remove(){}
/* methods from SessionBean */
public void ejbActivate() {
if(debug) System.out.println(this + " - ejbActivate");
}
public void ejbPassivate() {
if(debug) System.out.println(this + " - ejbPassivate");
}
public void ejbRemove() {
if(debug) System.out.println(this + " - ejbRemove");
}
public void setSessionContext(SessionContext c){
if(debug) System.out.println(this + " - setSessionContext");
ejbContext = c;
try{
namingContext = new InitialContext();
}
catch(NamingException ex){
throw new EJBException(ex);
}
}
}
-
DefaultSessionBean (2 messages)
- Posted by: Dave Ford
- Posted on: July 03 2001 09:00 EDT
Threaded Messages (2)
- DefaultSessionBean by Tolga Togan Duz on July 03 2001 12:53 EDT
- DefaultSessionBean by Dave Ford on July 04 2001 04:11 EDT
-
DefaultSessionBean[ Go to top ]
- Posted by: Tolga Togan Duz
- Posted on: July 03 2001 12:53 EDT
- in response to Dave Ford
i can advice you a good EJB book with title "Enterprise JavaBeans" by Richard Monson-Haefel from O'REILLY -
DefaultSessionBean[ Go to top ]
- Posted by: Dave Ford
- Posted on: July 04 2001 04:11 EDT
- in response to Tolga Togan Duz
That's funny. I own that book. Does it address this topic? Either I missed it or I have old version of the book.