Implementatation of the Service locator pattern

This commit is contained in:
MSaifAsif
2014-12-06 02:39:54 +05:00
parent 3e42a10060
commit 1cb62f543b
10 changed files with 282 additions and 0 deletions
@@ -0,0 +1,29 @@
package com.iluwater;
/**
* For JNDI lookup of services from the web.xml. Will match name of the service name that
* is being requested and return a newly created service object with the name
* @author saifasif
*
*/
public class InitContext {
/**
* Perform the lookup based on the service name. The returned object will need to be
* casted into a {@link Service}
* @param serviceName
* @return
*/
public Object lookup(String serviceName){
if( serviceName.equals("jndi/serviceA") ){
System.out.println("Looking up service A and creating new serivce for A");
return new ServiceImpl("jndi/serviceA");
} else if( serviceName.equals("jndi/serviceB") ){
System.out.println("Looking up service B and creating new serivce for B");
return new ServiceImpl("jndi/serviceB");
} else {
return null;
}
}
}