Hi Sajid,
i guess the following piece of code can address your query.
public class EJBServiceLocator {
private static EJBServiceLocator myServiceLocator;
private static InitialContext context= null;
private static Map homes;
private EJBServiceLocator() {
homes= Collections.synchronizedMap(new HashMap());
}
public static EJBServiceLocator getInstance() throws NamingException {
return getInstance(null);
}
public static EJBServiceLocator getInstance(Hashtable contextParams) throws NamingException {
if (myServiceLocator == null) {
myServiceLocator= new EJBServiceLocator();
if (context == null) {
if (contextParams == null) {
context= new InitialContext();
} else {
context= new InitialContext (contextParams);
}
}
}
return myServiceLocator;
}
public EJBHome getHome(
String name, Class clazz) throws NamingException {
EJBHome aHome= (EJBHome) homes.get(name);
if (aHome == null) {
Object objref= context.lookup(name);
aHome= (EJBHome) PortableRemoteObject.narrow(objref, clazz);
homes.put(name, aHome);
}
return aHome;
}
}
Please shoot a mail at
ramveersingh@yahoo.co.in if u have any further queries.
cheers
ramveer