Project

General

Profile

1
package gr.uoa.di.driver.util;
2

    
3
import eu.dnetlib.api.DriverService;
4

    
5
public class FallBackServiceLocator<S extends DriverService>
6
	implements ServiceLocator<S> {
7

    
8
	private ServiceLocator<S> mainLocator = null;
9
	private ServiceLocator<S> fallBackLocator = null;
10
	
11
	@Override
12
	public S getService() {
13
		S service = null;
14
		
15
		if (mainLocator != null)
16
			service = mainLocator.getService();
17
		
18
		if (service == null && fallBackLocator != null)
19
			service = fallBackLocator.getService();
20
		
21
		return service;
22
	}
23

    
24
	public FallBackServiceLocator(ServiceLocator<S> mainLocator,
25
			ServiceLocator<S> fallBackLocator) {
26
		this.mainLocator = mainLocator;
27
		this.fallBackLocator = fallBackLocator;
28
	}
29

    
30
	public void setMainLocator(ServiceLocator<S> mainLocator) {
31
		this.mainLocator = mainLocator;
32
	}
33

    
34
	public void setFallBackLocator(ServiceLocator<S> fallBackLocator) {
35
		this.fallBackLocator = fallBackLocator;
36
	}
37
}
(1-1/6)