package it.nch.yava.rte.wfm.services.mapper; import java.util.HashMap; import java.util.Map; public class ServiceInfoMapperImpl implements ServiceInfoMapper { private Map map = new HashMap(); public ServiceInfoSupplier getServiceInfo(ServiceName serviceName, String portName, String operationName) { return getServiceInfo(createServiceKey(serviceName, portName, operationName)); } private ServiceInfoSupplier getServiceInfo(ServiceId key) { return (ServiceInfoSupplier) map.get(key); } public void addServiceInfo(ServiceName serviceName, String portName, String operationName, ServiceInfoSupplier serviceInfoSupplier) { addServiceInfo(createServiceKey(serviceName, portName, operationName), serviceInfoSupplier); } private void addServiceInfo(ServiceId key, ServiceInfoSupplier serviceInfoSupplier) { if (map.containsKey(key)) { throw new ServiceInfoMapperException("Service info key [" + key + "] already present in map!"); } map.put(key, serviceInfoSupplier); } private static ServiceId createServiceKey(ServiceName serviceName, String portName, String operationName) { return new ServiceId(serviceName, portName, operationName); } private static class ServiceId { private final ServiceName serviceName; private final String portName; private final String operationName; public ServiceId(final ServiceName serviceName, final String portName, final String operationName) { checkParametersForValidity(serviceName, portName, operationName); this.serviceName = serviceName; this.portName = portName; this.operationName = operationName; } private void checkParametersForValidity(ServiceName serviceName, String portName, String operationName) { if (serviceName == null || portName == null || operationName == null) { throw new IllegalArgumentException("Arguments in ServiceId cannot be null!"); } } @Override public boolean equals(Object obj) { boolean result = false; if (obj instanceof ServiceId) { ServiceId oKey = (ServiceId) obj; result = serviceName.equals(oKey.serviceName) && portName.equals(oKey.portName) && operationName.equals(oKey.operationName); } return result; } @Override public int hashCode() { int result = 17; result *= 37 + serviceName.hashCode(); result *= 37 + portName.hashCode(); result *= 37 + operationName.hashCode(); return result; } @Override public String toString() { return "[serviceName=[" + serviceName + "] portName=[" + portName + "] operationName=[" + operationName + "]]"; } } }