Use an Adapter Class To Provide Empty Implementations For Javabean Interfaces

Like many high-level, abstract, and portable concepts, EJB spec has itsdownsides. One of them is the very generality that makes beans so portable.Interfaces javax.ejb.EntityBean and javax.ejb.SessionBean declare quite a few methods and most of them are not used by simple bean implementation. Yet developers must provide empty implementations for all these methods. As with many generic interfaces (Swing, etc.), one possible solution is an adapter class. This class would “implement” the respective interface by providing emptyor default implementations for all the methods declared in the interface. For instance:

  	public class EntityBeanAdapter implements javax.ejb.EntityBean {		EntityContext myContext;public void ejbActivate() throws RemoteException {}public void ejbLoad() throws RemoteException {}public void ejbStore() throws RemoteException {}public void ejbPassivate() throws RemoteException {}public void ejbRemove() throws RemoteException {}public void setEntityContext(EntityContext _ctxt) {			myContext = _ctxt;		}public EntityContext getEntityContext() {			return myContext;		}public void unsetEntityContext() {			myContext = null;		}	}


This process would be similar for the SessionBean.

Now, the implementations can just extend these adapters instead ofimplementing the EntityBean and SessionBean interfaces directly. Like:

 public class AccountBean extends EntityBeanAdapter {		... the code	}


If any of the callback methods are needed, they can be overridden here.CAUTION: As with all adapters, if you misspell the method while attempting to override it, the compiler won’t bark, but the methods will never get invoked. So, check your spelling!

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS