com.jpattern.core.SystemProvider Maven / Gradle / Ivy
package com.jpattern.core;
import java.util.HashMap;
import java.util.Map;
import com.jpattern.service.log.ALoggerServiceBuilder;
import com.jpattern.service.log.ILoggerService;
import com.jpattern.service.log.NullLoggerService;
import com.jpattern.service.mail.AMailServiceBuilder;
import com.jpattern.service.mail.IMailService;
import com.jpattern.service.mail.NullMailService;
import com.jpattern.core.command.ICommand;
/**
*
* @author Francesco Cina'
*
* 29/gen/2011
*/
public class SystemProvider implements IProvider, ISystem {
private static final long serialVersionUID = 1L;
private Map serviceMap = new HashMap();
@Override
public IService getService(String aServiceName) {
if (!contains(aServiceName)) {
return new NullService();
}
return getServiceMap().get(aServiceName);
}
@Override
public ILoggerService getLoggerService() {
IService service = getService(IServicesName.LOGGER_SERVICE);
if (service instanceof ILoggerService) {
return (ILoggerService) service;
}
return new NullLoggerService();
}
@Override
public IMailService getMailService() {
IService service = getService(IServicesName.MAIL_SENDER_SERVICE);
if (service instanceof IMailService) {
return (IMailService) service;
}
return new NullMailService();
}
@Override
public void accept(ICommand aCommand) {
aCommand.visit( this );
}
@Override
public void buildService(AServiceBuilder aServiceBuilder) {
serviceMap.put(aServiceBuilder.getName(), aServiceBuilder.build());
}
@Override
public void buildLoggerService(ALoggerServiceBuilder aLoggerServiceBuilder) {
buildService(aLoggerServiceBuilder);
}
@Override
public void buildMailService(AMailServiceBuilder aMailServiceBuilder) {
buildService(aMailServiceBuilder);
}
@Override
public void remove(String aServiceName) {
serviceMap.remove(aServiceName);
}
@Override
public boolean contains(String aServiceName) {
return serviceMap.containsKey(aServiceName);
}
@Override
public void removeAllServices() {
serviceMap.clear();
}
@Override
public Map getServiceMap() {
return serviceMap;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy