/* * 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.jws2.jabaws2; import jalview.gui.Desktop; import jalview.util.MessageManager; import jalview.ws.api.JalviewServiceEndpointProviderI; import jalview.ws.api.ServiceWithParameters; import jalview.ws.jws2.JabaParamStore; import jalview.ws.params.ParamDatastoreI; import jalview.ws.params.ParamManager; import java.io.Closeable; import java.net.URL; import compbio.data.msa.JABAService; import compbio.data.msa.MsaWS; import compbio.data.msa.SequenceAnnotation; import compbio.metadata.PresetManager; import compbio.metadata.RunnerConfig; public class Jws2Instance extends ServiceWithParameters implements JalviewServiceEndpointProviderI, AutoCloseable { public JABAService service; /** * * @param hosturl * Service endpoint * @param serviceType * Category for this service's analysis * @param action * text describing their action that service performs (eg 'aligning', * 'analysing') * @param description * Description from JABAWS registry * @param service * JABAWS registry ID for service */ public Jws2Instance(String hosturl, String serviceType, String action, String description, JABAService service) { super(action, action, serviceType, description, hosturl); this.service = service; if (service instanceof MsaWS) { style = ServiceClient.MSAWSCLIENT; } else if (service instanceof SequenceAnnotation) { style = ServiceClient.SEQUENCEANNOTATIONWSCLIENT; } int p = description.indexOf("MORE INFORMATION:"); if (p > -1) { String docUrl = description.substring(description.indexOf("http", p)) .trim(); if (docUrl.indexOf('\n') > -1) { docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim(); } if (docUrl.length() > 0) { try { URL url = new URL(docUrl); if (url != null) { setDocumentationUrl(docUrl); } } catch (Exception x) { } } } } PresetManager presets = null; public JabaParamStore paramStore = null; /** * non thread safe - gets the presets for this service (blocks whilst it calls * the service to get the preset set) * * @return service presets or null if exceptions were raised. */ public PresetManager getPresets() { if (presets == null) { try { if (service instanceof MsaWS) { presets = ((MsaWS) service).getPresets(); } if (service instanceof SequenceAnnotation) { presets = ((SequenceAnnotation) service).getPresets(); } } catch (Exception ex) { System.err.println("Exception when retrieving presets for service " + getServiceType() + " at " + getHostURL()); } } return presets; } /** * non-thread safe - blocks whilst accessing service to get complete set of * available options and parameters * * @return */ public RunnerConfig getRunnerConfig() { if (service instanceof MsaWS) { return ((MsaWS) service).getRunnerOptions(); } if (service instanceof SequenceAnnotation) { return ((SequenceAnnotation) service).getRunnerOptions(); } throw new Error(MessageManager.formatMessage( "error.implementation_error_runner_config_not_available", new String[] { getServiceType(), service.getClass().toString() })); } @Override public void close() { if (service != null) { try { ((Closeable) service).close(); } catch (Throwable t) { // ignore } } // super.finalize(); } @Override public ParamDatastoreI getParamStore() { if (paramStore == null) { try { paramStore = new JabaParamStore(this, (Desktop.getInstance() != null ? Desktop.getUserParameterStore() : null)); } catch (Exception ex) { System.err.println("Unexpected exception creating JabaParamStore."); ex.printStackTrace(); } } return paramStore; } private boolean hasParams = false, lookedForParams = false; @Override public boolean hasParameters() { if (!lookedForParams) { lookedForParams = true; try { hasParams = (getRunnerConfig().getArguments().size() > 0); } catch (Exception e) { } } return hasParams; } /** * initialise a parameter store for this service * * @param userParameterStore * - the user ParamManager (e.g. Desktop.getUserParameterStore() ) */ @Override public void initParamStore(ParamManager userParameterStore) { if (paramStore == null) { paramStore = new JabaParamStore(this, userParameterStore); } } /** * an object that implements one or more interfaces in jalview.ws.api * * @return */ @Override public Object getEndpoint() { if (service instanceof MsaWS) { if (aaui != null) { throw new Error( "JABAWS MsaWS based instant calculation not implemented."); } else { return new JabawsMsaInstance(this); } } else { if (service instanceof compbio.data.msa.SequenceAnnotation) { if (aaui != null) { try { // probably a factory would be nicer but.. return aaui.getClient().getConstructor(getClass()) .newInstance(this); } catch (Throwable t) { throw new Error("Implementation Error in web service framework", t); } } return new AADisorderClient(this); } return null; } } }