mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-17 06:59:29 +00:00
Implementatation of the Service locator pattern
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user