/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.ws.dbsources.das.datamodel;
import jalview.bin.Cache;
import jalview.ws.dbsources.das.api.DasSourceRegistryI;
import jalview.ws.dbsources.das.api.jalviewSourceI;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.StringTokenizer;
import org.biodas.jdas.client.ConnectionPropertyProviderI;
import org.biodas.jdas.client.SourcesClient;
import org.biodas.jdas.client.threads.MultipleConnectionPropertyProviderI;
import org.biodas.jdas.dassources.Capabilities;
import org.biodas.jdas.schema.sources.CAPABILITY;
import org.biodas.jdas.schema.sources.SOURCE;
import org.biodas.jdas.schema.sources.SOURCES;
import org.biodas.jdas.schema.sources.VERSION;
/**
*
*/
public class DasSourceRegistry implements DasSourceRegistryI,
MultipleConnectionPropertyProviderI
{
// private org.biodas.jdas.schema.sources.SOURCE[] dasSources = null;
private List dasSources = null;
private Hashtable sourceNames = null;
private Hashtable localSources = null;
// public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das/";
public static String DEFAULT_REGISTRY = "http://www.ebi.ac.uk/das-srv/registry/das/";
/**
* true if thread is running and we are talking to DAS registry service
*/
private boolean loadingDasSources = false;
public boolean isLoadingDasSources()
{
return loadingDasSources;
}
@Override
public String getDasRegistryURL()
{
String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",
DEFAULT_REGISTRY);
if (registry.indexOf("/registry/das1/sources/") > -1)
{
jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,
DEFAULT_REGISTRY);
registry = DEFAULT_REGISTRY;
}
if (registry.lastIndexOf("sources.xml") == registry.length() - 11)
{
// no trailing sources.xml document for registry in JDAS
jalview.bin.Cache.setProperty(
jalview.bin.Cache.DAS_REGISTRY_URL,
registry = registry.substring(0,
registry.lastIndexOf("sources.xml")));
}
return registry;
}
/**
* query the default DAS Source Registry for sources. Uses value of jalview
* property DAS_REGISTRY_URL and the DasSourceBrowser.DEFAULT_REGISTRY if that
* doesn't exist.
*
* @return list of sources
*/
private List getDASSources()
{
return getDASSources(getDasRegistryURL(), this);
}
/**
* query the given URL for DasSources.
*
* @param registryURL
* return sources from registryURL
*/
private static List getDASSources(String registryURL,
MultipleConnectionPropertyProviderI registry)
{
try
{
URL url = new URL(registryURL);
org.biodas.jdas.client.SourcesClientInterface client = new SourcesClient();
SOURCES sources = client.fetchDataRegistry(registryURL, null, null,
null, null, null, null);
List