Is EJB3.0 supporting ServiceLocator design pattern
hi,
Does EJB3.0 support service locator design pattern.If it supports how we write the code in that ServiceLocator class
hi,
Does EJB3.0 support service locator design pattern.If it supports how we write the code in that ServiceLocator class
Yap there is EJB 3.0 supporting ServiceLocator.. You must think how to get a handle of EJB for Localhome or Remote. It means to support for the services like Web Services, JMS Messaging in a seperate way and you must instance him refer to the support you need..
Example for this..
public class ServiceLocator {
....
//Get EJB Localhome Services
public EJBLocalHome getLocalHome(String jndiHomeName) throws ServiceLocationException{
EJBLocalHome localhome = null;
try{
if(cache.containsKey(jndiHomeName)){
localhome = (EJBLocalHome)cache.get(jndiHomeName);
}else{
localhome = (EJBLocalHome)initialContext.lookup(jndiHomeName);
cache.put(jndiHomeName, localhome);
}
}catch(NamingException cex){
throw new ServiceLocationException(cex.toString());
}catch(Exception ex){
throw new ServiceLocationException(ex.toString());
}
return localhome;
}
//Get EJB RemoteHome Services
public EJBHome getRemoteHome(String jndiRemoteHome, Class homeclassname) throws ServiceLocationException{
EJBHome remotehome = null;
try{
if(cache.containsKey(jndiRemoteHome)){
remotehome = (EJBHome)cache.get(jndiRemoteHome);
}else{
Object objref = (EJBHome)initialContext.lookup(jndiRemoteHome);
Object obj = javax.rmi.PortableRemoteObject.narrow(objref, homeclassname);
remotehome = (EJBHome)obj;
cache.put(jndiRemoteHome, remotehome);
}
}catch(NamingException ne){
throw new ServiceLocationException(ne.toString());
}catch(Exception ex){
throw new ServiceLocationException(ex.toString());
}
return remotehome;
}
.........
}