package eu.dnetlib.data.information;

import java.net.URI;
import java.net.URISyntaxException;

public class EPRDataSourceResolverImpl implements DataSourceResolver {
	
	private static final String URI_AUTHORITY = "EPR";

	@Override
	public DataSource resolve(String descriptor) {

		try {
			final URI uri = new URI(descriptor);

			if (!uri.getAuthority().equals(URI_AUTHORITY))
				throw new IllegalStateException("unexpected uri descriptor " + descriptor + ". This sink resolver is specific for " + URI_AUTHORITY);
			
			return new EPRDataSource(uri.getPath().substring(1));

		} catch (URISyntaxException e) {
			throw new IllegalArgumentException(e);
		}

	}

}
