changes to placeholder identifier and (de)serialization

This commit is contained in:
Fredrik Teschke committed 2014-03-10 15:00:35 +01:00
1 parent 10f0b01576
commit 1ebed6373e
62 files changed
+812 -350

No files matched your search

@@ -1,21 +1,37 @@
package com.sap.sailing.domain.common.racelog.tracking;
/**
* Only can provide the service for a single {@code type}, e.g. on smartphones with no OSGi context.
* Optionally, a {@link #setFallbackService(Object) fallback} can be set.
* @author Fredrik Teschke
*/
public class SingleTypeBasedServiceFinderImpl<ServiceType> implements
TypeBasedServiceFinder<ServiceType> {
private final ServiceType service;
private final String type;
private ServiceType fallback;
public SingleTypeBasedServiceFinderImpl(ServiceType service, String type) {
public SingleTypeBasedServiceFinderImpl(ServiceType service, ServiceType fallback, String type) {
this.service = service;
this.type = type;
this.fallback = fallback;
}
public SingleTypeBasedServiceFinderImpl(ServiceType service, String type) {
this(service, null, type);
}
@Override
public ServiceType findService(String type)
throws NoCorrespondingServiceRegisteredException {
if (type.equals(this.type)) return service;
if (fallback != null) return fallback;
throw new NoCorrespondingServiceRegisteredException("Only one service registered", type, service.getClass());
}
@Override
public void setFallbackService(ServiceType fallback) {
this.fallback = fallback;
}
}
@@ -12,7 +12,18 @@ public interface TypeBasedServiceFinder<ServiceType> {
* Find a service that implements the <ServiceType> interface for the specified {@code type}
* of object (e.g. type of a {@link GPSFix}).
* @param type A {@link String} that specifies for which type the service should be registered
* @throws NoCorrespondingServiceRegisteredException
* @throws NoCorrespondingServiceRegisteredException Thrown, if no service is registered for this type.
*/
ServiceType findService(String type) throws NoCorrespondingServiceRegisteredException;
/**
* Sets a fallback service (optional), that is used if no service is registered for a {@code type}.
* This should be a generic service, that can deal with any {@code type}, and provides a
* "better-than-nothing" implementation, which will be returned instead of throwing a
* {@link NoCorrespondingServiceRegisteredException}.
* <p>
* This method does not need to be implemented, but can remain a stub, if no fallback behaviour
* is desired.
*/
void setFallbackService(ServiceType fallback);
}