variable name changes

This commit is contained in:
mherbaghinyan 2018-04-22 17:13:38 +04:00
parent 81b9a8971e
commit e269f7e599
2 changed files with 6 additions and 6 deletions

View File

@ -5,11 +5,11 @@ package com.baeldung.designpatterns.service.locator;
*/ */
public class InitialContext { public class InitialContext {
public Object lookup(String jndiName) { public Object lookup(String serviceName) {
if (jndiName.equalsIgnoreCase("EmailService")) { if (serviceName.equalsIgnoreCase("EmailService")) {
return new EmailService(); return new EmailService();
} else if (jndiName.equalsIgnoreCase("SMSService")) { } else if (serviceName.equalsIgnoreCase("SMSService")) {
return new SMSService(); return new SMSService();
} }
return null; return null;

View File

@ -11,16 +11,16 @@ public class ServiceLocator {
cache = new Cache(); cache = new Cache();
} }
public static MessagingService getService(String jndiName){ public static MessagingService getService(String serviceName){
MessagingService service = cache.getService(jndiName); MessagingService service = cache.getService(serviceName);
if(service != null){ if(service != null){
return service; return service;
} }
InitialContext context = new InitialContext(); InitialContext context = new InitialContext();
MessagingService service1 = (MessagingService)context.lookup(jndiName); MessagingService service1 = (MessagingService)context.lookup(serviceName);
cache.addService(service1); cache.addService(service1);
return service1; return service1;
} }