Software:
News ToolsReg Shops |
Migrating EJB 2.1 Entity and Session Beans to EJB 3.0The nuts and boltsPublished Tuesday 25th April 2006 06:02 GMT Listing 2. CatalogBean.java EJB 3.0 Session Bean
@Stateless
@Local ({CatalogLocal.java})
public class CatalogBean implements CatalogLocal {
public String getJournal(String publisher) {
if (publisher.equals("Oracle Publisher"))
return new String("Oracle Magazine");
if (journal.equals("OReilly"))
return new String("dev2dev");
}
}
In EJB 3.0, the component and home interfaces of EJB 2.1 are replaced with a business interface. The business interfaces for the session bean are POJIs, and do not extend the Listing 3. CatalogLocal.java. Local Interface of Session Bean
@Local
public interface CatalogLocal{
public String getJournal(String publisher);
}
A client for an EJB 2.1 session bean gets a reference to the session bean with JNDI. The JNDI name for the Listing 4. EJB 2.1 Session Bean Client Class
import javax.naming.InitialContext;
public class CatalogClient {
public static void main(String[] argv) {
try {
InitialContext ctx=new InitialContext();
Object objref=ctx.lookup("CatalogLocalHome");
CatalogLocalHome catalogLocalHome=(CatalogLocalHome)objref;
CatalogLocal catalogLocal=(CatalogLocal)catalogLocalHome.create();
String publisher="OReilly";
String journal=catalogLocal.getJournal(publisher);
System.out.println("Journal for Publisher: "+publisher +" "+journal);
}
catch (Exception e) {}
}
}
In EJB 3.0 a reference to a resource is obtained with dependency injection with the
Track this type of story as a custom Atom/RSS feed or by email.
|
|
||||||||
Top 20 stories • All The Week’s Headlines • Archive • Search