}
}
+ /**
+ * pick the user's preferred service based on a set of URLs (jaba server
+ * locations) and service URIs (specifying version and service interface
+ * class)
+ *
+ * @param serviceURL
+ * @return null or best match for given uri/ls.
+ */
+ public ServiceWithParameters getPreferredServiceFor(String[] serviceURLs)
+ {
+ HashSet<String> urls = new HashSet<>();
+ urls.addAll(Arrays.asList(serviceURLs));
+ ServiceWithParameters match = null;
+ List<ServiceWithParameters> ourServices = getServices();
+
+ if (ourServices != null)
+ {
+ for (ServiceWithParameters svc : ourServices)
+ {
+ // TODO getNameURI Should return a versioned URI for the service, but
+ // doesn't as of 2.11
+ if (urls.contains(svc.getNameURI()))
+ {
+ if (match == null)
+ {
+ // for moment we always pick service from server ordered first in
+ // user's preferences
+ match = svc;
+ }
+ if (urls.contains(svc.getUri()))
+ {
+ // stop and return - we've matched type URI and URI for service
+ // endpoint
+ return svc;
+ }
+ }
+ }
+ }
+ return match;
+ }
+
+ Map<String, Map<String, String>> preferredServiceMap = new HashMap<>();
+
+ /**
+ * get current preferred endpoint of the given Jabaws service, or global
+ * default
+ *
+ * @param af
+ * null or a specific alignFrame
+ * @param serviceName
+ * Jws2Instance.getName() for service
+ * @return null if no service of this type is available, the preferred service
+ * for the serviceType and af if specified and if defined.
+ */
+ public ServiceWithParameters getPreferredServiceFor(AlignFrame af,
+ String serviceName)
+ {
+ String serviceurl = null;
+ synchronized (preferredServiceMap)
+ {
+ String afid = (af == null) ? "" : af.getViewport().getSequenceSetId();
+ Map<String, String> prefmap = preferredServiceMap.get(afid);
+ if (afid.length() > 0 && prefmap == null)
+ {
+ // recover global setting, if any
+ prefmap = preferredServiceMap.get("");
+ }
+ if (prefmap != null)
+ {
+ serviceurl = prefmap.get(serviceName);
+ }
+
+ }
+ ServiceWithParameters response = null;
+ for (ServiceWithParameters svc : getServices())
+ {
+ if (svc.getName().equals(serviceName))
+ {
+ if (serviceurl == null || serviceurl.equals(svc.getHostURL()))
+ {
+ response = svc;
+ break;
+ }
+ }
+ }
+ return response;
+ }
+
+ public void setPreferredServiceFor(AlignFrame af, String serviceName,
+ String serviceAction, ServiceWithParameters selectedServer)
+ {
+ // TODO: pull out and generalise for the selectedServer's attributes
+ String afid = (af == null) ? "" : af.getViewport().getSequenceSetId();
+ if (preferredServiceMap == null)
+ {
+ preferredServiceMap = new HashMap<>();
+ }
+ Map<String, String> prefmap = preferredServiceMap.get(afid);
+ if (prefmap == null)
+ {
+ prefmap = new HashMap<>();
+ preferredServiceMap.put(afid, prefmap);
+ }
+ prefmap.put(serviceName, selectedServer.getHostURL());
+ prefmap.put(serviceAction, selectedServer.getHostURL());
+ }
+
+ public void setPreferredServiceFor(String serviceType,
+ String serviceAction, ServiceWithParameters selectedServer)
+ {
+ setPreferredServiceFor(null, serviceType, serviceAction,
+ selectedServer);
+ }
+
public static void main(String[] args)
{
if (args.length > 0)
}
/**
- * pick the user's preferred service based on a set of URLs (jaba server
- * locations) and service URIs (specifying version and service interface
- * class)
- *
- * @param serviceURL
- * @return null or best match for given uri/ls.
- */
- public ServiceWithParameters getPreferredServiceFor(String[] serviceURLs)
- {
- HashSet<String> urls = new HashSet<>();
- urls.addAll(Arrays.asList(serviceURLs));
- ServiceWithParameters match = null;
- List<ServiceWithParameters> ourServices = getServices();
-
- if (ourServices != null)
- {
- for (ServiceWithParameters svc : ourServices)
- {
- // TODO getNameURI Should return a versioned URI for the service, but
- // doesn't as of 2.11
- if (urls.contains(svc.getNameURI()))
- {
- if (match == null)
- {
- // for moment we always pick service from server ordered first in
- // user's preferences
- match = svc;
- }
- if (urls.contains(svc.getUri()))
- {
- // stop and return - we've matched type URI and URI for service
- // endpoint
- return svc;
- }
- }
- }
- }
- return match;
- }
-
- Map<String, Map<String, String>> preferredServiceMap = new HashMap<>();
-
- /**
- * get current preferred endpoint of the given Jabaws service, or global
- * default
- *
- * @param af
- * null or a specific alignFrame
- * @param serviceName
- * Jws2Instance.getName() for service
- * @return null if no service of this type is available, the preferred service
- * for the serviceType and af if specified and if defined.
- */
- public ServiceWithParameters getPreferredServiceFor(AlignFrame af,
- String serviceName)
- {
- String serviceurl = null;
- synchronized (preferredServiceMap)
- {
- String afid = (af == null) ? "" : af.getViewport().getSequenceSetId();
- Map<String, String> prefmap = preferredServiceMap.get(afid);
- if (afid.length() > 0 && prefmap == null)
- {
- // recover global setting, if any
- prefmap = preferredServiceMap.get("");
- }
- if (prefmap != null)
- {
- serviceurl = prefmap.get(serviceName);
- }
-
- }
- ServiceWithParameters response = null;
- for (ServiceWithParameters svc : getServices())
- {
- if (svc.getName().equals(serviceName))
- {
- if (serviceurl == null || serviceurl.equals(svc.getHostURL()))
- {
- response = svc;
- break;
- }
- }
- }
- return response;
- }
-
- public void setPreferredServiceFor(AlignFrame af, String serviceName,
- String serviceAction, ServiceWithParameters selectedServer)
- {
- // TODO: pull out and generalise for the selectedServer's attributes
- String afid = (af == null) ? "" : af.getViewport().getSequenceSetId();
- if (preferredServiceMap == null)
- {
- preferredServiceMap = new HashMap<>();
- }
- Map<String, String> prefmap = preferredServiceMap.get(afid);
- if (prefmap == null)
- {
- prefmap = new HashMap<>();
- preferredServiceMap.put(afid, prefmap);
- }
- prefmap.put(serviceName, selectedServer.getHostURL());
- prefmap.put(serviceAction, selectedServer.getHostURL());
- }
-
- public void setPreferredServiceFor(String serviceType,
- String serviceAction, ServiceWithParameters selectedServer)
- {
- setPreferredServiceFor(null, serviceType, serviceAction,
- selectedServer);
- }
-
- /**
* Set a URL to try before any others. For use with command-line parameter to
* configure a local Jabaws installation without the need to add to property
* files.