|
Using EJB toString() functionality for debugging |
|
|
Adding toString() functionality to EJBs is a quick way to provide an excellent logging and debugging tool for future development work and problem solving. However, we cannot expose a toString() method remotely, because we would have to override the method and add a RemoteException (which cannot be done when overriding a method). Therefore, you must create a new method with the same functionality.
To implement toString() functionality for an EJB, define a method, ejbToString(), that describes the implementing EJB. The ejbToString() method can be exposed on the remote or local interface to be used by EJB clients.
EJB interface declaration:
public interface SomeBean extends EJBObject{
...
public String ejbToString() throws RemoteException;
...
}
|
Implementation of ejbToString() method:
public abstract class SomeBeanImpl implements EntityBean {
...
public String ejbToString() {
StringBuffer buffer = new StringBuffer();
buffer.append("======= [ SomeBean Dump] =======\n");
// add to the buffer bean state:
...
buffer.append("================================\n");
return buffer.toString();
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.